Skip to content

Commit

Permalink
Pests Destroyer:
Browse files Browse the repository at this point in the history
 + Added 'Pests Destroyer on the track' - Macro will try to kill pest if any is in range during normal farming (not sure how effective it is with lower tier vacuums lol). Make sure to enable it, by default it's disabled
 = Tweaks

Visitors Macro:
 = Fixed another Hypixel's tablist addition
 = Tweaks and fixes

Memory and cpu optimizations
  • Loading branch information
May2Beez committed Mar 16, 2024
1 parent f870c09 commit 308842b
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 342 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.5.0-pre5
version=2.5.0-pre6
shouldRelease=true
35 changes: 0 additions & 35 deletions src/main/java/com/jelly/farmhelperv2/FarmHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.handler.RotationHandler;
import com.jelly.farmhelperv2.pathfinder.FlyPathFinderExecutor;
import com.jelly.farmhelperv2.pathfinder.WorldCache;
import com.jelly.farmhelperv2.remote.DiscordBotHandler;
import com.jelly.farmhelperv2.remote.WebsocketHandler;
import com.jelly.farmhelperv2.util.*;
Expand All @@ -25,10 +24,7 @@
import com.jelly.farmhelperv2.util.helper.FlyPathfinder;
import com.jelly.farmhelperv2.util.helper.TickTask;
import net.minecraft.client.Minecraft;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -37,7 +33,6 @@
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.lwjgl.opengl.Display;

