diff --git a/gradle.properties b/gradle.properties index 0323d62c..7af6b265 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2 mcVersion=1.8.9 modid=farmhelperv2 modName=FarmHelper -version=2.8.14 +version=2.9.0 shouldRelease=true diff --git a/src/main/java/com/jelly/farmhelperv2/command/FarmHelperMainCommand.java b/src/main/java/com/jelly/farmhelperv2/command/FarmHelperMainCommand.java index 0fd0b219..9c1bc20f 100644 --- a/src/main/java/com/jelly/farmhelperv2/command/FarmHelperMainCommand.java +++ b/src/main/java/com/jelly/farmhelperv2/command/FarmHelperMainCommand.java @@ -6,6 +6,7 @@ import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; import com.jelly.farmhelperv2.FarmHelper; import com.jelly.farmhelperv2.config.FarmHelperConfig; +import com.jelly.farmhelperv2.feature.impl.AutoWardrobe; import com.jelly.farmhelperv2.handler.GameStateHandler; import com.jelly.farmhelperv2.pathfinder.FlyPathFinderExecutor; import com.jelly.farmhelperv2.util.LogUtils; @@ -68,9 +69,4 @@ public void update() { PlayerUtils.closeScreen(); FarmHelperConfig.checkForUpdate(); } - - @SubCommand - public void test(){ - LogUtils.sendSuccess("SprayonatorState: " + GameStateHandler.getInstance().getSprayonatorState()); - } -} +} \ No newline at end of file diff --git a/src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java b/src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java index 70a5562e..04743128 100644 --- a/src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java +++ b/src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java @@ -43,6 +43,7 @@ // THIS IS RAT - CatalizCS @SuppressWarnings({"unused", "DefaultAnnotationParam"}) public class FarmHelperConfig extends Config { + private transient static final Minecraft mc = Minecraft.getMinecraft(); private transient static final String GENERAL = "General"; private transient static final String MISCELLANEOUS = "Miscellaneous"; @@ -51,6 +52,7 @@ public class FarmHelperConfig extends Config { private transient static final String JACOBS_CONTEST = "Jacob's Contest"; private transient static final String VISITORS_MACRO = "Visitors Macro"; private transient static final String PESTS_DESTROYER = "Pests Destroyer"; + private transient static final String PEST_FARMER = "Pest Farmer"; private transient static final String AUTO_PEST_EXCHANGE = "Auto Pest Exchange"; private transient static final String AUTO_GOD_POT = "Auto God Pot"; private transient static final String AUTO_SELL = "Auto Sell"; @@ -802,26 +804,26 @@ public class FarmHelperConfig extends Config { ) public static boolean openInventoryOnSchedulerBreaks = true; @Switch( - name = "Disconnect during break", category = SCHEDULER, subcategory = "Scheduler", - description = "Logs out of game and logs back in after break ends" + name = "Disconnect during break", category = SCHEDULER, subcategory = "Scheduler", + description = "Logs out of game and logs back in after break ends" ) public static boolean schedulerDisconnectDuringBreak = false; @Switch( - name = "Wait Until Rewarp Point for break", category = SCHEDULER, subcategory = "Scheduler", - description = "Waits until player is standing on rewarp point to take break" + name = "Wait Until Rewarp Point for break", category = SCHEDULER, subcategory = "Scheduler", + description = "Waits until player is standing on rewarp point to take break" ) public static boolean schedulerWaitUntilRewarp = false; @Switch( - name = "Reset Scheduler on Macro Disabled", category = SCHEDULER, subcategory = "Scheduler", - description = "Resets Scheduler When macro is disabled" + name = "Reset Scheduler on Macro Disabled", category = SCHEDULER, subcategory = "Scheduler", + description = "Resets Scheduler When macro is disabled" ) public static boolean schedulerResetOnDisable = true; @Button( - name = "Reset Scheduler", category = SCHEDULER, subcategory = "Scheduler", - text = "Reset Scheduler", description = "Resets Scheduler (Only works when macro is of)" + name = "Reset Scheduler", category = SCHEDULER, subcategory = "Scheduler", + text = "Reset Scheduler", description = "Resets Scheduler (Only works when macro is of)" ) public Runnable schedulerReset = () -> { - if(!MacroHandler.getInstance().isMacroToggled()){ + if (!MacroHandler.getInstance().isMacroToggled()) { boolean old = FarmHelperConfig.schedulerResetOnDisable; FarmHelperConfig.schedulerResetOnDisable = true; Scheduler.getInstance().stop(); @@ -1196,6 +1198,11 @@ public class FarmHelperConfig extends Config { ) public static int pestAdditionalGUIDelay = 0; + @Switch( + name = "Force Enable Pest Destroyer at X Pests", category = PESTS_DESTROYER, subcategory = "Pests Destroyer" + ) + public static boolean pestForceEnable = false; + @Switch( name = "Sprint while flying", category = PESTS_DESTROYER, subcategory = "Pests Destroyer", description = "Sprints while flying" @@ -1290,11 +1297,35 @@ public static void triggerManuallyPestsDestroyer() { size = 2 ) public static OneKeyBind enablePestsDestroyerKeyBind = new OneKeyBind(Keyboard.KEY_NONE); + // + + // + @Switch( + name = "Swap Armor Before Killing", category = PESTS_DESTROYER, subcategory = "Armor Swapper" + ) + public static boolean pestSwapArmorBefore = false; + + @Slider( + name = "Wardrobe Slot To Kill With", category = PESTS_DESTROYER, subcategory = "Armor Swapper", + description = "Wardrobe slot to use before turning on pest destroyer", + min = 1, max = 18 + ) + public static int pestArmorSlot0 = 1; + + @Switch( + name = "Swap Armor After Killing", category = PESTS_DESTROYER, subcategory = "Armor Swapper" + ) + public static boolean pestSwapArmorAfter = false; + @Slider( + name = "Wardrobe Slot To Farm With", category = PESTS_DESTROYER, subcategory = "Armor Swapper", + description = "Wardrobe slot to equip after turning off pest destroyer", + min = 1, max = 18 + ) + public static int pestArmorSlot1 = 1; // // - @Switch( name = "Pests ESP", category = PESTS_DESTROYER, subcategory = "Drawings", description = "Draws a box around pests" @@ -1350,6 +1381,81 @@ public static void triggerManuallyPestsDestroyer() { // // + // + @Header( + text = "Read the comments below this page before using pest farmer.", + category = PEST_FARMER, size = 2 + ) + public static boolean ignored1; + + @Switch( + name = "Enable Pest Farming", category = PEST_FARMER, + description = "Enables Pest Farming" + ) + public static boolean pestFarming = false; + + @Switch( + name = "Hold Daedalus Axe", category = PEST_FARMER, + description = "Farms with daedalus axe while waiting for pests to spawn" + ) + public static boolean pestFarmingHoldDaedalus = false; + + @Slider( + name = "Farming Armor Slot", category = PEST_FARMER, + min = 1, max = 18 + ) + public static int pestFarmingSet0Slot = 1; + + @Slider( + name = "Pest Chance Armor Slot", category = PEST_FARMER, + min = 1, max = 18 + ) + public static int pestFarmingSet1Slot = 1; + + @Slider( + name = "Pest Spawn Timer (In seconds)", category = PEST_FARMER, + description = "The time it should wait after pests spawn to swap slots (should be your pest spawn time - 5/10 seconds)", + min = 30, max = 300 + ) + public static int pestFarmingWaitTime = 255; + + @Info( + text = "It's supposed to swap armor before pest spawns, swap back after pest spawns and kill with Pest Destryoer/the other one.", + type = InfoType.INFO, category = PEST_FARMER, size = 2 + ) + public static boolean ignored0; + @Info( + text = "Use this Auto-Pet Rule:", + type = InfoType.INFO, category = PEST_FARMER, size = 2 + ) + public static boolean ignored2; + @Info( + text = " 1. On Gain Crop Collection -> Farming Pet, Except if slug is Equipped", + type = InfoType.INFO, category = PEST_FARMER, size = 2 + ) + public static boolean ignored3; + @Info( + text = " 2. On Equip Farming Armor -> Farming Pet", + type = InfoType.INFO, category = PEST_FARMER, size = 2 + ) + public static boolean ignored4; + @Info( + text = " 3. On Equip Pest Chance Armor -> Slug Pet", + type = InfoType.INFO, category = PEST_FARMER, size = 2 + ) + public static boolean ignored5; + @Info( + text = " 4. On Enter Combat -> Hedgehog Pet", + type = InfoType.INFO, category = PEST_FARMER, size = 2 + ) + public static boolean ignored6; + @Info( + text = "Use Armor Swapper in Pest Destroyer. Swap to Farming Armor On Start Just in case Pest Farmer doesn't do that itself.", + type = InfoType.INFO, category = PEST_FARMER, size = 2 + ) + public static boolean ignored7; + + // // // @Switch( @@ -1973,7 +2079,7 @@ public static void triggerManuallyAutoPestExchange() { name = "Reset stats between disabling", category = HUD, subcategory = "Profit Calculator" ) public static boolean resetStatsBetweenDisabling = false; -// @Button( + // @Button( // name = "Reset Profit Calculator", category = HUD, subcategory = "Profit Calculator", // text = "Reset Now", size = 2 // ) @@ -2008,7 +2114,6 @@ public static void triggerManuallyAutoPestExchange() { ) public static boolean debugMode = false; - // // @@ -2089,7 +2194,6 @@ public static void triggerManuallyAutoPestExchange() { ) public static boolean showDebugLogsAboutPDOTT = false; - // @Number(name = "Config Version", category = EXPERIMENTAL, subcategory = "Experimental", min = 0, max = 1337) @@ -2182,8 +2286,8 @@ public FarmHelperConfig() { this.addDependency("sprintWhileFlying", "enablePestsDestroyer"); this.addDependency("pausePestsDestroyerDuringJacobsContest", "enablePestsDestroyer"); - - this.hideIf("infoCookieBuffRequired", () -> GameStateHandler.getInstance().inGarden() || GameStateHandler.getInstance().getCookieBuffState() == BuffState.NOT_ACTIVE); + this.hideIf("infoCookieBuffRequired", + () -> GameStateHandler.getInstance().inGarden() || GameStateHandler.getInstance().getCookieBuffState() == BuffState.NOT_ACTIVE); this.addDependency("sendLogs", "enableWebHook"); this.addDependency("sendStatusUpdates", "enableWebHook"); @@ -2194,9 +2298,9 @@ public FarmHelperConfig() { this.addDependency("discordRemoteControlAddress", "enableRemoteControl"); this.addDependency("remoteControlPort", "enableRemoteControl"); - this.hideIf("infoRemoteControl", () -> Loader.isModLoaded("farmhelperjdadependency")); - this.hideIf("info2RemoteControl", () -> !Loader.isModLoaded("farmhelperjdadependency") || (Loader.isModLoaded("farmhelperjdadependency") && FarmHelper.isJDAVersionCorrect)); + this.hideIf("info2RemoteControl", () -> !Loader.isModLoaded("farmhelperjdadependency") || (Loader.isModLoaded("farmhelperjdadependency") + && FarmHelper.isJDAVersionCorrect)); this.hideIf("failsafeSoundTimes", () -> true); this.addDependency("debugMode", "Streamer Mode", () -> !streamerMode); @@ -2256,6 +2360,9 @@ public FarmHelperConfig() { this.addDependency("rotationTimeDuringJacob", "customRotationDelaysDuringJacob"); this.addDependency("rotationTimeRandomnessDuringJacob", "customRotationDelaysDuringJacob"); + this.addDependency("pestArmorSlot0", "pestSwapArmorBefore"); + this.addDependency("pestArmorSlot1", "pestSwapArmorAfter"); + this.addDependency("leaveTime", "leaveTimer"); this.hideIf("shownWelcomeGUI", () -> true); @@ -2338,8 +2445,9 @@ public static void removeAllRewarps() { public static void saveRewarpConfig() { try { - if (!configRewarpFile.exists()) + if (!configRewarpFile.exists()) { Files.createFile(configRewarpFile.toPath()); + } Files.write(configRewarpFile.toPath(), FarmHelper.gson.toJson(rewarpList).getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { @@ -2352,8 +2460,9 @@ public static MacroEnum getMacro() { } public static long getRandomTimeBetweenChangingRows() { - if (customRowChangeDelaysDuringJacob && GameStateHandler.getInstance().inJacobContest()) + if (customRowChangeDelaysDuringJacob && GameStateHandler.getInstance().inJacobContest()) { return (long) (timeBetweenChangingRowsDuringJacob + (float) Math.random() * randomTimeBetweenChangingRowsDuringJacob); + } return (long) (timeBetweenChangingRows + (float) Math.random() * randomTimeBetweenChangingRows); } @@ -2362,8 +2471,9 @@ public static long getMaxTimeBetweenChangingRows() { } public static long getRandomRotationTime() { - if (customRotationDelaysDuringJacob && GameStateHandler.getInstance().inJacobContest()) + if (customRotationDelaysDuringJacob && GameStateHandler.getInstance().inJacobContest()) { return (long) (rotationTimeDuringJacob + (float) Math.random() * rotationTimeRandomnessDuringJacob); + } return (long) (rotationTime + (float) Math.random() * rotationTimeRandomness); } diff --git a/src/main/java/com/jelly/farmhelperv2/feature/FeatureManager.java b/src/main/java/com/jelly/farmhelperv2/feature/FeatureManager.java index 4baef0a3..e571d82c 100644 --- a/src/main/java/com/jelly/farmhelperv2/feature/FeatureManager.java +++ b/src/main/java/com/jelly/farmhelperv2/feature/FeatureManager.java @@ -48,7 +48,9 @@ public List fillFeatures() { Scheduler.getInstance(), UngrabMouse.getInstance(), VisitorsMacro.getInstance(), - PiPMode.getInstance() + PiPMode.getInstance(), + AutoWardrobe.instance, + PestFarmer.instance// sue me ); features.addAll(featuresList); return features; diff --git a/src/main/java/com/jelly/farmhelperv2/feature/impl/AutoWardrobe.java b/src/main/java/com/jelly/farmhelperv2/feature/impl/AutoWardrobe.java new file mode 100644 index 00000000..cdcb7de1 --- /dev/null +++ b/src/main/java/com/jelly/farmhelperv2/feature/impl/AutoWardrobe.java @@ -0,0 +1,208 @@ +package com.jelly.farmhelperv2.feature.impl; + +import com.jelly.farmhelperv2.config.FarmHelperConfig; +import com.jelly.farmhelperv2.feature.IFeature; +import com.jelly.farmhelperv2.util.InventoryUtils; +import com.jelly.farmhelperv2.util.InventoryUtils.ClickMode; +import com.jelly.farmhelperv2.util.InventoryUtils.ClickType; +import com.jelly.farmhelperv2.util.LogUtils; +import com.jelly.farmhelperv2.util.PlayerUtils; +import com.jelly.farmhelperv2.util.helper.Clock; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; + +public class AutoWardrobe implements IFeature { + + public static AutoWardrobe instance = new AutoWardrobe(); + public static int activeSlot = -1; + private final Minecraft mc = Minecraft.getMinecraft(); + private boolean enabled = false; + private int swapTo = -1; + private State state = State.STARTING; + private Clock timer = new Clock(); + + @Override + public String getName() { + return "AutoWardrobe"; + } + + @Override + public boolean isRunning() { + return enabled; + } + + @Override + public boolean shouldPauseMacroExecution() { + return true; + } + + @Override + public boolean shouldStartAtMacroStart() { + return false; + } + + @Override + public void resetStatesAfterMacroDisabled() { + activeSlot = -1; + } + + @Override + public boolean isToggled() { + return true; + } + + @Override + public boolean shouldCheckForFailsafes() { + return false; + } + + public void swapTo(int slot) { + if (slot < 1 || slot > 18) { + return; + } + + swapTo = slot; + enabled = true; + LogUtils.sendSuccess("[AutoWardrobe] Starting. Swapping to slot " + slot); + } + + @Override + public void stop() { + if (!enabled) { + return; + } + enabled = false; + swapTo = -1; + state = State.STARTING; + timer.reset(); + + LogUtils.sendSuccess("[AutoWardrobe] Stopping."); + } + + public void setState(State state, long time) { + this.state = state; + timer.schedule(time); + if (time == 0) { + timer.reset(); + } + } + + public boolean isTimerRunning() { + return timer.isScheduled() && !timer.passed(); + } + + public boolean hasTimerEnded() { + return !timer.isScheduled() || timer.passed(); + } + + @SubscribeEvent + public void onTick(ClientTickEvent event) { + if (!enabled) { + return; + } + + switch (state) { + case STARTING: + setState(State.OPENING_WD, FarmHelperConfig.getRandomGUIMacroDelay()); + break; + case OPENING_WD: + if (isTimerRunning()) { + return; + } + + mc.thePlayer.sendChatMessage("/wd"); + setState(State.WD_VERIFY, 2000); + break; + case WD_VERIFY: + if (hasTimerEnded()) { + LogUtils.sendError("Could not open wardrobe in under 2 seconds. Stopping"); + setState(State.WAITING, 0); + return; + } + + if (inventoryName().startsWith("Wardrobe")) { + setState(State.NAVIGATING, FarmHelperConfig.getRandomGUIMacroDelay()); + } + break; + case NAVIGATING: + if (isTimerRunning()) { + return; + } + if (swapTo < 9) { + setState(State.CLICKING_SLOT, 0); + return; + } + InventoryUtils.clickContainerSlot(InventoryUtils.getSlotIdOfItemInContainer("Next Page"), ClickType.LEFT, ClickMode.PICKUP); + setState(State.NAVIGATION_VERIFY, 2000); + break; + case NAVIGATION_VERIFY: + if (hasTimerEnded()) { + LogUtils.sendError("Could not switch to next page in under 2 seconds. Stopping"); + setState(State.WAITING, 0); + return; + } + + if (inventoryName().endsWith("2)")) { + setState(State.CLICKING_SLOT, FarmHelperConfig.getRandomGUIMacroDelay()); + } + break; + case CLICKING_SLOT: + if (isTimerRunning()) { + return; + } + int slotId = 35 + (swapTo - 1) % 9 + 1; + Slot slot = InventoryUtils.getSlotOfIdInContainer(slotId); + if (slot != null && slot.getHasStack()) { + ItemStack stack = slot.getStack(); + // remove this to make it unequip armor (click the same slot) + if (stack.hasDisplayName() && !stack.getDisplayName().contains("Equipped") && !stack.getDisplayName().contains("Locked")) { + InventoryUtils.clickContainerSlot(35 + (swapTo - 1) % 9 + 1, ClickType.LEFT, ClickMode.PICKUP); + } + } + activeSlot = swapTo; + setState(State.WAITING, FarmHelperConfig.getRandomGUIMacroDelay()); + break; + case WAITING: + if (isTimerRunning()) { + return; + } + PlayerUtils.closeScreen(); + setState(State.ENDING, FarmHelperConfig.getRandomGUIMacroDelay()); + break; + // this is just here to give a bit extra pause before it stops + case ENDING: + if (isTimerRunning()) { + return; + } + stop(); + break; + } + } + + private String inventoryName() { + try { + if (mc.currentScreen instanceof GuiChest) { + final ContainerChest chest = (ContainerChest) mc.thePlayer.openContainer; + if (chest == null) { + return ""; + } + final IInventory inv = chest.getLowerChestInventory(); + return inv.hasCustomName() ? inv.getName() : ""; + } + return ""; + } catch (Exception e) { + return ""; + } + } + + + enum State { + STARTING, OPENING_WD, WD_VERIFY, NAVIGATING, NAVIGATION_VERIFY, CLICKING_SLOT, WAITING, ENDING + } +} diff --git a/src/main/java/com/jelly/farmhelperv2/feature/impl/BPSTracker.java b/src/main/java/com/jelly/farmhelperv2/feature/impl/BPSTracker.java index 96c836de..5c32aed2 100644 --- a/src/main/java/com/jelly/farmhelperv2/feature/impl/BPSTracker.java +++ b/src/main/java/com/jelly/farmhelperv2/feature/impl/BPSTracker.java @@ -93,11 +93,7 @@ public void start() { } private boolean checkForBPS(AbstractMacro.State currentState) { - return currentState != AbstractMacro.State.NONE && - currentState != AbstractMacro.State.DROPPING && - currentState != AbstractMacro.State.SWITCHING_SIDE && - currentState != AbstractMacro.State.SWITCHING_LANE && - Minecraft.getMinecraft().currentScreen == null; + return currentState.ordinal() > 3 && Minecraft.getMinecraft().currentScreen == null; } public float elapsedTime = 0; diff --git a/src/main/java/com/jelly/farmhelperv2/feature/impl/PestFarmer.java b/src/main/java/com/jelly/farmhelperv2/feature/impl/PestFarmer.java new file mode 100644 index 00000000..688a751d --- /dev/null +++ b/src/main/java/com/jelly/farmhelperv2/feature/impl/PestFarmer.java @@ -0,0 +1,175 @@ +package com.jelly.farmhelperv2.feature.impl; + +import com.jelly.farmhelperv2.FarmHelper; +import com.jelly.farmhelperv2.config.FarmHelperConfig; +import com.jelly.farmhelperv2.failsafe.FailsafeManager; +import com.jelly.farmhelperv2.feature.FeatureManager; +import com.jelly.farmhelperv2.feature.IFeature; +import com.jelly.farmhelperv2.handler.GameStateHandler; +import com.jelly.farmhelperv2.handler.MacroHandler; +import com.jelly.farmhelperv2.util.InventoryUtils; +import com.jelly.farmhelperv2.util.LogUtils; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; + +public class PestFarmer implements IFeature { + + public static PestFarmer instance = new PestFarmer(); + private boolean enabled = false; + private long pestSpawnTime = 0L; + private int swapTo = -1; + private State state = State.SWAPPING; + private boolean pestSpawned = false; + private boolean holdDae = false; + + @Override + public String getName() { + return "PestFarmer"; + } + + @Override + public boolean isRunning() { + return enabled; + } + + @Override + public boolean shouldPauseMacroExecution() { + return true; + } + + @Override + public boolean shouldStartAtMacroStart() { + return false; + } + + @Override + public void resetStatesAfterMacroDisabled() { + state = State.SWAPPING; + pestSpawned = false; + holdDae = false; + swapTo = -1; + } + + @Override + public boolean isToggled() { + return FarmHelperConfig.pestFarming; + } + + @Override + public boolean shouldCheckForFailsafes() { + return false; + } + + @Override + public void start() { + if (enabled) { + return; + } + MacroHandler.getInstance().pauseMacro(); + enabled = true; + } + + @Override + public void stop() { + if (!enabled) { + return; + } + + enabled = false; + state = State.SWAPPING; + if (MacroHandler.getInstance().isMacroToggled()) { + MacroHandler.getInstance().resumeMacro(); + } + } + + public boolean holdDaedalus() { + return holdDae && FarmHelperConfig.pestFarming && FarmHelperConfig.pestFarmingHoldDaedalus + && AutoWardrobe.activeSlot == FarmHelperConfig.pestFarmingSet1Slot && InventoryUtils.holdItem("Daedalus Axe"); + } + + @SubscribeEvent + public void onTick(ClientTickEvent event) { + if (event.phase != Phase.START) { + return; + } + if (!this.isToggled() || !MacroHandler.getInstance().isCurrentMacroEnabled() + || MacroHandler.getInstance().getCurrentMacro().get().currentState.ordinal() < 4 || enabled) { + return; + } + if (!GameStateHandler.getInstance().inGarden()) { + return; + } + if (GameStateHandler.getInstance().getServerClosingSeconds().isPresent()) { + return; + } + if (!Scheduler.getInstance().isFarming()) { + return; + } + if (FailsafeManager.getInstance().triggeredFailsafe.isPresent()) { + return; + } + if (FeatureManager.getInstance().isAnyOtherFeatureEnabled(this)) { + return; + } + + if (pestSpawned) { + long timeDiff = System.currentTimeMillis() - pestSpawnTime; + if (timeDiff >= FarmHelperConfig.pestFarmingWaitTime * 1000L && AutoWardrobe.activeSlot != FarmHelperConfig.pestFarmingSet1Slot) { + LogUtils.sendDebug("Swapping to " + FarmHelperConfig.pestFarmingSet1Slot); + swapTo = FarmHelperConfig.pestFarmingSet1Slot; + pestSpawned = false; + holdDae = true; + start(); + } else if (AutoWardrobe.activeSlot != FarmHelperConfig.pestFarmingSet0Slot) { + LogUtils.sendDebug("Swapping to " + FarmHelperConfig.pestFarmingSet0Slot); + swapTo = FarmHelperConfig.pestFarmingSet0Slot; + holdDae = false; + start(); + } + } + } + + @SubscribeEvent + public void onChat(ClientChatReceivedEvent event) { + if (event.type != 0) { + return; + } + String message = event.message.getUnformattedText(); + if (message.startsWith("§6§lYUCK!") || message.startsWith("§6§lEWW!") || message.startsWith("§6§lGROSS!")) { + pestSpawnTime = System.currentTimeMillis(); + pestSpawned = true; + LogUtils.sendDebug("[PestFarmer] Pest Spawned."); + } + } + + @SubscribeEvent + public void onTickSwap(ClientTickEvent event) { + if (!enabled) { + return; + } + + switch (state) { + case SWAPPING: + AutoWardrobe.instance.swapTo(swapTo); + state = State.ENDING; + break; + case ENDING: + if (AutoWardrobe.instance.isRunning()) { + return; + } + stop(); + break; + } + } + + // bleh, its only for the tracker basically + enum State { + SWAPPING, + ENDING + } +} diff --git a/src/main/java/com/jelly/farmhelperv2/feature/impl/PestsDestroyer.java b/src/main/java/com/jelly/farmhelperv2/feature/impl/PestsDestroyer.java index def6660e..24b4030e 100644 --- a/src/main/java/com/jelly/farmhelperv2/feature/impl/PestsDestroyer.java +++ b/src/main/java/com/jelly/farmhelperv2/feature/impl/PestsDestroyer.java @@ -48,19 +48,30 @@ import java.util.stream.Collectors; public class PestsDestroyer implements IFeature { + private static PestsDestroyer instance; private final Minecraft mc = Minecraft.getMinecraft(); private final List> pests = Arrays.asList( - new Tuple<>("Beetle", "ewogICJ0aW1lc3RhbXAiIDogMTcyMzE3OTc4OTkzNCwKICAicHJvZmlsZUlkIiA6ICJlMjc5NjliODYyNWY0NDg1YjkyNmM5NTBhMDljMWMwMSIsCiAgInByb2ZpbGVOYW1lIiA6ICJLRVZJTktFTE9LRSIsCiAgInNpZ25hdHVyZVJlcXVpcmVkIiA6IHRydWUsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgInVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS83MGExZTgzNmJmMTk2OGIyZWFhNDgzNzIyN2ExOTIwNGYxNzI5NWQ4NzBlZTllNzU0YmQ2YjZkNjBkZGJlZDNjIgogICAgfQogIH0KfQ"), - new Tuple<>("Cricket", "ewogICJ0aW1lc3RhbXAiIDogMTcyMzE3OTgxMTI2NCwKICAicHJvZmlsZUlkIiA6ICJjZjc4YzFkZjE3ZTI0Y2Q5YTIxYmU4NWQ0NDk5ZWE4ZiIsCiAgInByb2ZpbGVOYW1lIiA6ICJNYXR0c0FybW9yU3RhbmRzIiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2EyNGM2OWY5NmNlNTU2MjIxZTE5NWM4ZWYyYmZhZDcxZWJmN2Y5NWY1YWU5MTRhNDg0YThkMGVjMjE2NzI2NzQiCiAgICB9CiAgfQp9"), - new Tuple<>("Earthworm", "ewogICJ0aW1lc3RhbXAiIDogMTY5NzQ3MDQ1OTc0NywKICAicHJvZmlsZUlkIiA6ICIyNTBlNzc5MjZkNDM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NkMTNjZGRmNGU0Y2IzODJmYWZiYWIwOGIyNzQ4OSIsCiAgInByb2ZpbGVOYW1lIiA6ICJaYWNoeVphY2giLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2E3OWQwZmQ2NzdiNTQ1MzA5NjExMTdlZjg0YWRjMjA2ZTJjYzUwNDVjMTM0NGQ2MWQ3NzZiZjhhYzJmZTFiYSIKICAgIH0KICB9Cn0") ); private Optional closestPlot = Optional.empty(); @Getter @@ -104,6 +115,8 @@ public class PestsDestroyer implements IFeature { private boolean isPlotObstructed = false; private long lastKillTimestamp = 0; private int previousCurrentPlotPestsCount = 0; + private int currentSlot = -1; + private boolean finishing = false; private final List killedPestsFrom = new ArrayList<>(); @@ -136,7 +149,9 @@ public boolean shouldStartAtMacroStart() { @Override public void start() { - if (enabled) return; + if (enabled) { + return; + } gotRangeOfVacuum = false; isPlotObstructed = false; preparing = true; @@ -152,7 +167,9 @@ public void start() { killedEntities.clear(); killedPestsFrom.clear(); Multithreading.schedule(() -> { - if (!preparing) return; + if (!preparing) { + return; + } enabled = true; preparing = false; LogUtils.sendWarning("[Pests Destroyer] Starting killing shitters!"); @@ -191,6 +208,8 @@ public void stop() { state = States.IDLE; FlyPathFinderExecutor.getInstance().stop(); KeyBindUtils.stopMovement(); + finishing = false; + currentSlot = -1; IFeature.super.stop(); } @@ -198,7 +217,9 @@ public void stop() { public void resetStatesAfterMacroDisabled() { stop(); gotRangeOfVacuum = false; - if (!FarmHelperConfig.pestsDestroyerAfkInfiniteMode) return; + if (!FarmHelperConfig.pestsDestroyerAfkInfiniteMode) { + return; + } FarmHelperConfig.pestsDestroyerAfkInfiniteMode = false; LogUtils.sendWarning("[Pests Destroyer] AFK Mode has been disabled"); } @@ -220,7 +241,9 @@ public boolean shouldCheckForFailsafes() { @SubscribeEvent public void onKeyInput(InputEvent.KeyInputEvent event) { - if (!FarmHelperConfig.pestsDestroyerAfkInfiniteMode) return; + if (!FarmHelperConfig.pestsDestroyerAfkInfiniteMode) { + return; + } if (Keyboard.getEventKeyState() && Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { LogUtils.sendWarning("[Pests Destroyer] Disabling Pests Destroyer AFK Infinite Mode!"); stop(); @@ -230,12 +253,24 @@ public void onKeyInput(InputEvent.KeyInputEvent event) { @SubscribeEvent public void onTickAFKMode(TickEvent.ClientTickEvent event) { - if (event.phase == TickEvent.Phase.END) return; - if (mc.thePlayer == null || mc.theWorld == null) return; - if (!FarmHelperConfig.pestsDestroyerAfkInfiniteMode) return; - if (MacroHandler.getInstance().isMacroToggled()) return; - if (!isToggled()) return; - if (isRunning()) return; + if (event.phase == TickEvent.Phase.END) { + return; + } + if (mc.thePlayer == null || mc.theWorld == null) { + return; + } + if (!FarmHelperConfig.pestsDestroyerAfkInfiniteMode) { + return; + } + if (MacroHandler.getInstance().isMacroToggled()) { + return; + } + if (!isToggled()) { + return; + } + if (isRunning()) { + return; + } if (canEnableMacro(true)) { start(); @@ -247,15 +282,31 @@ public boolean canEnableMacro() { } public boolean canEnableMacro(boolean manually) { - if (!isToggled()) return false; - if (isRunning()) return false; - if (!GameStateHandler.getInstance().inGarden()) return false; - if (!MacroHandler.getInstance().isMacroToggled() && !manually) return false; - if (!FailsafeManager.getInstance().getEmergencyQueue().isEmpty()) return false; - if (FailsafeManager.getInstance().triggeredFailsafe.isPresent()) return false; - if (enabled || preparing) return false; - if (GameStateHandler.getInstance().getPestsCount() < FarmHelperConfig.startKillingPestsAt && !manually || (manually && GameStateHandler.getInstance().getPestsCount() == 0)) + if (!isToggled()) { + return false; + } + if (isRunning()) { + return false; + } + if (!GameStateHandler.getInstance().inGarden()) { + return false; + } + if (!MacroHandler.getInstance().isMacroToggled() && !manually) { + return false; + } + if (!FailsafeManager.getInstance().getEmergencyQueue().isEmpty()) { + return false; + } + if (FailsafeManager.getInstance().triggeredFailsafe.isPresent()) { + return false; + } + if (enabled || preparing) { + return false; + } + if (GameStateHandler.getInstance().getPestsCount() < FarmHelperConfig.startKillingPestsAt && !manually || (manually + && GameStateHandler.getInstance().getPestsCount() == 0)) { return false; + } if (!manually && FarmHelperConfig.pausePestsDestroyerDuringJacobsContest && GameStateHandler.getInstance().inJacobContest()) { LogUtils.sendError("[Pests Destroyer] Pests Destroyer won't activate during Jacob's Contest!"); return false; @@ -273,7 +324,9 @@ public boolean canEnableMacro(boolean manually) { @SubscribeEvent public void onTickExecute(TickEvent.ClientTickEvent event) { - if (mc.thePlayer == null || mc.theWorld == null) return; + if (mc.thePlayer == null || mc.theWorld == null) { + return; + } if (mc.currentScreen == null && checkedThisGui) { checkedThisGui = false; } @@ -291,20 +344,31 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { } } } - if (!isToggled()) return; - if (event.phase != TickEvent.Phase.END) return; - if (!GameStateHandler.getInstance().inGarden() && escapeState == EscapeState.NONE) return; - if (!enabled) return; - if (!FailsafeManager.getInstance().getEmergencyQueue().isEmpty()) return; + if (!isToggled()) { + return; + } + if (event.phase != TickEvent.Phase.END) { + return; + } + if (!GameStateHandler.getInstance().inGarden() && escapeState == EscapeState.NONE) { + return; + } + if (!enabled) { + return; + } + if (!FailsafeManager.getInstance().getEmergencyQueue().isEmpty()) { + return; + } if (FailsafeManager.getInstance().triggeredFailsafe.isPresent()) { stop(); return; } - if (stuckClock.isScheduled() && stuckClock.passed()) { - LogUtils.sendWarning("[Pests Destroyer] The player is struggling killing pest for 5 minutes, will do a quick Garden -> Hub -> Garden teleport."); - LogUtils.sendFailsafeMessage("[Pests Destroyer] Couldn't kill pest for 5 minutes, will do a quick Garden -> Hub -> Garden teleport.", true); + LogUtils.sendWarning( + "[Pests Destroyer] The player is struggling killing pest for 5 minutes, will do a quick Garden -> Hub -> Garden teleport."); + LogUtils.sendFailsafeMessage("[Pests Destroyer] Couldn't kill pest for 5 minutes, will do a quick Garden -> Hub -> Garden teleport.", + true); escapeState = EscapeState.GO_TO_HUB; KeyBindUtils.stopMovement(); delayClock.schedule(300); @@ -312,7 +376,9 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { return; } - if (delayClock.isScheduled() && !delayClock.passed()) return; + if (delayClock.isScheduled() && !delayClock.passed()) { + return; + } LogUtils.sendDebug("[Pests Destroyer] State: " + state); @@ -326,7 +392,9 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { KeyBindUtils.stopMovement(); switch (escapeState) { case GO_TO_HUB: - if (isInventoryOpen()) break; + if (isInventoryOpen()) { + break; + } if (GameStateHandler.getInstance().getLocation() == GameStateHandler.Location.HUB) { escapeState = EscapeState.GO_TO_GARDEN; delayClock.schedule((long) (5_500 + Math.random() * 3_500)); @@ -349,7 +417,9 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { } break; case GO_TO_GARDEN: - if (isInventoryOpen()) break; + if (isInventoryOpen()) { + break; + } if (GameStateHandler.getInstance().inGarden()) { escapeState = EscapeState.GO_TO_HUB; delayClock.schedule((long) (2_500 + Math.random() * 1_500)); @@ -373,7 +443,9 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { } break; case RESUME_MACRO: - if (isInventoryOpen()) break; + if (isInventoryOpen()) { + break; + } if (GameStateHandler.getInstance().inGarden()) { escapeState = EscapeState.NONE; state = States.IDLE; @@ -407,24 +479,53 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { case IDLE: ItemStack currentItem = mc.thePlayer.getHeldItem(); if (GameStateHandler.getInstance().getPestsCount() == 0) { - if (isInventoryOpen()) return; - finishMacro(); + if (isInventoryOpen()) { + return; + } +// finishMacro(); + state = States.FINISH; return; } - if (getVacuum(currentItem)) return; - if (needToUpdatePlots || PlotUtils.needToUpdatePlots()) { - state = States.OPEN_DESK; + if (getVacuum(currentItem)) { + return; + } + state = States.SWAP_ARMOR; + delayClock.schedule((long) (200 + Math.random() * 200)); + break; + case SWAP_ARMOR: + if (FarmHelperConfig.pestSwapArmorBefore) { + currentSlot = FarmHelperConfig.pestArmorSlot0; + if (finishing) { + currentSlot = FarmHelperConfig.pestArmorSlot1; + } + if (AutoWardrobe.activeSlot != currentSlot) { + AutoWardrobe.instance.swapTo(currentSlot); + } + } + state = States.ARMOR_SWAP_VERIFY; + break; + case ARMOR_SWAP_VERIFY: + if (AutoWardrobe.instance.isRunning()) { + return; + } + if (finishing) { + state = States.FINISH; } else { - if (FarmHelperConfig.dontTeleportToPlots) { - state = States.GET_CLOSEST_PLOT; + if (needToUpdatePlots || PlotUtils.needToUpdatePlots()) { + state = States.OPEN_DESK; } else { - state = States.TELEPORT_TO_PLOT; + if (FarmHelperConfig.dontTeleportToPlots) { + state = States.GET_CLOSEST_PLOT; + } else { + state = States.TELEPORT_TO_PLOT; + } } } - delayClock.schedule((long) (200 + Math.random() * 200)); break; case OPEN_DESK: - if (isInventoryOpen()) break; + if (isInventoryOpen()) { + break; + } mc.thePlayer.sendChatMessage("/desk"); state = States.OPEN_PLOTS; delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 500 + Math.random() * 500)); @@ -435,7 +536,9 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300)); break; } - if (!InventoryUtils.isInventoryLoaded()) break; + if (!InventoryUtils.isInventoryLoaded()) { + break; + } if (chestName == null || !chestName.equals("Desk")) { break; } @@ -486,7 +589,9 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { delayClock.schedule((long) (200 + Math.random() * 200)); break; case CHECKING_PLOT: - if (isInventoryOpenDelayed()) break; + if (isInventoryOpenDelayed()) { + break; + } KeyBindUtils.stopMovement(); if (PlayerUtils.isPlayerSuffocating() || !BlockUtils.canFlyHigher(5)) { @@ -500,20 +605,26 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { state = States.GET_LOCATION; break; case CHECKING_SPAWN: - if (MacroHandler.getInstance().isTeleporting()) return; + if (MacroHandler.getInstance().isTeleporting()) { + return; + } if (PlayerUtils.isPlayerSuffocating() || !BlockUtils.canFlyHigher(5)) { - LogUtils.sendError("[Pests Destroyer] Your spawnpoint is obstructed! Make sure there is no block above your spawnpoint! Disabling Pests Destroyer!"); + LogUtils.sendError( + "[Pests Destroyer] Your spawnpoint is obstructed! Make sure there is no block above your spawnpoint! Disabling Pests Destroyer!"); stop(); FarmHelperConfig.enablePestsDestroyer = false; - finishMacro(); +// finishMacro(); + state = States.FINISH; } else { state = States.GET_CLOSEST_PLOT; LogUtils.sendDebug("[Pests Destroyer] Spawnpoint is not obstructed"); } break; case GET_CLOSEST_PLOT: - if (isInventoryOpenDelayed()) break; + if (isInventoryOpenDelayed()) { + break; + } PlotUtils.Plot closestPlot = getClosestPlot(); @@ -530,7 +641,8 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { if (FarmHelperConfig.dontTeleportToPlots) { if (PlayerUtils.isPlayerSuffocating() || !BlockUtils.canFlyHigher(3)) { state = States.TELEPORT_TO_PLOT; - LogUtils.sendWarning("[Pests Destroyer] The player is suffocating and/or it can't fly higher. Forcing going back to spawnpoint."); + LogUtils.sendWarning( + "[Pests Destroyer] The player is suffocating and/or it can't fly higher. Forcing going back to spawnpoint."); } else { state = States.FLY_TO_THE_CLOSEST_PLOT; } @@ -545,8 +657,12 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { delayClock.schedule((long) (500 + Math.random() * 500)); break; case FLY_TO_THE_CLOSEST_PLOT: - if (MacroHandler.getInstance().isTeleporting()) return; - if (isInventoryOpenDelayed()) break; + if (MacroHandler.getInstance().isTeleporting()) { + return; + } + if (isInventoryOpenDelayed()) { + break; + } if (!this.closestPlot.isPresent()) { LogUtils.sendError("[Pests Destroyer] Couldn't find closest plot!"); @@ -586,9 +702,13 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { state = States.GO_BACK; return; } - if (isInventoryOpenDelayed()) break; + if (isInventoryOpenDelayed()) { + break; + } ItemStack currentItem2 = mc.thePlayer.getHeldItem(); - if (getVacuum(currentItem2)) return; + if (getVacuum(currentItem2)) { + return; + } if (getClosestPest() != null) { FlyPathFinderExecutor.getInstance().stop(); @@ -635,7 +755,9 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { resetFireworkInfo(); lastFireworkTime = System.currentTimeMillis(); MovingObjectPosition mop = mc.objectMouseOver; - if (RotationHandler.getInstance().isRotating()) break; + if (RotationHandler.getInstance().isRotating()) { + break; + } float yaw = -1; Vec3 playerPos = mc.thePlayer.getPositionEyes(1); for (float i = 0; i < 360; i += 10) { @@ -648,7 +770,8 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { } } Rotation upRotation = new Rotation((float) (yaw + (Math.random() * 5 - 2.5)), (float) (-20 + (Math.random() * 6 - 4))); - if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && RotationHandler.getInstance().shouldRotate(upRotation, 10)) { + if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && RotationHandler.getInstance() + .shouldRotate(upRotation, 10)) { RotationHandler.getInstance().easeTo(new RotationConfiguration( upRotation, FarmHelperConfig.getRandomRotationTime(), @@ -665,14 +788,19 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { } KeyBindUtils.leftClick(); getLocationTries++; - if (!stuckClock.isScheduled()) + if (!stuckClock.isScheduled()) { stuckClock.schedule(1_000 * 60 * FarmHelperConfig.pestsKillerStuckTime); + } delayClock.schedule(300); break; case WAIT_FOR_LOCATION: - if (isInventoryOpenDelayed()) break; + if (isInventoryOpenDelayed()) { + break; + } - if (RotationHandler.getInstance().isRotating()) return; + if (RotationHandler.getInstance().isRotating()) { + return; + } if (getClosestPest() != null) { state = States.FIND_PEST; @@ -703,7 +831,9 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { FlyPathFinderExecutor.getInstance().setSprinting(false); FlyPathFinderExecutor.getInstance().setDontRotate(true); FlyPathFinderExecutor.getInstance().findPath(new Vec3(firework.xCoord, y, firework.zCoord), true, true); - LogUtils.sendWarning("[Pests Destroyer] Firework is too close to player. Flying to x: " + firework.xCoord + " y: " + y + " z: " + firework.zCoord); + LogUtils.sendWarning( + "[Pests Destroyer] Firework is too close to player. Flying to x: " + firework.xCoord + " y: " + y + " z: " + + firework.zCoord); break; } RotationHandler.getInstance().reset(); @@ -718,7 +848,9 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { } break; case FIND_PEST: - if (isInventoryOpenDelayed()) break; + if (isInventoryOpenDelayed()) { + break; + } getLocationTries = 0; if (GameStateHandler.getInstance().getPestsCount() == 0) { RotationHandler.getInstance().reset(); @@ -754,7 +886,8 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { break; } if (closestPest instanceof EntityArmorStand) { - Entity realEntity = PlayerUtils.getEntityCuttingOtherEntity(closestPest, (e) -> e instanceof EntityBat || e instanceof EntitySilverfish); + Entity realEntity = PlayerUtils.getEntityCuttingOtherEntity(closestPest, + (e) -> e instanceof EntityBat || e instanceof EntitySilverfish); if (realEntity != null) { closestPest = realEntity; } @@ -768,12 +901,15 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { state = States.KILL_PEST; cantReachPest = 0; KeyBindUtils.stopMovement(); - if (!stuckClock.isScheduled()) + if (!stuckClock.isScheduled()) { stuckClock.schedule(1_000 * 60 * FarmHelperConfig.pestsKillerStuckTime); + } delayClock.schedule(300); break; case KILL_PEST: - if (isInventoryOpenDelayed()) break; + if (isInventoryOpenDelayed()) { + break; + } if (mc.thePlayer.posY < 67 && FlyPathFinderExecutor.getInstance().isRunning()) { FlyPathFinderExecutor.getInstance().stop(); RotationHandler.getInstance().reset(); @@ -821,12 +957,14 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { FlyPathFinderExecutor.getInstance().stop(); LogUtils.sendDebug("[Pests Destroyer] Stopping pathfinder because the pest is close enough"); float playerVelocity = (float) (Math.abs(mc.thePlayer.motionX) + Math.abs(mc.thePlayer.motionZ)); - if (playerVelocity > 0.9) + if (playerVelocity > 0.9) { KeyBindUtils.onTick(mc.gameSettings.keyBindBack); + } } else { float playerVelocity = (float) (Math.abs(mc.thePlayer.motionX) + Math.abs(mc.thePlayer.motionZ)); - if (playerVelocity > 0.15 && distanceXZ < 3) + if (playerVelocity > 0.15 && distanceXZ < 3) { KeyBindUtils.onTick(mc.gameSettings.keyBindBack); + } } } if (rotationState != RotationState.CLOSE) { @@ -881,7 +1019,8 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { null )); } - FlyPathFinderExecutor.getInstance().setUseAOTV(distanceXZ > vacuumMinRange && InventoryUtils.hasItemInHotbar("Aspect of the Void", "Aspect of the End")); + FlyPathFinderExecutor.getInstance() + .setUseAOTV(distanceXZ > vacuumMinRange && InventoryUtils.hasItemInHotbar("Aspect of the Void", "Aspect of the End")); if (distance2 < currentVacuumRange && getVacuum(mc.thePlayer.getHeldItem())) { break; } @@ -889,10 +1028,14 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { } break; case CHECK_ANOTHER_PEST: - if (previousCurrentPlotPestsCount == GameStateHandler.getInstance().getCurrentPlotPestsCount() && System.currentTimeMillis() - lastKillTimestamp < 2_000) + if (previousCurrentPlotPestsCount == GameStateHandler.getInstance().getCurrentPlotPestsCount() + && System.currentTimeMillis() - lastKillTimestamp < 2_000) { return; + } - LogUtils.sendDebug(GameStateHandler.getInstance().getPestsCount() + " pest" + (GameStateHandler.getInstance().getPestsCount() == 1 ? "" : "s") + " left"); + LogUtils.sendDebug( + GameStateHandler.getInstance().getPestsCount() + " pest" + (GameStateHandler.getInstance().getPestsCount() == 1 ? "" : "s") + + " left"); if (GameStateHandler.getInstance().getPestsCount() == 0) { state = States.GO_BACK; delayClock.schedule((long) (500 + Math.random() * 500)); @@ -929,7 +1072,16 @@ public void onTickExecute(TickEvent.ClientTickEvent event) { } break; case GO_BACK: + state = States.FINISH; + break; + case FINISH: + finishing = true; + if (FarmHelperConfig.pestSwapArmorAfter && currentSlot != FarmHelperConfig.pestArmorSlot1) { + state = States.SWAP_ARMOR; + return; + } finishMacro(); +// state = States.FINISH; break; } } @@ -955,7 +1107,8 @@ public boolean getVacuum(ItemStack currentItem2) { LogUtils.sendError("[Pests Destroyer] Failed to find vacuum in hotbar!"); state = States.GO_BACK; FarmHelperConfig.enablePestsDestroyer = false; - finishMacro(); +// finishMacro(); + state = States.FINISH; return true; } mc.thePlayer.inventory.currentItem = vacuum; @@ -991,7 +1144,9 @@ private boolean isInventoryOpen() { private void finishMacro() { - if (isInventoryOpen()) return; + if (isInventoryOpen()) { + return; + } if (FlyPathFinderExecutor.getInstance().isPathing()) { FlyPathFinderExecutor.getInstance().stop(); } @@ -1010,24 +1165,34 @@ private boolean hasBlocksAround() { Vec3 angle180 = AngleUtils.getVectorForRotation(180, mc.thePlayer.rotationYaw); Vec3 angle270 = AngleUtils.getVectorForRotation(270, mc.thePlayer.rotationYaw); Vec3 playerPos = mc.thePlayer.getPositionEyes(1); - if (checkIfBlockExists(angle0, playerPos)) return true; - if (checkIfBlockExists(angle90, playerPos)) return true; - if (checkIfBlockExists(angle180, playerPos)) return true; + if (checkIfBlockExists(angle0, playerPos)) { + return true; + } + if (checkIfBlockExists(angle90, playerPos)) { + return true; + } + if (checkIfBlockExists(angle180, playerPos)) { + return true; + } return checkIfBlockExists(angle270, playerPos); } private boolean checkIfBlockExists(Vec3 angle0, Vec3 playerPos) { - MovingObjectPosition mop0 = mc.theWorld.rayTraceBlocks(playerPos, playerPos.addVector(angle0.xCoord * 1.5, angle0.yCoord * 1.5, angle0.zCoord * 1.5), false, true, false); + MovingObjectPosition mop0 = mc.theWorld.rayTraceBlocks(playerPos, + playerPos.addVector(angle0.xCoord * 1.5, angle0.yCoord * 1.5, angle0.zCoord * 1.5), false, true, false); return mop0 != null && mop0.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK; } @SubscribeEvent(receiveCanceled = true) public void onChat(ClientChatReceivedEvent event) { - if (event.type != 0 || event.message == null) return; + if (event.type != 0 || event.message == null) { + return; + } String message = StringUtils.stripControlCodes(event.message.getUnformattedText().trim()); if (message.startsWith("You can't fast travel while in combat!") && enabled) { LogUtils.sendWarning("[Pests Destroyer] Can't fast travel while in combat, will try again to teleport."); - Multithreading.schedule(this::finishMacro, 1_000 + (long) (Math.random() * 1_000), TimeUnit.MILLISECONDS); +// Multithreading.schedule(this::finishMacro, 1_000 + (long) (Math.random() * 1_000), TimeUnit.MILLISECONDS); + state = States.FINISH; return; } if (message.toLowerCase().startsWith("there are not any pests on your garden right now") && enabled && state != States.GO_BACK) { @@ -1050,22 +1215,40 @@ public void onChat(ClientChatReceivedEvent event) { @SubscribeEvent public void onRender(RenderWorldLastEvent event) { - if (mc.thePlayer == null || mc.theWorld == null) return; - if (!GameStateHandler.getInstance().inGarden()) return; + if (mc.thePlayer == null || mc.theWorld == null) { + return; + } + if (!GameStateHandler.getInstance().inGarden()) { + return; + } killedEntities.removeIf(e -> !mc.theWorld.loadedEntityList.contains(e)); List pests = mc.theWorld.loadedEntityList.stream().filter(entity -> { - if (entity.isDead) return false; - if (entity.posY < 50) return false; + if (entity.isDead) { + return false; + } + if (entity.posY < 50) { + return false; + } if (entity instanceof EntityArmorStand) { - if (killedEntities.contains(entity)) return false; + if (killedEntities.contains(entity)) { + return false; + } ItemStack itemStack = ((EntityArmorStand) entity).getEquipmentInSlot(4); - if (itemStack == null || !itemStack.hasTagCompound()) return false; + if (itemStack == null || !itemStack.hasTagCompound()) { + return false; + } String displayName = itemStack.getTagCompound().toString(); - if (displayName.contains("display:")) return false; - if (this.pests.stream().noneMatch(pest -> displayName.contains(pest.getSecond()))) return false; - if (killedEntities.contains(entity)) return false; + if (displayName.contains("display:")) { + return false; + } + if (this.pests.stream().noneMatch(pest -> displayName.contains(pest.getSecond()))) { + return false; + } + if (killedEntities.contains(entity)) { + return false; + } Entity realEntity = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityBat || e instanceof EntitySilverfish); Entity nameEntity = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityArmorStand && e != entity); if (realEntity != null && (killedEntities.contains(realEntity) || realEntity.isDead)) { @@ -1075,8 +1258,9 @@ public void onRender(RenderWorldLastEvent event) { return false; } if (killedEntities.stream().noneMatch(ke -> ke.getDistanceToEntity(entity) < 1.5)) { - if (!FarmHelperConfig.streamerMode) + if (!FarmHelperConfig.streamerMode) { drawESP(entity); + } return true; } return false; @@ -1087,15 +1271,20 @@ public void onRender(RenderWorldLastEvent event) { pestsLocations.clear(); pestsLocations.addAll(pests); - if (!FarmHelperConfig.highlightPlotWithPests) return; + if (!FarmHelperConfig.highlightPlotWithPests) { + return; + } double d0 = Minecraft.getMinecraft().getRenderManager().viewerPosX; double d1 = Minecraft.getMinecraft().getRenderManager().viewerPosY; double d2 = Minecraft.getMinecraft().getRenderManager().viewerPosZ; for (int plotNumber : GameStateHandler.getInstance().getInfestedPlots()) { List> chunks = PlotUtils.getPlotChunksBasedOnNumber(plotNumber); - if (chunks.isEmpty()) continue; - AxisAlignedBB boundingBox = new AxisAlignedBB(chunks.get(0).getFirst() * 16, 66, chunks.get(0).getSecond() * 16, chunks.get(chunks.size() - 1).getFirst() * 16 + 16, 80, chunks.get(chunks.size() - 1).getSecond() * 16 + 16); + if (chunks.isEmpty()) { + continue; + } + AxisAlignedBB boundingBox = new AxisAlignedBB(chunks.get(0).getFirst() * 16, 66, chunks.get(0).getSecond() * 16, + chunks.get(chunks.size() - 1).getFirst() * 16 + 16, 80, chunks.get(chunks.size() - 1).getSecond() * 16 + 16); float centerX = (float) (boundingBox.minX + (boundingBox.maxX - boundingBox.minX) / 2); float centerZ = (float) (boundingBox.minZ + (boundingBox.maxZ - boundingBox.minZ) / 2); boundingBox = boundingBox.offset(-d0, -d1, -d2); @@ -1103,19 +1292,28 @@ public void onRender(RenderWorldLastEvent event) { RenderUtils.drawText("Plot " + plotNumber, centerX, 80, centerZ, 1); } - if (!FarmHelperConfig.debugMode) return; + if (!FarmHelperConfig.debugMode) { + return; + } ItemStack currentItem = mc.thePlayer.getHeldItem(); - if (currentItem == null || !currentItem.getDisplayName().contains("Vacuum")) return; + if (currentItem == null || !currentItem.getDisplayName().contains("Vacuum")) { + return; + } Vec3 lookVec = mc.thePlayer.getLookVec(); Vec3 playerPos = new Vec3(0, mc.thePlayer.eyeHeight, 0); - Vec3 vacuumRange = playerPos.addVector(lookVec.xCoord * currentVacuumRange, lookVec.yCoord * currentVacuumRange, lookVec.zCoord * currentVacuumRange); - AxisAlignedBB aabb = new AxisAlignedBB(vacuumRange.xCoord - 0.05, vacuumRange.yCoord - 0.05, vacuumRange.zCoord - 0.05, vacuumRange.xCoord + 0.05, vacuumRange.yCoord + 0.05, vacuumRange.zCoord + 0.05); + Vec3 vacuumRange = playerPos.addVector(lookVec.xCoord * currentVacuumRange, lookVec.yCoord * currentVacuumRange, + lookVec.zCoord * currentVacuumRange); + AxisAlignedBB aabb = new AxisAlignedBB(vacuumRange.xCoord - 0.05, vacuumRange.yCoord - 0.05, vacuumRange.zCoord - 0.05, + vacuumRange.xCoord + 0.05, + vacuumRange.yCoord + 0.05, vacuumRange.zCoord + 0.05); RenderUtils.drawBox(aabb, vacuumRangeColor); } private void drawESP(Entity entity) { - AxisAlignedBB boundingBox = new AxisAlignedBB(entity.posX - 0.5, entity.posY + entity.getEyeHeight() - 0.35, entity.posZ - 0.5, entity.posX + 0.5, entity.posY + entity.getEyeHeight() + 0.65, entity.posZ + 0.5); + AxisAlignedBB boundingBox = new AxisAlignedBB(entity.posX - 0.5, entity.posY + entity.getEyeHeight() - 0.35, entity.posZ - 0.5, + entity.posX + 0.5, + entity.posY + entity.getEyeHeight() + 0.65, entity.posZ + 0.5); double d0 = Minecraft.getMinecraft().getRenderManager().viewerPosX; double d1 = Minecraft.getMinecraft().getRenderManager().viewerPosY; double d2 = Minecraft.getMinecraft().getRenderManager().viewerPosZ; @@ -1133,16 +1331,20 @@ private void drawESP(Entity entity) { EnumChatFormatting distanceColor = distance > currentVacuumRange ? EnumChatFormatting.RED : EnumChatFormatting.GREEN; ItemStack itemStack = ((EntityArmorStand) entity).getEquipmentInSlot(4); NBTTagCompound tagCompound = itemStack.getTagCompound(); - String texture = tagCompound.getCompoundTag("SkullOwner").getCompoundTag("Properties").getTagList("textures", 10).getCompoundTagAt(0).getString("Value"); + String texture = tagCompound.getCompoundTag("SkullOwner").getCompoundTag("Properties").getTagList("textures", 10) + .getCompoundTagAt(0) + .getString("Value"); String pestName = this.pests.stream().filter(pest -> texture.equals(pest.getSecond())).findFirst().get().getFirst(); - RenderUtils.drawText(pestName + String.format(distanceColor + " %.1fm", distance), entity.posX, entity.posY + entity.getEyeHeight() + 0.65 + 0.5, entity.posZ, (float) (1 + Math.min((distance / 20f), 2f))); + RenderUtils.drawText(pestName + String.format(distanceColor + " %.1fm", distance), entity.posX, + entity.posY + entity.getEyeHeight() + 0.65 + 0.5, entity.posZ, (float) (1 + Math.min((distance / 20f), 2f))); } catch (Exception ignored) { } } RenderUtils.drawBox(boundingBox, color); } if (FarmHelperConfig.pestsTracers) { - RenderUtils.drawTracer(new Vec3(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ), FarmHelperConfig.pestsTracersColor.toJavaColor()); + RenderUtils.drawTracer(new Vec3(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ), + FarmHelperConfig.pestsTracersColor.toJavaColor()); } } @@ -1150,13 +1352,18 @@ private boolean canEntityBeSeenIgnoreNonCollidable(Entity entity) { 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) || !BlockUtils.hasCollision(mop.getBlockPos())); + return mop == null || mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && ( + mc.theWorld.getBlockState(mop.getBlockPos()).getBlock().equals(Blocks.cactus) || !BlockUtils.hasCollision(mop.getBlockPos())); } @SubscribeEvent(receiveCanceled = true, priority = EventPriority.HIGHEST) public void onEntityDeath(LivingDeathEvent event) { - if (mc.thePlayer == null || mc.theWorld == null) return; - if (!GameStateHandler.getInstance().inGarden()) return; + if (mc.thePlayer == null || mc.theWorld == null) { + return; + } + if (!GameStateHandler.getInstance().inGarden()) { + return; + } Entity entity = event.entity; LogUtils.sendDebug("[Pests Destroyer] Entity died: " + entity.getName() + "(" + entity.getEntityId() + ")" + " at: " + entity.getPosition()); @@ -1170,43 +1377,51 @@ public void onEntityDeath(LivingDeathEvent event) { Entity realEntity = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityBat || e instanceof EntitySilverfish); Entity nameEntity = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityArmorStand && e != entity); if (realEntity != null) { - LogUtils.sendDebug("[Pests Destroyer] Found real entity: " + realEntity.getName() + "(" + realEntity.getEntityId() + ")" + " at: " + realEntity.getPosition()); + LogUtils.sendDebug("[Pests Destroyer] Found real entity: " + realEntity.getName() + "(" + realEntity.getEntityId() + ")" + " at: " + + realEntity.getPosition()); killedEntities.add(realEntity); } if (nameEntity != null) { - LogUtils.sendDebug("[Pests Destroyer] Found name entity: " + nameEntity.getName() + "(" + nameEntity.getEntityId() + ")" + " at: " + nameEntity.getPosition()); + LogUtils.sendDebug("[Pests Destroyer] Found name entity: " + nameEntity.getName() + "(" + nameEntity.getEntityId() + ")" + " at: " + + nameEntity.getPosition()); killedEntities.add(nameEntity); } } if (entity instanceof EntityBat || entity instanceof EntitySilverfish) { - Entity armorStand = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityArmorStand && e.getName().contains("Armor Stand")); + Entity armorStand = PlayerUtils.getEntityCuttingOtherEntity(entity, + (e) -> e instanceof EntityArmorStand && e.getName().contains("Armor Stand")); Entity nameEntity = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityArmorStand && e != armorStand); if (armorStand != null) { - LogUtils.sendDebug("[Pests Destroyer] Found armor stand: " + armorStand.getName() + "(" + armorStand.getEntityId() + ")" + " at: " + armorStand.getPosition()); + LogUtils.sendDebug("[Pests Destroyer] Found armor stand: " + armorStand.getName() + "(" + armorStand.getEntityId() + ")" + " at: " + + armorStand.getPosition()); killedEntities.add(armorStand); } if (nameEntity != null) { - LogUtils.sendDebug("[Pests Destroyer] Found name entity: " + nameEntity.getName() + "(" + nameEntity.getEntityId() + ")" + " at: " + nameEntity.getPosition()); + LogUtils.sendDebug("[Pests Destroyer] Found name entity: " + nameEntity.getName() + "(" + nameEntity.getEntityId() + ")" + " at: " + + nameEntity.getPosition()); killedEntities.add(nameEntity); } } - if (isRunning()) + if (isRunning()) { FlyPathFinderExecutor.getInstance().stop(); + } resetFireworkInfo(); lastFireworkTime = 0; currentEntityTarget.ifPresent(e -> { if (!e.equals(event.entity)) { return; } - if (isRunning()) + if (isRunning()) { KeyBindUtils.stopMovement(); + } currentEntityTarget = Optional.empty(); stuckClock.reset(); }); PlotUtils.Plot plot = PlotUtils.getPlotNumberBasedOnLocation(entity.getPosition()); if (plot == null) { - if (isRunning()) + if (isRunning()) { LogUtils.sendDebug("[Pests Destroyer] Failed to get plot for entity: " + entity.getName() + " at: " + entity.getPosition()); + } return; } LogUtils.sendDebug("[Pests Destroyer] Removed 1 pest from plot number: " + plot.number); @@ -1219,17 +1434,29 @@ public void onEntityDeath(LivingDeathEvent event) { @SubscribeEvent(receiveCanceled = true, priority = EventPriority.HIGHEST) public void onFirework(SpawnParticleEvent event) { - if (mc.thePlayer == null || mc.theWorld == null) return; - if (!GameStateHandler.getInstance().inGarden()) return; - if (!enabled) return; - if (state != States.WAIT_FOR_LOCATION) return; + if (mc.thePlayer == null || mc.theWorld == null) { + return; + } + if (!GameStateHandler.getInstance().inGarden()) { + return; + } + if (!enabled) { + return; + } + if (state != States.WAIT_FOR_LOCATION) { + return; + } EnumParticleTypes type = event.getParticleTypes(); - if (type != EnumParticleTypes.VILLAGER_ANGRY) return; + if (type != EnumParticleTypes.VILLAGER_ANGRY) { + return; + } lastFireworkTime = System.currentTimeMillis(); if (firstLocation == null) { - if (mc.thePlayer.getPositionVector().distanceTo(event.getPos()) > 5) return; + if (mc.thePlayer.getPositionVector().distanceTo(event.getPos()) > 5) { + return; + } firstLocation = event.getPos(); locations.add(firstLocation); lastLocation = firstLocation; @@ -1244,7 +1471,9 @@ public void onFirework(SpawnParticleEvent event) { } private Vec3 calculateWaypoint() { - if (lastLocation == null) return null; + if (lastLocation == null) { + return null; + } Vec3 direction = lastLocation.subtract(firstLocation).normalize(); return lastLocation.addVector(direction.xCoord * 10, 0, direction.zCoord * 10); } @@ -1258,11 +1487,21 @@ public void resetFireworkInfo() { @SubscribeEvent public void onSpawnObject(SpawnObjectEvent event) { - if (mc.thePlayer == null || mc.theWorld == null) return; - if (!GameStateHandler.getInstance().inGarden()) return; - if (event.type != 76) return; - if (!enabled) return; - if (state != States.WAIT_FOR_LOCATION) return; + if (mc.thePlayer == null || mc.theWorld == null) { + return; + } + if (!GameStateHandler.getInstance().inGarden()) { + return; + } + if (event.type != 76) { + return; + } + if (!enabled) { + return; + } + if (state != States.WAIT_FOR_LOCATION) { + return; + } double distance = mc.thePlayer.getDistance(event.pos.xCoord, event.pos.yCoord, event.pos.zCoord); if (distance < 3) { @@ -1275,7 +1514,8 @@ public void onSpawnObject(SpawnObjectEvent event) { FlyPathFinderExecutor.getInstance().setDontRotate(true); FlyPathFinderExecutor.getInstance().setSprinting(false); FlyPathFinderExecutor.getInstance().findPath(new Vec3(event.pos.xCoord, y, event.pos.zCoord), true, true); - LogUtils.sendWarning("[Pests Destroyer] Firework is too close to player. Flying to x: " + event.pos.xCoord + " y: " + y + " z: " + event.pos.zCoord); + LogUtils.sendWarning( + "[Pests Destroyer] Firework is too close to player. Flying to x: " + event.pos.xCoord + " y: " + y + " z: " + event.pos.zCoord); state = States.GET_LOCATION; } } @@ -1284,22 +1524,38 @@ public void onSpawnObject(SpawnObjectEvent event) { @SubscribeEvent public void onGuiOpen(DrawScreenAfterEvent event) { - if (mc.thePlayer == null || mc.theWorld == null) return; - if (!GameStateHandler.getInstance().inGarden()) return; - if (checkedThisGui) return; - if (!(event.guiScreen instanceof GuiChest)) return; + if (mc.thePlayer == null || mc.theWorld == null) { + return; + } + if (!GameStateHandler.getInstance().inGarden()) { + return; + } + if (checkedThisGui) { + return; + } + if (!(event.guiScreen instanceof GuiChest)) { + return; + } String guiName = InventoryUtils.getInventoryName(); - if (guiName == null) return; - if (!delayClock.passed()) return; + if (guiName == null) { + return; + } + if (!delayClock.passed()) { + return; + } ContainerChest guiChest = (ContainerChest) ((GuiChest) event.guiScreen).inventorySlots; - if (!InventoryUtils.isInventoryLoaded()) return; + if (!InventoryUtils.isInventoryLoaded()) { + return; + } int plotCounter = 0; if (StringUtils.stripControlCodes(guiName).equals("Configure Plots")) { for (int i = 0; i < guiChest.inventorySlots.size(); i++) { Slot slot = guiChest.inventorySlots.get(i); - if (slot == null || !slot.getHasStack()) continue; + if (slot == null || !slot.getHasStack()) { + continue; + } if (slot.getStack().getDisplayName().contains("Plot")) { String displayName = StringUtils.stripControlCodes(slot.getStack().getDisplayName()); try { @@ -1310,8 +1566,9 @@ public void onGuiOpen(DrawScreenAfterEvent event) { LogUtils.sendError("[Pests Destroyer] Failed to parse plot number: " + displayName); } plotCounter++; - } else if (StringUtils.stripControlCodes(slot.getStack().getDisplayName()).equals("The Barn")) + } else if (StringUtils.stripControlCodes(slot.getStack().getDisplayName()).equals("The Barn")) { plotCounter++; + } } } else { @@ -1339,7 +1596,7 @@ private void fly() { KeyBindUtils.holdThese(mc.gameSettings.keyBindJump); return; } - if (mc.thePlayer.motionY < -0.0784000015258789 || BlockUtils.getRelativeBlock(0, 0, 0).getMaterial().isLiquid()) + if (mc.thePlayer.motionY < -0.0784000015258789 || BlockUtils.getRelativeBlock(0, 0, 0).getMaterial().isLiquid()) { if (flyDelay.passed()) { if (!mc.thePlayer.capabilities.isFlying) { mc.thePlayer.capabilities.isFlying = true; @@ -1349,6 +1606,7 @@ private void fly() { } else if (flyDelay.isScheduled()) { return; } + } if (mc.thePlayer.onGround) { mc.thePlayer.jump(); flyDelay.schedule(80 + (long) (Math.random() * 80)); @@ -1383,7 +1641,9 @@ private PlotUtils.Plot getClosestPlot() { } private boolean isNearPlotCenter() { - if (!closestPlot.isPresent()) return false; + if (!closestPlot.isPresent()) { + return false; + } BlockPos plotCenter = PlotUtils.getPlotCenter(closestPlot.get().number); double distance = mc.thePlayer.getDistance(plotCenter.getX(), mc.thePlayer.posY, plotCenter.getZ()); return distance < 15; @@ -1391,6 +1651,8 @@ private boolean isNearPlotCenter() { public enum States { IDLE, + SWAP_ARMOR, + ARMOR_SWAP_VERIFY, OPEN_DESK, OPEN_PLOTS, WAIT_FOR_INFO, @@ -1405,7 +1667,8 @@ public enum States { FIND_PEST, KILL_PEST, CHECK_ANOTHER_PEST, - GO_BACK + GO_BACK, + FINISH } enum RotationState { diff --git a/src/main/java/com/jelly/farmhelperv2/macro/AbstractMacro.java b/src/main/java/com/jelly/farmhelperv2/macro/AbstractMacro.java index afda426a..d03d89cc 100644 --- a/src/main/java/com/jelly/farmhelperv2/macro/AbstractMacro.java +++ b/src/main/java/com/jelly/farmhelperv2/macro/AbstractMacro.java @@ -7,6 +7,8 @@ import com.jelly.farmhelperv2.feature.FeatureManager; import com.jelly.farmhelperv2.feature.impl.DesyncChecker; import com.jelly.farmhelperv2.feature.impl.LagDetector; +import com.jelly.farmhelperv2.feature.impl.PestFarmer; +import com.jelly.farmhelperv2.feature.impl.PestsDestroyer; import com.jelly.farmhelperv2.handler.GameStateHandler; import com.jelly.farmhelperv2.handler.MacroHandler; import com.jelly.farmhelperv2.handler.RotationHandler; @@ -147,6 +149,13 @@ public void onTick() { } checkOnSpawnClock.schedule(5000); } + + if (FarmHelperConfig.pestForceEnable && PestsDestroyer.getInstance().canEnableMacro()) { + PestsDestroyer.getInstance().start(); + LogUtils.sendDebug("Activating Pests Destroyer"); + return; + } + if (mc.thePlayer.getPosition().getY() < 0) { LogUtils.sendError("Build a wall between the rewarp point and the void to prevent falling out of the garden! Disabling the macro..."); MacroHandler.getInstance().disableMacro(); @@ -226,7 +235,9 @@ public void onTick() { return; } - PlayerUtils.getTool(); + if (!PestFarmer.instance.holdDaedalus()) { + PlayerUtils.getTool(); + } // Update or invoke state, based on if player is moving or not if (GameStateHandler.getInstance().canChangeDirection()) { @@ -382,14 +393,15 @@ public void setBreakTime(double time, double timeBefore) { public enum State { // Add default values like NONE and DROPPING + // DO NOT REARRAGE, IT WILL BREAK PEST FARMER IF YOU DO - osama NONE, DROPPING, + SWITCHING_SIDE, + SWITCHING_LANE, LEFT, RIGHT, BACKWARD, FORWARD, - SWITCHING_SIDE, - SWITCHING_LANE, A, D, diff --git a/src/main/java/com/jelly/farmhelperv2/mixin/client/MixinMinecraft.java b/src/main/java/com/jelly/farmhelperv2/mixin/client/MixinMinecraft.java index 9925d6cd..f5a42504 100644 --- a/src/main/java/com/jelly/farmhelperv2/mixin/client/MixinMinecraft.java +++ b/src/main/java/com/jelly/farmhelperv2/mixin/client/MixinMinecraft.java @@ -4,22 +4,26 @@ import com.jelly.farmhelperv2.feature.impl.BanInfoWS; import com.jelly.farmhelperv2.handler.GameStateHandler; import com.jelly.farmhelperv2.handler.MacroHandler; +import com.jelly.farmhelperv2.util.LogUtils; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.multiplayer.PlayerControllerMP; +import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.settings.GameSettings; import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; import net.minecraft.util.BlockPos; import net.minecraft.util.MovingObjectPosition; +import org.lwjgl.opengl.Display; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = Minecraft.class, priority = Integer.MAX_VALUE) @@ -110,4 +114,13 @@ private void sendClickBlockToController(CallbackInfo ci) { } } + + @Redirect(method = "setIngameFocus", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/Display;isActive()Z")) + public boolean isActive() { + System.out.println("Trying to set in game focus. Macro Toggled: " + MacroHandler.getInstance().isMacroToggled()); + if (MacroHandler.getInstance().isMacroToggled()) { + return true; + } + return Display.isActive(); + } } \ No newline at end of file