Skip to content

Commit

Permalink
v2.4.1-pre3 update
Browse files Browse the repository at this point in the history
+ Auto Pest Hunter BETA - for now it's manual only
+ Profilt calculator - added reset button
+ Discord Webhook - added ban stats
  • Loading branch information
onixiya1337 committed Jan 9, 2024
1 parent 0d6a47a commit 397fe57
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2
mcVersion=1.8.9
modid=farmhelperv2
modName=FarmHelper
version=2.4.1-pre2
version=2.4.1-pre3
shouldRelease=true
51 changes: 51 additions & 0 deletions src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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 AUTO_PEST_HUNTER = "Auto Pest Hunter";
private transient static final String DISCORD_INTEGRATION = "Discord Integration";
private transient static final String DELAYS = "Delays";
private transient static final String HUD = "HUD";
Expand Down Expand Up @@ -1260,6 +1261,52 @@ public static void triggerManuallyPestsDestroyer() {
//</editor-fold>
//</editor-fold>

//<editor-fold desc="AUTO PEST HUNTER">
@Switch(
name = "Enable Auto Pest Hunter", category = AUTO_PEST_HUNTER, subcategory = "Auto Pest Hunter",
description = "Automatically hunts pests"
)
public static boolean autoPestHunter = false;
@Button(
name = "Trigger now Auto Pest Hunter", category = AUTO_PEST_HUNTER, subcategory = "Auto Pest Hunter",
description = "Triggers the auto pest hunter manually",
text = "Trigger now"
)
public static void triggerManuallyAutoPestHunter() {
AutoPestHunter.getInstance().setManuallyStarted(true);
AutoPestHunter.getInstance().start();
}
@Button(
name = "Set the pest hunter location", category = AUTO_PEST_HUNTER, subcategory = "Auto Pest Hunter",
description = "Sets the pest hunter location",
text = "Set desk"
)
public static Runnable setPestHunterLocation = () -> {
if (!VisitorsMacro.getInstance().isInBarn()) {
LogUtils.sendError("[Auto Pest Hunter] You need to be in the barn to set the pest hunter location!");
return;
}
pestHunterDeskX = mc.thePlayer.getPosition().getX();
pestHunterDeskY = mc.thePlayer.getPosition().getY();
pestHunterDeskZ = mc.thePlayer.getPosition().getZ();
};
@Number(
name = "Pest Hunter Desk X", category = AUTO_PEST_HUNTER, subcategory = "Auto Pest Hunter",
min = -300, max = 300
)
public static int pestHunterDeskX = 0;
@Number(
name = "Pest Hunter Desk Y", category = AUTO_PEST_HUNTER, subcategory = "Auto Pest Hunter",
min = 50, max = 150
)
public static int pestHunterDeskY = 0;
@Number(
name = "Pest Hunter Desk Z", category = AUTO_PEST_HUNTER, subcategory = "Auto Pest Hunter",
min = -300, max = 300
)
public static int pestHunterDeskZ = 0;
//</editor-fold>

//<editor-fold desc="DISCORD INTEGRATION">
//<editor-fold desc="Webhook Discord">
@Switch(
Expand Down Expand Up @@ -1708,6 +1755,10 @@ public FarmHelperConfig() {
this.addDependency("pingEveryoneOnPestsDetectionNumberExceeded", "sendWebhookLogIfPestsDetectionNumberExceeded");
this.addDependency("pingEveryoneOnPestsDetectionNumberExceeded", "enableWebHook");

this.hideIf("pestHunterDeskX", () -> true);
this.hideIf("pestHunterDeskY", () -> true);
this.hideIf("pestHunterDeskZ", () -> true);

this.addDependency("pestRepellentType", "autoPestRepellent");

this.addDependency("averageBPSDrop", "averageBPSDropCheck");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public List<IFeature> fillFeatures() {
AutoCookie.getInstance(),
AutoGodPot.getInstance(),
AutoReconnect.getInstance(),
AutoPestHunter.getInstance(),
AutoRepellent.getInstance(),
AutoSell.getInstance(),
BanInfoWS.getInstance(),
Expand Down
299 changes: 299 additions & 0 deletions src/main/java/com/jelly/farmhelperv2/feature/impl/AutoPestHunter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
package com.jelly.farmhelperv2.feature.impl;

import cc.polyfrost.oneconfig.utils.Multithreading;
import com.jelly.farmhelperv2.config.FarmHelperConfig;
import com.jelly.farmhelperv2.feature.IFeature;
import com.jelly.farmhelperv2.handler.BaritoneHandler;
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.handler.RotationHandler;
import com.jelly.farmhelperv2.util.InventoryUtils;
import com.jelly.farmhelperv2.util.KeyBindUtils;
import com.jelly.farmhelperv2.util.LogUtils;
import com.jelly.farmhelperv2.util.PlayerUtils;
import com.jelly.farmhelperv2.util.helper.Clock;
import com.jelly.farmhelperv2.util.helper.RotationConfiguration;
import com.jelly.farmhelperv2.util.helper.Target;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

import java.util.Comparator;
import java.util.concurrent.TimeUnit;

public class AutoPestHunter implements IFeature {
private final Minecraft mc = Minecraft.getMinecraft();
private static AutoPestHunter instance;

public static AutoPestHunter getInstance() {
if (instance == null) {
instance = new AutoPestHunter();
}
return instance;
}

private boolean enabled = false;
@Setter
public boolean manuallyStarted = false;
@Getter
private State state = State.NONE;
@Getter
private final Clock stuckClock = new Clock();
@Getter
private final Clock delayClock = new Clock();
private BlockPos positionBeforeTp;
private BlockPos deskPos() {
return new BlockPos(FarmHelperConfig.pestHunterDeskX, FarmHelperConfig.pestHunterDeskY, FarmHelperConfig.pestHunterDeskZ);
}
private static final RotationHandler rotation = RotationHandler.getInstance();

@Override
public String getName() {
return "Auto Pest Hunter";
}

@Override
public boolean isRunning() {
return enabled;
}

@Override
public boolean shouldPauseMacroExecution() {
return true;
}

@Override
public boolean shouldStartAtMacroStart() {
return false;
}

@Override
public void start() {
if (enabled) return;
if (!canEnableMacro(manuallyStarted)) return;
if (!GameStateHandler.getInstance().inGarden()) return;
if (!isToggled()) return;
if (mc.thePlayer == null || mc.theWorld == null) return;
resetStatesAfterMacroDisabled();
enabled = true;
LogUtils.sendWarning("[Auto Pest Hunter] Starting...");
}

@Override
public void stop() {
enabled = false;
LogUtils.sendWarning("[Auto Pest Hunter] Stopping...");
KeyBindUtils.stopMovement();
resetStatesAfterMacroDisabled();
if (BaritoneHandler.isPathing())
BaritoneHandler.stopPathing();
}

@Override
public void resetStatesAfterMacroDisabled() {
manuallyStarted = false;
state = State.NONE;
stuckClock.reset();
delayClock.reset();
positionBeforeTp = null;
}

@Override
public boolean isToggled() {
return FarmHelperConfig.autoPestHunter;
}

@Override
public boolean shouldCheckForFailsafes() {
return false;
}

enum State {
NONE,
TELEPORT_TO_DESK,
GO_TO_PHILLIP,
CLICK_PHILLIP,
WAIT_FOR_GUI,
EMPTY_VACUUM,
WAIT_FOR_VACUUM,
GO_BACK,
}

public boolean canEnableMacro(boolean manually) {
if (!isToggled()) return false;
if (!GameStateHandler.getInstance().inGarden()) return false;
if (!MacroHandler.getInstance().isMacroToggled() && !manually) return false;
if (FarmHelperConfig.pestHunterDeskX == 0 && FarmHelperConfig.pestHunterDeskY == 0 && FarmHelperConfig.pestHunterDeskZ == 0) {
LogUtils.sendError("[Auto Pest Hunter] The desk position is not set!");
return false;
}
return true;
}

@SubscribeEvent
public void onTickExecution(TickEvent.ClientTickEvent event) {
if (!enabled) return;
if (mc.thePlayer == null || mc.theWorld == null) return;
if (!isToggled()) return;
if (event.phase != TickEvent.Phase.START) return;
if (!GameStateHandler.getInstance().inGarden()) return;
if (!enabled) return;

if (stuckClock.isScheduled() && stuckClock.passed()) {
LogUtils.sendError("[Auto Pest Hunter] The player is stuck!");
state = State.GO_BACK;
return;
}

if (delayClock.isScheduled() && !delayClock.passed()) return;

switch (state) {
case NONE:
if (mc.currentScreen != null) {
PlayerUtils.closeScreen();
break;
}
positionBeforeTp = mc.thePlayer.getPosition();
state = State.TELEPORT_TO_DESK;
mc.thePlayer.sendChatMessage("/tptoplot barn");
delayClock.schedule((long) (1_000 + Math.random() * 500));
stuckClock.schedule(10_000L);
break;
case TELEPORT_TO_DESK:
if (mc.thePlayer.getPosition().equals(positionBeforeTp) || PlayerUtils.isPlayerSuffocating()) {
LogUtils.sendDebug("[Auto Pest Hunter] Waiting for teleportation...");
break;
}
if (!mc.thePlayer.onGround || mc.thePlayer.capabilities.isFlying) {
KeyBindUtils.setKeyBindState(mc.gameSettings.keyBindSneak, true);
LogUtils.sendDebug("[Auto Pest Hunter] The player is not on the ground, waiting...");
stuckClock.schedule(5_000L);
break;
}
KeyBindUtils.stopMovement();
if (positionBeforeTp.distanceSq(mc.thePlayer.getPosition()) > 3) {
state = State.GO_TO_PHILLIP;
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
stuckClock.schedule(30_000L);
break;
}
case GO_TO_PHILLIP:
if (BaritoneHandler.hasFailed() && deskPos().distanceSq(mc.thePlayer.getPosition()) > 3) {
LogUtils.sendError("[Auto Pest Hunter] Baritone failed to reach the destination!");
state = State.GO_BACK;
break;
}
if (BaritoneHandler.isWalkingToGoalBlock()) break;
if (mc.thePlayer.getDistanceSqToCenter(deskPos()) < 2) {
state = State.CLICK_PHILLIP;
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
stuckClock.schedule(30_000L);
break;
}
BaritoneHandler.walkToBlockPos(deskPos());
delayClock.schedule(1000L);
break;
case CLICK_PHILLIP:
if (mc.thePlayer.getDistanceSqToCenter(deskPos()) > 3) {
state = State.GO_TO_PHILLIP;
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
stuckClock.schedule(15_000L);
break;
}
Entity closest = mc.theWorld.getLoadedEntityList().
stream().
filter(entity ->
entity.hasCustomName() && entity.getCustomNameTag().contains(StringUtils.stripControlCodes("Phillip")))
.min(Comparator.comparingDouble(entity -> entity.getDistanceSqToCenter(mc.thePlayer.getPosition()))).orElse(null);
rotation.easeTo(
new RotationConfiguration(
new Target(closest),
FarmHelperConfig.getRandomRotationTime(),
() -> {
KeyBindUtils.leftClick();
state = State.WAIT_FOR_GUI;
RotationHandler.getInstance().reset();
stuckClock.schedule(10_000L);
}
).easeOutBack(true)
);
delayClock.schedule(FarmHelperConfig.getRandomRotationTime() + 500L);
break;
case WAIT_FOR_GUI:
String invName = InventoryUtils.getInventoryName();
if (invName != null && !invName.contains("Pesthunter")) {
PlayerUtils.closeScreen();
state = State.CLICK_PHILLIP;
} else {
state = State.EMPTY_VACUUM;
}
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
break;
case EMPTY_VACUUM:
Slot vacuumSlot = InventoryUtils.getSlotOfItemInContainer("Empty Vacuum Bag");
if (vacuumSlot == null) {
break;
}
ItemStack itemLore = vacuumSlot.getStack();
if (InventoryUtils.getItemLore(itemLore).contains("Click to empty the vacuum")) {
state = State.WAIT_FOR_VACUUM;
} else {
state = State.GO_BACK;
LogUtils.sendWarning("[Auto Pest Hunter] The vacuum is empty!");
}
InventoryUtils.clickContainerSlot(vacuumSlot.slotNumber, InventoryUtils.ClickType.LEFT, InventoryUtils.ClickMode.PICKUP);
state = State.WAIT_FOR_VACUUM;
stuckClock.schedule(10_000L);
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
break;
case GO_BACK:
if (!manuallyStarted) {
Multithreading.schedule(() -> {
MacroHandler.getInstance().getCurrentMacro().ifPresent(cm -> cm.triggerWarpGarden(true, false));
Multithreading.schedule(() -> {
MacroHandler.getInstance().resumeMacro();
}, 1_000, TimeUnit.MILLISECONDS);
}, 500, TimeUnit.MILLISECONDS);
}
stop();
break;
}
}

private final String[] dialogueMessages = {
"Howdy, ",
"Sorry for the intrusion, but I got a report of a Pest outbreak around here?",
"Err...vermin? Swine? Buggers? Y'know...Pests!",
"They seem to pop up when you're breaking crops on your Garden!",
"Okay, feller. Take this SkyMart Vacuum!",
"There's a Pest out there somewhere, I'm certain of it.",
"When you find one, simply aim the vacuum, hold down the button, and you can suck them buggers up real quick!",
"When you've done that, come back and tell me all about how much fun you had!"
};

@SubscribeEvent
public void onChatMessageReceived(ClientChatReceivedEvent event) {
if (enabled && event.type == 0 && event.message != null && state == State.WAIT_FOR_VACUUM) {
if (event.message.getFormattedText().contains("§e[NPC] §6Phillip§f: Thanks for the §6Pests§f,"))
LogUtils.sendSuccess("[Auto Pest Hunter] Successfully emptied the vacuum!");
else {
for (String message : dialogueMessages) {
if (event.message.getFormattedText().contains("§e[NPC] §6Phillip§f: " + message)) {
LogUtils.sendError("[Auto Pest Hunter] You haven't unlocked Phillip yet!");
break;
}
}
}
state = State.GO_BACK;
delayClock.schedule((long) (FarmHelperConfig.pestAdditionalGUIDelay + 300 + Math.random() * 300));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public void toggleMacro() {
PestsDestroyer.getInstance().stop();
return;
}
if (AutoPestHunter.getInstance().isRunning()) {
AutoPestHunter.getInstance().stop();
return;
}
if (VisitorsMacro.getInstance().isInBarn()) {
if (VisitorsMacro.getInstance().isToggled()) {
VisitorsMacro.getInstance().setManuallyStarted(true);
Expand Down
Loading

0 comments on commit 397fe57

Please sign in to comment.