Skip to content

Commit

Permalink
Auto Pest Exchange:
Browse files Browse the repository at this point in the history
 = Swapped pathfinder with flying pathfinder until Yuro's proper fix

Auto Repellent:
 + Added auto disable if failed

Auto Sprayonator:
 + Added auto disable if can't find item to spray and buying is disabled

Failsafes:
 = Fixed numerous issues with tping back to garden if out of track
 = Possible fix of Jacob's contest

GameState:
 = Scoreboard:
   = Possible fix for Apec mod users

Pests Destroyer on the track:
 = Possible fix for macro not detecting pests
 = Possible fix for not fully rotating back after killing pests

Rotation:
 = Followable rotation's speed (for example the one in Pests Destroyer on close range) is now independent of fps

Visitors Macro:
 = Swapped pathfinder with flying pathfinder until Yuro's proper fix
  • Loading branch information
May2Beez committed Mar 21, 2024
1 parent 135922b commit 649b861
Show file tree
Hide file tree
Showing 26 changed files with 249 additions and 146 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.5.5-pre1
version=2.5.6
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,7 @@ public FarmHelperConfig() {
// new RotationConfiguration(
// new Target(entity),
// 1000,
// RotationConfiguration.RotationType.SERVER,
// RotationConfiguration.RotationType.CLIENT,
// null
// ).followTarget(true)
// );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ else if (BlockUtils.getRelativeBlock(1, 1, 0).equals(Blocks.bedrock))
FailsafeManager.getInstance().scheduleRandomDelay(800, 200);
break;
case END:
if (MacroHandler.getInstance().isTeleporting()) break;
if (MovRecPlayer.getInstance().isRunning())
break;
this.endOfFailsafeTrigger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,15 @@ public void duringFailsafeTrigger() {
break;
case ROTATE_TO_POS_BEFORE_2:
if (rotation.isRotating()) break;
if (MacroHandler.getInstance().isTeleporting()) break;
FailsafeManager.getInstance().rotation.easeTo(new RotationConfiguration(new Rotation((float) (rotationBeforeReacting.getYaw() + (Math.random() * 30 - 15)), (float) (Math.random() * 30 + 30)),
500, null));
knockbackCheckState = KnockbackCheckState.END;
FailsafeManager.getInstance().scheduleRandomDelay(500, 1000);
break;
case WARP_GARDEN:
if (mc.thePlayer.getPosition().distanceSq(new BlockPos(PlayerUtils.getSpawnLocation())) < 3) {
knockbackCheckState = KnockbackCheckState.ROTATE_TO_POS_BEFORE_2;
break;
}
MacroHandler.getInstance().triggerWarpGarden(true, true);
knockbackCheckState = KnockbackCheckState.ROTATE_TO_POS_BEFORE_2;
FailsafeManager.getInstance().scheduleRandomDelay(3000, 1000);
break;
case END:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,16 @@ public void duringFailsafeTrigger() {
FailsafeManager.getInstance().scheduleDelay(200);
break;
case ROTATE_TO_POS_BEFORE_2:
if (MacroHandler.getInstance().isTeleporting()) break;
if (rotation.isRotating()) break;
FailsafeManager.getInstance().rotation.easeTo(new RotationConfiguration(new Rotation((float) (rotationBeforeReacting.getYaw() + (Math.random() * 30 - 15)), (float) (Math.random() * 30 + 30)),
500, null));
teleportCheckState = TeleportCheckState.END;
FailsafeManager.getInstance().scheduleRandomDelay(500, 1000);
break;
case WARP_GARDEN:
if (mc.thePlayer.getPosition().distanceSq(new BlockPos(PlayerUtils.getSpawnLocation())) < 3) {
teleportCheckState = TeleportCheckState.ROTATE_TO_POS_BEFORE_2;
break;
}
MacroHandler.getInstance().triggerWarpGarden(true, true);
teleportCheckState = TeleportCheckState.ROTATE_TO_POS_BEFORE_2;
FailsafeManager.getInstance().scheduleRandomDelay(3000, 1000);
break;
case END:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void stop() {
LogUtils.sendWarning("[Auto Pest Exchange] Stopping...");
KeyBindUtils.stopMovement();
resetStatesAfterMacroDisabled();
FlyPathFinderExecutor.getInstance().stop();
BaritoneHandler.stopPathing();
}

Expand Down Expand Up @@ -224,7 +225,7 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
break;
}
if (PlayerUtils.isInBarn()) {
state = State.GO_TO_PHILLIP;
state = State.FIND_PHILLIP;
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
stuckClock.schedule(30_000L);
break;
Expand Down Expand Up @@ -255,6 +256,8 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
if (FarmHelperConfig.pestExchangeDeskX == 0 && FarmHelperConfig.pestExchangeDeskY == 0 && FarmHelperConfig.pestExchangeDeskZ == 0) {
LogUtils.sendWarning("[Auto Pest Exchange] The desk position is not set! Trying to find Phillip...");
state = State.FIND_PHILLIP;
FlyPathFinderExecutor.getInstance().setDontRotate(true);
FlyPathFinderExecutor.getInstance().findPath(new Vec3(initialDeskPos).addVector(0.5f, 0.5f, 0.5f), false, true);
} else {
state = State.GO_TO_PHILLIP;
}
Expand All @@ -268,28 +271,30 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
delayClock.schedule(1_000 + Math.random() * 500);
break;
}
if (BaritoneHandler.hasFailed() && initialDeskPos.distanceSq(mc.thePlayer.getPosition()) > 7) {
LogUtils.sendError("[Auto Pest Exchange] Baritone failed to reach the destination!");
state = State.GO_BACK;
break;
}
if (!BaritoneHandler.isWalkingToGoalBlock()) {
BaritoneHandler.walkToBlockPos(initialDeskPos);
delayClock.schedule(250L);
break;
}
// if (BaritoneHandler.hasFailed() && initialDeskPos.distanceSq(mc.thePlayer.getPosition()) > 7) {
// LogUtils.sendError("[Auto Pest Exchange] Baritone failed to reach the destination!");
// state = State.GO_BACK;
// break;
// }
// if (!BaritoneHandler.isWalkingToGoalBlock()) {
// BaritoneHandler.walkToBlockPos(initialDeskPos);
// delayClock.schedule(250L);
// break;
// }
phillip = getPhillip();
if (phillip == null)
break;
if (BlockUtils.getHorizontalDistance(mc.thePlayer.getPositionVector(), phillip.getPositionVector()) < 7) {
BaritoneHandler.stopPathing();
// BaritoneHandler.stopPathing();
FlyPathFinderExecutor.getInstance().stop();
state = State.CLICK_PHILLIP;
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
stuckClock.schedule(30_000L);
break;
}
LogUtils.sendSuccess("[Auto Pest Exchange] Found Phillip! " + phillip.getPosition().toString());
BaritoneHandler.stopPathing();
FlyPathFinderExecutor.getInstance().stop();
// BaritoneHandler.stopPathing();
state = State.GO_TO_PHILLIP;
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
stuckClock.schedule(30_000L);
Expand All @@ -300,31 +305,57 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
delayClock.schedule(1_000 + Math.random() * 500);
break;
}
if (BaritoneHandler.hasFailed() && deskPos().distanceSq(mc.thePlayer.getPosition()) > 7) {
LogUtils.sendError("[Auto Pest Exchange] Baritone failed to reach the destination!");
state = State.GO_BACK;
// if (BaritoneHandler.hasFailed() && deskPos().distanceSq(mc.thePlayer.getPosition()) > 7) {
// LogUtils.sendError("[Auto Pest Exchange] Baritone failed to reach the destination!");
// state = State.GO_BACK;
// break;
// }
// if (BaritoneHandler.isWalkingToGoalBlock())
// break;
if (FlyPathFinderExecutor.getInstance().isRunning()) {
break;
}
if (BaritoneHandler.isWalkingToGoalBlock())
break;
if (Math.sqrt(mc.thePlayer.getDistanceSqToCenter(deskPos())) < 4.5) {
BaritoneHandler.stopPathing();
if (Math.sqrt(mc.thePlayer.getDistanceSqToCenter(deskPos())) < 3.5) {
// BaritoneHandler.stopPathing();
FlyPathFinderExecutor.getInstance().stop();
RotationHandler.getInstance().reset();
state = State.CLICK_PHILLIP;
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
stuckClock.schedule(30_000L);
break;
}
if (isDeskPosSet()) {
LogUtils.sendDebug("[Auto Pest Exchange] Walking to the desk position...");
BaritoneHandler.walkToBlockPos(deskPos());
// BaritoneHandler.walkToBlockPos(deskPos());
FlyPathFinderExecutor.getInstance().setDontRotate(true);
FlyPathFinderExecutor.getInstance().findPath(new Vec3(deskPos()).addVector(0.5f, 0.5f, 0.5f), false, true);
RotationHandler.getInstance().easeTo(
new RotationConfiguration(
new Target(deskPos().up()),
FarmHelperConfig.getRandomRotationTime(),
null
).followTarget(true)
);
state = State.WAIT_UNTIL_REACHED_DESK;
} else if (phillip != null) {
LogUtils.sendDebug("[Auto Pest Exchange] Phillip is found, but the desk position is not set! Walking to Phillip...");
BaritoneHandler.walkCloserToBlockPos(phillip.getPosition(), 2);
// BaritoneHandler.walkCloserToBlockPos(phillip.getPosition(), 2);
Vec3 closestVec = PlayerUtils.getClosestVecAround(phillip, 2.5);
if (closestVec == null) {
LogUtils.sendError("[Auto Pest Exchange] Can't find a valid position around Phillip!");
state = State.GO_BACK;
break;
}
FlyPathFinderExecutor.getInstance().setDontRotate(true);
FlyPathFinderExecutor.getInstance().findPath(closestVec, false, true);
state = State.WAIT_UNTIL_REACHED_DESK;
FarmHelperConfig.pestExchangeDeskX = (int) closestVec.xCoord;
FarmHelperConfig.pestExchangeDeskY = (int) (closestVec.yCoord - 1.4f);
FarmHelperConfig.pestExchangeDeskZ = (int) closestVec.zCoord;
} else {
LogUtils.sendError("[Auto Pest Exchange] Can't find Phillip!");
state = State.GO_BACK;
FarmHelperConfig.autoPestExchange = false;
break;
}
stuckClock.schedule(30_000L);
Expand All @@ -336,14 +367,14 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
delayClock.schedule(1_000 + Math.random() * 500);
break;
}
if (BaritoneHandler.hasFailed()) {
LogUtils.sendError("[Auto Pest Exchange] Baritone failed to reach the destination!");
FlyPathFinderExecutor.getInstance().setDontRotate(true);
FlyPathFinderExecutor.getInstance().findPath(new Vec3(deskPos()).addVector(0.5, 0.5, 0.5), false, true);
break;
}
if (BaritoneHandler.isWalkingToGoalBlock())
break;
// if (BaritoneHandler.hasFailed()) {
//// LogUtils.sendError("[Auto Pest Exchange] Baritone failed to reach the destination!");
//// FlyPathFinderExecutor.getInstance().setDontRotate(true);
//// FlyPathFinderExecutor.getInstance().findPath(new Vec3(deskPos()).addVector(0.5, 0.5, 0.5), false, true);
//// break;
//// }
//// if (BaritoneHandler.isWalkingToGoalBlock())
//// break;
phillip = getPhillip();
if (FlyPathFinderExecutor.getInstance().isRunning()) {
if (phillip == null) {
Expand Down Expand Up @@ -371,7 +402,7 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
}
KeyBindUtils.stopMovement();
LogUtils.sendDebug("[Auto Pest Exchange] Desk position reached!");
BaritoneHandler.stopPathing();
// BaritoneHandler.stopPathing();
FlyPathFinderExecutor.getInstance().stop();
state = State.CLICK_PHILLIP;
stuckClock.schedule(30_000L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
}
int cookieSlot = InventoryUtils.getSlotIdOfItemInInventory("Pest Repellent");
if (cookieSlot == -1) {
LogUtils.sendError("Something went wrong while trying to get the slot of the Pest Repellent! Restarting...");
LogUtils.sendError("Something went wrong while trying to get the slot of the Pest Repellent! Disabling Auto Repellent until manual check");
FarmHelperConfig.autoPestRepellent = false;
stop();
enabled = true;
break;
}
this.hotbarSlot = cookieSlot;
Expand Down Expand Up @@ -301,9 +301,9 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
int repellentSlot = InventoryUtils.getSlotIdOfItemInHotbar(!FarmHelperConfig.pestRepellentType ? "Pest Repellent" : "Pest Repellent MAX");
LogUtils.sendDebug("Repellent slot: " + repellentSlot);
if (repellentSlot == -1 || repellentSlot > 8) {
LogUtils.sendError("Something went wrong while trying to get the slot of the Pest Repellent! Restarting...");
LogUtils.sendError("Something went wrong while trying to get the slot of the Pest Repellent! Disabling Auto Repellent until manual check");
FarmHelperConfig.autoPestRepellent = false;
stop();
enabled = true;
break;
}
mc.thePlayer.inventory.currentItem = repellentSlot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void onTickShouldEnable(TickEvent.ClientTickEvent event) {
System.out.println("Has sprayonator: " + hasSprayonator());
if (!hasSprayonator()) {
LogUtils.sendError("[Auto Sprayonator] Disabling due to no sprayonator");
FarmHelperConfig.autoSprayonatorEnable = false;
return;
}
if (GameStateHandler.getInstance().getSprayonatorState() == GameStateHandler.BuffState.ACTIVE) {
Expand Down Expand Up @@ -411,7 +412,8 @@ public void onClientTick(TickEvent.ClientTickEvent event) {
} else {
stop();
LogUtils.sendError("[Auto Sprayonator] Disabling until restart due to no spray item");
sprayState = AUTO_SPRAYONATOR_STATE.NONE;
FarmHelperConfig.autoSprayonatorEnable = false;
stop();
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
}

if (!FlyPathFinderExecutor.getInstance().isRunning()) {
FlyPathFinderExecutor.getInstance().setSprinting(true);
FlyPathFinderExecutor.getInstance().setDontRotate(false);
FlyPathFinderExecutor.getInstance().findPath(new Vec3(plotCenter.getX(), 80, plotCenter.getZ()), true, true);
}
break;
Expand Down Expand Up @@ -726,10 +728,14 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
y--;
}
y += 3;
FlyPathFinderExecutor.getInstance().setSprinting(false);
FlyPathFinderExecutor.getInstance().setDontRotate(true);
FlyPathFinderExecutor.getInstance().findPath(new Vec3(firework.xCoord, y, firework.zCoord), true, true);
LogUtils.sendWarning("[Pests Destroyer] Firework is too close to player. Flying to x: " + firework.xCoord + " y: " + y + " z: " + firework.zCoord);
break;
}
FlyPathFinderExecutor.getInstance().setSprinting(true);
FlyPathFinderExecutor.getInstance().setDontRotate(false);
FlyPathFinderExecutor.getInstance().findPath(firework, true, true);
}
break;
Expand Down Expand Up @@ -833,6 +839,7 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
}
if (!FlyPathFinderExecutor.getInstance().isRunning()) {
LogUtils.sendDebug("Should pathfind to: " + entity.posX + " " + (entity.posY + 2.75) + " " + entity.posZ);
FlyPathFinderExecutor.getInstance().setSprinting(FarmHelperConfig.sprintWhileFlying);
FlyPathFinderExecutor.getInstance().findPath(entity, true, true, 2.75f, true);
}
if (FlyPathFinderExecutor.getInstance().getState() == FlyPathFinderExecutor.State.FAILED
Expand Down Expand Up @@ -1221,6 +1228,8 @@ public void onSpawnObject(SpawnObjectEvent event) {
y--;
}
y += 3;
FlyPathFinderExecutor.getInstance().setDontRotate(true);
FlyPathFinderExecutor.getInstance().setSprinting(false);
FlyPathFinderExecutor.getInstance().findPath(new Vec3(event.pos.xCoord, y, event.pos.zCoord), true, true);
LogUtils.sendWarning("[Pests Destroyer] Firework is too close to player. Flying to x: " + event.pos.xCoord + " y: " + y + " z: " + event.pos.zCoord);
state = States.GET_LOCATION;
Expand Down
Loading

0 comments on commit 649b861

Please sign in to comment.