Skip to content

Commit

Permalink
add waystone color setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Oct 14, 2023
1 parent 63cd3a4 commit 95bc006
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
forge "net.minecraftforge:forge:${project.forge_version}"

forgeRuntimeLibrary(jarLibs "com.github.ben-manes.caffeine:caffeine:3.1.7")
forgeRuntimeLibrary(jarLibs "com.github.ben-manes.caffeine:caffeine:3.1.8")
forgeRuntimeLibrary(jarLibs "com.github.collarmc:pounce:0e8492b68e")
forgeRuntimeLibrary(jarLibs 'org.xerial:sqlite-jdbc:3.43.0.0')

modImplementation "maven.modrinth:xaeros-world-map:1.34.1_Forge_1.20.2"
modImplementation "maven.modrinth:xaeros-minimap:23.8.2_Forge_1.20.2"
modImplementation files("libs/baritone-unoptimized-forge-1.10.2.jar")
modCompileOnly "maven.modrinth:waystones:14.0.2+forge-1.20"
modCompileOnly "maven.modrinth:balm:7.1.4+forge-1.20.1"
modCompileOnly "maven.modrinth:waystones:15.0.0+forge-1.20.2"
modCompileOnly "maven.modrinth:balm:8.0.1+forge-1.20.2"
}

