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.
This commit is contained in:
Daniel E 2019-11-19 15:30:55 -07:00
parent 82296cd221
commit 0bb08e035d
1 changed files with 15 additions and 4 deletions

View File

@ -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();