Skip to content

Commit

Permalink
AntiStuck:
Browse files Browse the repository at this point in the history
 = Potential fixes for infinite loop

Auto Pest Hunter:
 + Added flying fallback if walking didn't work

Auto Reconnect:
 = Added fallback if it didn't trigger through packets

Pests Destroyer:
 = Spawnpoint is obstructed - Additional Tweaks
  • Loading branch information
May2Beez committed Mar 10, 2024
1 parent 8fe0558 commit 4b48588
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 30 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.5-pre29
version=2.4.5-pre30
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void onWorldUnloadDetection(WorldEvent.Unload event) {
public void onDisconnectDetection(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
if (!MacroHandler.getInstance().isMacroToggled()) return;
if (triggeredFailsafe.isPresent()) return;
if (FeatureManager.getInstance().shouldIgnoreFalseCheck()) return;
// if (FeatureManager.getInstance().shouldIgnoreFalseCheck()) return;

failsafes.forEach(failsafe -> failsafe.onDisconnectDetection(event));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class DisconnectFailsafe extends Failsafe {
private static DisconnectFailsafe instance;

public static DisconnectFailsafe getInstance() {
if (instance == null) {
instance = new DisconnectFailsafe();
Expand Down Expand Up @@ -51,7 +52,7 @@ public boolean shouldAltTab() {

@Override
public void onDisconnectDetection(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
if (MacroHandler.getInstance().isTeleporting()) return;
// if (MacroHandler.getInstance().isTeleporting()) return;
if (BanInfoWS.getInstance().isBanwave() && FarmHelperConfig.enableLeavePauseOnBanwave && !FarmHelperConfig.banwaveAction)
return;

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/jelly/farmhelperv2/feature/impl/AntiStuck.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ public void onTickUnstuck(TickEvent.ClientTickEvent event) {
delayBetweenMovementsClock.schedule(150 + (int) (Math.random() * 150));
break;
case PRESS:
if (unstuckTries > FarmHelperConfig.antiStuckTriesUntilRewarp) {
LogUtils.sendError("[Anti Stuck] Can't unstuck from this place. That's a rare occurrence. Warping back to spawn...");
KeyBindUtils.stopMovement();
stop();
unstuckTries = 0;
MacroHandler.getInstance().triggerWarpGarden(true, true);
return;
}
if (intersectingBlockPos == null && directionBlockPos == null) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindSneak, mc.gameSettings.keyBindBack);
unstuckState = UnstuckState.RELEASE;
Expand All @@ -228,14 +236,6 @@ public void onTickUnstuck(TickEvent.ClientTickEvent event) {
List<KeyBinding> keys;
if (intersectingBlockPos != null) {
Optional<EnumFacing> closestSide = findClosestSide(intersectingBlockPos);
if (!closestSide.isPresent() || unstuckTries > FarmHelperConfig.antiStuckTriesUntilRewarp) {
LogUtils.sendError("[Anti Stuck] Can't unstuck from this place. That's a rare occurrence. Warping back to spawn...");
KeyBindUtils.stopMovement();
stop();
unstuckTries = 0;
MacroHandler.getInstance().triggerWarpGarden(true, true);
return;
}
EnumFacing facing = closestSide.get();
Vec3 movementTarget = getMovementTarget(intersectingBlockPos, facing);
keys = KeyBindUtils.getNeededKeyPresses(mc.thePlayer.getPositionVector(), movementTarget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.handler.RotationHandler;
import com.jelly.farmhelperv2.pathfinder.FlyPathFinderExecutor;
import com.jelly.farmhelperv2.util.*;
import com.jelly.farmhelperv2.util.helper.Clock;
import com.jelly.farmhelperv2.util.helper.RotationConfiguration;
Expand All @@ -15,9 +16,11 @@
import lombok.Setter;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityArmorStand;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StringUtils;
import net.minecraft.util.Vec3;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
Expand Down Expand Up @@ -111,8 +114,7 @@ public void stop() {
LogUtils.sendWarning("[Auto Pest Hunter] Stopping...");
KeyBindUtils.stopMovement();
resetStatesAfterMacroDisabled();
if (BaritoneHandler.isPathing())
BaritoneHandler.stopPathing();
BaritoneHandler.stopPathing();
}

@Override
Expand Down Expand Up @@ -251,6 +253,10 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
stuckClock.schedule(5_000L);
break;
}
if (PlayerUtils.isPlayerSuffocating()) {
stuckClock.schedule(5_000L);
break;
}
KeyBindUtils.stopMovement();
if (positionBeforeTp.distanceSq(mc.thePlayer.getPosition()) > 7) {
if (FarmHelperConfig.pestHunterDeskX == 0 && FarmHelperConfig.pestHunterDeskY == 0 && FarmHelperConfig.pestHunterDeskZ == 0) {
Expand Down Expand Up @@ -318,6 +324,7 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
if (isDeskPosSet()) {
LogUtils.sendDebug("[Auto Pest Hunter] Walking to the desk position...");
BaritoneHandler.walkToBlockPos(deskPos());
state = State.WAIT_UNTIL_REACHED_DESK;
} else if (phillip != null) {
LogUtils.sendDebug("[Auto Pest Hunter] Phillip is found, but the desk position is not set! Walking to Phillip...");
BaritoneHandler.walkCloserToBlockPos(phillip.getPosition(), 2);
Expand All @@ -338,20 +345,41 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
}
if (BaritoneHandler.hasFailed()) {
LogUtils.sendError("[Auto Pest Hunter] Baritone failed to reach the destination!");
state = State.GO_BACK;
FlyPathFinderExecutor.getInstance().setDontRotate(true);
FlyPathFinderExecutor.getInstance().findPath(new Vec3(deskPos()).addVector(0.5, 0.5, 0.5), false, true);
break;
}
phillip = getPhillip();
if (BaritoneHandler.isPathing())
break;
if (BlockUtils.getHorizontalDistance(mc.thePlayer.getPositionVector(), phillip.getPositionVector()) > 7) {
LogUtils.sendDebug("Distance: " + BlockUtils.getHorizontalDistance(mc.thePlayer.getPositionVector(), phillip.getPositionVector()));
if (FlyPathFinderExecutor.getInstance().isRunning()) {
if (phillip == null) {
break;
}
Entity rotateTo;
if (phillip instanceof EntityArmorStand) {
rotateTo = PlayerUtils.getEntityCuttingOtherEntity(phillip, e -> !(e instanceof EntityArmorStand));
} else {
rotateTo = phillip;
}
if (rotateTo == null) {
break;
}

if (rotation.isRotating()) break;
rotation.easeTo(
new RotationConfiguration(
new Target(rotateTo),
FarmHelperConfig.getRandomRotationTime(),
null
).easeOutBack(true)
);
break;
}
KeyBindUtils.stopMovement();
LogUtils.sendDebug("[Auto Pest Hunter] Desk position reached!");
BaritoneHandler.stopPathing();
FarmHelperConfig.pestHunterDeskX = mc.thePlayer.getPosition().getX();
FarmHelperConfig.pestHunterDeskY = mc.thePlayer.getPosition().getY();
FarmHelperConfig.pestHunterDeskZ = mc.thePlayer.getPosition().getZ();
FlyPathFinderExecutor.getInstance().stop();
state = State.CLICK_PHILLIP;
stuckClock.schedule(30_000L);
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
Expand All @@ -371,16 +399,23 @@ public void onTickExecution(TickEvent.ClientTickEvent event) {
}
if (rotation.isRotating())
break;
MovingObjectPosition mop = mc.objectMouseOver;
if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
Entity entity = mop.entityHit;
Entity armorStand = PlayerUtils.getEntityCuttingOtherEntity(entity, e -> e instanceof EntityArmorStand);
if (entity.getCustomNameTag().contains("Phillip") || armorStand != null && armorStand.getCustomNameTag().contains("Phillip")) {
KeyBindUtils.leftClick();
state = State.WAIT_FOR_GUI;
RotationHandler.getInstance().reset();
stuckClock.schedule(10_000L);
break;
}
}
rotation.easeTo(
new RotationConfiguration(
new Target(phillip),
FarmHelperConfig.getRandomRotationTime(),
() -> {
KeyBindUtils.leftClick();
state = State.WAIT_FOR_GUI;
RotationHandler.getInstance().reset();
stuckClock.schedule(10_000L);
}
null
).easeOutBack(true)
);
delayClock.schedule(FarmHelperConfig.getRandomRotationTime() + 500L);
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/jelly/farmhelperv2/macro/AbstractMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public abstract class AbstractMacro {
private WalkingDirection walkingDirection = WalkingDirection.X;
@Setter
private int previousWalkingCoord = 0;
private boolean hitOnce = false;


public boolean isEnabledAndNoFeature() {
Expand Down Expand Up @@ -113,6 +114,9 @@ public void onTick() {
if (GameStateHandler.getInstance().notMoving() && KeyBindUtils.getHoldingKeybinds().length > 0) {
KeyBindUtils.stopMovement();
}
if (!GameStateHandler.getInstance().notMoving()) {
return;
}
if (GameStateHandler.getInstance().canRewarp()) {
MacroHandler.getInstance().triggerWarpGarden(false, true);
checkOnSpawnClock.schedule(5000);
Expand Down Expand Up @@ -212,6 +216,11 @@ public void onTick() {

PlayerUtils.getTool();

if (!hitOnce) {
KeyBindUtils.onTick(mc.gameSettings.keyBindAttack);
hitOnce = true;
}

// Update or invoke state, based on if player is moving or not
if (GameStateHandler.getInstance().canChangeDirection()) {
KeyBindUtils.stopMovement(FarmHelperConfig.holdLeftClickWhenChangingRow);
Expand Down Expand Up @@ -283,7 +292,6 @@ public void onEnable() {
analyticsClock.schedule(60_000);
if (getCurrentState() == null)
changeState(State.NONE);
KeyBindUtils.onTick(mc.gameSettings.keyBindAttack);
}

public void onDisable() {
Expand All @@ -295,6 +303,7 @@ public void onDisable() {
rotation.reset();
rewarpDelay.reset();
sentWarning = false;
hitOnce = false;
setEnabled(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public void drawScreen(CallbackInfo ci) {
}
}
}

if (!AutoReconnect.getInstance().isRunning() && AutoReconnect.getInstance().isToggled()) {
AutoReconnect.getInstance().getReconnectDelay().schedule(FarmHelperConfig.delayBeforeReconnecting * 1_000L);
AutoReconnect.getInstance().start();
}

if (AutoReconnect.getInstance().isRunning() && AutoReconnect.getInstance().getState() == AutoReconnect.State.CONNECTING) {
multilineMessage = farmHelperV2$multilineMessageCopy;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/jelly/farmhelperv2/util/BlockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ public static boolean canWalkThroughDoor(BlockPos blockPos, Direction direction)
}

private static final Vec3[] BLOCK_SIDE_MULTIPLIERS = new Vec3[]{
new Vec3(-0.45, 0, -0.45),
new Vec3(-0.45, 0, 0.45),
new Vec3(0.45, 0, -0.45),
new Vec3(0.45, 0, 0.45)
new Vec3(-0.25, 0.1, -0.25),
new Vec3(-0.25, 0.1, 0.25),
new Vec3(0.25, 0.1, -0.25),
new Vec3(0.25, 0.1, 0.25)
};

public static boolean canFlyHigher(int distance) {
Expand Down

0 comments on commit 4b48588

Please sign in to comment.