tasks.withType(JavaCompile).configureEach {
Expand Down
23 changes: 18 additions & 5 deletions src/main/java/xaeroplus/module/impl/WaystoneSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import xaeroplus.event.ClientTickEvent;
import xaeroplus.event.XaeroWorldChangeEvent;
import xaeroplus.module.Module;
import xaeroplus.util.ColorHelper.WaystoneColor;
import xaeroplus.util.IWaypointDimension;
import xaeroplus.util.WaypointsHelper;
import xaeroplus.util.WaystonesHelper;
Expand All @@ -31,6 +32,7 @@ public class WaystoneSync extends Module {
private boolean subscribed = false;
private boolean shouldSync = false;
private List<IWaystone> toSyncWaystones = new ArrayList<>();
private WaystoneColor color = WaystoneColor.RANDOM;

@Override
public void onEnable() {
Expand Down Expand Up @@ -134,7 +136,9 @@ private void crossDimWaystoneSync(Waystone waystone, WaypointsManager waypointsM
waystone.y(),
waystone.z(),
waystone.name() + " [Waystone]",
waystone.name().substring(0, 1).toUpperCase(Locale.ROOT),
waystone.name().isEmpty()
? "W"
: waystone.name().substring(0, 1).toUpperCase(Locale.ROOT),
getWaystoneColor(waystone),
0,
true
Expand All @@ -158,9 +162,9 @@ private void currentDimWaystoneSync(Waystone waystone, WaypointsManager waypoint
waystone.y(),
z,
waystone.name() + " [Waystone]",
waystone.name().isEmpty() ? "W" : waystone.name()
.substring(0, 1)
.toUpperCase(Locale.ROOT),
waystone.name().isEmpty()
? "W"
: waystone.name().substring(0, 1).toUpperCase(Locale.ROOT),
getWaystoneColor(waystone),
0,
true
Expand All @@ -183,7 +187,16 @@ private double getDimensionDivision(final RegistryKey<World> waystoneDim, final
}

private int getWaystoneColor(Waystone waystone) {
return Math.abs(Hashing. murmur3_128().hashUnencodedChars(waystone.name()).asInt()) % COLORS.length;
if (color == WaystoneColor.RANDOM) {
return Math.abs(Hashing. murmur3_128().hashUnencodedChars(waystone.name()).asInt()) % COLORS.length;
} else {
return color.getColorIndex();
}
}

public void setColor(final WaystoneColor color) {
this.color = color;
// todo: reload all waypoints with new color
}

private record Waystone(String name, RegistryKey<World> dimension, int x, int y, int z) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import xaeroplus.module.impl.*;
import xaeroplus.util.BaritoneHelper;
import xaeroplus.util.ColorHelper;
import xaeroplus.util.ColorHelper.WaystoneColor;
import xaeroplus.util.Shared;
import xaeroplus.util.WaystonesHelper;

Expand Down Expand Up @@ -78,6 +79,14 @@ public final class XaeroPlusSettingRegistry {
},
true,
SettingLocation.WORLD_MAP_MAIN);
public static final XaeroPlusEnumSetting<WaystoneColor> waystoneColorSetting = XaeroPlusEnumSetting.create(
"Waystone Color",
"setting.world_map.waystone_color",
"setting.world_map.waystone_color.tooltip",
(b) -> ModuleManager.getModule(WaystoneSync.class).setColor(b),
ColorHelper.WaystoneColor.values(),
WaystoneColor.RANDOM,
SettingLocation.WORLD_MAP_MAIN);
public static final XaeroPlusBooleanSetting persistMapDimensionSwitchSetting = XaeroPlusBooleanSetting.create(
"Persist WM Dim Switch",
"setting.world_map.persist_dimension_switch",
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/xaeroplus/util/ColorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,42 @@ public String getTranslationKey() {
return translationKey;
}
}

public enum WaystoneColor implements TranslatableSettingEnum {

BLACK(0, "gui.xaero_black"),
DARK_BLUE(1, "gui.xaero_dark_blue"),
DARK_GREEN(2, "gui.xaero_dark_green"),
DARK_AQUA(3, "gui.xaero_dark_aqua"),
DARK_RED(4, "gui.xaero_dark_red"),
DARK_PURPLE(5, "gui.xaero_dark_purple"),
GOLD(6, "gui.xaero_gold"),
GRAY(7, "gui.xaero_gray"),
DARK_GRAY(8, "gui.xaero_dark_gray"),
BLUE(9, "gui.xaero_blue"),
GREEN(10, "gui.xaero_green"),
AQUA(11, "gui.xaero_aqua"),
RED(12, "gui.xaero_red"),
LIGHT_PURPLE(13, "gui.xaero_purple"),
YELLOW(14, "gui.xaero_yellow"),
WHITE(15, "gui.xaero_white"),
RANDOM(16, "gui.xaeroplus.random");

private final int colorIndex;
private final String translationKey;

WaystoneColor(final int colorIndex, final String translationKey) {
this.colorIndex = colorIndex;
this.translationKey = translationKey;
}

public int getColorIndex() {
return colorIndex;
}

@Override
public String getTranslationKey() {
return translationKey;
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/xaeroplus/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"gui.xaeroplus.on": "On",
"gui.xaeroplus.off": "Off",
"gui.xaeroplus.world_map_settings": "XaeroPlus WorldMap Settings",
"gui.xaeroplus.random": "Random",
"gui.world_map.go_to_coordinates": "Go to Coordinates",
"gui.world_map.baritone_goal_here": "Baritone Goal Here",
"gui.world_map.baritone_path_here": "Baritone Path Here",
Expand All @@ -122,6 +123,8 @@
"gui.waypoints.toggle_enable_all": "Toggle Enable All",
"setting.world_map.waystones_sync": "Waystones Sync",
"setting.world_map.waystones_sync.tooltip": "Syncs Waystones as waypoints.",
"setting.world_map.waystone_color": "Waystone Waypoint Color",
"setting.world_map.waystone_color.tooltip": "Uses an optional preset color for all waystone waypoints or a random color.",
"setting.world_map.cross_dim_waystones_sync": "Waystones Dimension Sync",
"setting.world_map.cross_dim_waystones_sync.tooltip": "Syncs Waystones to the (default) waypoint set according to its dimension",
"setting.world_map.cross_dimension_teleport": "Cross Dimension Teleport",
Expand Down

0 comments on commit 95bc006

Please sign in to comment.