Skip to content

Commit

Permalink
more teams enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticdrew committed Oct 18, 2023
1 parent cc79b7c commit d58a813
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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<Color> teamColor;
private final EnumOption<Color> 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();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down

0 comments on commit d58a813

Please sign in to comment.