Skip to content

Commit

Permalink
Macros:
Browse files Browse the repository at this point in the history
 + Saving last crop in between pauses

Auto Update:
 + You can now trigger auto update from config and with command /fh update

Fly Pathfinder:
 = Change how rotation works, they are slower if it will do 180's, and you can modify the speed of it (don't go too high, otherwise you might loop itself)

Pests Destroyer:
 = Fixes for no tp to plot mode
 + Rotations to pests are slower if it will do 180's
  • Loading branch information
May2Beez committed May 1, 2024
1 parent 77895bf commit 7a02bf5
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 69 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.17
version=2.6.18
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cc.polyfrost.oneconfig.utils.commands.annotations.Main;
import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand;
import com.jelly.farmhelperv2.FarmHelper;
import com.jelly.farmhelperv2.config.FarmHelperConfig;
import com.jelly.farmhelperv2.pathfinder.FlyPathFinderExecutor;
import com.jelly.farmhelperv2.util.LogUtils;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -59,4 +60,9 @@ public void pathfind(int x, int y, int z,
public void stoppath() {
FlyPathFinderExecutor.getInstance().stop();
}

@SubCommand(aliases = {"up"})
public void update() {
FarmHelperConfig.checkForUpdate();
}
}
73 changes: 59 additions & 14 deletions src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.jelly.farmhelperv2.failsafe.FailsafeManager;
import com.jelly.farmhelperv2.failsafe.impl.LowerAvgBpsFailsafe;
import com.jelly.farmhelperv2.feature.impl.*;
import com.jelly.farmhelperv2.gui.AutoUpdaterGUI;
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.hud.DebugHUD;
Expand Down Expand Up @@ -282,6 +283,16 @@ public class FarmHelperConfig extends Config {
size = 2
)
public static boolean autoUpdaterDownloadBetaVersions = false;

@Button(
name = "Check for update", category = MISCELLANEOUS, subcategory = "Miscellaneous",
description = "Checks for updates",
text = "Check for update"
)
Runnable _checkForUpdate = () -> {
FarmHelperConfig.checkForUpdate();
};