import java.awt.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -98,11 +93,6 @@ public void onTickSendInfoAboutShittyClient(TickEvent.PlayerTickEvent event) {
Notifications.INSTANCE.send("FarmHelper", "Pests Killer Ticks Of Not Seeing Pest While Attacking has been set to 100 ticks because of a bug in the previous version.", 15000);
LogUtils.sendWarning("Pests Killer Ticks Of Not Seeing Pest While Attacking has been set to 100 ticks because of a bug in the previous version.");
}
if (getAllocatedMemoryMB() < 2500 && FarmHelperConfig.useCachingInFlyPathfinder) {
FarmHelperConfig.useCachingInFlyPathfinder = false;
Notifications.INSTANCE.send("FarmHelper", "You don't have enough of RAM allocated to Minecraft need for pathfinder caching! Disabling it...", 15000);
LogUtils.sendWarning("You don't have enough of RAM allocated to Minecraft need for pathfinder caching. Disabling it... It's recommended to have at least 4GB of RAM allocated to Minecraft to avoid stutters.");
}
if (!FarmHelperConfig.flyPathfinderOringoCompatible && ReflectionUtils.hasModFile("oringo")) {
FarmHelperConfig.flyPathfinderOringoCompatible = true;
Notifications.INSTANCE.send("FarmHelper", "You've got Oringo installed in your mods folder! FarmHelper will use Oringo compatibility mode for FlyPathfinder.", 15000);
Expand All @@ -126,7 +116,6 @@ private void initializeListeners() {
MinecraftForge.EVENT_BUS.register(AudioManager.getInstance());
MinecraftForge.EVENT_BUS.register(RotationHandler.getInstance());
MinecraftForge.EVENT_BUS.register(FlyPathfinder.getInstance());
MinecraftForge.EVENT_BUS.register(WorldCache.getInstance());
MinecraftForge.EVENT_BUS.register(FlyPathFinderExecutor.getInstance());
MinecraftForge.EVENT_BUS.register(new TablistUtils());
MinecraftForge.EVENT_BUS.register(new ScoreboardUtils());
Expand All @@ -141,30 +130,6 @@ private void initializeCommands() {
CommandManager.register(new FarmHelperMainCommand());
}

@SubscribeEvent
public void onLastRender(RenderWorldLastEvent event) {
if (mc.thePlayer == null || mc.theWorld == null) return;
if (!FarmHelperConfig.showDebugPathfindingRoute) return;
if (FarmHelperConfig.streamerMode) return;

Vec3 position = mc.thePlayer.getPositionVector();

for (int x = (int) (position.xCoord - 5); x < position.xCoord + 5; x++) {
for (int y = (int) (position.yCoord - 5); y < position.yCoord + 5; y++) {
for (int z = (int) (position.zCoord - 5); z < position.zCoord + 5; z++) {
WorldCache.CacheEntry pathNodeType = WorldCache.getInstance().getWorldCache().get(new BlockPos(x, y, z));
if (pathNodeType == null)
continue;
if (pathNodeType.getPathNodeType().equals(BlockUtils.PathNodeType.OPEN)) {
RenderUtils.drawBlockBox(new BlockPos(x, y, z), new Color(0, 200, 0, 35));
} else if (pathNodeType.getPathNodeType().equals(BlockUtils.PathNodeType.BLOCKED)) {
RenderUtils.drawBlockBox(new BlockPos(x, y, z), new Color(200, 0, 0, 35));
}
}
}
}
}

public int getAllocatedMemoryMB() {
Runtime runtime = Runtime.getRuntime();
long maxMemory = runtime.maxMemory();
Expand Down
47 changes: 26 additions & 21 deletions src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1068,22 +1068,6 @@ else if (testFailsafeTypeSelected != 6)
)
public static boolean flyPathfinderOringoCompatible = false;

@Switch(
name = "Use caching in fly pathfinder",
description = "Speeds up finding path (You need to re-enter the world to trigger first caching scan)",
category = PESTS_DESTROYER, subcategory = "Pests Destroyer"
)
public static boolean useCachingInFlyPathfinder = true;

@Info(
text = "You need to have at least 4 GB of RAM to use the fly pathfinder caching feature to avoid stutters.",
type = InfoType.INFO,
category = PESTS_DESTROYER,
subcategory = "Pests Destroyer",
size = 2
)
public static boolean pestsDestroyerInfo2;

@Switch(
name = "Pause the Pests Destroyer during Jacob's contests", category = PESTS_DESTROYER, subcategory = "Pests Destroyer",
description = "Pauses the Pests Destroyer during Jacob's contests",
Expand All @@ -1109,6 +1093,28 @@ public static void triggerManuallyPestsDestroyer() {
)
public static boolean pestsDestroyerAfkInfiniteMode = false;

@Switch(
name = "Pests Destroyer on the track",
description = "Will kill pests if they are in your range while farming",
category = PESTS_DESTROYER, subcategory = "Pests Destroyer on the track"
)
public static boolean pestsDestroyerOnTheTrack = false;

@Slider(
name = "Pests Destroyer on the track FOV",
description = "The field of view of the pests destroyer on the track",
category = PESTS_DESTROYER, subcategory = "Pests Destroyer on the track",
min = 1, max = 360
)
public static int pestsDestroyerOnTheTrackFOV = 360;

@Switch(
name = "Don't kill pests on track during Jacob's Contest",
description = "Prevents the macro from killing pests on the track during Jacob's Contest",
category = PESTS_DESTROYER, subcategory = "Pests Destroyer on the track"
)
public static boolean dontKillPestsOnTrackDuringJacobsContest = true;

@KeyBind(
name = "Enable Pests Destroyer", category = PESTS_DESTROYER, subcategory = "Pests Destroyer",
description = "Enables the pests destroyer",
Expand Down Expand Up @@ -1756,11 +1762,6 @@ public enum SPRAYONATOR_ITEM {
)
public static boolean showRotationDebugMessages = false;

@Switch(
name = "Show debug pathfinding route", category = DEBUG, subcategory = "Debug",
description = "Shows debug pathfinding route"
)
public static boolean showDebugPathfindingRoute = false;

//</editor-fold>

Expand Down Expand Up @@ -2021,6 +2022,10 @@ public FarmHelperConfig() {
this.addDependency("clipCapturingType", "", () -> captureClipAfterFailsafe || captureClipAfterGettingBanned);
this.addDependency("captureClipDelay", "", () -> captureClipAfterFailsafe || captureClipAfterGettingBanned);

this.addDependency("pestsDestroyerOnTheTrackFOV", "pestsDestroyerOnTheTrack");
this.addDependency("dontKillPestsOnTrackDuringJacobsContest", "pestsDestroyerOnTheTrack");


this.addDependency("leaveTime", "leaveTimer");

this.hideIf("shownWelcomeGUI", () -> true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

import net.minecraftforge.fml.common.eventhandler.Event;

import java.time.LocalDateTime;

public class MillisecondEvent extends Event {
public LocalDateTime dateTime;
public long timestamp;

public MillisecondEvent() {
timestamp = System.currentTimeMillis();
dateTime = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public List<IFeature> fillFeatures() {
LeaveTimer.getInstance(),
PerformanceMode.getInstance(),
PestsDestroyer.getInstance(),
PestsDestroyerOnTheTrack.getInstance(),
AutoSprayonator.getInstance(),
PetSwapper.getInstance(),
PlotCleaningHelper.getInstance(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ public void onInventoryKeyPress(InventoryInputEvent event) {
if (!isRunning()) return;

if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
event.setCanceled(true);
LogUtils.sendWarning("[Auto Sell] Stopping Auto Sell manually");
stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public class PestsDestroyer implements IFeature {
put("InfiniVacuum™ Hooverius", 15F);
put("InfiniVacuum", 12.5F);
}};
private float currentVacuumRange = 5F;
@Getter
private float currentVacuumRange = -1;

private boolean gotRangeOfVacuum = false;
private boolean isPlotObstructed = false;
Expand Down Expand Up @@ -188,6 +189,7 @@ public void stop() {
@Override
public void resetStatesAfterMacroDisabled() {
stop();
gotRangeOfVacuum = false;
if (!FarmHelperConfig.pestsDestroyerAfkInfiniteMode) return;
FarmHelperConfig.pestsDestroyerAfkInfiniteMode = false;
LogUtils.sendWarning("[Pests Destroyer] AFK Mode has been disabled");
Expand Down Expand Up @@ -273,8 +275,7 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
if (mc.currentScreen == null && checkedThisGui) {
checkedThisGui = false;
}
if (!isToggled()) return;
if (!gotRangeOfVacuum) {
if (!gotRangeOfVacuum && (isToggled() || PestsDestroyerOnTheTrack.getInstance().isToggled())) {
Slot vacuumSlot = InventoryUtils.getSlotOfItemInInventory("Vacuum");
if (vacuumSlot != null) {
ItemStack vacuumItem = vacuumSlot.getStack();
Expand All @@ -288,6 +289,7 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
}
}
}
if (!isToggled()) return;
if (event.phase != TickEvent.Phase.START) return;
if (!GameStateHandler.getInstance().inGarden() && escapeState == EscapeState.NONE) return;
if (!enabled) return;
Expand Down Expand Up @@ -909,11 +911,6 @@ private Entity getClosestPest() {
Entity closestPest = null;
double closestDistance = Double.MAX_VALUE;
for (Entity entity : pestsLocations) {
if (killedEntities.contains(entity)) continue;
Entity realEntity = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityBat || e instanceof EntitySilverfish);
if (realEntity != null && (killedEntities.contains(realEntity) || realEntity.isDead)) continue;
if (mc.thePlayer.getDistanceToEntity(entity) < 5 && killedEntities.stream().anyMatch(ke -> ke.getDistanceToEntity(entity) < 1.5))
continue;
double distance = mc.thePlayer.getDistanceToEntity(entity);
if (distance < closestDistance) {
closestDistance = distance;
Expand All @@ -923,7 +920,7 @@ private Entity getClosestPest() {
return closestPest;
}

private boolean getVacuum(ItemStack currentItem2) {
public boolean getVacuum(ItemStack currentItem2) {
if (currentItem2 == null || !currentItem2.getDisplayName().contains("Vacuum")) {
int vacuum = InventoryUtils.getSlotIdOfItemInHotbar("Vacuum");
if (vacuum == -1) {
Expand Down Expand Up @@ -1038,7 +1035,13 @@ public void onRender(RenderWorldLastEvent event) {
if (itemStack != null && itemStack.hasTagCompound()) {
String displayName = itemStack.getTagCompound().toString();
if (!displayName.contains("display:")) {
return this.pests.stream().anyMatch(pest -> displayName.contains(pest.getSecond()));
if (this.pests.stream().anyMatch(pest -> displayName.contains(pest.getSecond()))) {
if (killedEntities.contains(entity)) return false;
Entity realEntity = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityBat || e instanceof EntitySilverfish);
if (realEntity != null && (killedEntities.contains(realEntity) || realEntity.isDead))
return false;
return !(mc.thePlayer.getDistanceToEntity(entity) < 5) || killedEntities.stream().noneMatch(ke -> ke.getDistanceToEntity(entity) < 1.5);
}
}
}
}
Expand All @@ -1056,8 +1059,10 @@ public void onRender(RenderWorldLastEvent event) {
boundingBox = boundingBox.offset(-d0, -d1, -d2);
if (FarmHelperConfig.pestsESP) {
Color color = FarmHelperConfig.pestsESPColor.toJavaColor();
if (canEntityBeSeenIgnoreNonCollidable(entity)) {
color = new Color(color.getRed(), color.getGreen(), color.getBlue(), Math.min(50, color.getAlpha()));
Vec3 entityPos = new Vec3(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
boolean isInVacuumRange = mc.thePlayer.getPositionEyes(1).distanceTo(entityPos) < currentVacuumRange;
if (isInVacuumRange) {
color = new Color(color.getRed(), 255, color.getBlue(), Math.min(50, color.getAlpha()));
}
float distance = mc.thePlayer.getDistanceToEntity(entity);
if (distance > 5) {
Expand Down Expand Up @@ -1284,7 +1289,7 @@ private void fly() {
private PlotUtils.Plot getClosestPlot() {
List<Integer> infestedPlots = GameStateHandler.getInstance().getInfestedPlots();
if (infestedPlots.isEmpty()) {
LogUtils.sendDebug("[Pests Destroyer] No infested plots found");
LogUtils.sendError("[Pests Destroyer] Couldn't find infested plots on Tablist! Make sure you have it enabled in Tablist Widgets");
return null;
}
if (GameStateHandler.getInstance().getCurrentPlotPestsCount() == 0) {
Expand Down
Loading

0 comments on commit 308842b

Please sign in to comment.