Skip to content

Commit

Permalink
Cross-dimension waystones sync
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jul 22, 2023

Unverified

This user has not yet uploaded their public signing key.
1 parent a651391 commit 749461e
Showing 3 changed files with 49 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/main/java/xaeroplus/module/impl/WaystoneSync.java
Original file line number Diff line number Diff line change
@@ -7,15 +7,16 @@
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import xaero.common.XaeroMinimapSession;
import xaero.common.minimap.waypoints.Waypoint;
import xaero.common.minimap.waypoints.WaypointSet;
import xaero.common.minimap.waypoints.WaypointsManager;
import xaero.common.minimap.waypoints.*;
import xaero.common.misc.OptimizedMath;
import xaero.map.mods.SupportMods;
import xaeroplus.XaeroPlus;
import xaeroplus.event.XaeroWorldChangeEvent;
import xaeroplus.module.Module;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.util.WaystonesHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

@@ -59,6 +60,42 @@ private void syncWaystones() {
final List<Waypoint> waypoints = waypointSet.getList();
waypoints.removeIf(waypoint -> waypoint.isTemporary() && waypoint.getName().endsWith(" [Waystone]"));
for (WaystoneEntry waystoneEntry : knownWaystones) {
final int waystoneDim = waystoneEntry.getDimensionId();
final String currentContainerId = waypointsManager.getCurrentContainerID();
final int currentWaypointDim = Integer.parseInt(currentContainerId.substring(currentContainerId.lastIndexOf(37) + 1));
if (XaeroPlusSettingRegistry.waystonesCrossDimSyncSetting.getValue() && waystoneDim != currentWaypointDim) { // special case handling
// god i hate how there's no easy way to get waypoint sets in other dimensions. also the entire handling of waypoint dimensions...
// this will probably (definitely) fail if there are nonstandard waypoint sets in use.
try {
WaypointWorldContainer waypointWorldContainer = waypointsManager.getWorldContainer(currentContainerId.substring(
0,
currentContainerId.lastIndexOf(37) + 1) + waystoneDim);
WaypointWorld crossDimWaypointWorld = waypointWorldContainer.worlds.get("waypoints");
if (crossDimWaypointWorld == null) {
waypointWorldContainer.worlds.put("waypoints", new WaypointWorld(waypointWorldContainer, "waypoints"));
crossDimWaypointWorld = waypointWorldContainer.worlds.get("waypoints");
}
ArrayList<Waypoint> crossDimWaypoints = crossDimWaypointWorld.getSets().get(
"gui.xaero_default").getList();
// todo: support waystone removal sync for cross-dimension waystones
crossDimWaypoints.removeIf(waypoint -> waypoint.isTemporary() && waypoint.getName().equals(waystoneEntry.getName() + " [Waystone]"));
crossDimWaypoints.add(new Waypoint(
waystoneEntry.getPos().getX(),
waystoneEntry.getPos().getY(),
waystoneEntry.getPos().getZ(),
waystoneEntry.getName() + " [Waystone]",
waystoneEntry.getName().substring(0, 1).toUpperCase(Locale.ROOT),
Math.abs(waystoneEntry.getName().hashCode()) % COLORS.length,
0,
true
));
} catch (final Exception e) {
XaeroPlus.LOGGER.warn("Failed to add cross-dimension waystone", e);
}
continue;
}

// places all waystones in the current waypoint set regardless of dimension
final double dimDiv = getDimensionDivision(waystoneEntry.getDimensionId(), waypointsManager);
final int x = OptimizedMath.myFloor(waystoneEntry.getPos().getX() * dimDiv);
final int z = OptimizedMath.myFloor(waystoneEntry.getPos().getZ() * dimDiv);
Original file line number Diff line number Diff line change
@@ -59,6 +59,13 @@ public final class XaeroPlusSettingRegistry {
},
true,
SettingLocation.WORLD_MAP_MAIN);
public static final XaeroPlusBooleanSetting waystonesCrossDimSyncSetting = XaeroPlusBooleanSetting.create(
"Waystones Dimension Sync",
"setting.world_map.cross_dim_waystones_sync",
"setting.world_map.cross_dim_waystones_sync.tooltip",
WaystonesHelper::isWaystonesPresent,
false,
SettingLocation.WORLD_MAP_MAIN);
public static final XaeroPlusBooleanSetting persistMapDimensionSwitchSetting = XaeroPlusBooleanSetting.create(
"Persist WM Dim Switch",
"setting.world_map.persist_dimension_switch",
2 changes: 2 additions & 0 deletions src/main/resources/assets/xaeroplus/lang/en_us.lang
Original file line number Diff line number Diff line change
@@ -92,5 +92,7 @@ gui.xaeroplus.check_github_button=Go to XaeroPlus Github for updates
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.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
setting.world_map.cross_dimension_teleport.tooltip=If the XaeroPlus dimension is switched, also modify teleport commands to that dimension

0 comments on commit 749461e

Please sign in to comment.