Skip to content

Commit

Permalink
Failsafes:
Browse files Browse the repository at this point in the history
 = A lot of fixes and tweaks

Fly Pathfinder:
 = Decreased amount of false tp or rotation checks during using aote/v

Macros:
 + Lowered minimum time for changing lane from 80ms to 0ms (use it if you want)
 = Tweaks for changing lanes and saving state

Pests Destroyer:
 = Fixed issue of scanning plot names
  • Loading branch information
May2Beez committed Apr 28, 2024
1 parent e616a18 commit 3c703c2
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 62 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.6.11
version=2.6.12
shouldRelease=true
20 changes: 13 additions & 7 deletions src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ public class FarmHelperConfig extends Config {
category = FAILSAFE, subcategory = "Restart After FailSafe",
type = InfoType.INFO, size = 2
)
public static boolean restartAfterFailSafeInfo;

@Switch(
name = "Always teleport to /warp garden after the failsafe",
Expand Down Expand Up @@ -1680,7 +1681,7 @@ public enum SPRAYONATOR_ITEM {
@Slider(
name = "Time between changing rows", category = DELAYS, subcategory = "Changing rows",
description = "The minimum time to wait before changing rows (in milliseconds)",
min = 80, max = 2000
min = 0, max = 2000
)
public static float timeBetweenChangingRows = 400f;
@Slider(
Expand Down Expand Up @@ -1802,10 +1803,10 @@ public enum SPRAYONATOR_ITEM {
//<editor-fold desc="DEBUG">
//<editor-fold desc="Debug">

// @KeyBind(
// name = "Debug Keybind", category = DEBUG, subcategory = "Debug"
// )
// public static OneKeyBind debugKeybind = new OneKeyBind(Keyboard.KEY_NONE);
@KeyBind(
name = "Debug Keybind", category = DEBUG, subcategory = "Debug"
)
public static OneKeyBind debugKeybind = new OneKeyBind(Keyboard.KEY_NONE);
// @KeyBind(
// name = "Debug Keybind 2", category = DEBUG
// )
Expand Down Expand Up @@ -2074,8 +2075,13 @@ public FarmHelperConfig() {

registerKeyBind(openGuiKeybind, this::openGui);
registerKeyBind(toggleMacro, () -> MacroHandler.getInstance().toggleMacro());
// registerKeyBind(debugKeybind, () -> {
// });
registerKeyBind(debugKeybind, () -> {
// if (MacroHandler.getInstance().isCurrentMacroPaused()) {
// MacroHandler.getInstance().resumeMacro();
// } else {
// MacroHandler.getInstance().pauseMacro();
// }
});
registerKeyBind(freelookKeybind, () -> Freelook.getInstance().toggle());
registerKeyBind(plotCleaningHelperKeybind, () -> PlotCleaningHelper.getInstance().toggle());
registerKeyBind(enablePestsDestroyerKeyBind, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,17 @@ public void onTickRestartMacro(TickEvent.ClientTickEvent event) {
PlayerUtils.closeScreen();
}
if (FarmHelperConfig.alwaysTeleportToGarden) {
MacroHandler.getInstance().triggerWarpGarden(true, true);
MacroHandler.getInstance().triggerWarpGarden(true, false);
MacroHandler.getInstance().getCurrentMacro().ifPresent(cm -> cm.setSavedState(Optional.empty()));
}
restartMacroAfterFailsafeDelay.reset();
Multithreading.schedule(() -> {
LogUtils.sendDebug("[Failsafe] Restarting the macro...");
MacroHandler.getInstance().enableMacro();
if (MacroHandler.getInstance().isCurrentMacroPaused()) {
MacroHandler.getInstance().getCurrentMacro().ifPresent(cm -> cm.setSavedState(Optional.empty()));
MacroHandler.getInstance().resumeMacro();
} else
MacroHandler.getInstance().enableMacro();
FailsafeManager.getInstance().setHadEmergency(false);
FailsafeManager.getInstance().getRestartMacroAfterFailsafeDelay().reset();
}, FarmHelperConfig.alwaysTeleportToGarden ? 1_500 : 0, TimeUnit.MILLISECONDS);
Expand Down Expand Up @@ -345,7 +350,9 @@ public void onRenderOverlay(RenderGameOverlayEvent.Post event) {
public void restartMacroAfterDelay() {
if (FarmHelperConfig.enableRestartAfterFailSafe) {
MacroHandler.getInstance().pauseMacro();
MacroHandler.getInstance().getCurrentMacro().ifPresent(cm -> cm.setSavedState(Optional.empty()));
Multithreading.schedule(() -> {
if (!MacroHandler.getInstance().isMacroToggled()) return;
InventoryUtils.openInventory();
LogUtils.sendDebug("[Failsafe] Finished " + (triggeredFailsafe.map(failsafe -> (failsafe.getType().label + " ")).orElse("")) + "failsafe");
if (FarmHelperConfig.enableRestartAfterFailSafe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ else if (BlockUtils.getRelativeBlock(1, 1, 0).equals(Blocks.bedrock))
// FailsafeManager.getInstance().scheduleDelay(200);
// break;
case WARP_GARDEN:
MacroHandler.getInstance().triggerWarpGarden(true, true);
MacroHandler.getInstance().triggerWarpGarden(true, false);
bedrockCageCheckState = BedrockCageCheckState.END;
FailsafeManager.getInstance().scheduleRandomDelay(3000, 1000);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void duringFailsafeTrigger() {
FailsafeManager.getInstance().scheduleRandomDelay(500, 1000);
} else {
if (GameStateHandler.getInstance().getLocation() == GameStateHandler.Location.HUB) {
MacroHandler.getInstance().triggerWarpGarden(true, true);
MacroHandler.getInstance().triggerWarpGarden(true, false);
FailsafeManager.getInstance().scheduleRandomDelay(5500, 2000);
} else {
mc.thePlayer.sendChatMessage("/skyblock");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void duringFailsafeTrigger() {
FailsafeManager.getInstance().scheduleRandomDelay(500, 1000);
break;
case WARP_GARDEN:
MacroHandler.getInstance().triggerWarpGarden(true, true);
MacroHandler.getInstance().triggerWarpGarden(true, false);
knockbackCheckState = KnockbackCheckState.ROTATE_TO_POS_BEFORE_2;
FailsafeManager.getInstance().scheduleRandomDelay(3000, 1000);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void duringFailsafeTrigger() {
break;
case WARP_BACK:
if (GameStateHandler.getInstance().inGarden()) {
MacroHandler.getInstance().triggerWarpGarden(true, true);
MacroHandler.getInstance().triggerWarpGarden(true, false);
FailsafeManager.getInstance().scheduleRandomDelay(500, 1000);
lowerBPSState = LowerBPSState.END;
} else {
Expand All @@ -118,11 +118,6 @@ public void duringFailsafeTrigger() {
(float) (30 + Math.random() * 20 - 10))
, (long) randomTime, null));
FailsafeManager.getInstance().stopFailsafes();
if (FarmHelperConfig.enableRestartAfterFailSafe) {
MacroHandler.getInstance().pauseMacro();
} else {
MacroHandler.getInstance().disableMacro();
}
FailsafeManager.getInstance().restartMacroAfterDelay();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,20 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
double yawDiff = Math.abs(packetYaw - playerYaw);
double pitchDiff = Math.abs(packetPitch - playerPitch);
if (FlyPathFinderExecutor.getInstance().isRunning() && (FlyPathFinderExecutor.getInstance().isTping() || FlyPathFinderExecutor.getInstance().getLastTpTime() + 100 > System.currentTimeMillis() || FlyPathFinderExecutor.getInstance().isRotationInCache((float) packetYaw, (float) packetPitch))) {
LogUtils.sendDebug("[Failsafe] Teleport packet received while Fly pathfinder is running. Ignoring");
LogUtils.sendDebug("tp: " + FlyPathFinderExecutor.getInstance().isTping() + " lastTpTime: " + (FlyPathFinderExecutor.getInstance().getLastTpTime() + 100 > System.currentTimeMillis()) + " isInCache: " + FlyPathFinderExecutor.getInstance().isRotationInCache((float) packetYaw, (float) packetPitch));
if (FlyPathFinderExecutor.getInstance().isTping()) {
LogUtils.sendDebug("[Failsafe] Rotation packet received while Fly pathfinder is teleporting. Ignoring");
return;
}
if (FlyPathFinderExecutor.getInstance().getLastTpTime() + 100 > System.currentTimeMillis()) {
LogUtils.sendDebug("[Failsafe] Rotation packet received while Fly pathfinder is waiting for teleport. Ignoring");
return;
}
if (FlyPathFinderExecutor.getInstance().isRotationInCache((float) packetYaw, (float) packetPitch)) {
LogUtils.sendDebug("[Failsafe] Rotation packet received while Fly pathfinder is in cache. Ignoring");
return;
}
LogUtils.sendDebug("[Failsafe] Rotation packet received while Fly pathfinder is running. Ignoring");
return;
}
if (yawDiff == 360 && pitchDiff == 0) // prevents false checks
Expand Down Expand Up @@ -204,6 +217,7 @@ public void duringFailsafeTrigger() {
if (!FarmHelperConfig.sendFailsafeMessage || Math.random() < 0.3) {
rotationCheckState = RotationCheckState.GO_BACK_START;
FailsafeManager.getInstance().scheduleRandomDelay(300, 600);
break;
}
if (CustomFailsafeMessagesPage.customContinueMessages.isEmpty()) {
randomContinueMessage = FailsafeManager.getRandomContinueMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import net.minecraftforge.fml.common.gameevent.TickEvent;

import java.awt.*;
import java.util.Comparator;
import java.util.Optional;

public class TeleportFailsafe extends Failsafe {
Expand Down Expand Up @@ -90,18 +89,42 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {

S08PacketPlayerPosLook packet = (S08PacketPlayerPosLook) event.packet;
Vec3 currentPlayerPos = mc.thePlayer.getPositionVector();
Vec3 packetPlayerPos = new Vec3(packet.getX(), packet.getY(), packet.getZ());
Vec3 packetPlayerPos = new Vec3(
packet.getX() + (packet.func_179834_f().contains(S08PacketPlayerPosLook.EnumFlags.X) ? currentPlayerPos.xCoord : 0),
packet.getY() + (packet.func_179834_f().contains(S08PacketPlayerPosLook.EnumFlags.Y) ? currentPlayerPos.yCoord : 0),
packet.getZ() + (packet.func_179834_f().contains(S08PacketPlayerPosLook.EnumFlags.Z) ? currentPlayerPos.zCoord : 0)
);

BlockPos packetPlayerBlockPos = new BlockPos(packetPlayerPos);
if (currentPlayerPos.yCoord < 0) {
LogUtils.sendDebug("[Failsafe] Player is below Y = 0. Ignoring");
return;
}
if (FlyPathFinderExecutor.getInstance().isRunning() && (FlyPathFinderExecutor.getInstance().isTping() || FlyPathFinderExecutor.getInstance().getLastTpTime() + 100 > System.currentTimeMillis() || FlyPathFinderExecutor.getInstance().isPositionInCache(packetPlayerBlockPos))) {
LogUtils.sendDebug("tp: " + FlyPathFinderExecutor.getInstance().isTping() + " lastTpTime: " + (FlyPathFinderExecutor.getInstance().getLastTpTime() + 100 > System.currentTimeMillis()) + " isInCache: " + FlyPathFinderExecutor.getInstance().isPositionInCache(packetPlayerBlockPos));
if (FlyPathFinderExecutor.getInstance().isTping()) {
LogUtils.sendDebug("[Failsafe] Teleport packet received while Fly pathfinder is teleporting. Ignoring");
return;
}
if (FlyPathFinderExecutor.getInstance().getLastTpTime() + 100 > System.currentTimeMillis()) {
LogUtils.sendDebug("[Failsafe] Teleport packet received while Fly pathfinder is waiting for teleport. Ignoring");
return;
}
if (FlyPathFinderExecutor.getInstance().isPositionInCache(packetPlayerBlockPos)) {
LogUtils.sendDebug("[Failsafe] Teleport packet received while Fly pathfinder is in cache. Ignoring");
return;
}
LogUtils.sendDebug("[Failsafe] Teleport packet received while Fly pathfinder is running. Ignoring");
return;
}
Comparator<Tuple<BlockPos, AbstractMacro.State>> comparator = Comparator.comparing(Tuple::getFirst, Comparator.reverseOrder());
Optional<Tuple<BlockPos, AbstractMacro.State>> lastWalkedPosition = lastWalkedPositions.stream().filter(pos -> pos.getFirst().equals(packetPlayerBlockPos)).min(comparator);
Optional<Tuple<BlockPos, AbstractMacro.State>> lastWalkedPosition = Optional.empty();
for (int i = lastWalkedPositions.size() - 1; i >= 0; i--) {
Tuple<BlockPos, AbstractMacro.State> pos = lastWalkedPositions.toArray(new Tuple[0])[i];
if (pos.getFirst().equals(packetPlayerBlockPos)) {
lastWalkedPosition = Optional.of(pos);
break;
}
}
if (lastWalkedPosition.isPresent()) {
if (packetPlayerPos.distanceTo(currentPlayerPos) < 1) {
LogUtils.sendDebug("[Failsafe] AntiStuck should trigger there. Ignoring");
Expand All @@ -113,8 +136,9 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
LogUtils.sendFailsafeMessage("[Failsafe] You got lag backed into previous row! Fixing state", FailsafeNotificationsPage.tagEveryoneOnLagBackFailsafe);
if (FailsafeNotificationsPage.notifyOnLagBackFailsafe)
FailsafeUtils.getInstance().sendNotification("You got lag backed into previous row! Fixing state", TrayIcon.MessageType.WARNING);
Optional<Tuple<BlockPos, AbstractMacro.State>> finalLastWalkedPosition = lastWalkedPosition;
MacroHandler.getInstance().getCurrentMacro().ifPresent(macro -> {
macro.setCurrentState(lastWalkedPosition.get().getSecond());
macro.setCurrentState(finalLastWalkedPosition.get().getSecond());
long delay = (long) (1_500 + Math.random() * 1_000);
long delayBefore = Math.max(500, delay - 500);
macro.setBreakTime(delay, delayBefore);
Expand Down Expand Up @@ -335,7 +359,7 @@ public void duringFailsafeTrigger() {
FailsafeManager.getInstance().scheduleRandomDelay(500, 1000);
break;
case WARP_GARDEN:
MacroHandler.getInstance().triggerWarpGarden(true, true);
MacroHandler.getInstance().triggerWarpGarden(true, false);
teleportCheckState = TeleportCheckState.ROTATE_TO_POS_BEFORE_2;
FailsafeManager.getInstance().scheduleRandomDelay(3000, 1000);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void duringFailsafeTrigger() {
return;
} else if (!LagDetector.getInstance().isLagging()) {
LogUtils.sendDebug("[Failsafe] Sending /warp garden command...");
MacroHandler.getInstance().triggerWarpGarden(true, true);
MacroHandler.getInstance().triggerWarpGarden(true, false);
FailsafeManager.getInstance().scheduleRandomDelay(8500, 1000);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void onTickUnstuck(TickEvent.ClientTickEvent event) {
KeyBindUtils.stopMovement();
stop();
unstuckTries = 0;
MacroHandler.getInstance().triggerWarpGarden(true, true);
MacroHandler.getInstance().triggerWarpGarden(true, false);
return;
}
if (intersectingBlockPos == null && directionBlockPos == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void start() {
try {
mc.getNetHandler().getNetworkManager().closeChannel(new ChatComponentText("Reconnecting in " + LogUtils.formatTime(reconnectDelay.getRemainingTime())));
} catch (Exception e) {
e.printStackTrace();
LogUtils.sendDebug("[Reconnect] Failed to close the channel. Probably not in game.");
}
state = State.CONNECTING;
LogUtils.sendDebug("[Reconnect] Reconnecting to the server...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
break;
}
if (!InventoryUtils.isInventoryLoaded()) return;
if (!InventoryUtils.isInventoryLoaded()) break;
if (chestName == null || !chestName.equals("Desk")) {
break;
}
Slot configurePlots = InventoryUtils.getSlotOfItemInContainer("Configure Plots");
if (configurePlots == null) {
return;
break;
}
state = States.WAIT_FOR_INFO;
InventoryUtils.clickContainerSlot(configurePlots.slotNumber, InventoryUtils.ClickType.LEFT, InventoryUtils.ClickMode.PICKUP);
Expand Down Expand Up @@ -1296,7 +1296,6 @@ public void onGuiOpen(DrawScreenAfterEvent event) {
}

} else {
checkedThisGui = true;
return;
}
needToUpdatePlots = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public class GameStateHandler {
private Optional<Integer> serverClosingSeconds = Optional.empty();
@Getter
private int speed = 0;
@Setter
private boolean updatedState = false;

public static GameStateHandler getInstance() {
if (INSTANCE == null) {
Expand Down Expand Up @@ -213,7 +215,7 @@ public void onUpdateScoreboardList(UpdateScoreboardListEvent event) {
}

@SubscribeEvent
public void onTick(TickEvent.PlayerTickEvent event) {
public void onTick(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.END) return;
if (mc.theWorld == null || mc.thePlayer == null) {
return;
Expand Down Expand Up @@ -526,12 +528,14 @@ public void onTickCheckMoving() {
randomValueToWaitNextTime = -1;
notMovingTimer.reset();
randomValueToWait = FarmHelperConfig.getRandomTimeBetweenChangingRows();
updatedState = false;
}
}
}
} else {
notMovingTimer.schedule();
}

float yaw;
if (MacroHandler.getInstance().getCurrentMacro().isPresent() && MacroHandler.getInstance().getCurrentMacro().get().getClosest90Deg().isPresent()) {
yaw = MacroHandler.getInstance().getCurrentMacro().get().getClosest90Deg().get();
Expand All @@ -545,6 +549,7 @@ public void onTickCheckMoving() {
frontWalkable = BlockUtils.canWalkThroughDoor(BlockUtils.Direction.FORWARD) && BlockUtils.canWalkThrough(BlockUtils.getRelativeBlockPos(0, 0, 1, yaw), BlockUtils.Direction.FORWARD);
backWalkable = BlockUtils.canWalkThroughDoor(BlockUtils.Direction.BACKWARD) && BlockUtils.canWalkThrough(BlockUtils.getRelativeBlockPos(0, 0, -1, yaw), BlockUtils.Direction.BACKWARD);
}

rightWalkable = BlockUtils.canWalkThroughDoor(BlockUtils.Direction.RIGHT) && BlockUtils.canWalkThrough(BlockUtils.getRelativeBlockPos(1, 0, 0, yaw), BlockUtils.Direction.RIGHT);
leftWalkable = BlockUtils.canWalkThroughDoor(BlockUtils.Direction.LEFT) && BlockUtils.canWalkThrough(BlockUtils.getRelativeBlockPos(-1, 0, 0, yaw), BlockUtils.Direction.LEFT);
}
Expand Down Expand Up @@ -589,7 +594,7 @@ public boolean hasPassedSinceStopped() {
}

public boolean notMoving() {
if ((dx < 0.01 && dz < 0.01 && dyIsRest() && mc.currentScreen == null)) {
if (dx < 0.01 && dz < 0.01 && dyIsRest() && mc.currentScreen == null) {
return true;
}
return !holdingKeybindIsWalkable() && (playerIsInFlowingWater(0) || playerIsInFlowingWater(1)) && mc.thePlayer.isInWater();
Expand Down Expand Up @@ -625,7 +630,7 @@ public boolean holdingKeybindIsWalkable() {
}

public boolean canChangeDirection() {
return !notMovingTimer.isScheduled();
return !updatedState && !notMovingTimer.isScheduled();
}

public void scheduleNotMoving(int time) {
Expand Down
Loading

0 comments on commit 3c703c2

Please sign in to comment.