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:
parent
82296cd221
commit
0bb08e035d
|
@ -24,6 +24,7 @@ import net.minecraft.util.EnumActionResult;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
|
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 PlacementRequest placementRequest = placementRequests.poll();
|
||||||
final BlockPos position = placementRequest.getBlockPosition();
|
final BlockPos position = placementRequest.getBlockPosition();
|
||||||
final double playerToBlockDistance = player.getPositionEyes(1.0f)
|
final double playerToBlockDistance = calculateReachDistance(
|
||||||
.distanceTo(new Vec3d(position.getX(), position.getY(), position.getZ()));
|
minecraft.player.getPositionEyes(1.0f), position.getX(),
|
||||||
|
position.getY(), position.getZ());
|
||||||
if (playerToBlockDistance <= getExtendedReachDistance(minecraft))
|
if (playerToBlockDistance <= getExtendedReachDistance(minecraft))
|
||||||
handlePlaceRequest(minecraft, placementRequest);
|
handlePlaceRequest(minecraft, placementRequest);
|
||||||
|
|
||||||
|
@ -104,8 +106,9 @@ public final class ObsidianReplaceModule extends Module {
|
||||||
final SPacketBlockChange blockChange = (SPacketBlockChange) event.getPacket();
|
final SPacketBlockChange blockChange = (SPacketBlockChange) event.getPacket();
|
||||||
if (blockChange.getBlockState().getBlock() instanceof BlockAir) {
|
if (blockChange.getBlockState().getBlock() instanceof BlockAir) {
|
||||||
final BlockPos position = blockChange.getBlockPosition();
|
final BlockPos position = blockChange.getBlockPosition();
|
||||||
final double playerToBlockDistance = minecraft.player.getPositionEyes(1.0f)
|
final double playerToBlockDistance = calculateReachDistance(
|
||||||
.distanceTo(new Vec3d(position.getX(), position.getY(), position.getZ()));
|
minecraft.player.getPositionEyes(1.0f), position.getX(),
|
||||||
|
position.getY(), position.getZ());
|
||||||
if (playerToBlockDistance <= getExtendedReachDistance(minecraft))
|
if (playerToBlockDistance <= getExtendedReachDistance(minecraft))
|
||||||
buildPlacementRequest(minecraft, position);
|
buildPlacementRequest(minecraft, position);
|
||||||
}
|
}
|
||||||
|
@ -227,6 +230,14 @@ public final class ObsidianReplaceModule extends Module {
|
||||||
return minecraft.playerController.getBlockReachDistance();
|
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) {
|
private void processHandSwap(final HandSwapContext context, final boolean restore, final Minecraft minecraft) {
|
||||||
minecraft.player.inventory.currentItem = restore ? context.getOldSlot() : context.getNewSlot();
|
minecraft.player.inventory.currentItem = restore ? context.getOldSlot() : context.getNewSlot();
|
||||||
minecraft.playerController.updateController();
|
minecraft.playerController.updateController();
|
||||||
|
|
Loading…
Reference in New Issue