-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Baritone goal waypoint sync and right click action to path to goal
- Loading branch information
Showing
6 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package xaeroplus.module.impl; | ||
|
||
import baritone.api.BaritoneAPI; | ||
import baritone.api.pathing.goals.Goal; | ||
import baritone.api.pathing.goals.GoalXZ; | ||
import baritone.api.utils.interfaces.IGoalRenderPos; | ||
import com.collarmc.pounce.Subscribe; | ||
import net.minecraft.util.math.BlockPos; | ||
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.misc.OptimizedMath; | ||
import xaero.map.mods.SupportMods; | ||
import xaeroplus.event.ClientTickEvent; | ||
import xaeroplus.module.Module; | ||
import xaeroplus.util.BaritoneHelper; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Module.ModuleInfo() | ||
public class BaritoneGoalSync extends Module { | ||
|
||
@Subscribe | ||
public void onClientTickEvent(final ClientTickEvent.Post event) { | ||
if (!BaritoneHelper.isBaritonePresent()) return; | ||
XaeroMinimapSession minimapSession = XaeroMinimapSession.getCurrentSession(); | ||
if (minimapSession == null) return; | ||
final WaypointsManager waypointsManager = minimapSession.getWaypointsManager(); | ||
WaypointSet waypointSet = waypointsManager.getWaypoints(); | ||
if (waypointSet == null) return; | ||
final List<Waypoint> waypoints = waypointSet.getList(); | ||
Optional<Waypoint> baritoneGoalWaypoint = waypoints.stream() | ||
.filter(waypoint -> waypoint.getName().equals("Baritone Goal")) | ||
.findFirst(); | ||
final Goal goal = BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().getGoal(); | ||
if (goal == null) { | ||
baritoneGoalWaypoint.ifPresent(waypoint -> removeBaritoneGoalWaypoint(waypoints, waypoint)); | ||
return; | ||
} | ||
final BlockPos baritoneGoalBlockPos = getBaritoneGoalBlockPos(goal); | ||
if (baritoneGoalBlockPos == null) { | ||
baritoneGoalWaypoint.ifPresent(waypoint -> removeBaritoneGoalWaypoint(waypoints, waypoint)); | ||
return; | ||
}; | ||
final double dimDiv = waypointsManager.getDimensionDivision(waypointsManager.getCurrentContainerID()); | ||
final int x = OptimizedMath.myFloor(baritoneGoalBlockPos.getX() * dimDiv); | ||
final int z = OptimizedMath.myFloor(baritoneGoalBlockPos.getZ() * dimDiv); | ||
if (baritoneGoalWaypoint.isPresent()) { | ||
final Waypoint waypoint = baritoneGoalWaypoint.get(); | ||
if (waypoint.getX() != x || | ||
waypoint.getY() != baritoneGoalBlockPos.getY() || | ||
waypoint.getZ() != z) { | ||
waypoint.setX(x); | ||
waypoint.setY(baritoneGoalBlockPos.getY()); | ||
waypoint.setZ(z); | ||
SupportMods.xaeroMinimap.requestWaypointsRefresh(); | ||
} | ||
} else { | ||
final Waypoint waypoint = new Waypoint( | ||
x, | ||
baritoneGoalBlockPos.getY(), | ||
z, | ||
"Baritone Goal", | ||
"B", | ||
10, // green | ||
0, | ||
true); | ||
waypoints.add(waypoint); | ||
SupportMods.xaeroMinimap.requestWaypointsRefresh(); | ||
} | ||
|
||
} | ||
|
||
private void removeBaritoneGoalWaypoint(List<Waypoint> waypoints, Waypoint waypoint) { | ||
if (waypoints.remove(waypoint)) { | ||
SupportMods.xaeroMinimap.requestWaypointsRefresh(); | ||
} | ||
} | ||
|
||
private BlockPos getBaritoneGoalBlockPos(Goal goal) { | ||
if (goal instanceof GoalXZ) { | ||
return new BlockPos(((GoalXZ) goal).getX(), 64, ((GoalXZ) goal).getZ()); | ||
} else if (goal instanceof IGoalRenderPos) { | ||
return ((IGoalRenderPos) goal).getGoalPos(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package xaeroplus.util; | ||
|
||
import baritone.api.BaritoneAPI; | ||
import xaeroplus.XaeroPlus; | ||
|
||
public class BaritoneHelper { | ||
private static boolean isBaritonePresent = false; | ||
private static boolean checked = false; | ||
|
||
public static boolean isBaritonePresent() { | ||
if (!checked) { | ||
try { | ||
Class.forName(BaritoneAPI.class.getName()); | ||
XaeroPlus.LOGGER.info("Found Baritone API. Enabling Baritone support."); | ||
isBaritonePresent = true; | ||
} catch (final Throwable e) { | ||
XaeroPlus.LOGGER.info("Baritone API not found. Disabling Baritone support."); | ||
isBaritonePresent = false; | ||
} | ||
checked = true; | ||
} | ||
return isBaritonePresent; | ||
} | ||
} |