From ddd57504ee69ad89f70becf281059429b02a142b Mon Sep 17 00:00:00 2001 From: thebuildcraft <104298589+thebuildcraft@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:03:24 +0200 Subject: [PATCH] implement friend list features, closes #21 --- .../common/CommonModConfig.java | 22 +++++++- .../common/PlayerWaypoint.java | 4 +- .../common/UpdateTask.java | 42 ++++++++++++--- .../lang/en_us.json | 19 ++++++- .../fabric/CommonModConfigFabric.java | 52 ++++++++++++++++++- .../fabric/ModConfig.java | 44 +++++++++++++++- .../mods/xaerominimap/MinimapRadarMixin.java | 24 ++++++++- .../forge/CommonModConfigForge.java | 52 ++++++++++++++++++- .../forge/ModConfig.java | 44 +++++++++++++++- .../mods/xaerominimap/MinimapRadarMixin.java | 24 ++++++++- .../mods/xaerominimap/MinimapRadarMixin.java | 28 +++++++++- .../neoforge/CommonModConfigNeoForge.java | 52 ++++++++++++++++++- .../neoforge/ModConfig.java | 44 +++++++++++++++- 13 files changed, 427 insertions(+), 24 deletions(-) diff --git a/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/CommonModConfig.java b/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/CommonModConfig.java index d55ff3b..de518d7 100644 --- a/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/CommonModConfig.java +++ b/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/CommonModConfig.java @@ -25,7 +25,7 @@ /** * @author Leander Knüttel - * @version 03.07.2024 + * @version 07.07.2024 */ public abstract class CommonModConfig { public CommonModConfig() { @@ -42,6 +42,7 @@ public CommonModConfig() { public abstract int updateDelay(); public abstract int minDistance(); public abstract int maxDistance(); + public abstract int maxIconDistance(); public abstract int minDistanceMarker(); public abstract int maxDistanceMarker(); public abstract int defaultY(); @@ -57,6 +58,25 @@ public CommonModConfig() { public abstract void setIgnoreMarkerMessage(boolean on); public abstract boolean ignoreMarkerMessage(); + public abstract List friendList(); + public abstract boolean onlyShowFriendsWaypoints(); + public abstract boolean onlyShowFriendsIcons(); + public abstract boolean overwriteFriendDistances(); + public abstract int minFriendDistance(); + public abstract int maxFriendDistance(); + public abstract int maxFriendIconDistance(); + public abstract boolean overwriteFriendWaypointColor(); + public abstract int friendWaypointColor(); + + public int getPlayerWaypointColor(String playerName) { + if (overwriteFriendWaypointColor() && friendList().contains(playerName)){ + return friendWaypointColor(); + } + else { + return playerWaypointColor(); + } + } + public static class ServerEntry { public Maptype maptype; public String ip; diff --git a/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/PlayerWaypoint.java b/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/PlayerWaypoint.java index fd4fccb..ab967cd 100644 --- a/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/PlayerWaypoint.java +++ b/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/PlayerWaypoint.java @@ -29,7 +29,7 @@ * @author ewpratten * @author eatmyvenom * @author Leander Knüttel - * @version 03.07.2024 + * @version 07.07.2024 */ public class PlayerWaypoint extends Waypoint { public PlayerWaypoint(PlayerPosition player) { @@ -38,7 +38,7 @@ public PlayerWaypoint(PlayerPosition player) { public PlayerWaypoint(int x, int y, int z, String name) { super(x, y, z, name, getAbbreviation(name), - CommonModConfig.Instance.playerWaypointColor(), 0, true); + CommonModConfig.Instance.getPlayerWaypointColor(name), 0, true); } public static String getAbbreviation(String name){ diff --git a/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/UpdateTask.java b/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/UpdateTask.java index e6d48c0..fa70571 100644 --- a/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/UpdateTask.java +++ b/common/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/common/UpdateTask.java @@ -41,7 +41,6 @@ #else import xaero.common.HudMod; #endif -import org.apache.commons.lang3.StringUtils; import xaero.common.XaeroMinimapSession; import xaero.common.minimap.waypoints.Waypoint; import xaero.common.minimap.waypoints.WaypointWorld; @@ -57,7 +56,7 @@ * @author eatmyvenom * @author TheMrEngMan * @author Leander Knüttel - * @version 25.06.2024 + * @version 07.07.2024 */ public class UpdateTask extends TimerTask { private final Minecraft mc; @@ -85,6 +84,9 @@ public UpdateTask() { private int previousPlayerWaypointColor = 0; private int previousMarkerWaypointColor = 0; + private int previousFriendWaypointColor = 0; + private boolean previousFriendColorOverride = false; + private int previousFriendListHashCode = 0; @Override public void run() { @@ -270,6 +272,8 @@ public void runUpdate() { } } + Vec3 camPosition = mc.cameraEntity.position(); + try { synchronized (playerWaypointList) { if (CommonModConfig.Instance.enablePlayerWaypoints()){ @@ -298,14 +302,27 @@ public void runUpdate() { if (playerPosition == null) continue; String playerName = playerPosition.player; - int minimumWaypointDistanceToUse = CommonModConfig.Instance.minDistance(); - int maximumWaypointDistanceToUse = CommonModConfig.Instance.maxDistance(); + boolean isFriend = CommonModConfig.Instance.friendList().contains(playerName); + + if (CommonModConfig.Instance.onlyShowFriendsWaypoints() && !isFriend) continue; + + int minimumWaypointDistanceToUse; + int maximumWaypointDistanceToUse; + if (CommonModConfig.Instance.overwriteFriendDistances() && isFriend) { + minimumWaypointDistanceToUse = CommonModConfig.Instance.minFriendDistance(); + maximumWaypointDistanceToUse = CommonModConfig.Instance.maxFriendDistance(); + } + else { + minimumWaypointDistanceToUse = CommonModConfig.Instance.minDistance(); + maximumWaypointDistanceToUse = CommonModConfig.Instance.maxDistance(); + } + if (minimumWaypointDistanceToUse > maximumWaypointDistanceToUse) maximumWaypointDistanceToUse = minimumWaypointDistanceToUse; // If closer than the minimum waypoint distance or further away than the maximum waypoint distance, // don't show waypoint - double d = mc.cameraEntity.position().distanceTo(new Vec3(playerPosition.x, playerPosition.y, playerPosition.z)); + double d = camPosition.distanceTo(new Vec3(playerPosition.x, playerPosition.y, playerPosition.z)); if (d < minimumWaypointDistanceToUse || d > maximumWaypointDistanceToUse) continue; // Check if this player is within the server's player entity tracking range @@ -343,10 +360,19 @@ public void runUpdate() { playerWaypointList.removeIf(waypoint -> !currentPlayerWaypointNames.contains(waypoint.getName())); int newPlayerWaypointColor = CommonModConfig.Instance.playerWaypointColor(); - if (previousPlayerWaypointColor != newPlayerWaypointColor){ + int newFriendWaypointColor = CommonModConfig.Instance.friendWaypointColor(); + boolean newFriendColorOverride = CommonModConfig.Instance.overwriteFriendWaypointColor(); + int newFriendListHashCode = CommonModConfig.Instance.friendList().hashCode(); + if ((previousPlayerWaypointColor != newPlayerWaypointColor) + || (previousFriendWaypointColor != newFriendWaypointColor) + || (previousFriendColorOverride != newFriendColorOverride) + || (previousFriendListHashCode != newFriendListHashCode)) { previousPlayerWaypointColor = newPlayerWaypointColor; + previousFriendWaypointColor = newFriendWaypointColor; + previousFriendColorOverride = newFriendColorOverride; + previousFriendListHashCode = newFriendListHashCode; for (Waypoint waypoint : playerWaypointList){ - waypoint.setColor(newPlayerWaypointColor); + waypoint.setColor(CommonModConfig.Instance.getPlayerWaypointColor(waypoint.getName())); } } } @@ -380,7 +406,7 @@ public void runUpdate() { // If closer than the minimum waypoint distance or further away than the maximum waypoint distance, // don't show waypoint - double d = mc.cameraEntity.position().distanceTo(new Vec3(markerPosition.x, markerPosition.y, markerPosition.z)); + double d = camPosition.distanceTo(new Vec3(markerPosition.x, markerPosition.y, markerPosition.z)); if (d < minimumWaypointDistanceToUse || d > maximumWaypointDistanceToUse) continue; // If a waypoint for this marker already exists, update it diff --git a/common/src/main/resources/assets/remote_player_waypoints_for_xaero/lang/en_us.json b/common/src/main/resources/assets/remote_player_waypoints_for_xaero/lang/en_us.json index d4e0628..f89c1ad 100644 --- a/common/src/main/resources/assets/remote_player_waypoints_for_xaero/lang/en_us.json +++ b/common/src/main/resources/assets/remote_player_waypoints_for_xaero/lang/en_us.json @@ -21,6 +21,8 @@ "text.autoconfig.remote_player_waypoints_for_xaero.option.general.minDistance.@Tooltip": "in m", "text.autoconfig.remote_player_waypoints_for_xaero.option.general.maxDistance": "max player waypoint distance", "text.autoconfig.remote_player_waypoints_for_xaero.option.general.maxDistance.@Tooltip": "in m", + "text.autoconfig.remote_player_waypoints_for_xaero.option.general.maxIconDistance": "max player icon distance", + "text.autoconfig.remote_player_waypoints_for_xaero.option.general.maxIconDistance.@Tooltip": "in m", "text.autoconfig.remote_player_waypoints_for_xaero.option.general.minDistanceMarker": "min marker waypoint distance", "text.autoconfig.remote_player_waypoints_for_xaero.option.general.minDistanceMarker.@Tooltip": "in m", "text.autoconfig.remote_player_waypoints_for_xaero.option.general.maxDistanceMarker": "max marker waypoint distance", @@ -62,5 +64,20 @@ "text.autoconfig.remote_player_waypoints_for_xaero.option.general.ignoredServers.@PrefixText": "these options are handled for you", "text.autoconfig.remote_player_waypoints_for_xaero.option.general.defaultY": "default y", "text.autoconfig.remote_player_waypoints_for_xaero.option.general.defaultY.@Tooltip": "default Y coordinate for maps that don't provide Y coordinates", - "text.autoconfig.remote_player_waypoints_for_xaero.option.general.ignoreMarkerMessage": "ignore marker message" + "text.autoconfig.remote_player_waypoints_for_xaero.option.general.ignoreMarkerMessage": "ignore marker message", + "text.autoconfig.remote_player_waypoints_for_xaero.category.a": "general settings", + "text.autoconfig.remote_player_waypoints_for_xaero.category.b": "friend-list and overrides", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.friendList": "friend-list", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.friendList.@Tooltip": "Add your friends' names here.\nClick on the (+) on the left.", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.onlyShowFriendsWaypoints": "only show player waypoints of friends", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.onlyShowFriendsIcons": "only show player icons of friends", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.overwriteFriendDistances": "overwrite min and max waypoint and icon distance for friends", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.minFriendDistance": "min friend waypoint distance", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.minFriendDistance.@Tooltip": "in m", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.maxFriendDistance": "max friend waypoint distance", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.maxFriendDistance.@Tooltip": "in m", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.maxFriendIconDistance": "max friend icon distance", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.maxFriendIconDistance.@Tooltip": "in m", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.overwriteFriendWaypointColor": "overwrite waypoint color of friends", + "text.autoconfig.remote_player_waypoints_for_xaero.option.friends.friendWaypointColor": "friend waypoint color" } \ No newline at end of file diff --git a/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/fabric/CommonModConfigFabric.java b/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/fabric/CommonModConfigFabric.java index 7470028..a812345 100644 --- a/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/fabric/CommonModConfigFabric.java +++ b/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/fabric/CommonModConfigFabric.java @@ -30,7 +30,7 @@ /** * @author Leander Knüttel - * @version 03.07.2024 + * @version 07.07.2024 */ public class CommonModConfigFabric extends CommonModConfig { public CommonModConfigFabric(){ @@ -83,6 +83,11 @@ public int maxDistance() { return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.maxDistance; } + @Override + public int maxIconDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.maxIconDistance; + } + @Override public int minDistanceMarker() { return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.minDistanceMarker; @@ -158,4 +163,49 @@ public void setIgnoreMarkerMessage(boolean on) { public boolean ignoreMarkerMessage() { return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.ignoreMarkerMessage; } + + @Override + public List friendList() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.friendList; + } + + @Override + public boolean onlyShowFriendsWaypoints() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.onlyShowFriendsWaypoints; + } + + @Override + public boolean onlyShowFriendsIcons() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.onlyShowFriendsIcons; + } + + @Override + public boolean overwriteFriendDistances() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.overwriteFriendDistances; + } + + @Override + public int minFriendDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.minFriendDistance; + } + + @Override + public int maxFriendDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.maxFriendDistance; + } + + @Override + public int maxFriendIconDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.maxFriendIconDistance; + } + + @Override + public boolean overwriteFriendWaypointColor() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.overwriteFriendWaypointColor; + } + + @Override + public int friendWaypointColor() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.friendWaypointColor.ordinal(); + } } diff --git a/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/fabric/ModConfig.java b/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/fabric/ModConfig.java index 4aa4f8c..18655ae 100644 --- a/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/fabric/ModConfig.java +++ b/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/fabric/ModConfig.java @@ -31,14 +31,14 @@ /** * @author Leander Knüttel - * @version 03.07.2024 + * @version 07.07.2024 */ @Config(name = "remote_player_waypoints_for_xaero") #if MC_VER < MC_1_20_6 @Config.Gui.Background("minecraft:textures/block/acacia_planks.png") @Config.Gui.CategoryBackground( category = "b", - background = "minecraft:textures/block/stone.png" + background = "minecraft:textures/block/oak_planks.png" ) #endif public class ModConfig extends PartitioningSerializer.GlobalData { @@ -46,6 +46,10 @@ public class ModConfig extends PartitioningSerializer.GlobalData { @ConfigEntry.Gui.TransitiveObject public ModuleA general = new ModuleA(); + @ConfigEntry.Category("b") + @ConfigEntry.Gui.TransitiveObject + public ModuleB friends = new ModuleB(); + public ModConfig() { } @@ -84,6 +88,10 @@ public static class ModuleA implements ConfigData { @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) int maxDistance = 100000; + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) + int maxIconDistance = 100000; + @ConfigEntry.Gui.Tooltip() @ConfigEntry.BoundedDiscrete(min = 60, max = 600) public int timeUntilAfk = 120; @@ -131,6 +139,38 @@ public ModuleA() { } } + @Config(name = "friends") + public static class ModuleB implements ConfigData { + @ConfigEntry.Gui.Tooltip() + public List friendList = new ArrayList<>(); + + public boolean onlyShowFriendsWaypoints = false; + + public boolean onlyShowFriendsIcons = false; + + public boolean overwriteFriendDistances = false; + + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 0, max = 20) + int minFriendDistance = 0; + + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) + int maxFriendDistance = 100000; + + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) + int maxFriendIconDistance = 100000; + + public boolean overwriteFriendWaypointColor = false; + + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public CommonModConfig.WaypointColor friendWaypointColor = CommonModConfig.WaypointColor.Black; + + public ModuleB() { + } + } + public static class ServerEntry { @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public Maptype maptype; diff --git a/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/fabric/mods/xaerominimap/MinimapRadarMixin.java b/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/fabric/mods/xaerominimap/MinimapRadarMixin.java index 96922b9..f464544 100644 --- a/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/fabric/mods/xaerominimap/MinimapRadarMixin.java +++ b/fabric/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/fabric/mods/xaerominimap/MinimapRadarMixin.java @@ -28,6 +28,7 @@ import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.RemotePlayer; import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.injection.At; @@ -40,7 +41,7 @@ /** * @author TheMrEngMan * @author Leander Knüttel - * @version 03.07.2024 + * @version 06.07.2024 */ @Pseudo @@ -55,6 +56,8 @@ private Iterable updateRadarEntities(Iterable worldEntities) { if(UpdateTask.playerPositions == null || UpdateTask.playerPositions.isEmpty()) return worldEntities; // Don't render if can't get access to world to check for players in range if(Minecraft.getInstance().level == null) return worldEntities; + // Don't render if can't get access to cameraEntity to check for player distance + if(Minecraft.getInstance().cameraEntity == null) return worldEntities; List playerClientEntityList = Minecraft.getInstance().level.players(); ArrayList renderedPlayerNames = new ArrayList<>(); @@ -62,6 +65,8 @@ private Iterable updateRadarEntities(Iterable worldEntities) { renderedPlayerNames.add(playerClientEntity.getName().plainCopy().getString()); } + Vec3 camPosition = Minecraft.getInstance().cameraEntity.position(); + // For each remote player ArrayList playerEntities = new ArrayList<>(UpdateTask.playerPositions.size()); for (PlayerPosition playerPosition : UpdateTask.playerPositions.values()) { @@ -70,6 +75,23 @@ private Iterable updateRadarEntities(Iterable worldEntities) { // Don't render same player when they are actually in range if(renderedPlayerNames.contains(playerPosition.player)) continue; + boolean isFriend = CommonModConfig.Instance.friendList().contains(playerPosition.player); + + if (CommonModConfig.Instance.onlyShowFriendsIcons() && !isFriend) continue; + + int maxIconDistance; + if (CommonModConfig.Instance.overwriteFriendDistances() && isFriend) { + maxIconDistance = CommonModConfig.Instance.maxFriendIconDistance(); + } + else { + maxIconDistance = CommonModConfig.Instance.maxIconDistance(); + } + + // If further away than the maximum icon distance, + // don't show icon + double d = camPosition.distanceTo(new Vec3(playerPosition.x, playerPosition.y, playerPosition.z)); + if (d > maxIconDistance) continue; + // Add remote player to list as an entity #if MC_VER == MC_1_19_2 RemotePlayer playerEntity = new RemotePlayer(Minecraft.getInstance().level, playerPosition.gameProfile, null); diff --git a/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/forge/CommonModConfigForge.java b/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/forge/CommonModConfigForge.java index accfbc3..157407f 100644 --- a/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/forge/CommonModConfigForge.java +++ b/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/forge/CommonModConfigForge.java @@ -41,7 +41,7 @@ /** * @author Leander Knüttel - * @version 03.07.2024 + * @version 07.07.2024 */ public class CommonModConfigForge extends CommonModConfig { public CommonModConfigForge(){ @@ -107,6 +107,11 @@ public int maxDistance() { return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.maxDistance; } + @Override + public int maxIconDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.maxIconDistance; + } + @Override public int minDistanceMarker() { return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.minDistanceMarker; @@ -182,4 +187,49 @@ public void setIgnoreMarkerMessage(boolean on) { public boolean ignoreMarkerMessage() { return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.ignoreMarkerMessage; } + + @Override + public List friendList() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.friendList; + } + + @Override + public boolean onlyShowFriendsWaypoints() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.onlyShowFriendsWaypoints; + } + + @Override + public boolean onlyShowFriendsIcons() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.onlyShowFriendsIcons; + } + + @Override + public boolean overwriteFriendDistances() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.overwriteFriendDistances; + } + + @Override + public int minFriendDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.minFriendDistance; + } + + @Override + public int maxFriendDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.maxFriendDistance; + } + + @Override + public int maxFriendIconDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.maxFriendIconDistance; + } + + @Override + public boolean overwriteFriendWaypointColor() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.overwriteFriendWaypointColor; + } + + @Override + public int friendWaypointColor() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.friendWaypointColor.ordinal(); + } } diff --git a/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/forge/ModConfig.java b/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/forge/ModConfig.java index 8708899..42da8b4 100644 --- a/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/forge/ModConfig.java +++ b/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/forge/ModConfig.java @@ -31,14 +31,14 @@ /** * @author Leander Knüttel - * @version 03.07.2024 + * @version 07.07.2024 */ @Config(name = "remote_player_waypoints_for_xaero") #if MC_VER < MC_1_20_6 @Config.Gui.Background("minecraft:textures/block/acacia_planks.png") @Config.Gui.CategoryBackground( category = "b", - background = "minecraft:textures/block/stone.png" + background = "minecraft:textures/block/oak_planks.png" ) #endif public class ModConfig extends PartitioningSerializer.GlobalData { @@ -46,6 +46,10 @@ public class ModConfig extends PartitioningSerializer.GlobalData { @ConfigEntry.Gui.TransitiveObject public ModuleA general = new ModuleA(); + @ConfigEntry.Category("b") + @ConfigEntry.Gui.TransitiveObject + public ModuleB friends = new ModuleB(); + public ModConfig() { } @@ -84,6 +88,10 @@ public static class ModuleA implements ConfigData { @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) int maxDistance = 100000; + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) + int maxIconDistance = 100000; + @ConfigEntry.Gui.Tooltip() @ConfigEntry.BoundedDiscrete(min = 60, max = 600) public int timeUntilAfk = 120; @@ -131,6 +139,38 @@ public ModuleA() { } } + @Config(name = "friends") + public static class ModuleB implements ConfigData { + @ConfigEntry.Gui.Tooltip() + public List friendList = new ArrayList<>(); + + public boolean onlyShowFriendsWaypoints = false; + + public boolean onlyShowFriendsIcons = false; + + public boolean overwriteFriendDistances = false; + + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 0, max = 20) + int minFriendDistance = 0; + + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) + int maxFriendDistance = 100000; + + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) + int maxFriendIconDistance = 100000; + + public boolean overwriteFriendWaypointColor = false; + + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public CommonModConfig.WaypointColor friendWaypointColor = CommonModConfig.WaypointColor.Black; + + public ModuleB() { + } + } + public static class ServerEntry { @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public Maptype maptype; diff --git a/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/forge/mods/xaerominimap/MinimapRadarMixin.java b/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/forge/mods/xaerominimap/MinimapRadarMixin.java index 8d7d95e..57cc978 100644 --- a/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/forge/mods/xaerominimap/MinimapRadarMixin.java +++ b/forge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/forge/mods/xaerominimap/MinimapRadarMixin.java @@ -28,6 +28,7 @@ import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.RemotePlayer; import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.injection.At; @@ -40,7 +41,7 @@ /** * @author TheMrEngMan * @author Leander Knüttel - * @version 03.07.2024 + * @version 06.07.2024 */ @Pseudo @@ -55,6 +56,8 @@ private Iterable updateRadarEntities(Iterable worldEntities) { if(UpdateTask.playerPositions == null || UpdateTask.playerPositions.isEmpty()) return worldEntities; // Don't render if can't get access to world to check for players in range if(Minecraft.getInstance().level == null) return worldEntities; + // Don't render if can't get access to cameraEntity to check for player distance + if(Minecraft.getInstance().cameraEntity == null) return worldEntities; List playerClientEntityList = Minecraft.getInstance().level.players(); ArrayList renderedPlayerNames = new ArrayList<>(); @@ -62,6 +65,8 @@ private Iterable updateRadarEntities(Iterable worldEntities) { renderedPlayerNames.add(playerClientEntity.getName().plainCopy().getString()); } + Vec3 camPosition = Minecraft.getInstance().cameraEntity.position(); + // For each remote player ArrayList playerEntities = new ArrayList<>(UpdateTask.playerPositions.size()); for (PlayerPosition playerPosition : UpdateTask.playerPositions.values()) { @@ -70,6 +75,23 @@ private Iterable updateRadarEntities(Iterable worldEntities) { // Don't render same player when they are actually in range if(renderedPlayerNames.contains(playerPosition.player)) continue; + boolean isFriend = CommonModConfig.Instance.friendList().contains(playerPosition.player); + + if (CommonModConfig.Instance.onlyShowFriendsIcons() && !isFriend) continue; + + int maxIconDistance; + if (CommonModConfig.Instance.overwriteFriendDistances() && isFriend) { + maxIconDistance = CommonModConfig.Instance.maxFriendIconDistance(); + } + else { + maxIconDistance = CommonModConfig.Instance.maxIconDistance(); + } + + // If further away than the maximum icon distance, + // don't show icon + double d = camPosition.distanceTo(new Vec3(playerPosition.x, playerPosition.y, playerPosition.z)); + if (d > maxIconDistance) continue; + // Add remote player to list as an entity #if MC_VER == MC_1_19_2 RemotePlayer playerEntity = new RemotePlayer(Minecraft.getInstance().level, playerPosition.gameProfile, null); diff --git a/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/neoforge/mods/xaerominimap/MinimapRadarMixin.java b/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/neoforge/mods/xaerominimap/MinimapRadarMixin.java index 171a83c..45470bd 100644 --- a/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/neoforge/mods/xaerominimap/MinimapRadarMixin.java +++ b/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/mixins/neoforge/mods/xaerominimap/MinimapRadarMixin.java @@ -28,6 +28,7 @@ import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.RemotePlayer; import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.injection.At; @@ -40,7 +41,7 @@ /** * @author TheMrEngMan * @author Leander Knüttel - * @version 03.07.2024 + * @version 06.07.2024 */ @Pseudo @@ -55,6 +56,8 @@ private Iterable updateRadarEntities(Iterable worldEntities) { if(UpdateTask.playerPositions == null || UpdateTask.playerPositions.isEmpty()) return worldEntities; // Don't render if can't get access to world to check for players in range if(Minecraft.getInstance().level == null) return worldEntities; + // Don't render if can't get access to cameraEntity to check for player distance + if(Minecraft.getInstance().cameraEntity == null) return worldEntities; List playerClientEntityList = Minecraft.getInstance().level.players(); ArrayList renderedPlayerNames = new ArrayList<>(); @@ -62,6 +65,8 @@ private Iterable updateRadarEntities(Iterable worldEntities) { renderedPlayerNames.add(playerClientEntity.getName().plainCopy().getString()); } + Vec3 camPosition = Minecraft.getInstance().cameraEntity.position(); + // For each remote player ArrayList playerEntities = new ArrayList<>(UpdateTask.playerPositions.size()); for (PlayerPosition playerPosition : UpdateTask.playerPositions.values()) { @@ -70,8 +75,29 @@ private Iterable updateRadarEntities(Iterable worldEntities) { // Don't render same player when they are actually in range if(renderedPlayerNames.contains(playerPosition.player)) continue; + boolean isFriend = CommonModConfig.Instance.friendList().contains(playerPosition.player); + + if (CommonModConfig.Instance.onlyShowFriendsIcons() && !isFriend) continue; + + int maxIconDistance; + if (CommonModConfig.Instance.overwriteFriendDistances() && isFriend) { + maxIconDistance = CommonModConfig.Instance.maxFriendIconDistance(); + } + else { + maxIconDistance = CommonModConfig.Instance.maxIconDistance(); + } + + // If further away than the maximum icon distance, + // don't show icon + double d = camPosition.distanceTo(new Vec3(playerPosition.x, playerPosition.y, playerPosition.z)); + if (d > maxIconDistance) continue; + // Add remote player to list as an entity + #if MC_VER == MC_1_19_2 + RemotePlayer playerEntity = new RemotePlayer(Minecraft.getInstance().level, playerPosition.gameProfile, null); + #else RemotePlayer playerEntity = new RemotePlayer(Minecraft.getInstance().level, playerPosition.gameProfile); + #endif playerEntity.moveTo(playerPosition.x, playerPosition.y, playerPosition.z, 0, 0); playerEntities.add(playerEntity); } diff --git a/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/neoforge/CommonModConfigNeoForge.java b/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/neoforge/CommonModConfigNeoForge.java index 9450090..8b7b714 100644 --- a/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/neoforge/CommonModConfigNeoForge.java +++ b/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/neoforge/CommonModConfigNeoForge.java @@ -36,7 +36,7 @@ /** * @author Leander Knüttel - * @version 03.07.2024 + * @version 07.07.2024 */ public class CommonModConfigNeoForge extends CommonModConfig { public CommonModConfigNeoForge(){ @@ -98,6 +98,11 @@ public int maxDistance() { return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.maxDistance; } + @Override + public int maxIconDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.maxIconDistance; + } + @Override public int minDistanceMarker() { return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.minDistanceMarker; @@ -173,4 +178,49 @@ public void setIgnoreMarkerMessage(boolean on) { public boolean ignoreMarkerMessage() { return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.ignoreMarkerMessage; } + + @Override + public List friendList() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.friendList; + } + + @Override + public boolean onlyShowFriendsWaypoints() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.onlyShowFriendsWaypoints; + } + + @Override + public boolean onlyShowFriendsIcons() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.onlyShowFriendsIcons; + } + + @Override + public boolean overwriteFriendDistances() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.overwriteFriendDistances; + } + + @Override + public int minFriendDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.minFriendDistance; + } + + @Override + public int maxFriendDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.maxFriendDistance; + } + + @Override + public int maxFriendIconDistance() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.maxFriendIconDistance; + } + + @Override + public boolean overwriteFriendWaypointColor() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.overwriteFriendWaypointColor; + } + + @Override + public int friendWaypointColor() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig().friends.friendWaypointColor.ordinal(); + } } diff --git a/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/neoforge/ModConfig.java b/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/neoforge/ModConfig.java index 68bacb6..f11d100 100644 --- a/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/neoforge/ModConfig.java +++ b/neoforge/src/main/java/de/the_build_craft/remote_player_waypoints_for_xaero/neoforge/ModConfig.java @@ -31,14 +31,14 @@ /** * @author Leander Knüttel - * @version 03.07.2024 + * @version 07.07.2024 */ @Config(name = "remote_player_waypoints_for_xaero") #if MC_VER < MC_1_20_6 @Config.Gui.Background("minecraft:textures/block/acacia_planks.png") @Config.Gui.CategoryBackground( category = "b", - background = "minecraft:textures/block/stone.png" + background = "minecraft:textures/block/oak_planks.png" ) #endif public class ModConfig extends PartitioningSerializer.GlobalData { @@ -46,6 +46,10 @@ public class ModConfig extends PartitioningSerializer.GlobalData { @ConfigEntry.Gui.TransitiveObject public ModuleA general = new ModuleA(); + @ConfigEntry.Category("b") + @ConfigEntry.Gui.TransitiveObject + public ModuleB friends = new ModuleB(); + public ModConfig() { } @@ -84,6 +88,10 @@ public static class ModuleA implements ConfigData { @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) int maxDistance = 100000; + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) + int maxIconDistance = 100000; + @ConfigEntry.Gui.Tooltip() @ConfigEntry.BoundedDiscrete(min = 60, max = 600) public int timeUntilAfk = 120; @@ -131,6 +139,38 @@ public ModuleA() { } } + @Config(name = "friends") + public static class ModuleB implements ConfigData { + @ConfigEntry.Gui.Tooltip() + public List friendList = new ArrayList<>(); + + public boolean onlyShowFriendsWaypoints = false; + + public boolean onlyShowFriendsIcons = false; + + public boolean overwriteFriendDistances = false; + + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 0, max = 20) + int minFriendDistance = 0; + + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) + int maxFriendDistance = 100000; + + @ConfigEntry.Gui.Tooltip() + @ConfigEntry.BoundedDiscrete(min = 100, max = 100000) + int maxFriendIconDistance = 100000; + + public boolean overwriteFriendWaypointColor = false; + + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public CommonModConfig.WaypointColor friendWaypointColor = CommonModConfig.WaypointColor.Black; + + public ModuleB() { + } + } + public static class ServerEntry { @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public Maptype maptype;