From 0bb08e035d7fdc57493d314dd89d3c5ae221ee24 Mon Sep 17 00:00:00 2001 From: Daniel E Date: Tue, 19 Nov 2019 15:30:55 -0700 Subject: [PATCH] One less Vec3d Didn't really want to make a new Vec3d every time to convert the BlockPos, so we just made a simple function that compares both for distance. --- .../module/combat/ObsidianReplaceModule.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java index eecce17..0db4f47 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java @@ -24,6 +24,7 @@ import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; @@ -83,8 +84,9 @@ public final class ObsidianReplaceModule extends Module { final PlacementRequest placementRequest = placementRequests.poll(); final BlockPos position = placementRequest.getBlockPosition(); - final double playerToBlockDistance = player.getPositionEyes(1.0f) - .distanceTo(new Vec3d(position.getX(), position.getY(), position.getZ())); + final double playerToBlockDistance = calculateReachDistance( + minecraft.player.getPositionEyes(1.0f), position.getX(), + position.getY(), position.getZ()); if (playerToBlockDistance <= getExtendedReachDistance(minecraft)) handlePlaceRequest(minecraft, placementRequest); @@ -104,8 +106,9 @@ public final class ObsidianReplaceModule extends Module { final SPacketBlockChange blockChange = (SPacketBlockChange) event.getPacket(); if (blockChange.getBlockState().getBlock() instanceof BlockAir) { final BlockPos position = blockChange.getBlockPosition(); - final double playerToBlockDistance = minecraft.player.getPositionEyes(1.0f) - .distanceTo(new Vec3d(position.getX(), position.getY(), position.getZ())); + final double playerToBlockDistance = calculateReachDistance( + minecraft.player.getPositionEyes(1.0f), position.getX(), + position.getY(), position.getZ()); if (playerToBlockDistance <= getExtendedReachDistance(minecraft)) buildPlacementRequest(minecraft, position); } @@ -227,6 +230,14 @@ public final class ObsidianReplaceModule extends Module { return minecraft.playerController.getBlockReachDistance(); } + private double calculateReachDistance(final Vec3d vector, final int blockX, + final int blockY, final int blockZ) { + final double diffX = blockX - vector.x; + final double diffY = blockY - vector.y; + final double diffZ = blockZ - vector.z; + return MathHelper.sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ); + } + private void processHandSwap(final HandSwapContext context, final boolean restore, final Minecraft minecraft) { minecraft.player.inventory.currentItem = restore ? context.getOldSlot() : context.getNewSlot(); minecraft.playerController.updateController();