Skip to content

Commit

Permalink
Pests Destroyer:
Browse files Browse the repository at this point in the history
 = Fix regarding flying to the closest plot
 = Some additional fixes for false teleport checks
 = Better collision checking in fly pathfinder
 + Detection of Oringo for fly pathfinder checks if the mod is disabled
 - Removed some useless logs

= Other small fixes
  • Loading branch information
May2Beez committed Feb 17, 2024
1 parent e560364 commit abae1fb
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 70 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-pre8
version=2.4.5-pre9
shouldRelease=true
17 changes: 10 additions & 7 deletions src/main/java/com/jelly/farmhelperv2/config/FarmHelperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1954,13 +1954,16 @@ public FarmHelperConfig() {
// 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)
// );
// Multithreading.schedule(() -> {
// RotationHandler.getInstance().easeTo(
// new RotationConfiguration(
// new Target(entity),
// 1000,
// RotationConfiguration.RotationType.SERVER,
// null
// ).followTarget(true)
// );
// }, 2, TimeUnit.SECONDS);
});
registerKeyBind(freelookKeybind, () -> Freelook.getInstance().toggle());
registerKeyBind(plotCleaningHelperKeybind, () -> PlotCleaningHelper.getInstance().toggle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ public void onReceivedPacketDetection(ReceivePacketEvent event) {
return;
}

// if (BlockUtils.cropAroundAmount(packetPlayerBlockPos) > 5) {
// LogUtils.sendDebug("[Failsafe] Still in the farm! Not reacting");
// LogUtils.sendFailsafeMessage("[Failsafe] You probably got tp check forward into farm! Not reacting", shouldTagEveryone());
// return;
// }

rotationBeforeReacting = new Rotation(mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch);
double distance = currentPlayerPos.distanceTo(packetPlayerPos);
LogUtils.sendDebug("[Failsafe] Teleport 2 detected! Distance: " + distance);
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/com/jelly/farmhelperv2/handler/RotationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,17 @@ public void easeTo(RotationConfiguration configuration) {

private float getTime(float pythagoras, float time) {
if (pythagoras < 25) {
LogUtils.sendDebug("[Rotation] Very close rotation, speeding up by 0.65");
return (long) (time * 0.65);
}
if (pythagoras < 45) {
LogUtils.sendDebug("[Rotation] Close rotation, speeding up by 0.77");
return (long) (time * 0.77);
}
if (pythagoras < 80) {
LogUtils.sendDebug("[Rotation] Not so close, but not that far rotation, speeding up by 0.9");
return (long) (time * 0.9);
}
if (pythagoras > 100) {
LogUtils.sendDebug("[Rotation] Far rotation, slowing down by 1.1");
return (long) (time * 1.1);
}
LogUtils.sendDebug("[Rotation] Normal rotation");
return (long) (time * 1.0);
}

Expand Down Expand Up @@ -271,18 +266,16 @@ public void onRender(RenderWorldLastEvent event) {
return;
}

if (configuration.followTarget() && configuration.target().isPresent() && delayBetweenTargetFollow.passed()) {
if (configuration.followTarget() && configuration.target().isPresent()) {
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);
needYaw *= (float) (Math.random() * 0.04f + getTime(pythagoras, 0.065f));
needPitch *= (float) (Math.random() * 0.04f + getTime(pythagoras, 0.065f));
mc.thePlayer.rotationYaw += needYaw;
mc.thePlayer.rotationPitch += needPitch;
}
Expand Down Expand Up @@ -352,11 +345,11 @@ private void adjustTargetRotation(boolean serverSide) {
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public void findPath(Vec3 pos, boolean follow, boolean smooth) {
LogUtils.sendSuccess("Already at destination");
return;
}
lastPositions.clear();
lastPosition = new Position(mc.thePlayer.getPosition(), new Rotation(mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch));
lastPositions.add(lastPosition);
state = State.CALCULATING;
Expand Down Expand Up @@ -181,7 +180,7 @@ public boolean isRotationInCache(float yaw, float pitch) {
}

public boolean isPositionInCache(BlockPos pos) {
return lastPositions.stream().anyMatch(position -> position.pos.equals(pos));
return lastPositions.stream().anyMatch(position -> position.pos.equals(pos) || Math.sqrt(position.pos.distanceSq(pos)) < 1);
}

private List<Vec3> smoothPath(List<Vec3> path) {
Expand Down Expand Up @@ -431,10 +430,10 @@ public void onTickNeededYaw(TickEvent.ClientTickEvent event) {
} else if (verticalDirection.equals(VerticalDirection.LOWER)) {
keyBindings.add(mc.gameSettings.keyBindSneak);
System.out.println("Lowering 1");
} else if ((getBlockUnder() instanceof BlockCactus || distanceY > 0.201) && (((EntityPlayerAccessor) mc.thePlayer).getFlyToggleTimer() == 0 || mc.gameSettings.keyBindJump.isKeyDown())) {
} else if ((getBlockUnder() instanceof BlockCactus || distanceY > 0.25) && (((EntityPlayerAccessor) mc.thePlayer).getFlyToggleTimer() == 0 || mc.gameSettings.keyBindJump.isKeyDown())) {
keyBindings.add(mc.gameSettings.keyBindJump);
System.out.println("Raising 2");
} else if (distanceY < -0.201) {
} else if (distanceY < -0.25) {
Block blockUnder = getBlockUnder();
if (!mc.thePlayer.onGround && mc.thePlayer.capabilities.isFlying && !(blockUnder instanceof BlockCactus) && !(blockUnder instanceof BlockSoulSand)) {
keyBindings.add(mc.gameSettings.keyBindSneak);
Expand Down Expand Up @@ -521,12 +520,12 @@ public VerticalDirection shouldChangeHeight(double relativeDistanceX, double rel
return VerticalDirection.NONE;
}
Vec3 directionGoing = AngleUtils.getVectorForRotation(0, neededYaw);
Vec3 target = mc.thePlayer.getPositionVector().addVector(directionGoing.xCoord * 0.6, 0, directionGoing.zCoord * 0.6);
Vec3 target = mc.thePlayer.getPositionVector().addVector(directionGoing.xCoord * 0.6, -0.05, directionGoing.zCoord * 0.6);
MovingObjectPosition trace = mc.theWorld.rayTraceBlocks(mc.thePlayer.getPositionVector(), target, false, true, false);
if (trace != null && trace.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
return VerticalDirection.HIGHER;
}
Vec3 targetUp = mc.thePlayer.getPositionVector().addVector(directionGoing.xCoord * 0.6, mc.thePlayer.height, directionGoing.zCoord * 0.6);
Vec3 targetUp = mc.thePlayer.getPositionVector().addVector(directionGoing.xCoord * 0.6, mc.thePlayer.height + 0.05, directionGoing.zCoord * 0.6);
MovingObjectPosition traceUp = mc.theWorld.rayTraceBlocks(mc.thePlayer.getPositionVector(), targetUp, false, true, false);
if (traceUp != null && traceUp.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
return VerticalDirection.LOWER;
Expand Down Expand Up @@ -581,7 +580,12 @@ private boolean fly(Vec3 next, Vec3 current) {
flyDelay.schedule(80 + (long) (Math.random() * 80));
return true;
} else {
Vec3 closestToPlayer = path.stream().min((vec1, vec2) -> (int) (vec1.distanceTo(mc.thePlayer.getPositionVector()) - vec2.distanceTo(mc.thePlayer.getPositionVector()))).orElse(path.get(0));
Vec3 closestToPlayer;
try {
closestToPlayer = path.stream().min((vec1, vec2) -> (int) (vec1.distanceTo(mc.thePlayer.getPositionVector()) - vec2.distanceTo(mc.thePlayer.getPositionVector()))).orElse(path.get(0));
} catch (IndexOutOfBoundsException e) {
return false;
}
if (next.yCoord - closestToPlayer.yCoord > 0.5) {
if (!flyDelay.isScheduled()) {
flyDelay.schedule(80 + (long) (Math.random() * 80));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void cacheChunk(Chunk c, Coordinate coordinate) {
BlockPos pos = new BlockPos(x + coordinate.x * 16, y, z + coordinate.z * 16);
BlockPos chunkPos = new BlockPos(x, y, z);
IBlockState chunkState = c.getBlockState(chunkPos);
if (!BlockUtils.blockHasCollision(pos, chunkState, chunkState.getBlock())) {
if (!BlockUtils.blockHasCollision(pos, chunkState, chunkState.getBlock(), c.getWorld())) {
worldCache.put(pos, new CacheEntry(chunkState.getBlock(), pos, BlockUtils.PathNodeType.OPEN));
} else {
worldCache.put(pos, new CacheEntry(chunkState.getBlock(), pos, BlockUtils.PathNodeType.BLOCKED));
Expand Down
39 changes: 8 additions & 31 deletions src/main/java/com/jelly/farmhelperv2/util/BlockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.init.Blocks;
import net.minecraft.util.*;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import java.util.*;
import java.util.function.Predicate;
Expand Down Expand Up @@ -317,7 +318,7 @@ private static boolean blockHasCollision(BlockPos blockPos) {
return !mc.theWorld.getBlockState(blockPos).getBlock().isPassable(mc.theWorld, blockPos) || axisAlignedBB != null;
}

public static boolean blockHasCollision(BlockPos blockPos, IBlockState blockState, Block block) {
public static boolean blockHasCollision(BlockPos blockPos, IBlockState blockState, Block block, IBlockAccess blockAccess) {
if (block.equals(Blocks.air) || block.equals(Blocks.water) || block.equals(Blocks.flowing_water)) {
return false;
}
Expand All @@ -326,35 +327,11 @@ public static boolean blockHasCollision(BlockPos blockPos, IBlockState blockStat
return false;
}

return true;

// if (CropUtils.isCrop(block) && !block.equals(Blocks.melon_block) && !block.equals(Blocks.pumpkin) && !block.equals(Blocks.cactus) && !block.equals(Blocks.cocoa)) {
// return false;
// }

// return true;

// if (block instanceof BlockStainedGlass || block instanceof BlockStainedGlassPane) {
// return true;
// }
//
// if (block instanceof BlockSlab && !block.equals(Blocks.double_stone_slab) && !block.equals(Blocks.double_wooden_slab) && !block.equals(Blocks.double_stone_slab2)) {
// return true;
// }
//
// if (block instanceof BlockFence) {
// return true;
// }
//
// if (block instanceof BlockDoor) {
// return true;
// }
//
// if (!block.isPassable(mc.theWorld, blockPos)) {
// return true;
// }
// AxisAlignedBB axisAlignedBB = block.getCollisionBoundingBox(mc.theWorld, blockPos, blockState);
// return axisAlignedBB != null;
try {
return !block.isPassable(blockAccess, blockPos) || block.getCollisionBoundingBox((World) blockAccess, blockPos, blockState) != null;
} catch (Exception e) {
return true;
}
}

public static boolean canWalkThroughDoor(Direction direction) {
Expand Down Expand Up @@ -831,7 +808,7 @@ public static boolean isFree(float x, float y, float z, IBlockAccess blockaccess
if (pathnodetype.getBlock().equals(blockaccess.getBlockState(blockpos).getBlock()))
return pathnodetype.getPathNodeType() == PathNodeType.OPEN;
}
if (blockHasCollision(blockpos, blockState, block)) {
if (blockHasCollision(blockpos, blockState, block, blockaccess)) {
WorldCache.getInstance().getWorldCache().put(blockpos, new WorldCache.CacheEntry(block, blockpos, PathNodeType.BLOCKED));
if (block instanceof BlockFenceGate) {
WorldCache.getInstance().getWorldCache().put(blockpos.up(), new WorldCache.CacheEntry(blockaccess.getBlockState(blockpos.up()).getBlock(), blockpos.up(), PathNodeType.BLOCKED));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/jelly/farmhelperv2/util/PlotUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ private static List<Tuple<Integer, Integer>> getChunks(int fromX, int toX, int f

public static BlockPos getPlotCenter(int plotNumber) {
List<Tuple<Integer, Integer>> chunks = getPlotBasedOnNumber(plotNumber);
int minX = chunks.get(0).getFirst();
int maxX = chunks.get(0).getFirst();
int minZ = chunks.get(chunks.size() - 1).getSecond();
int maxZ = chunks.get(chunks.size() - 1).getSecond();
int minX = chunks.get(0).getFirst() * 16;
int maxX = chunks.get(chunks.size() - 1).getFirst() * 16;
int minZ = chunks.get(0).getSecond() * 16;
int maxZ = chunks.get(chunks.size() - 1).getSecond() * 16;
float centerX = (float) (minX + (maxX - minX) / 2);
float centerZ = (float) (minZ + (maxZ - minZ) / 2);
return new BlockPos(centerX, 80, centerZ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public static boolean hasPackageInstalled(String name) {
public static boolean hasModFile(String name) {
Path modsDir = Minecraft.getMinecraft().mcDataDir.toPath().resolve("mods");
String[] modFiles = modsDir.toFile().list();
return modFiles != null && Arrays.stream(modFiles).anyMatch(modFile -> modFile.toLowerCase().contains(name.toLowerCase()));
return modFiles != null && Arrays.stream(modFiles).anyMatch(modFile -> modFile.toLowerCase().contains(name.toLowerCase()) && !modFile.toLowerCase().endsWith(".disabled"));
}
}

0 comments on commit abae1fb

Please sign in to comment.