|
3 | 3 | import lombok.NonNull; |
4 | 4 | import net.bitbylogic.packetblocks.PacketBlocks; |
5 | 5 | import net.bitbylogic.packetblocks.block.PacketBlockManager; |
| 6 | +import org.bukkit.FluidCollisionMode; |
6 | 7 | import org.bukkit.Location; |
7 | 8 | import org.bukkit.Material; |
8 | 9 | import org.bukkit.World; |
@@ -47,38 +48,34 @@ public static RayTraceResult rayTrace(Player player, double range) { |
47 | 48 | Location eye = player.getEyeLocation(); |
48 | 49 | Vector direction = eye.getDirection().normalize(); |
49 | 50 |
|
50 | | - Vector current = eye.toVector(); |
51 | 51 | World world = player.getWorld(); |
52 | 52 |
|
53 | | - double step = 0.1; |
54 | | - double eps = 1e-6; |
| 53 | + RayTraceResult vanillaResult = world.rayTraceBlocks(eye, direction, range, FluidCollisionMode.NEVER, false); |
| 54 | + |
| 55 | + Vector current = eye.toVector(); |
| 56 | + double step = 0.05; |
55 | 57 |
|
56 | 58 | for (double traveled = 0; traveled <= range; traveled += step) { |
57 | 59 | current.add(direction.clone().multiply(step)); |
58 | 60 | Block block = world.getBlockAt(current.getBlockX(), current.getBlockY(), current.getBlockZ()); |
59 | 61 |
|
60 | | - BoundingBox pointBox = new BoundingBox( |
61 | | - current.getX() - eps, current.getY() - eps, current.getZ() - eps, |
62 | | - current.getX() + eps, current.getY() + eps, current.getZ() + eps |
63 | | - ); |
64 | | - |
65 | 62 | if (PacketBlockManager.getBlock(block.getLocation()).isPresent()) { |
66 | 63 | Material blockMaterial = PacketBlockManager.getBlock(block.getLocation()).get().getBlockData().getMaterial(); |
67 | 64 | BoundingBox boundingBox = BoundingBoxes.getBoxAt(blockMaterial, block.getLocation()); |
68 | 65 |
|
69 | | - if(boundingBox == null || !boundingBox.overlaps(pointBox)) { |
| 66 | + if(boundingBox == null) { |
70 | 67 | continue; |
71 | 68 | } |
72 | 69 |
|
73 | | - return new RayTraceResult(current, block, null); |
74 | | - } |
| 70 | + RayTraceResult boxResult = boundingBox.rayTrace(eye.toVector(), direction, range); |
75 | 71 |
|
76 | | - if (!block.isEmpty()) { |
77 | | - return new RayTraceResult(current, block, null); |
| 72 | + if (boxResult != null) { |
| 73 | + return new RayTraceResult(boxResult.getHitPosition(), block, boxResult.getHitBlockFace()); |
| 74 | + } |
78 | 75 | } |
79 | 76 | } |
80 | 77 |
|
81 | | - return null; |
| 78 | + return vanillaResult; |
82 | 79 | } |
83 | 80 |
|
84 | 81 | } |
0 commit comments