Skip to content

Commit

Permalink
implement friend list features, closes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
thebuildcraft committed Jul 7, 2024
1 parent f2a4622 commit ddd5750
Show file tree
Hide file tree
Showing 13 changed files with 427 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/**
* @author Leander Knüttel
* @version 03.07.2024
* @version 07.07.2024
*/
public abstract class CommonModConfig {
public CommonModConfig() {
Expand All @@ -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();
Expand All @@ -57,6 +58,25 @@ public CommonModConfig() {
public abstract void setIgnoreMarkerMessage(boolean on);
public abstract boolean ignoreMarkerMessage();

public abstract List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -270,6 +272,8 @@ public void runUpdate() {
}
}

Vec3 camPosition = mc.cameraEntity.position();

try {
synchronized (playerWaypointList) {
if (CommonModConfig.Instance.enablePlayerWaypoints()){
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()));
}
}
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/**
* @author Leander Knüttel
* @version 03.07.2024
* @version 07.07.2024
*/
public class CommonModConfigFabric extends CommonModConfig {
public CommonModConfigFabric(){
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -158,4 +163,49 @@ public void setIgnoreMarkerMessage(boolean on) {
public boolean ignoreMarkerMessage() {
return AutoConfig.getConfigHolder(ModConfig.class).getConfig().general.ignoreMarkerMessage;
}

@Override
public List<String> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@

/**
* @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 {
@ConfigEntry.Category("a")
@ConfigEntry.Gui.TransitiveObject
public ModuleA general = new ModuleA();

@ConfigEntry.Category("b")
@ConfigEntry.Gui.TransitiveObject
public ModuleB friends = new ModuleB();

public ModConfig() {
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -131,6 +139,38 @@ public ModuleA() {
}
}

@Config(name = "friends")
public static class ModuleB implements ConfigData {
@ConfigEntry.Gui.Tooltip()
public List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +41,7 @@
/**
* @author TheMrEngMan
* @author Leander Knüttel
* @version 03.07.2024
* @version 06.07.2024
*/

@Pseudo
Expand All @@ -55,13 +56,17 @@ private Iterable<Entity> updateRadarEntities(Iterable<Entity> 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<AbstractClientPlayer> playerClientEntityList = Minecraft.getInstance().level.players();
ArrayList<String> renderedPlayerNames = new ArrayList<>();
for (AbstractClientPlayer playerClientEntity : playerClientEntityList) {
renderedPlayerNames.add(playerClientEntity.getName().plainCopy().getString());
}

Vec3 camPosition = Minecraft.getInstance().cameraEntity.position();

// For each remote player
ArrayList<Entity> playerEntities = new ArrayList<>(UpdateTask.playerPositions.size());
for (PlayerPosition playerPosition : UpdateTask.playerPositions.values()) {
Expand All @@ -70,6 +75,23 @@ private Iterable<Entity> updateRadarEntities(Iterable<Entity> 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);
Expand Down
Loading

0 comments on commit ddd5750

Please sign in to comment.