Skip to content

Commit

Permalink
Pests Destroyer:
Browse files Browse the repository at this point in the history
 + Now it should fly to the plot nearby, if the distance is not higher than 150 blocks to it, instead of insta tping
 = Fixed some another issues with false staff detection during pathfinder
 = Additional cache fixes
 = Fixes for firework scanning
 + Rotation is now a little smoother while targeting pest
  • Loading branch information
May2Beez committed Feb 16, 2024
1 parent bcabbb8 commit e560364
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 79 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.5-pre7
version=2.4.5-pre8
shouldRelease=true
5 changes: 5 additions & 0 deletions src/main/java/com/jelly/farmhelperv2/FarmHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public void onTickSendInfoAboutShittyClient(TickEvent.PlayerTickEvent event) {
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);
LogUtils.sendWarning("You've got §6§lOringo §cinstalled in your mods folder! FarmHelper will use Oringo compatibility mode for FlyPathfinder.");
}
if (FarmHelperConfig.configVersion == 1)
FarmHelperConfig.configVersion = 2;
sentInfoAboutShittyClient = true;
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1949,8 +1949,19 @@ public FarmHelperConfig() {

registerKeyBind(openGuiKeybind, this::openGui);
registerKeyBind(toggleMacro, () -> MacroHandler.getInstance().toggleMacro());
// registerKeyBind(debugKeybind, () -> {
// });
registerKeyBind(debugKeybind, () -> {
// MovingObjectPosition objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
// if (objectMouseOver == null || objectMouseOver.typeOfHit != MovingObjectPosition.MovingObjectType.ENTITY)
// return;
// Entity entity = objectMouseOver.entityHit;
// RotationHandler.getInstance().easeTo(
// new RotationConfiguration(
// new Target(entity),
// 0,
// null
// ).followTarget(true)
// );
});
registerKeyBind(freelookKeybind, () -> Freelook.getInstance().toggle());
registerKeyBind(plotCleaningHelperKeybind, () -> PlotCleaningHelper.getInstance().toggle());
registerKeyBind(enablePestsDestroyerKeyBind, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.handler.RotationHandler;
import com.jelly.farmhelperv2.pathfinder.FlyPathFinderExecutor;
import com.jelly.farmhelperv2.util.AngleUtils;
import com.jelly.farmhelperv2.util.BlockUtils;
import com.jelly.farmhelperv2.util.LogUtils;
import com.jelly.farmhelperv2.util.PlayerUtils;
import com.jelly.farmhelperv2.util.helper.Rotation;
import com.jelly.farmhelperv2.util.helper.RotationConfiguration;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.network.play.server.S12PacketEntityVelocity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;

public class KnockbackFailsafe extends Failsafe {
Expand Down Expand Up @@ -72,6 +76,17 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
if (((S12PacketEntityVelocity) event.packet).getMotionY() < FarmHelperConfig.knockbackCheckVerticalSensitivity)
return;

if (FlyPathFinderExecutor.getInstance().isRunning()) {
AxisAlignedBB boundingBox = mc.thePlayer.getEntityBoundingBox().expand(1, 1, 1);
for (BlockPos blockPos : BlockUtils.getBlocksInBB(boundingBox)) {
Block block = mc.theWorld.getBlockState(blockPos).getBlock();
if (block.equals(Blocks.cactus)) {
LogUtils.sendDebug("[Failsafe] Knockback detected, but cactus is inside the bounding box. Ignoring.");
return;
}
}
}

rotationBeforeReacting = new Rotation(mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch);
positionBeforeReacting = mc.thePlayer.getPosition();
LogUtils.sendWarning("[Failsafe] Knockback detected! MotionY: " + ((S12PacketEntityVelocity) event.packet).getMotionY());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.jelly.farmhelperv2.handler.GameStateHandler;
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.handler.RotationHandler;
import com.jelly.farmhelperv2.pathfinder.FlyPathFinderExecutor;
import com.jelly.farmhelperv2.util.AngleUtils;
import com.jelly.farmhelperv2.util.LogUtils;
import com.jelly.farmhelperv2.util.helper.Rotation;
Expand Down Expand Up @@ -66,10 +67,6 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
if (!(event.packet instanceof S08PacketPlayerPosLook)) {
return;
}
// if (LagDetector.getInstance().isLagging() || LagDetector.getInstance().wasJustLagging()) {
// LogUtils.sendWarning("[Failsafe] Got rotation packet while lagging! Ignoring that one.");
// return;
// }

if (AntiStuck.getInstance().isRunning()) {
LogUtils.sendDebug("[Failsafe] Rotation packet received while AntiStuck is running. Ignoring");
Expand All @@ -83,6 +80,10 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
double playerPitch = mc.thePlayer.rotationPitch;
double yawDiff = Math.abs(packetYaw - playerYaw);
double pitchDiff = Math.abs(packetPitch - playerPitch);
if (FlyPathFinderExecutor.getInstance().isRunning() && FlyPathFinderExecutor.getInstance().isRotationInCache((float) packetYaw, (float) packetPitch)) {
LogUtils.sendDebug("[Failsafe] Rotation packet received while Fly pathfinder is running. Ignoring");
return;
}
double threshold = FarmHelperConfig.rotationCheckSensitivity;
if (yawDiff == 360 && pitchDiff == 0) // prevents false checks
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.jelly.farmhelperv2.handler.MacroHandler;
import com.jelly.farmhelperv2.handler.RotationHandler;
import com.jelly.farmhelperv2.macro.AbstractMacro;
import com.jelly.farmhelperv2.pathfinder.FlyPathFinderExecutor;
import com.jelly.farmhelperv2.util.*;
import com.jelly.farmhelperv2.util.helper.Rotation;
import com.jelly.farmhelperv2.util.helper.RotationConfiguration;
Expand Down Expand Up @@ -95,10 +96,6 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
if (!(event.packet instanceof S08PacketPlayerPosLook)) {
return;
}
// if (LagDetector.getInstance().isLagging() || LagDetector.getInstance().wasJustLagging()) {
// LogUtils.sendWarning("[Failsafe] Got rotation packet while lagging! Ignoring that one.");
// return;
// }

if (AntiStuck.getInstance().isRunning()) {
LogUtils.sendDebug("[Failsafe] Teleportation packet received while AntiStuck is running. Ignoring");
Expand All @@ -109,6 +106,10 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
Vec3 currentPlayerPos = mc.thePlayer.getPositionVector();
Vec3 packetPlayerPos = new Vec3(packet.getX(), packet.getY(), packet.getZ());
BlockPos packetPlayerBlockPos = new BlockPos(packetPlayerPos);
if (FlyPathFinderExecutor.getInstance().isRunning() && FlyPathFinderExecutor.getInstance().isPositionInCache(packetPlayerBlockPos)) {
LogUtils.sendDebug("[Failsafe] Teleport packet received while Fly pathfinder is running. Ignoring");
return;
}
Optional<Tuple<BlockPos, AbstractMacro.State>> lastWalkedPosition = lastWalkedPositions.stream().filter(pos -> pos.getFirst().equals(packetPlayerBlockPos)).findFirst();
if (lastWalkedPosition.isPresent()) {
if (packetPlayerPos.distanceTo(currentPlayerPos) < 1) {
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/com/jelly/farmhelperv2/feature/FeatureManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jelly.farmhelperv2.feature;

import com.jelly.farmhelperv2.failsafe.FailsafeManager;
import com.jelly.farmhelperv2.feature.impl.*;
import com.jelly.farmhelperv2.util.LogUtils;

Expand Down Expand Up @@ -95,17 +94,6 @@ public boolean shouldIgnoreFalseCheck() {
}
if (PestsDestroyer.getInstance().isRunning()) {
if (!PestsDestroyer.getInstance().shouldCheckForFailsafes()) return true;
boolean result = false;
result = FailsafeManager.getInstance().emergencyQueue.stream().anyMatch(f -> {
if (f.getType().equals(FailsafeManager.EmergencyType.KNOCKBACK_CHECK)) {
return true;
}
if (f.getType().equals(FailsafeManager.EmergencyType.TELEPORT_CHECK)) {
return true;
}
return f.getType().equals(FailsafeManager.EmergencyType.ROTATION_CHECK);
});
return result;
}
if (PlotCleaningHelper.getInstance().isRunning() && !PlotCleaningHelper.getInstance().shouldCheckForFailsafes()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,8 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
}

if (!FlyPathFinderExecutor.getInstance().isRunning()) {
Vec3 firework = new Vec3(lastFireworkLocation.get().xCoord, mc.thePlayer.posY, lastFireworkLocation.get().zCoord);
Vec3 player = mc.thePlayer.getPositionVector();
Vec3 direction = firework.subtract(player).normalize();
Vec3 target = firework.addVector(direction.xCoord * 25, Math.min(direction.yCoord * 25, 7), direction.zCoord * 25);
FlyPathFinderExecutor.getInstance().findPath(target, false, true);
Vec3 firework = new Vec3(lastFireworkLocation.get().xCoord, Math.min(mc.thePlayer.posY + 1, 80), lastFireworkLocation.get().zCoord);
FlyPathFinderExecutor.getInstance().findPath(firework, true, true);
state = States.GET_LOCATION;
}
break;
Expand Down Expand Up @@ -713,29 +710,34 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
return;
}

// System.out.println(distance);

if (distance < 3) {
if (distance < 1.3) {
float targetVelocity = (float) (Math.abs(entity.motionX) + Math.abs(entity.motionZ));
if (distance < 2 && targetVelocity < 0.15 && mc.thePlayer.canEntityBeSeen(entity)) {
if (FlyPathFinderExecutor.getInstance().isRunning()) {
FlyPathFinderExecutor.getInstance().stop();
}
KeyBindUtils.onTick(mc.gameSettings.keyBindBack);
float playerVelocity = (float) (Math.abs(mc.thePlayer.motionX) + Math.abs(mc.thePlayer.motionZ));
if (playerVelocity > 0.15)
KeyBindUtils.onTick(mc.gameSettings.keyBindBack);
}
if (rotationState != RotationState.CLOSE) {
rotationState = RotationState.CLOSE;
RotationHandler.getInstance().reset();
}
if (!RotationHandler.getInstance().isRotating()) {
RotationHandler.getInstance().easeTo(new RotationConfiguration(
new Target(entity).additionalY(0.5f),
(long) (400 + Math.random() * 200),
null
));
).followTarget(true));
}
KeyBindUtils.setKeyBindState(mc.gameSettings.keyBindUseItem, true);
} else {
if (rotationState != RotationState.FAR) {
FlyPathFinderExecutor.getInstance().stop();
rotationState = RotationState.FAR;
RotationHandler.getInstance().reset();
}
if (!FlyPathFinderExecutor.getInstance().isRunning()) {
LogUtils.sendDebug("Should pathfind to: " + entity.posX + " " + (entity.posY + 2.75) + " " + entity.posZ);
Expand Down Expand Up @@ -781,9 +783,16 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
state = States.GET_LOCATION;
delayClock.schedule(300 + (long) (Math.random() * 250));
} else {
LogUtils.sendDebug("Teleporting to plot");
state = States.TELEPORT_TO_PLOT;
delayClock.schedule(600 + (long) (Math.random() * 500));
Optional<Map.Entry<Plot, Integer>> closestOptionalPlot = pestsPlotMap.entrySet().stream().min(Comparator.comparingDouble(entry -> mc.thePlayer.getDistanceSqToCenter(PlotUtils.getPlotCenter(entry.getKey().plotNumber))));
if (Math.sqrt(mc.thePlayer.getDistanceSqToCenter(PlotUtils.getPlotCenter(closestOptionalPlot.get().getKey().plotNumber))) < 150) {
LogUtils.sendDebug("Going manually another plot");
state = States.GET_CLOSEST_PLOT;
delayClock.schedule(300 + (long) (Math.random() * 250));
} else {
LogUtils.sendDebug("Teleporting to plot");
state = States.TELEPORT_TO_PLOT;
delayClock.schedule(600 + (long) (Math.random() * 500));
}
}
}
KeyBindUtils.stopMovement();
Expand Down Expand Up @@ -1053,6 +1062,8 @@ public void onEntityDeath(LivingDeathEvent event) {
pestsPlotMap.remove(plot);
LogUtils.sendDebug("[Pests Destroyer] Removed all pests from plot number: " + plotNumber);
}
RotationHandler.getInstance().reset();
FlyPathFinderExecutor.getInstance().stop();
lastFireworkLocation = Optional.empty();
lastFireworkTime = 0;
currentEntityTarget.ifPresent(e -> {
Expand All @@ -1062,8 +1073,6 @@ public void onEntityDeath(LivingDeathEvent event) {
KeyBindUtils.stopMovement();
currentEntityTarget = Optional.empty();
stuckClock.reset();
FlyPathFinderExecutor.getInstance().stop();
RotationHandler.getInstance().reset();
delayClock.schedule(150);
});
}
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/com/jelly/farmhelperv2/handler/RotationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void onRender(RenderWorldLastEvent event) {
return;
}

if (System.currentTimeMillis() >= endTime) {
if (System.currentTimeMillis() >= endTime && !configuration.followTarget()) {
// finish
if (configuration.callback().isPresent()) {
configuration.callback().get().run();
Expand All @@ -273,9 +273,23 @@ public void onRender(RenderWorldLastEvent event) {

if (configuration.followTarget() && configuration.target().isPresent() && delayBetweenTargetFollow.passed()) {
adjustTargetRotation(false);
float currentYaw = mc.thePlayer.rotationYaw;
float currentPitch = mc.thePlayer.rotationPitch;
if (shouldRotate(targetRotation, 0.1f)) {
float needYaw = (targetRotation.getYaw() - currentYaw);
float needPitch = (targetRotation.getPitch() - currentPitch);
System.out.println("Need yaw: " + needYaw + " need pitch: " + needPitch);
float pythagoras = pythagoras(Math.abs(needYaw), Math.abs(needPitch));
needYaw *= (float) (Math.random() * 0.04f + getTime(pythagoras, 0.055f));
needPitch *= (float) (Math.random() * 0.04f + getTime(pythagoras, 0.055f));
System.out.println("Scaled Need yaw: " + needYaw + " Scaled need pitch: " + needPitch);
mc.thePlayer.rotationYaw += needYaw;
mc.thePlayer.rotationPitch += needPitch;
}
} else {
mc.thePlayer.rotationYaw = interpolate(startRotation.getYaw(), targetRotation.getYaw(), configuration.easeOutBack() ? this::easeOutBack : this::easeOutExpo);
mc.thePlayer.rotationPitch = interpolate(startRotation.getPitch(), targetRotation.getPitch(), configuration.easeOutBack() ? this::easeOutBack : this::easeOutQuart);
}
mc.thePlayer.rotationYaw = interpolate(startRotation.getYaw(), targetRotation.getYaw(), configuration.easeOutBack() ? this::easeOutBack : this::easeOutExpo);
mc.thePlayer.rotationPitch = interpolate(startRotation.getPitch(), targetRotation.getPitch(), configuration.easeOutBack() ? this::easeOutBack : this::easeOutQuart);
}

@SubscribeEvent(receiveCanceled = true)
Expand Down Expand Up @@ -336,22 +350,13 @@ private void adjustTargetRotation(boolean serverSide) {
} else {
throw new IllegalArgumentException("No target or rotation specified!");
}
// if (target.getEntity() != null) {
// rot = getRotation(target.getEntity());
// } else if (target.getBlockPos() != null) {
// rot = getRotation(target.getBlockPos());
// } else if (target.getTarget().isPresent()) {
// rot = getRotation(target.getTarget().get());
// } else {
// throw new IllegalArgumentException("No target specified!");
// }
startRotation.setPitch(serverSide ? serverSidePitch : mc.thePlayer.rotationPitch);
startRotation.setYaw(serverSide ? serverSideYaw : mc.thePlayer.rotationYaw);
startTime = System.currentTimeMillis();
// startTime = System.currentTimeMillis();
Rotation neededChange = getNeededChange(startRotation, rot);
targetRotation.setYaw(startRotation.getYaw() + neededChange.getYaw());
targetRotation.setPitch(startRotation.getPitch() + neededChange.getPitch());
delayBetweenTargetFollow.schedule(160 + Math.random() * 80);
// delayBetweenTargetFollow.schedule(160 + Math.random() * 80);
}

@SubscribeEvent(receiveCanceled = true)
Expand Down
Loading

0 comments on commit e560364

Please sign in to comment.