Last active
February 23, 2022 22:37
-
-
Save cerus/b2be8f3f8d9fcd0b865d1abbcad4e58d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The RayTracer interface was written by me, it's not an interface from Bukkit or Minecraft | |
public class RayTracerImpl implements RayTracer { | |
private final CachedBlockAccess cachedBlockAccess; | |
public RayTracerImpl(final ChunkCacheImpl chunkCache) { | |
this.cachedBlockAccess = new CachedBlockAccess(chunkCache); | |
} | |
@Override | |
public RayTraceResult rayTraceBlocks(final Location location, | |
final Vector direction, | |
final int maxDistance, | |
final FluidCollisionMode fluidCollisionMode, | |
final boolean ignorePassableBlocks) { | |
final Vector dir = direction.clone().normalize().multiply(maxDistance); | |
final Vec3D startPos = new Vec3D(location.getX(), location.getY(), location.getZ()); | |
final Vec3D endPos = new Vec3D(location.getX() + dir.getX(), location.getY() + dir.getY(), location.getZ() + dir.getZ()); | |
return CraftRayTraceResult.fromNMS(location.getWorld(), this.cachedBlockAccess.rayTrace(new RayTrace( | |
startPos, | |
endPos, | |
ignorePassableBlocks ? RayTrace.BlockCollisionOption.COLLIDER : RayTrace.BlockCollisionOption.OUTLINE, | |
CraftFluidCollisionMode.toNMS(fluidCollisionMode), | |
null | |
))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment