Skip to content

Commit

Permalink
= Visitors macro - bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
onixiya1337 committed Jan 8, 2024
1 parent 8e9aa28 commit dcd0a24
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 38 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2
mcVersion=1.8.9
modid=farmhelperv2
modName=FarmHelper
version=2.4.0-pre12
version=2.4.0-pre13
shouldRelease=true
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.jelly.farmhelperv2.feature.impl;

import baritone.api.BaritoneAPI;
import baritone.api.event.events.PathEvent;
import baritone.api.pathing.goals.GoalNear;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import cc.polyfrost.oneconfig.utils.Multithreading;
import com.jelly.farmhelperv2.config.FarmHelperConfig;
import com.jelly.farmhelperv2.feature.FeatureManager;
import com.jelly.farmhelperv2.feature.IFeature;
import com.jelly.farmhelperv2.handler.BaritoneHandler;
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.handler.RotationHandler;
Expand Down Expand Up @@ -169,7 +165,7 @@ public void stop() {
rotation.reset();
PlayerUtils.closeScreen();
KeyBindUtils.stopMovement();
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything();
BaritoneHandler.stopPathing();
}

@Override
Expand Down Expand Up @@ -389,8 +385,7 @@ private void onTravelState() {
}
LogUtils.sendDebug("[Visitors Macro] Closest visitor: " + closest.getCustomNameTag());
if (FarmHelperConfig.visitorsMacroUsePathFinder && mc.thePlayer.getDistance(closest.getPosition().getX(), mc.thePlayer.getPosition().getY(), closest.getPosition().getZ()) > 2.8) {
PathingCommand pathingCommand = new PathingCommand(new GoalNear(closest.getPosition(), 2), PathingCommandType.REVALIDATE_GOAL_AND_PATH);
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().secretInternalSetGoalAndPath(pathingCommand);
BaritoneHandler.walkCloserToBlockPos(closest.getPosition(), 2);
setTravelState(TravelState.END);
pathing = true;
} else {
Expand Down Expand Up @@ -432,7 +427,7 @@ private void onTravelState() {
setTravelState(TravelState.END);
break;
case END:
if (checkForPathingFinish()) return;
if (BaritoneHandler.isWalkingToGoalBlock(1.5)) return;
if (!mc.thePlayer.onGround) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindSneak);
break;
Expand Down Expand Up @@ -664,8 +659,7 @@ private void onVisitorsState() {
}
LogUtils.sendDebug("Position of visitor: " + closest.getPositionEyes(1));
if (FarmHelperConfig.visitorsMacroUsePathFinder && mc.thePlayer.getDistance(closest.getPosition().getX(), mc.thePlayer.getPosition().getY(), closest.getPosition().getZ()) > 2.8) {
PathingCommand pathingCommand = new PathingCommand(new GoalNear(closest.getPosition(), 2), PathingCommandType.REVALIDATE_GOAL_AND_PATH);
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().secretInternalSetGoalAndPath(pathingCommand);
BaritoneHandler.walkCloserToBlockPos(closest.getPosition(), 2);
setVisitorsState(VisitorsState.OPEN_VISITOR);
pathing = true;
} else {
Expand Down Expand Up @@ -716,7 +710,7 @@ private void onVisitorsState() {
delayClock.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
break;
}
if (checkForPathingFinish()) return;
if (BaritoneHandler.isWalkingToGoalBlock(1.5)) return;
if (rotation.isRotating()) return;
assert currentVisitor.isPresent();
if (moveAwayIfPlayerTooClose()) return;
Expand Down Expand Up @@ -936,8 +930,7 @@ private void onVisitorsState() {
}
LogUtils.sendDebug("Position of visitor: " + currentVisitor.get().getPositionEyes(1));
if (FarmHelperConfig.visitorsMacroUsePathFinder && mc.thePlayer.getDistance(currentVisitor.get().getPosition().getX(), mc.thePlayer.getPosition().getY(), currentVisitor.get().getPosition().getZ()) > 2.8) {
PathingCommand pathingCommand = new PathingCommand(new GoalNear(currentVisitor.get().getPosition(), 2), PathingCommandType.REVALIDATE_GOAL_AND_PATH);
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().secretInternalSetGoalAndPath(pathingCommand);
BaritoneHandler.walkCloserToBlockPos(currentVisitor.get().getPosition(), 2);
setVisitorsState(VisitorsState.OPEN_VISITOR);
pathing = true;
setVisitorsState(VisitorsState.OPEN_VISITOR_2);
Expand All @@ -959,7 +952,7 @@ private void onVisitorsState() {
delayClock.schedule(getRandomDelay());
break;
}
if (checkForPathingFinish()) return;
if (BaritoneHandler.isWalkingToGoalBlock(1.5)) return;
if (rotation.isRotating()) return;
assert currentVisitor.isPresent();
if (moveAwayIfPlayerTooClose()) return;
Expand Down Expand Up @@ -1067,24 +1060,6 @@ private Entity getClosestVisitor() {
.orElse(null);
}

private boolean checkForPathingFinish() {
if (pathing) {
if (!mc.thePlayer.onGround) return true;
// Pathing
GoalNear goal = (GoalNear) BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().getGoal();
double distance = mc.thePlayer.getDistance(goal.getGoalPos().getX() + 0.5f, mc.thePlayer.posY, goal.getGoalPos().getZ() + 0.5);
System.out.println(BaritoneEventListener.pathEvent);
if (distance <= 1.5 || BaritoneEventListener.pathEvent == PathEvent.AT_GOAL) {
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything();
pathing = false;
System.out.println("Finished pathing");
return false;
}
return true;
}
return false;
}

private boolean equalsWithoutFormatting(String name1, String name2) {
return StringUtils.stripControlCodes(name1).equals(StringUtils.stripControlCodes(name2));
}
Expand Down Expand Up @@ -1177,6 +1152,7 @@ private void onBuyState() {
LogUtils.sendDebug("[Visitors Macro] Price manipulation detected, skipping...");
rejectVisitor = true;
setVisitorsState(VisitorsState.ROTATE_TO_VISITOR_2);
setBuyState(BuyState.NONE);
delayClock.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
PlayerUtils.closeScreen();
break;
Expand All @@ -1185,6 +1161,7 @@ private void onBuyState() {
LogUtils.sendDebug("[Visitors Macro] Couldn't find " + itemsToBuy.get(0).getLeft() + " amount " + itemsToBuy.get(0).getRight() + ", skipping...");
rejectVisitor = true;
setVisitorsState(VisitorsState.ROTATE_TO_VISITOR_2);
setBuyState(BuyState.NONE);
delayClock.schedule(FarmHelperConfig.getRandomGUIMacroDelay());
PlayerUtils.closeScreen();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import baritone.api.BaritoneAPI;
import baritone.api.event.events.PathEvent;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.pathing.goals.GoalNear;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import com.jelly.farmhelperv2.util.helper.BaritoneEventListener;
Expand All @@ -16,12 +17,16 @@ public class BaritoneHandler {
public static boolean pathing = false;

public static boolean isWalkingToGoalBlock() {
return isWalkingToGoalBlock(0.75);
}

public static boolean isWalkingToGoalBlock(double nearGoalDistance) {
if (pathing) {
if (!mc.thePlayer.onGround) return true;
GoalBlock goal = (GoalBlock) BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().getGoal();
double distance = mc.thePlayer.getDistance(goal.getGoalPos().getX() + 0.5f, mc.thePlayer.posY, goal.getGoalPos().getZ() + 0.5);
System.out.println("Pathing result: " + BaritoneEventListener.pathEvent);
if (distance <= 1.5 || BaritoneEventListener.pathEvent == PathEvent.AT_GOAL) {
if (distance <= nearGoalDistance || BaritoneEventListener.pathEvent == PathEvent.AT_GOAL) {
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything();
pathing = false;
return false;
Expand All @@ -47,6 +52,12 @@ public static void walkToBlockPos(BlockPos blockPos) {
pathing = true;
}

public static void walkCloserToBlockPos(BlockPos blockPos, int range) {
PathingCommand pathingCommand = new PathingCommand(new GoalNear(blockPos, range), PathingCommandType.REVALIDATE_GOAL_AND_PATH);
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().secretInternalSetGoalAndPath(pathingCommand);
pathing = true;
}

public static void stopPathing() {
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything();
pathing = false;
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/jelly/farmhelperv2/handler/MacroHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jelly.farmhelperv2.handler;

import baritone.api.BaritoneAPI;
import cc.polyfrost.oneconfig.utils.Multithreading;
import com.jelly.farmhelperv2.config.FarmHelperConfig;
import com.jelly.farmhelperv2.config.struct.Rewarp;
Expand Down Expand Up @@ -119,6 +120,11 @@ public void toggleMacro() {
if (isMacroToggled()) {
this.disableMacro();
} else {
if (FlyPathfinder.getInstance().isRunning()) {
FlyPathfinder.getInstance().stop();
} else {
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything();
}
if (VisitorsMacro.getInstance().isRunning()) {
VisitorsMacro.getInstance().stop();
return;
Expand Down Expand Up @@ -225,9 +231,8 @@ public void disableMacro() {
setCurrentMacro(Optional.empty());
if (FlyPathfinder.getInstance().isRunning()) {
FlyPathfinder.getInstance().stop();
}
if (BaritoneHandler.isPathing()) {
BaritoneHandler.stopPathing();
} else {
BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().cancelEverything();
}
}

Expand Down

0 comments on commit dcd0a24

Please sign in to comment.