Skip to content

Commit

Permalink
= Pests Destroyer - Tweaks for deceleration
Browse files Browse the repository at this point in the history
= Auto God Pot - Fixed detections of message
  • Loading branch information
May2Beez committed Jan 12, 2024
1 parent 141a5a6 commit 67abd7b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 41 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.1-pre7
version=2.4.1-pre8
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ public void onChatReceived(ClientChatReceivedEvent event) {
}
}
if (consumePotState == ConsumePotState.WAIT_FOR_CONSUME) {
if (message.startsWith("GULP! The God Potion grants you powers for")) {
if (message.contains("The God Potion grants you powers for") && !message.contains(":")) {
if (this.hotbarSlot != -1) {
setMovePotState(MovePotState.PUT_ITEM_BACK_PICKUP);
setConsumePotState(ConsumePotState.MOVE_POT_TO_HOTBAR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class PestsDestroyer implements IFeature {
private Optional<Vec3> lastFireworkLocation = Optional.empty();
private long lastFireworkTime = 0;
private int getLocationTries = 0;
private RotationState rotationState = RotationState.NONE;

public static PestsDestroyer getInstance() {
if (instance == null) {
Expand Down Expand Up @@ -164,6 +165,8 @@ public void stop() {
enabled = false;
lastFireworkTime = 0;
getLocationTries = 0;
finishTries = 0;
rotationState = RotationState.NONE;
FlyPathfinder.getInstance().stuckCounterWithMotion = 0;
FlyPathfinder.getInstance().stuckCounterWithoutMotion = 0;
state = States.IDLE;
Expand Down Expand Up @@ -754,6 +757,10 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
}
break;
}
if (rotationState != RotationState.CLOSE) {
rotationState = RotationState.CLOSE;
RotationHandler.getInstance().reset();
}
if (!RotationHandler.getInstance().isRotating()) {
Rotation rotation2 = RotationHandler.getInstance().getRotation(entity);
Rotation neededRotation = new Rotation(rotation2.getYaw(), rotation2.getPitch() + 10);
Expand Down Expand Up @@ -788,13 +795,18 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
break;
}

if (distance <= 18 || distanceXZ <= 2) {
if (distance <= 12 || distanceXZ <= 2) {
if (!mc.thePlayer.capabilities.isFlying && entity.posY + entity.getEyeHeight() + 1 - mc.thePlayer.posY >= 2) {
flyAwayFromGround();
delayClock.schedule(350);
break;
}

if (rotationState != RotationState.MEDIUM) {
rotationState = RotationState.MEDIUM;
RotationHandler.getInstance().reset();
}

manipulateHeight(entity, distance, distanceXZ, yawDifference);
if (!RotationHandler.getInstance().isRotating()) {
Rotation rotation3 = RotationHandler.getInstance().getRotation(entity);
Expand All @@ -819,6 +831,11 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
break;
}

if (rotationState != RotationState.FAR) {
rotationState = RotationState.FAR;
RotationHandler.getInstance().reset();
}

boolean objects2 = objectsInFrontOfPlayer();

if (!GameStateHandler.getInstance().isLeftWalkable() && GameStateHandler.getInstance().isRightWalkable()) {
Expand Down Expand Up @@ -1031,34 +1048,27 @@ private void flyAwayFromStructures() {
}
}

private int finishTries = 0;

private void finishMacro() {
if (isInventoryOpen()) return;
stop();
if (MacroHandler.getInstance().isMacroToggled()) {
if (PlayerUtils.isStandingOnSpawnPoint()) {
stop();
MacroHandler.getInstance().resumeMacro();
return;
}
if (finishTries == 7) {
LogUtils.sendError("[Pests Destroyer] Couldn't enable macro after teleportation!");
LogUtils.webhookLog("[Pests Destroyer] Couldn't enable macro after teleportation!");
MacroHandler.getInstance().disableMacro();
return;
}
MacroHandler.getInstance().triggerWarpGarden(true, true);
Multithreading.schedule(() -> {
for (int tries = 1; tries <= 7; tries++) {
LogUtils.sendDebug("Trying to enable macro after teleportation: " + tries);
try {
if (!MacroHandler.getInstance().isLastWarpGardenSuccessful()) {
Thread.sleep(750 * tries);
MacroHandler.getInstance().triggerWarpGarden(true, true);
continue;
}
if (MacroHandler.getInstance().isCurrentMacroPaused()) {
LogUtils.sendDebug("Enabling macro after teleportation");
MacroHandler.getInstance().resumeMacro();
break;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
if (tries == 7) {
LogUtils.sendError("[Pests Destroyer] Couldn't enable macro after teleportation!");
LogUtils.webhookLog("[Pests Destroyer] Couldn't enable macro after teleportation!");
}
}
}, 1_500 + (long) (Math.random() * 1_500), TimeUnit.MILLISECONDS);
finishTries++;
delayClock.schedule(1_000 + Math.random() * 500);
} else {
stop();
}
}

Expand Down Expand Up @@ -1508,6 +1518,13 @@ enum States {
GO_BACK
}

enum RotationState {
NONE,
CLOSE,
MEDIUM,
FAR
}

public enum EscapeState {
NONE,
GO_TO_HUB,
Expand Down
18 changes: 4 additions & 14 deletions src/main/java/com/jelly/farmhelperv2/util/KeyBindUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,9 @@ public static List<KeyBinding> getNeededKeyPresses(Vec3 orig, Vec3 dest) {
}

public static List<KeyBinding> getKeyPressesToDecelerate() {
double motionX = mc.thePlayer.motionX;
double motionZ = mc.thePlayer.motionZ;
List<KeyBinding> keys = new ArrayList<>();
if (motionX > 0.1) {
keys.add(mc.gameSettings.keyBindLeft);
} else if (motionX < -0.1) {
keys.add(mc.gameSettings.keyBindRight);
}
if (motionZ > 0.1) {
keys.add(mc.gameSettings.keyBindBack);
} else if (motionZ < -0.1) {
keys.add(mc.gameSettings.keyBindForward);
}
return keys;
if (Math.abs(mc.thePlayer.motionX) < 0.05 && Math.abs(mc.thePlayer.motionZ) < 0.05) return new ArrayList<>();
Vec3 orig = mc.thePlayer.getPositionVector();
Vec3 dest = mc.thePlayer.getPositionVector().addVector(Math.abs(mc.thePlayer.motionX) >= 0.05 ? -mc.thePlayer.motionX : 0, 0, Math.abs(mc.thePlayer.motionZ) >= 0.05 ? -mc.thePlayer.motionZ : 0);
return getNeededKeyPresses(orig, dest);
}
}

0 comments on commit 67abd7b

Please sign in to comment.