Skip to content

Commit

Permalink
Merge branch '1.20.1' into 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Sep 6, 2024
2 parents 2acc1bf + f3a1c74 commit 6f2d011
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions common/src/main/java/xaeroplus/module/impl/BaritoneGoalSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class BaritoneGoalSync extends Module {
private WeakReference<Waypoint> baritoneWpRef = nullRef;
private WeakReference<WaypointSet> baritoneWpSetRef = nullRef;
private WeakReference<MinimapWorld> baritoneWpMinimapWorldRef = nullRef;
private WeakReference<BlockPos> baritoneGoalPos = nullRef;
private ResourceKey<Level> baritoneWpDimension = OVERWORLD;

@EventHandler
Expand All @@ -40,6 +41,8 @@ public void onClientTickEvent(final ClientTickEvent.Post event) {
if (minimapSession == null) return;
MinimapWorld currentWorld = minimapSession.getWorldManager().getCurrentWorld();
if (currentWorld == null) return;
WaypointSet currentWpSet = currentWorld.getCurrentWaypointSet();
if (currentWpSet == null) return;
try {
final Goal goal = BaritoneGoalHelper.getBaritoneGoal();
if (goal == null) {
Expand All @@ -52,19 +55,21 @@ public void onClientTickEvent(final ClientTickEvent.Post event) {
return;
}

if (baritoneWpRef.get() == null) {
baritoneWpDimension = ChunkUtils.getActualDimension();
if (baritoneGoalPos.get() == null) {
baritoneGoalPos = new WeakReference<>(baritoneGoalBlockPos);
}

if (baritoneWpMinimapWorldRef.get() == null) {
initBaritoneWpWorld(currentWorld);
if (baritoneGoalPos.get() != null && !baritoneGoalPos.get().equals(baritoneGoalBlockPos)) {
clearBaritoneWpAndState();
baritoneGoalPos = new WeakReference<>(baritoneGoalBlockPos);
}

if (currentWorld != baritoneWpMinimapWorldRef.get()) {
Waypoint baritoneWp = this.baritoneWpRef.get();
WaypointSet waypointSet = baritoneWpSetRef.get();
if (waypointSet != null && baritoneWp != null) waypointSet.remove(baritoneWp);
this.baritoneWpRef = nullRef;
if (baritoneWpMinimapWorldRef.get() == null || currentWorld != baritoneWpMinimapWorldRef.get()
|| baritoneWpSetRef.get() == null || baritoneWpSetRef.get() != currentWpSet) {
if (baritoneWpSetRef.get() != null && baritoneWpRef.get() != null) {
baritoneWpSetRef.get().remove(baritoneWpRef.get());
}
baritoneWpRef = nullRef;
initBaritoneWpWorld(currentWorld);
}

Expand Down Expand Up @@ -114,7 +119,7 @@ private double getBaritoneWpDimDiv() {

private void initBaritoneWpWorld(final MinimapWorld currentWorld) {
baritoneWpMinimapWorldRef = new WeakReference<>(currentWorld);
WaypointSet waypointSet = baritoneWpMinimapWorldRef.get().getWaypointSet("gui.xaero_default");
WaypointSet waypointSet = baritoneWpMinimapWorldRef.get().getCurrentWaypointSet();
baritoneWpSetRef = new WeakReference<>(waypointSet);
}

Expand All @@ -123,6 +128,8 @@ private void clearBaritoneWpAndState() {
baritoneWpRef = nullRef;
baritoneWpSetRef = nullRef;
baritoneWpMinimapWorldRef = nullRef;
baritoneGoalPos = nullRef;
baritoneWpDimension = ChunkUtils.getActualDimension();
}

private BlockPos getBaritoneGoalBlockPos(Goal goal) {
Expand Down

0 comments on commit 6f2d011

Please sign in to comment.