@Switch(
name = "Mute The Game", category = MISCELLANEOUS, subcategory = "Miscellaneous",
description = "Mutes the game while farming"
Expand Down Expand Up @@ -391,7 +402,7 @@ public class FarmHelperConfig extends Config {
name = "Auto alt-tab when failsafe triggered", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Automatically alt-tabs to the game when the dark times come"
)
public static boolean autoAltTab = true;
public static boolean autoAltTab = false;
@Switch(
name = "Try to use jumping and flying in failsafes reactions", category = FAILSAFE, subcategory = "Miscellaneous",
description = "Tries to use jumping and flying in failsafes reactions"
Expand Down Expand Up @@ -1089,6 +1100,19 @@ public class FarmHelperConfig extends Config {
)
public static boolean sprintWhileFlying = false;

@Switch(
name = "Use AOTE/V in Pests Destroyer", category = PESTS_DESTROYER, subcategory = "Pests Destroyer",
description = "Uses AOTE/V in Pests Destroyer"
)
public static boolean useAoteVInPestsDestroyer = true;

@Slider(
name = "Failsafe cutoff after using AOTE/V", category = PESTS_DESTROYER, subcategory = "Pests Destroyer",
description = "The time in ms after which macro will count failsafes after using AOTE/V",
min = 0, max = 750
)
public static int failsafeCutoffAfterUsingAoteV = 100;

@Switch(
name = "Don't teleport to plots", category = PESTS_DESTROYER, subcategory = "Pests Destroyer",
description = "Prevents the macro from teleporting to plots"
Expand Down Expand Up @@ -1701,12 +1725,27 @@ public enum SPRAYONATOR_ITEM {
public static float rotationTime = 500f;
@Slider(
name = "Additional random Rotation Time", category = DELAYS, subcategory = "Rotations",
description = "The maximum random time added to the delay time it takes to rotate the player (in seconds)",
description = "The maximum random time added to the delay time it takes to rotate the player (in milliseconds)",
min = 0f, max = 2000f
)
public static float rotationTimeRandomness = 300;
//</editor-fold>

//<editor-fold desc="Fly Pathexecutioner Rotation Time">
@Slider(
name = "Fly PathExecutioner Rotation Time", category = DELAYS, subcategory = "Fly PathExecutioner",
description = "The time it takes to rotate the player",
min = 200f, max = 2000f
)
public static float flyPathExecutionerRotationTime = 500f;
@Slider(
name = "Fly PathExecutioner Additional random Rotation Time", category = DELAYS, subcategory = "Fly PathExecutioner",
description = "The maximum random time added to the delay time it takes to rotate the player (in milliseconds)",
min = 0f, max = 2000f
)
public static float flyPathExecutionerRotationTimeRandomness = 300;
//</editor-fold>

//<editor-fold desc="Pests Destroyer Time">
@Slider(
name = "Pests Destroyer Stuck Time (in minutes)", category = DELAYS, subcategory = "Pests Destroyer",
Expand Down Expand Up @@ -1746,7 +1785,7 @@ public enum SPRAYONATOR_ITEM {
public static float plotCleaningHelperRotationTime = 50;
@Slider(
name = "Additional random Plot Cleaning Helper Rotation Time", category = DELAYS, subcategory = "Plot Cleaning Helper",
description = "The maximum random time added to the delay time it takes to rotate the player (in seconds)",
description = "The maximum random time added to the delay time it takes to rotate the player (in milliseconds)",
min = 0f, max = 500f
)

Expand Down Expand Up @@ -1892,12 +1931,6 @@ public enum SPRAYONATOR_ITEM {
public static boolean autoSwitchTool = true;
//</editor-fold>

@Switch(
name = "Use AOTE/V in Pests Destroyer", category = EXPERIMENTAL, subcategory = "Pests Destroyer",
description = "Uses AOTE/V in Pests Destroyer"
)
public static boolean useAoteVInPestsDestroyer = true;

@Switch(
name = "Count profit based on Cultivating enchant", category = EXPERIMENTAL, subcategory = "Profit Calculator",
description = "Counts profit based on Cultivating enchant"
Expand Down Expand Up @@ -1996,6 +2029,7 @@ public FarmHelperConfig() {
this.addDependency("pestAdditionalGUIDelay", "enablePestsDestroyer");
this.addDependency("sprintWhileFlying", "enablePestsDestroyer");
this.addDependency("pausePestsDestroyerDuringJacobsContest", "enablePestsDestroyer");
this.addDependency("failsafeCutoffAfterUsingAoteV", "useAoteVInPestsDestroyer");


this.hideIf("infoCookieBuffRequired", () -> GameStateHandler.getInstance().inGarden() || GameStateHandler.getInstance().getCookieBuffState() == GameStateHandler.BuffState.NOT_ACTIVE);
Expand Down Expand Up @@ -2076,11 +2110,6 @@ public FarmHelperConfig() {
registerKeyBind(openGuiKeybind, this::openGui);
registerKeyBind(toggleMacro, () -> MacroHandler.getInstance().toggleMacro());
registerKeyBind(debugKeybind, () -> {
if (MacroHandler.getInstance().isCurrentMacroPaused()) {
MacroHandler.getInstance().resumeMacro();
} else {
MacroHandler.getInstance().pauseMacro();
}
});
registerKeyBind(freelookKeybind, () -> Freelook.getInstance().toggle());
registerKeyBind(plotCleaningHelperKeybind, () -> PlotCleaningHelper.getInstance().toggle());
Expand Down Expand Up @@ -2175,6 +2204,10 @@ public static long getRandomRotationTime() {
return (long) (rotationTime + (float) Math.random() * rotationTimeRandomness);
}

public static long getRandomFlyPathExecutionerRotationTime() {
return (long) (flyPathExecutionerRotationTime + (float) Math.random() * flyPathExecutionerRotationTimeRandomness);
}

public static long getRandomGUIMacroDelay() {
return (long) (macroGuiDelay + (float) Math.random() * macroGuiDelayRandomness);
}
Expand All @@ -2195,6 +2228,18 @@ public String getJson() {
return json;
}

public static void checkForUpdate() {
AutoUpdaterGUI.checkedForUpdates = true;
AutoUpdaterGUI.shownGui = false;
AutoUpdaterGUI.getLatestVersion();
if (AutoUpdaterGUI.isOutdated) {
LogUtils.sendWarning("You are using an outdated version! The latest version is " + AutoUpdaterGUI.latestVersion + "!");
AutoUpdaterGUI.showGUI();
} else {
LogUtils.sendSuccess("You are using the latest version!");
}
}

public enum MacroEnum {
S_V_NORMAL_TYPE,
S_PUMPKIN_MELON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,12 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
case WAIT_FOR_INFO:
break;
case TELEPORT_TO_PLOT:
PlotUtils.Plot plot = getClosestPlot();
PlotUtils.Plot plot;
if (FarmHelperConfig.dontTeleportToPlots) {
plot = PlotUtils.getPlotBasedOnNumber(4);
} else {
plot = getClosestPlot();
}
if (plot == null) {
state = States.GO_BACK;
delayClock.schedule((long) (500 + Math.random() * 500));
Expand All @@ -459,42 +464,11 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
state = States.IDLE;
break;
}
if (!mc.thePlayer.getPosition().equals(preTpBlockPos.get())) {
Block northWest = BlockUtils.getRelativeBlock(-0.3f, 0, -0.3f);
Block northWestTop = BlockUtils.getRelativeBlock(-0.3f, 1, -0.3f);

Block northEast = BlockUtils.getRelativeBlock(0.3f, 0, -0.3f);
Block northEastTop = BlockUtils.getRelativeBlock(0.3f, 1, -0.3f);

Block southWest = BlockUtils.getRelativeBlock(-0.3f, 0, 0.3f);
Block southWestTop = BlockUtils.getRelativeBlock(-0.3f, 1, 0.3f);

Block southEast = BlockUtils.getRelativeBlock(0.3f, 0, 0.3f);
Block southEastTop = BlockUtils.getRelativeBlock(0.3f, 1, 0.3f);

if (!northWest.isCollidable() && !northWestTop.isCollidable()
&& !northEast.isCollidable() && !northEastTop.isCollidable()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindLeft);
} else if (!northWest.isCollidable() && !northWestTop.isCollidable()
&& !southWest.isCollidable() && !southWestTop.isCollidable()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindBack);
} else if (!northEast.isCollidable() && !northEastTop.isCollidable()
&& !southEast.isCollidable() && !southEastTop.isCollidable()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindForward);
} else if (!southWest.isCollidable() && !southWestTop.isCollidable()
&& !southEast.isCollidable() && !southEastTop.isCollidable()) {
KeyBindUtils.holdThese(mc.gameSettings.keyBindRight);
} else if (BlockUtils.hasCollision(BlockUtils.getRelativeBlockPos(0, 0, 0)) && !BlockUtils.hasCollision(BlockUtils.getRelativeBlockPos(0, 1, 0))) {
if (mc.thePlayer.onGround) {
mc.thePlayer.jump();
} else {
KeyBindUtils.holdThese(mc.gameSettings.keyBindJump);
Multithreading.schedule(KeyBindUtils::stopMovement, (long) (80 + Math.random() * 50), TimeUnit.MILLISECONDS);
}
}
state = States.CHECKING_PLOT;
delayClock.schedule((long) (200 + Math.random() * 200));
if (mc.thePlayer.getPosition().equals(preTpBlockPos.get())) {
break;
}
state = States.CHECKING_PLOT;
delayClock.schedule((long) (200 + Math.random() * 200));
break;
case CHECKING_PLOT:
if (isInventoryOpenDelayed()) break;
Expand Down Expand Up @@ -537,7 +511,17 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
double distance = Math.sqrt(mc.thePlayer.getDistanceSq(PlotUtils.getPlotCenter(closestPlot.number)));

this.closestPlot = Optional.of(closestPlot);
if (distance > 150 && !isPlotObstructed && !FarmHelperConfig.dontTeleportToPlots) {

if (FarmHelperConfig.dontTeleportToPlots) {
if (PlayerUtils.isPlayerSuffocating() || !BlockUtils.canFlyHigher(3)) {
state = States.TELEPORT_TO_PLOT;
} else {
state = States.FLY_TO_THE_CLOSEST_PLOT;
}
break;
}

if (distance > 150 && !isPlotObstructed) {
state = States.TELEPORT_TO_PLOT;
} else {
state = States.FLY_TO_THE_CLOSEST_PLOT;
Expand Down Expand Up @@ -896,12 +880,12 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
if (distanceToPlot < 150 || FarmHelperConfig.dontTeleportToPlots) {
LogUtils.sendDebug("Going manually to another plot");
state = States.GET_CLOSEST_PLOT;
delayClock.schedule(300 + (long) (Math.random() * 250));
delayClock.schedule(100 + (long) (Math.random() * 150));
break;
} else {
LogUtils.sendDebug("Teleporting to plot");
state = States.TELEPORT_TO_PLOT;
delayClock.schedule(600 + (long) (Math.random() * 500));
delayClock.schedule(400 + (long) (Math.random() * 400));
}
} else {
state = States.GO_BACK;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jelly/farmhelperv2/gui/AutoUpdaterGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class AutoUpdaterGUI extends GuiScreen {
private static final int READ_TIMEOUT = 10000;
public static boolean checkedForUpdates = false;
public static boolean isOutdated = false;
private static boolean shownGui = false;
private static String latestVersion = "";
public static boolean shownGui = false;
public static String latestVersion = "";
private static List<String> releaseMessage = new ArrayList<>();
private static List<String> previousReleasesMessage = new ArrayList<>();
private static final List<String> previousReleasesMessage = new ArrayList<>();
private static List<String> splitReleaseMessage = new ArrayList<>();
private static String downloadURL = null;
private final ExecutorService executor = Executors.newSingleThreadExecutor();
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/com/jelly/farmhelperv2/handler/RotationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ public Rotation getRotation(Vec3 from, Vec3 to, boolean randomness) {
return new Rotation(yaw, pitch);
}

public float distanceTo(Rotation to) {
Rotation neededChange = getNeededChange(to);
return Math.abs(neededChange.getYaw()) + Math.abs(neededChange.getPitch());
}

public boolean shouldRotate(Rotation to) {
return shouldRotate(to, 0.1f);
}
Expand Down Expand Up @@ -266,17 +271,19 @@ public void onRender(RenderWorldLastEvent event) {
if (shouldRotate(targetRotation, 0.1f)) {
float needYaw = (targetRotation.getYaw() - currentYaw);
float needPitch = (targetRotation.getPitch() - currentPitch);
float distance = Math.abs(needYaw) + Math.abs(needPitch);
needYaw *= (float) (0.04f + Math.random() * 0.04f);
needPitch *= (float) (0.04f + Math.random() * 0.04f);
float scaledFps = 60f / Minecraft.getDebugFPS();
needYaw *= scaledFps;
needPitch *= scaledFps;
needYaw /= Math.max(distance / 80, 1);
mc.thePlayer.rotationYaw += needYaw;
if (mc.thePlayer.rotationPitch + needPitch > 63 && needPitch < 0) {
if (mc.thePlayer.rotationPitch + needPitch > 75 && needPitch < 0) {
mc.thePlayer.rotationPitch += needPitch;
} else if (mc.thePlayer.rotationPitch + needPitch < -63 && needPitch > 0) {
} else if (mc.thePlayer.rotationPitch + needPitch < -75 && needPitch > 0) {
mc.thePlayer.rotationPitch += needPitch;
} else if (mc.thePlayer.rotationPitch + needPitch > -63 && mc.thePlayer.rotationPitch + needPitch < 63) {
} else if (mc.thePlayer.rotationPitch + needPitch > -75 && mc.thePlayer.rotationPitch + needPitch < 75) {
mc.thePlayer.rotationPitch += needPitch;
}
}
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/com/jelly/farmhelperv2/macro/AbstractMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,29 +283,33 @@ public void onPacketReceived(ReceivePacketEvent event) {
public abstract void invokeState();

public void onEnable() {
FarmHelperConfig.CropEnum crop = PlayerUtils.getFarmingCrop();
LogUtils.sendDebug("Crop: " + crop);
MacroHandler.getInstance().setCrop(crop);
PlayerUtils.getTool();

GameStateHandler.getInstance().scheduleRewarp();
if (FarmHelperConfig.customPitch) {
setPitch(FarmHelperConfig.customPitchLevel);
}
if (FarmHelperConfig.customYaw) {
setYaw(FarmHelperConfig.customYawLevel);
}
FarmHelperConfig.CropEnum crop;
if (savedState.isPresent()) {
LogUtils.sendDebug("Restoring state: " + savedState.get());
changeState(savedState.get().getState());
setYaw(savedState.get().getYaw());
setPitch(savedState.get().getPitch());
setClosest90Deg(savedState.get().getClosest90Deg());
crop = savedState.get().getCrop();
restoredState = true;
savedState = Optional.empty();
GameStateHandler.getInstance().setUpdatedState(true);
float randomTime = FarmHelperConfig.getRandomTimeBetweenChangingRows();
GameStateHandler.getInstance().scheduleNotMoving((int) Math.max(randomTime, 150));
} else {
crop = PlayerUtils.getFarmingCrop();
}
LogUtils.sendDebug("Crop: " + crop);
MacroHandler.getInstance().setCrop(crop);
PlayerUtils.getTool();
if (!closest90Deg.isPresent())
setClosest90Deg(Optional.of(AngleUtils.getClosest(getYaw())));
setEnabled(true);
Expand All @@ -332,7 +336,7 @@ public void onDisable() {
public void saveState() {
if (!savedState.isPresent()) {
LogUtils.sendDebug("Saving state: " + currentState);
savedState = Optional.of(new SavedState(currentState, getYaw(), getPitch(), closest90Deg.orElse(AngleUtils.getClosest())));
savedState = Optional.of(new SavedState(currentState, getYaw(), getPitch(), closest90Deg.orElse(AngleUtils.getClosest()), MacroHandler.getInstance().getCrop()));
}
}

Expand Down Expand Up @@ -416,12 +420,14 @@ public static class SavedState {
private float yaw;
private float pitch;
private Optional<Float> closest90Deg;
private FarmHelperConfig.CropEnum crop;

public SavedState(State state, float yaw, float pitch, float closest90Deg) {
public SavedState(State state, float yaw, float pitch, float closest90Deg, FarmHelperConfig.CropEnum crop) {
this.state = state;
this.yaw = yaw;
this.pitch = pitch;
this.closest90Deg = Optional.of(closest90Deg);
this.crop = crop;
}

@Override
Expand All @@ -431,6 +437,7 @@ public String toString() {
", yaw=" + yaw +
", pitch=" + pitch +
", closest90Deg=" + closest90Deg +
", crop=" + crop +
'}';
}
}
Expand Down
Loading

0 comments on commit 7a02bf5

Please sign in to comment.