Skip to content

Commit

Permalink
PestsDestroyer:
Browse files Browse the repository at this point in the history
 = Fixes regarding tping in combat, holding vacuum, movement etc
  • Loading branch information
May2Beez committed Mar 4, 2024
1 parent e1fd612 commit 7bdbb00
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 19 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-pre22
version=2.4.5-pre23
shouldRelease=true
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
return;

if (FlyPathFinderExecutor.getInstance().isRunning()) {
AxisAlignedBB boundingBox = mc.thePlayer.getEntityBoundingBox().expand(1, 1, 1);
AxisAlignedBB boundingBox = mc.thePlayer.getEntityBoundingBox().expand(2, 2, 2);
for (BlockPos blockPos : BlockUtils.getBlocksInBB(boundingBox)) {
Block block = mc.theWorld.getBlockState(blockPos).getBlock();
if (block.equals(Blocks.cactus)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,8 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
delayClock.schedule(300);
break;
case KILL_PEST:
ItemStack currentItem3 = mc.thePlayer.getHeldItem();
if (getVacuum(currentItem3)) return;
if (isInventoryOpenDelayed()) break;
if (!currentEntityTarget.isPresent()) {
FlyPathFinderExecutor.getInstance().stop();
Expand Down Expand Up @@ -738,7 +740,7 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {

if (distance < 3) {
float targetVelocity = (float) (Math.abs(entity.motionX) + Math.abs(entity.motionZ));
if (distance < 2 && targetVelocity < 0.15 && mc.thePlayer.canEntityBeSeen(entity)) {
if (distance < 2 && targetVelocity < 0.15) {
if (FlyPathFinderExecutor.getInstance().isRunning()) {
FlyPathFinderExecutor.getInstance().stop();
} else {
Expand All @@ -753,7 +755,7 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
}
if (!RotationHandler.getInstance().isRotating()) {
RotationHandler.getInstance().easeTo(new RotationConfiguration(
new Target(entity).additionalY(0.5f),
new Target(entity).additionalY(-0.5f),
(long) (400 + Math.random() * 200),
null
).followTarget(true));
Expand Down Expand Up @@ -786,7 +788,7 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
}
if (!RotationHandler.getInstance().isRotating()) {
RotationHandler.getInstance().easeTo(new RotationConfiguration(
new Target(entity).additionalY(0.8f),
new Target(entity).additionalY(-0.3f),
(long) (400 + Math.random() * 200),
null
));
Expand All @@ -798,11 +800,13 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
LogUtils.sendDebug(totalPests + " pest" + (totalPests == 1 ? "" : "s") + " left");
if (totalPests == 0) {
state = States.GO_BACK;
delayClock.schedule((long) (1_000 + Math.random() * 500));
delayClock.schedule((long) (500 + Math.random() * 500));
} else {
if (getClosestPest() != null) {
Entity closestPest2 = getClosestPest();
if (closestPest2 != null) {
LogUtils.sendDebug("Found another pest");
state = States.FLY_TO_PEST;
state = States.KILL_PEST;
currentEntityTarget = Optional.of(closestPest2);
delayClock.schedule(50 + (long) (Math.random() * 100));
} else if (pestsPlotMap.isEmpty()) {
LogUtils.sendDebug("Manually searching for pest");
Expand All @@ -811,7 +815,7 @@ public void onTickExecute(TickEvent.ClientTickEvent event) {
} else {
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");
LogUtils.sendDebug("Going manually to another plot");
state = States.GET_CLOSEST_PLOT;
delayClock.schedule(300 + (long) (Math.random() * 250));
} else {
Expand All @@ -834,8 +838,11 @@ private Entity getClosestPest() {
Entity closestPest = null;
double closestDistance = Double.MAX_VALUE;
for (Entity entity : pestsLocations) {
System.out.println(entity);
if (killedEntities.contains(entity)) continue;
Entity realEntity = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityBat || e instanceof EntitySilverfish);
System.out.println(realEntity);
System.out.println(killedEntities);
if (realEntity != null && (killedEntities.contains(realEntity) || realEntity.isDead)) continue;
double distance = mc.thePlayer.getDistanceToEntity(entity);
if (distance < closestDistance) {
Expand Down Expand Up @@ -1056,17 +1063,19 @@ public void onEntityDeath(LivingDeathEvent event) {
if (!GameStateHandler.getInstance().inGarden()) return;

Entity entity = event.entity;
LogUtils.sendDebug("[Pests Destroyer] Entity died: " + entity.getName() + " at: " + entity.getPosition());
LogUtils.sendDebug("[Pests Destroyer] Entity died: " + entity.getName() + "(" + entity.getEntityId() + ")" + " at: " + entity.getPosition());
killedEntities.add(entity);
if (entity instanceof EntityArmorStand) {
Entity realEntity = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityBat || e instanceof EntitySilverfish);
if (realEntity != null) {
LogUtils.sendDebug("[Pests Destroyer] Found real entity: " + realEntity.getName() + "(" + realEntity.getEntityId() + ")" + " at: " + realEntity.getPosition());
killedEntities.add(realEntity);
}
}
if (entity instanceof EntityBat || entity instanceof EntitySilverfish) {
Entity armorStand = PlayerUtils.getEntityCuttingOtherEntity(entity, (e) -> e instanceof EntityArmorStand);
if (armorStand != null) {
LogUtils.sendDebug("[Pests Destroyer] Found armor stand: " + armorStand.getName() + "(" + armorStand.getEntityId() + ")" + " at: " + armorStand.getPosition());
killedEntities.add(armorStand);
}
}
Expand Down Expand Up @@ -1101,6 +1110,7 @@ public void onEntityDeath(LivingDeathEvent event) {
KeyBindUtils.stopMovement();
currentEntityTarget = Optional.empty();
stuckClock.reset();
state = States.CHECK_ANOTHER_PEST;
delayClock.schedule(150);
});
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/jelly/farmhelperv2/handler/MacroHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ private void checkForTeleport() {
afterRewarpDelay.schedule(1_500);
LogUtils.sendDebug("Teleported!");
currentMacro.ifPresent(cm -> {
if (cm.isPaused()) {
if (cm.isPaused() && this.rewarpTeleport) {
resumeMacro();
}
cm.changeState(AbstractMacro.State.NONE);
Expand All @@ -467,6 +467,11 @@ private void checkForTeleport() {
beforeTeleportationPos = Optional.empty();
GameStateHandler.getInstance().scheduleNotMoving(750);
rewarpTeleport = false;
} else {
if (System.currentTimeMillis() - MacroHandler.getInstance().getLastTpTry() > 5_000) {
LogUtils.sendDebug("Teleporting again");
this.triggerWarpGarden(true, this.rewarpTeleport);
}
}
}

Expand All @@ -487,14 +492,14 @@ public void triggerWarpGarden(boolean force, boolean rewarpTeleport, boolean sen
return;
}
lastTpTry = System.currentTimeMillis();
currentMacro.ifPresent(cm -> cm.setRewarpState(AbstractMacro.RewarpState.TELEPORTING));
setBeforeTeleportationPos(Optional.ofNullable(mc.thePlayer.getPosition()));
AntiStuck.getInstance().resetUnstuckTries();
LogUtils.sendDebug("Before tp location: " + beforeTeleportationPos);
this.rewarpTeleport = rewarpTeleport;
LogUtils.sendDebug("Warping to spawn point");
mc.thePlayer.sendChatMessage("/warp garden");
this.rewarpTeleport = rewarpTeleport;
AntiStuck.getInstance().resetUnstuckTries();
GameStateHandler.getInstance().scheduleRewarp();
currentMacro.ifPresent(cm -> cm.setRewarpState(AbstractMacro.RewarpState.TELEPORTING));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public void onRender(RenderWorldLastEvent event) {
mc.thePlayer.rotationPitch += needPitch;
} else if (mc.thePlayer.rotationPitch + needPitch < -63 && needPitch > 0) {
mc.thePlayer.rotationPitch += needPitch;
} else if (mc.thePlayer.rotationPitch + needPitch < -63 && mc.thePlayer.rotationPitch + needPitch > 63) {
} else if (mc.thePlayer.rotationPitch + needPitch > -63 && mc.thePlayer.rotationPitch + needPitch < 63) {
mc.thePlayer.rotationPitch += needPitch;
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/jelly/farmhelperv2/macro/AbstractMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ public void onTick() {
return;
} else if (rewarpState == RewarpState.TELEPORTING) {
// teleporting
if (System.currentTimeMillis() - MacroHandler.getInstance().getLastTpTry() > 5_000) {
LogUtils.sendDebug("Teleporting again");
MacroHandler.getInstance().triggerWarpGarden(true, MacroHandler.getInstance().isRewarpTeleport());
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ public void onTickNeededYaw(TickEvent.ClientTickEvent event) {
if (entityVelocity > 0.12) {
targetPos = targetPos.addVector(targetEntity.motionX * 1.5, targetEntity.motionY, targetEntity.motionZ * 1.5);
}
if (distance < 1.75) {
stop();
return;
}
if (willArriveAtDestinationAfterStopping(targetPos)) {
stop();
return;
Expand Down

0 comments on commit 7bdbb00

Please sign in to comment.