From d58a813baeed4c058f53de1ee275641905294942 Mon Sep 17 00:00:00 2001 From: Mysticdrew Date: Wed, 18 Oct 2023 12:44:35 -0500 Subject: [PATCH] more teams enhancements --- .../integration/JourneyMapCommonPlugin.java | 2 +- .../handlers/AbstractHandler.java | 56 ++++++++++++++++++ .../handlers/FTBTeamsHandler.java | 22 +++---- .../journeymapteams/handlers/Handler.java | 4 +- .../handlers/VanillaTeamsHandler.java | 20 +++---- .../properties/DefaultHandlerProperties.java | 59 +++++++++++++++++++ .../properties/FTBTeamsHandlerProperties.java | 23 -------- .../handlers/properties/Properties.java | 16 +++++ .../properties/VanillaHandlerProperties.java | 23 -------- .../mixin/client/DrawEntityMixin.java | 8 +-- 10 files changed, 154 insertions(+), 79 deletions(-) create mode 100644 common/src/main/java/net/mysticdrew/journeymapteams/handlers/AbstractHandler.java create mode 100644 common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/DefaultHandlerProperties.java delete mode 100644 common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/FTBTeamsHandlerProperties.java create mode 100644 common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/Properties.java delete mode 100644 common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/VanillaHandlerProperties.java diff --git a/common/src/main/java/net/mysticdrew/journeymapteams/client/integration/JourneyMapCommonPlugin.java b/common/src/main/java/net/mysticdrew/journeymapteams/client/integration/JourneyMapCommonPlugin.java index 08385a7..656f4e6 100644 --- a/common/src/main/java/net/mysticdrew/journeymapteams/client/integration/JourneyMapCommonPlugin.java +++ b/common/src/main/java/net/mysticdrew/journeymapteams/client/integration/JourneyMapCommonPlugin.java @@ -51,7 +51,7 @@ public static void registerEvents(IClientAPI api) public void setPlayerColor(WrappedEntity entity) { - entity.setColor(handler.getRemotePlayerColor((Player) entity.getEntityLivingRef().get())); + entity.setColor(handler.getRemotePlayerIconColor((Player) entity.getEntityLivingRef().get(), entity.getColor())); } } diff --git a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/AbstractHandler.java b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/AbstractHandler.java new file mode 100644 index 0000000..2a8073c --- /dev/null +++ b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/AbstractHandler.java @@ -0,0 +1,56 @@ +package net.mysticdrew.journeymapteams.handlers; + +import net.minecraft.world.entity.player.Player; +import net.mysticdrew.journeymapteams.handlers.properties.DefaultHandlerProperties; +import net.mysticdrew.journeymapteams.handlers.properties.Properties; + +public abstract class AbstractHandler implements Handler +{ + protected final Properties properties; + + public AbstractHandler(String categoryToken, String categoryKey) + { + this.properties = new DefaultHandlerProperties(categoryToken, categoryKey); + } + + public AbstractHandler(Properties properties) + { + this.properties = properties; + } + + @Override + public int getRemotePlayerNameColor(Player remotePlayer, int currentColor) + { + if (this.properties.getShowNameColor()) + { + return getRemotePlayerColor(remotePlayer); + } + return currentColor; + } + + @Override + public int getRemotePlayerIconColor(Player remotePlayer, int currentColor) + { + if (this.properties.getShowIconColor()) + { + return getRemotePlayerColor(remotePlayer); + } + return currentColor; + } + + public int getColor(boolean teammates, boolean allied, int teamColor) + { + if (allied) + { + return properties.getForceAllyColor() ? properties.getAllyColor() : teamColor; + } + + if (teammates) + { + return properties.getForceTeamColor() ? properties.getTeamColor() : teamColor; + } + return properties.getTeamColor(); + } + + protected abstract int getRemotePlayerColor(Player remotePlayer); +} diff --git a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/FTBTeamsHandler.java b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/FTBTeamsHandler.java index 6dbcb37..91ec8ee 100644 --- a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/FTBTeamsHandler.java +++ b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/FTBTeamsHandler.java @@ -4,15 +4,12 @@ import dev.ftb.mods.ftbteams.data.ClientTeam; import net.minecraft.client.Minecraft; import net.minecraft.world.entity.player.Player; -import net.mysticdrew.journeymapteams.handlers.properties.FTBTeamsHandlerProperties; -public class FTBTeamsHandler implements Handler +public class FTBTeamsHandler extends AbstractHandler { - private FTBTeamsHandlerProperties properties; - public FTBTeamsHandler() { - properties = new FTBTeamsHandlerProperties(); + super("ftbteams", "prop.category.label.ftb"); } @Override @@ -33,8 +30,7 @@ public boolean isVisible(Player localPlayer, Player remotePlayer, boolean isOp, return visible; } - @Override - public int getRemotePlayerColor(Player remotePlayer) + protected int getRemotePlayerColor(Player remotePlayer) { var localPlayer = Minecraft.getInstance().player; var knownRemotePlayer = FTBTeamsAPI.getClientManager().getKnownPlayer(remotePlayer.getUUID()); @@ -43,15 +39,13 @@ public int getRemotePlayerColor(Player remotePlayer) { ClientTeam remoteTeam = FTBTeamsAPI.getClientManager().getTeam(knownRemotePlayer.teamId); ClientTeam localTeam = FTBTeamsAPI.getClientManager().getTeam(knownLocalPlayer.teamId); - - var allied = localTeam.isAlly(remotePlayer.getUUID()) || remoteTeam.isAlly(localPlayer.getUUID()); - if (remoteTeam != null - && localTeam != null - && remoteTeam.getId() == localTeam.getId() || allied) + if (remoteTeam != null && localTeam != null) { - return allied && properties.doOverrideAllyColor.get() ? properties.overrideAllyColor.get().getColor() : remoteTeam.getColor(); + var allied = localTeam.isAlly(remotePlayer.getUUID()) || remoteTeam.isAlly(localPlayer.getUUID()); + var teammates = remoteTeam.getId() == localTeam.getId(); + return getColor(teammates, allied, remoteTeam.getColor()); } } - return properties.defaultTeamColor.get().getColor(); + return properties.getTeamColor(); } } diff --git a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/Handler.java b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/Handler.java index 6104467..6bb6de3 100644 --- a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/Handler.java +++ b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/Handler.java @@ -6,5 +6,7 @@ public interface Handler { boolean isVisible(Player localPlayer, Player remotePlayer, boolean isOp, boolean visible); - int getRemotePlayerColor(Player remotePlayer); + int getRemotePlayerNameColor(Player remotePlayer, int currentColor); + + int getRemotePlayerIconColor(Player remotePlayer, int currentColo); } diff --git a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/VanillaTeamsHandler.java b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/VanillaTeamsHandler.java index 07d2cf3..be20ca1 100644 --- a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/VanillaTeamsHandler.java +++ b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/VanillaTeamsHandler.java @@ -2,15 +2,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.world.entity.player.Player; -import net.mysticdrew.journeymapteams.handlers.properties.VanillaHandlerProperties; +import net.mysticdrew.journeymapteams.handlers.properties.DefaultHandlerProperties; -public class VanillaTeamsHandler implements Handler +public class VanillaTeamsHandler extends AbstractHandler { - private VanillaHandlerProperties properties; - public VanillaTeamsHandler() { - properties = new VanillaHandlerProperties(); + super("vanilla", "prop.category.label.vanilla.tooltip"); } @Override @@ -32,8 +30,7 @@ public boolean isVisible(Player localPlayer, Player remotePlayer, boolean isOp, return visible; } - @Override - public int getRemotePlayerColor(Player remotePlayer) + protected int getRemotePlayerColor(Player remotePlayer) { var localPlayer = Minecraft.getInstance().player; var localTeam = localPlayer.getTeam(); @@ -42,14 +39,11 @@ public int getRemotePlayerColor(Player remotePlayer) if (localTeam != null && remoteTeam != null) { var allied = localTeam.isAlliedTo(remoteTeam) || remoteTeam.isAlliedTo(localTeam); + var color = remoteTeam.getColor().getColor() != null ? remoteTeam.getColor().getColor() : properties.getTeamColor(); + return getColor(remoteTeam == localTeam, allied, color); - if ((remoteTeam == localTeam || allied)) - { - var color = remoteTeam.getColor().getColor() != null ? remoteTeam.getColor().getColor() : properties.defaultTeamColor.get().getColor(); - return allied && properties.doOverrideAllyColor.get() ? properties.overrideAllyColor.get().getColor() : color; - } } - return properties.defaultTeamColor.get().getColor(); + return properties.getTeamColor(); } } diff --git a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/DefaultHandlerProperties.java b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/DefaultHandlerProperties.java new file mode 100644 index 0000000..953264b --- /dev/null +++ b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/DefaultHandlerProperties.java @@ -0,0 +1,59 @@ +package net.mysticdrew.journeymapteams.handlers.properties; + +import journeymap.client.api.option.BooleanOption; +import journeymap.client.api.option.EnumOption; +import journeymap.client.api.option.OptionCategory; + +import static net.mysticdrew.journeymapteams.Constants.MOD_ID; + +public class DefaultHandlerProperties implements Properties +{ + private final OptionCategory category; + private final EnumOption teamColor; + private final EnumOption allyColor; + private final BooleanOption forceAllyColor; + private final BooleanOption forceTeamColor; + private final BooleanOption showIconColor; + private final BooleanOption showNameColor; + + public DefaultHandlerProperties(String token, String labelKey) + { + this.category = new OptionCategory(MOD_ID + "-" + token, labelKey); + this.teamColor = new EnumOption<>(category, "team-color", "prop.option.label.team_color", Color.GREEN); + this.allyColor = new EnumOption<>(category, "ally-color", "prop.option.label.ally_color", Color.BLUE); + this.forceAllyColor = new BooleanOption(category, "force-ally-color", "prop.option.label.force_ally", false); + this.forceTeamColor = new BooleanOption(category, "force-team-color", "prop.option.label.force_team", false); + this.showIconColor = new BooleanOption(category, "show-icon-color", "prop.option.label.show_icon_color", true); + this.showNameColor = new BooleanOption(category, "show-name-color", "prop.option.label.show_name_color", true); + } + + public int getTeamColor() + { + return teamColor.get().getColor(); + } + + public int getAllyColor() + { + return allyColor.get().getColor(); + } + + public boolean getForceAllyColor() + { + return forceAllyColor.get(); + } + + public boolean getForceTeamColor() + { + return forceTeamColor.get(); + } + + public boolean getShowIconColor() + { + return showIconColor.get(); + } + + public boolean getShowNameColor() + { + return showNameColor.get(); + } +} diff --git a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/FTBTeamsHandlerProperties.java b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/FTBTeamsHandlerProperties.java deleted file mode 100644 index 5b11465..0000000 --- a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/FTBTeamsHandlerProperties.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.mysticdrew.journeymapteams.handlers.properties; - -import journeymap.client.api.option.BooleanOption; -import journeymap.client.api.option.EnumOption; -import journeymap.client.api.option.OptionCategory; - -import static net.mysticdrew.journeymapteams.Constants.MOD_ID; - -public class FTBTeamsHandlerProperties -{ - OptionCategory category = new OptionCategory(MOD_ID + "-ftbteams", "prop.category.label.ftb"); - - public final EnumOption defaultTeamColor; - public final BooleanOption doOverrideAllyColor; - public final EnumOption overrideAllyColor; - - public FTBTeamsHandlerProperties() - { - this.defaultTeamColor = new EnumOption<>(category, "default-team-color", "prop.option.label.ftb.default.team_color", Color.GREEN); - this.doOverrideAllyColor = new BooleanOption(category, "over-ride-ally-color", "prop.option.label.ftb.override_ally", false); - this.overrideAllyColor = new EnumOption<>(category, "default-ally-color", "prop.option.label.ftb.override_ally", Color.BLUE); - } -} diff --git a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/Properties.java b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/Properties.java new file mode 100644 index 0000000..3bf8d6f --- /dev/null +++ b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/Properties.java @@ -0,0 +1,16 @@ +package net.mysticdrew.journeymapteams.handlers.properties; + +public interface Properties +{ + int getTeamColor(); + + int getAllyColor(); + + boolean getForceAllyColor(); + + boolean getForceTeamColor(); + + boolean getShowIconColor(); + + boolean getShowNameColor(); +} diff --git a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/VanillaHandlerProperties.java b/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/VanillaHandlerProperties.java deleted file mode 100644 index 4e34b9a..0000000 --- a/common/src/main/java/net/mysticdrew/journeymapteams/handlers/properties/VanillaHandlerProperties.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.mysticdrew.journeymapteams.handlers.properties; - -import journeymap.client.api.option.BooleanOption; -import journeymap.client.api.option.EnumOption; -import journeymap.client.api.option.OptionCategory; - -import static net.mysticdrew.journeymapteams.Constants.MOD_ID; - -public class VanillaHandlerProperties -{ - OptionCategory category = new OptionCategory(MOD_ID + "-vanilla", "prop.category.label.vanilla", "prop.category.label.vanilla.tooltip"); - - public final EnumOption defaultTeamColor; - public final BooleanOption doOverrideAllyColor; - public final EnumOption overrideAllyColor; - - public VanillaHandlerProperties() - { - this.defaultTeamColor = new EnumOption<>(category, "default-team-color", "prop.option.label.vanilla.default.team_color", Color.GREEN); - this.doOverrideAllyColor = new BooleanOption(category, "over-ride-ally-color", "prop.option.label.vanilla.override_ally", false); - this.overrideAllyColor = new EnumOption<>(category, "default-ally-color", "prop.option.label.vanilla.override_ally", Color.BLUE); - } -} diff --git a/common/src/main/java/net/mysticdrew/journeymapteams/mixin/client/DrawEntityMixin.java b/common/src/main/java/net/mysticdrew/journeymapteams/mixin/client/DrawEntityMixin.java index d5d0b2c..4fe6bb9 100644 --- a/common/src/main/java/net/mysticdrew/journeymapteams/mixin/client/DrawEntityMixin.java +++ b/common/src/main/java/net/mysticdrew/journeymapteams/mixin/client/DrawEntityMixin.java @@ -38,7 +38,7 @@ public class DrawEntityMixin require = 0) public void drawVanillaTeamPlayer(PoseStack poseStack, DrawStep.Pass pass, MultiBufferSource buffers, double drawX, double drawY, GridRenderer gridRenderer, float alpha, double heading, double fontScale, double rotation, CallbackInfo ci, LivingEntity living, int labelOffset, Point2D labelPoint) { - int color = JourneyMapTeams.getInstance().getHandler().getRemotePlayerColor((Player) living); + int color = JourneyMapTeams.getInstance().getHandler().getRemotePlayerNameColor((Player) living, 16777215); DrawUtil.drawBatchLabel(poseStack, this.playerTeamName, buffers, labelPoint.getX(), labelPoint.getY(), DrawUtil.HAlign.Center, DrawUtil.VAlign.Below, RGB.BLACK_RGB, .8f, color, 1f, fontScale, false, rotation); ci.cancel(); } @@ -55,7 +55,7 @@ public void drawVanillaTeamPlayer(PoseStack poseStack, DrawStep.Pass pass, Multi require = 0) public void drawVanillaTeamPlayerSurrogate(PoseStack poseStack, DrawStep.Pass pass, MultiBufferSource buffers, double drawX, double drawY, GridRenderer gridRenderer, float alpha, double heading, double fontScale, double rotation, CallbackInfo ci, LivingEntity living, int labelOffset, Point2D labelPoint) { - int color = JourneyMapTeams.getInstance().getHandler().getRemotePlayerColor((Player) living); + int color = JourneyMapTeams.getInstance().getHandler().getRemotePlayerNameColor((Player) living, 16777215); DrawUtil.drawBatchLabel(poseStack, this.playerTeamName, buffers, labelPoint.getX(), labelPoint.getY(), DrawUtil.HAlign.Center, DrawUtil.VAlign.Below, RGB.BLACK_RGB, .8f, color, 1f, fontScale, false, rotation); ci.cancel(); } @@ -71,7 +71,7 @@ public void drawVanillaTeamPlayerSurrogate(PoseStack poseStack, DrawStep.Pass pa require = 0) public void drawTeamPlayer(PoseStack poseStack, DrawStep.Pass pass, MultiBufferSource buffers, double drawX, double drawY, GridRenderer gridRenderer, float alpha, double heading, double fontScale, double rotation, CallbackInfo ci, LivingEntity living, int labelOffset, Point2D labelPoint) { - int color = JourneyMapTeams.getInstance().getHandler().getRemotePlayerColor((Player) living); + int color = JourneyMapTeams.getInstance().getHandler().getRemotePlayerNameColor((Player) living, 65280); DrawUtil.drawBatchLabel(poseStack, living.getName(), buffers, labelPoint.getX(), labelPoint.getY(), DrawUtil.HAlign.Center, DrawUtil.VAlign.Below, RGB.BLACK_RGB, .8f, color, 1f, fontScale, false, rotation); ci.cancel(); } @@ -88,7 +88,7 @@ public void drawTeamPlayer(PoseStack poseStack, DrawStep.Pass pass, MultiBufferS require = 0) public void drawTeamPlayerSurrogate(PoseStack poseStack, DrawStep.Pass pass, MultiBufferSource buffers, double drawX, double drawY, GridRenderer gridRenderer, float alpha, double heading, double fontScale, double rotation, CallbackInfo ci, LivingEntity living, int labelOffset, Point2D labelPoint) { - int color = JourneyMapTeams.getInstance().getHandler().getRemotePlayerColor((Player) living); + int color = JourneyMapTeams.getInstance().getHandler().getRemotePlayerNameColor((Player) living, 65280); DrawUtil.drawBatchLabel(poseStack, living.getName(), buffers, labelPoint.getX(), labelPoint.getY(), DrawUtil.HAlign.Center, DrawUtil.VAlign.Below, RGB.BLACK_RGB, .8f, color, 1f, fontScale, false, rotation); ci.cancel(); }