Skip to content

Commit

Permalink
+ AntiStuck - Tweaks and additions, will trigger if got lag back whil…
Browse files Browse the repository at this point in the history
…e farming

= Always Hold W - Fixed changing lane
= Pests Destroyer - Additional kinda fix for false teleport check
+ Additional logs for auto switch tool
= Visitors Macro - Fixed sometimes not accepting profitable drops and speed tweaks
May2Beez committed Dec 16, 2023
1 parent a1c236a commit 8e79069
Showing 10 changed files with 92 additions and 45 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2
mcVersion=1.8.9
modid=farmhelperv2
modName=FarmHelper
version=2.2.0
shouldRelease=true
version=2.2.1
shouldRelease=false
20 changes: 11 additions & 9 deletions src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java
Original file line number Diff line number Diff line change
@@ -1126,6 +1126,7 @@ public enum SPRAYONATOR_ITEM {
size = 2
)
public static boolean pausePestsDestroyerDuringJacobsContest = true;

@Button(
name = "Trigger now Pests Destroyer", category = PESTS_DESTROYER, subcategory = "Pests Destroyer",
description = "Triggers the pests destroyer manually",
@@ -1417,11 +1418,11 @@ public static void triggerManuallyPestsDestroyer() {

//<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(
@KeyBind(
name = "Debug Keybind", category = DEBUG, subcategory = "Debug"
)
public static OneKeyBind debugKeybind = new OneKeyBind(Keyboard.KEY_NONE);
// @KeyBind(
// name = "Debug Keybind 2", category = DEBUG
// )
// public static OneKeyBind debugKeybind2 = new OneKeyBind(Keyboard.KEY_H);
@@ -1489,8 +1490,8 @@ public static void triggerManuallyPestsDestroyer() {

//<editor-fold desc="Auto Switch">
@Switch(
name = "Auto switch tool based on crop", category = EXPERIMENTAL, subcategory = "Auto Switch",
description = "Automatically switches to the best tool based on the crop"
name = "Automatically switch recognized crop", category = EXPERIMENTAL, subcategory = "Auto Switch",
description = "Macro will be recognizing farming crop, which will lead to auto switching tool to the best one"
)
public static boolean autoSwitchTool = true;
//</editor-fold>
@@ -1665,8 +1666,9 @@ public FarmHelperConfig() {

registerKeyBind(openGuiKeybind, this::openGui);
registerKeyBind(toggleMacro, () -> MacroHandler.getInstance().toggleMacro());
// registerKeyBind(debugKeybind, () -> {
// });
registerKeyBind(debugKeybind, () -> {
// AutoRepellent.getInstance().start();
});
registerKeyBind(freelookKeybind, () -> Freelook.getInstance().toggle());
registerKeyBind(plotCleaningHelperKeybind, () -> PlotCleaningHelper.getInstance().toggle());
registerKeyBind(enablePestsDestroyerKeyBind, () -> {
32 changes: 30 additions & 2 deletions src/main/java/com/jelly/farmhelperv2/feature/impl/AntiStuck.java
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import com.jelly.farmhelperv2.util.LogUtils;
import com.jelly.farmhelperv2.util.helper.Clock;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
@@ -42,7 +43,9 @@ public class AntiStuck implements IFeature {
);
private UnstuckState unstuckState = UnstuckState.NONE;
private boolean enabled = false;
@Setter
private BlockPos intersectingBlockPos = null;
private ArrayList<KeyBinding> oppositeKeys = null;

public static AntiStuck getInstance() {
if (instance == null) {
@@ -131,6 +134,20 @@ public void onTick(TickEvent.ClientTickEvent event) {
});
}

private KeyBinding getOppositeKey(KeyBinding key) {
if (key.equals(mc.gameSettings.keyBindForward)) {
return mc.gameSettings.keyBindBack;
} else if (key.equals(mc.gameSettings.keyBindBack)) {
return mc.gameSettings.keyBindForward;
} else if (key.equals(mc.gameSettings.keyBindLeft)) {
return mc.gameSettings.keyBindRight;
} else if (key.equals(mc.gameSettings.keyBindRight)) {
return mc.gameSettings.keyBindLeft;
} else {
return null;
}
}

private Optional<BlockPos> getIntersectingPos() {
BlockPos playerPos = mc.thePlayer.getPosition();

@@ -208,18 +225,28 @@ public void onTickUnstuck(TickEvent.ClientTickEvent event) {
EnumFacing facing = closestSide.get();
Vec3 movementTarget = getMovementTarget(intersectingBlockPos, facing);
List<KeyBinding> keys = getNeededKeyPresses(mc.thePlayer.getPositionVector(), movementTarget);
oppositeKeys = new ArrayList<>();
for (KeyBinding key : keys) {
oppositeKeys.add(getOppositeKey(key));
}
keys.add(mc.gameSettings.keyBindSneak);
keys.add(mc.gameSettings.keyBindAttack);
KeyBindUtils.holdThese(keys.toArray(new KeyBinding[0]));
unstuckState = UnstuckState.RELEASE;
delayBetweenMovementsClock.schedule(150 + (int) (Math.random() * 200));
delayBetweenMovementsClock.schedule(100 + (int) (Math.random() * 100));
break;
case RELEASE:
KeyBindUtils.stopMovement();
unstuckState = UnstuckState.COME_BACK;
delayBetweenMovementsClock.schedule(100 + (int) (Math.random() * 100));
break;
case COME_BACK:
KeyBindUtils.holdThese(oppositeKeys.toArray(new KeyBinding[0]));
unstuckState = UnstuckState.DISABLE;
delayBetweenMovementsClock.schedule(150 + (int) (Math.random() * 200));
delayBetweenMovementsClock.schedule(100 + (int) (Math.random() * 100));
break;
case DISABLE:
KeyBindUtils.stopMovement();
stop();
break;
}
@@ -279,6 +306,7 @@ enum UnstuckState {
NONE,
PRESS,
RELEASE,
COME_BACK,
DISABLE
}

Original file line number Diff line number Diff line change
@@ -178,7 +178,7 @@ public boolean isToggled() {

@Override
public boolean shouldCheckForFailsafes() {
return escapeState == EscapeState.NONE && state != States.TELEPORT_TO_PLOT && state != States.WAIT_FOR_TP;
return escapeState == EscapeState.NONE && state != States.TELEPORT_TO_PLOT && state != States.WAIT_FOR_TP && state != States.GET_LOCATION;
}

public boolean canEnableMacro() {
@@ -1022,7 +1022,7 @@ public void onRender(RenderWorldLastEvent event) {
}

private boolean canEntityBeSeenIgnoreNonCollidable(Entity entity) {
Vec3 vec3 = new Vec3(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
Vec3 vec3 = new Vec3(entity.posX, entity.posY + entity.getEyeHeight() + 0.5, entity.posZ);
Vec3 vec31 = new Vec3(mc.thePlayer.posX, mc.thePlayer.posY + mc.thePlayer.getEyeHeight(), mc.thePlayer.posZ);
MovingObjectPosition mop = mc.theWorld.rayTraceBlocks(vec31, vec3, false, true, false);
return mop == null || mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && mc.theWorld.getBlockState(mop.getBlockPos()).getBlock().equals(Blocks.cactus);
Original file line number Diff line number Diff line change
@@ -440,6 +440,7 @@ private void onTravelState() {
KeyBindUtils.holdThese(mc.gameSettings.keyBindSneak);
break;
}
KeyBindUtils.stopMovement();
if (FarmHelperConfig.visitorsMacroAutosellBeforeServing) {
setMainState(MainState.AUTO_SELL);
} else if (InventoryUtils.hasItemInHotbar("Compactor")) {
@@ -697,7 +698,7 @@ private void onVisitorsState() {
return;
}
if (mc.thePlayer.getDistance(closest2.getPosition().getX(), mc.thePlayer.getPosition().getY(), closest2.getPosition().getZ()) > 2.8) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindForward, shouldJump() ? mc.gameSettings.keyBindJump : null, GameStateHandler.getInstance().getSpeed() > 190 ? mc.gameSettings.keyBindSneak : null);
KeyBindUtils.holdThese(mc.gameSettings.keyBindForward, shouldJump() ? mc.gameSettings.keyBindJump : null, GameStateHandler.getInstance().getSpeed() > 250 ? mc.gameSettings.keyBindSneak : null);
stuckClock.schedule(STUCK_DELAY);
break;
}
@@ -979,7 +980,7 @@ private void onVisitorsState() {
LogUtils.sendDebug("[Visitors Macro] Looking at nothing");
LogUtils.sendDebug("[Visitors Macro] Distance: " + mc.thePlayer.getDistanceToEntity(currentVisitor.get()));
if (mc.thePlayer.getDistanceToEntity(currentVisitor.get()) > 2.8) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindForward, shouldJump() ? mc.gameSettings.keyBindJump : null, GameStateHandler.getInstance().getSpeed() > 190 ? mc.gameSettings.keyBindSneak : null);
KeyBindUtils.holdThese(mc.gameSettings.keyBindForward, shouldJump() ? mc.gameSettings.keyBindJump : null, GameStateHandler.getInstance().getSpeed() > 250 ? mc.gameSettings.keyBindSneak : null);
stuckClock.schedule(STUCK_DELAY);
break;
}
@@ -1091,17 +1092,17 @@ private boolean moveAwayIfPlayerTooClose() {
assert currentVisitor.isPresent();
if (mc.thePlayer.getDistanceToEntity(currentVisitor.get()) < 0.5) {
if (GameStateHandler.getInstance().isBackWalkable()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindBack, GameStateHandler.getInstance().getSpeed() > 190 ? mc.gameSettings.keyBindSneak : null);
KeyBindUtils.holdThese(mc.gameSettings.keyBindBack, GameStateHandler.getInstance().getSpeed() > 250 ? mc.gameSettings.keyBindSneak : null);
Multithreading.schedule(KeyBindUtils::stopMovement, 50, TimeUnit.MILLISECONDS);
return true;
}
if (GameStateHandler.getInstance().isLeftWalkable()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindLeft, GameStateHandler.getInstance().getSpeed() > 190 ? mc.gameSettings.keyBindSneak : null);
KeyBindUtils.holdThese(mc.gameSettings.keyBindLeft, GameStateHandler.getInstance().getSpeed() > 250 ? mc.gameSettings.keyBindSneak : null);
Multithreading.schedule(KeyBindUtils::stopMovement, 50, TimeUnit.MILLISECONDS);
return true;
}
if (GameStateHandler.getInstance().isRightWalkable()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindRight, GameStateHandler.getInstance().getSpeed() > 190 ? mc.gameSettings.keyBindSneak : null);
KeyBindUtils.holdThese(mc.gameSettings.keyBindRight, GameStateHandler.getInstance().getSpeed() > 250 ? mc.gameSettings.keyBindSneak : null);
Multithreading.schedule(KeyBindUtils::stopMovement, 50, TimeUnit.MILLISECONDS);
return true;
}
@@ -1112,18 +1113,15 @@ private boolean moveAwayIfPlayerTooClose() {
}

private void checkIfCurrentVisitorIsProfitable() {
if (itemsToBuy.stream().anyMatch(item -> {
String name = StringUtils.stripControlCodes(item.getLeft());
Optional<Tuple<String, String>> profitableReward = currentRewards.stream().filter(item -> {
String name = StringUtils.stripControlCodes(item.getFirst());
return profitRewards.stream().anyMatch(reward -> reward.contains(name));
})) {
}).findFirst();
if (profitableReward.isPresent()) {
LogUtils.sendDebug("[Visitors Macro] The visitor is profitable");
String profitableReward = itemsToBuy.stream().filter(item -> {
String name = StringUtils.stripControlCodes(item.getLeft());
return profitRewards.stream().anyMatch(reward -> reward.contains(name));
}).findFirst().get().getLeft();

String reward = profitableReward.get().getFirst();
if (FarmHelperConfig.sendVisitorsMacroLogs)
LogUtils.webhookLog("[Visitors Macro]\\nVisitors Macro found profitable item: " + profitableReward, FarmHelperConfig.pingEveryoneOnVisitorsMacroLogs);
LogUtils.webhookLog("[Visitors Macro]\\nVisitors Macro found profitable item: " + reward, FarmHelperConfig.pingEveryoneOnVisitorsMacroLogs);
LogUtils.sendDebug("[Visitors Macro] Accepting offer...");
} else {
LogUtils.sendWarning("[Visitors Macro] The visitor is not profitable, skipping...");
3 changes: 3 additions & 0 deletions src/main/java/com/jelly/farmhelperv2/macro/AbstractMacro.java
Original file line number Diff line number Diff line change
@@ -32,6 +32,8 @@ public abstract class AbstractMacro {
@Setter
public State currentState = State.NONE;
@Setter
public State previousState = State.NONE;
@Setter
private boolean enabled = false;
@Setter
private Optional<SavedState> savedState = Optional.empty();
@@ -291,6 +293,7 @@ public void clearSavedState() {

public void changeState(State state) {
LogUtils.sendDebug("Changing state from " + currentState + " to " + state);
setPreviousState(currentState);
setCurrentState(state);
}

Original file line number Diff line number Diff line change
@@ -242,14 +242,14 @@ public void invokeState() {
switch (getCurrentState()) {
case RIGHT:
KeyBindUtils.holdThese(
isHuggingBackWall() || FarmHelperConfig.alwaysHoldW ? mc.gameSettings.keyBindForward : null,
isHuggingBackWall() ? mc.gameSettings.keyBindForward : null,
mc.gameSettings.keyBindRight,
mc.gameSettings.keyBindAttack
);
break;
case LEFT: {
KeyBindUtils.holdThese(
isHuggingBackWall() || FarmHelperConfig.alwaysHoldW ? mc.gameSettings.keyBindForward : null,
isHuggingBackWall() ? mc.gameSettings.keyBindForward : null,
mc.gameSettings.keyBindLeft,
mc.gameSettings.keyBindAttack
);
Original file line number Diff line number Diff line change
@@ -137,7 +137,6 @@ private enum LookDirection {
}

private LookDirection mushroom45DegreeSide() {
System.out.println(getClosest90Deg());
if (!getClosest90Deg().isPresent()) return LookDirection.LEFT;
EnumFacing facing = PlayerUtils.getHorizontalFacing(getClosest90Deg().get());
double yaw180 = UMath.wrapAngleTo180(getYaw());
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jelly.farmhelperv2.macro.impl;

import com.jelly.farmhelperv2.config.FarmHelperConfig;
import com.jelly.farmhelperv2.feature.impl.AntiStuck;
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.macro.AbstractMacro;
@@ -28,7 +29,7 @@ public void updateState() {
// Probably stuck in dirt, continue going right
return;
}
if (GameStateHandler.getInstance().isFrontWalkable()) {
if (GameStateHandler.getInstance().isFrontWalkable() && !FarmHelperConfig.alwaysHoldW) {
if (changeLaneDirection == ChangeLaneDirection.BACKWARD) {
// Probably stuck in dirt
changeState(State.NONE);
@@ -37,7 +38,7 @@ public void updateState() {
changeState(State.SWITCHING_LANE);
changeLaneDirection = ChangeLaneDirection.FORWARD;
setWalkingDirection();
} else if (GameStateHandler.getInstance().isBackWalkable()) {
} else if (GameStateHandler.getInstance().isBackWalkable() && !FarmHelperConfig.alwaysHoldW) {
if (changeLaneDirection == ChangeLaneDirection.FORWARD) {
// Probably stuck in dirt
changeState(State.NONE);
@@ -62,16 +63,10 @@ public void updateState() {
case SWITCHING_LANE: {
if (getWalkingDirection() == WalkingDirection.X) {
int currentZ = mc.thePlayer.getPosition().getZ();
if (Math.abs(currentZ - getPreviousWalkingCoord()) < 1) {
LogUtils.sendWarning("Probability of lag back detected! Still going forward...");
break;
}
if (lagBackDetected(currentZ)) break;
} else if (getWalkingDirection() == WalkingDirection.Z) {
int currentX = mc.thePlayer.getPosition().getX();
if (Math.abs(currentX - getPreviousWalkingCoord()) < 1) {
LogUtils.sendWarning("Probability of lag back detected! Still going forward...");
break;
}
if (lagBackDetected(currentX)) break;
}
if (GameStateHandler.getInstance().isLeftWalkable()) {
changeState(State.LEFT);
@@ -120,6 +115,26 @@ public void updateState() {
}
}

private boolean lagBackDetected(int currentCoord) {
if (Math.abs(currentCoord - getPreviousWalkingCoord()) < 1) {
if (getPreviousState() == State.LEFT) {
AntiStuck.getInstance().setIntersectingBlockPos(BlockUtils.getRelativeBlockPos(-1, 0, 0, getYaw()));
} else if (getPreviousState() == State.RIGHT) {
AntiStuck.getInstance().setIntersectingBlockPos(BlockUtils.getRelativeBlockPos(1, 0, 0, getYaw()));
} else {
if (getCurrentState() == State.LEFT) {
AntiStuck.getInstance().setIntersectingBlockPos(BlockUtils.getRelativeBlockPos(-1, 0, 0, getYaw()));
} else if (getCurrentState() == State.RIGHT) {
AntiStuck.getInstance().setIntersectingBlockPos(BlockUtils.getRelativeBlockPos(1, 0, 0, getYaw()));
}
}
AntiStuck.getInstance().start();
LogUtils.sendWarning("Probability of lag back detected!");
return true;
}
return false;
}

@Override
public void invokeState() {
if (getCurrentState() == null) return;
8 changes: 5 additions & 3 deletions src/main/java/com/jelly/farmhelperv2/util/PlayerUtils.java
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
import net.minecraft.block.*;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityArmorStand;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.*;
@@ -116,10 +115,13 @@ public static void getTool() {
return;
}

changeItemEveryClock.schedule(2_000L);
changeItemEveryClock.schedule(1_500L);
int id = PlayerUtils.getFarmingTool(MacroHandler.getInstance().getCrop(), true, false);
if (id == -1) {
LogUtils.sendDebug("No tool found!");
return;
}
LogUtils.sendDebug("Tool id: " + id);
if (id == -1) return;
LogUtils.sendDebug("Current item: " + mc.thePlayer.inventory.currentItem);
if (id == mc.thePlayer.inventory.currentItem) return;
mc.thePlayer.inventory.currentItem = id;

0 comments on commit 8e79069

Please sign in to comment.