Skip to content

Commit ca19180

Browse files
committed
Adjust rayTrace method to account for sneaking player eye position and improve block detection accuracy.
1 parent 87914c4 commit ca19180

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/main/java/net/bitbylogic/packetblocks/util/PacketBlockUtil.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@ public static Material getBlockType(@NonNull Player player, @NonNull Location lo
4343
* @return a RayTraceResult containing information about the hit block and location, or null if no block was hit
4444
*/
4545
public static RayTraceResult rayTrace(Player player, double range) {
46-
PacketBlockManager PacketBlockManager = PacketBlocks.getInstance().getBlockManager();
46+
PacketBlockManager blockManager = PacketBlocks.getInstance().getBlockManager();
4747

48-
Location eye = player.getEyeLocation();
48+
Location eye = player.isSneaking() ? player.getEyeLocation().clone().add(0, 0.25, 0) : player.getEyeLocation();
4949
Vector direction = eye.getDirection().normalize();
5050

5151
World world = player.getWorld();
5252

5353
RayTraceResult vanillaResult = world.rayTraceBlocks(eye, direction, range, FluidCollisionMode.NEVER, false);
5454

5555
Vector current = eye.toVector();
56-
double step = 0.05;
56+
double step = 0.02;
5757

5858
for (double traveled = 0; traveled <= range; traveled += step) {
5959
current.add(direction.clone().multiply(step));
60-
Block block = world.getBlockAt(current.getBlockX(), current.getBlockY(), current.getBlockZ());
60+
Block block = world.getBlockAt(current.toLocation(world));
6161

62-
if (PacketBlockManager.getBlock(block.getLocation()).isPresent()) {
63-
Material blockMaterial = PacketBlockManager.getBlock(block.getLocation()).get().getBlockData().getMaterial();
62+
if (blockManager.getBlock(block.getLocation()).isPresent()) {
63+
Material blockMaterial = blockManager.getBlock(block.getLocation()).get().getBlockData().getMaterial();
6464
BoundingBox boundingBox = BoundingBoxes.getBoxAt(blockMaterial, block.getLocation());
6565

6666
if(boundingBox == null) {

0 commit comments

Comments
 (0)