REntity #148
@ -39,44 +39,6 @@ import java.util.List;
|
||||
@UtilityClass
|
||||
public class RayTraceUtils {
|
||||
|
||||
public static RayTraceResult trace(Player player, Location to, List<Entity> entityList) {
|
||||
if (player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Location startPos = to.clone().add(0.0, player.getEyeHeight(), 0.0);
|
||||
Vector direction = to.getDirection();
|
||||
RayTraceResult blocks = player.getWorld().rayTraceBlocks(startPos, direction, 10.0, FluidCollisionMode.NEVER, true);
|
||||
|
||||
Entity nearestHitEntity = null;
|
||||
RayTraceResult nearestHitResult = null;
|
||||
double nearestDistanceSq = Double.MAX_VALUE;
|
||||
for (Entity entity : entityList) {
|
||||
BoundingBox boundingBox = entity.getBoundingBox();
|
||||
RayTraceResult hitResult = boundingBox.rayTrace(startPos.toVector(), direction, 10.0);
|
||||
if (hitResult != null) {
|
||||
double distanceSq = startPos.toVector().distanceSquared(hitResult.getHitPosition());
|
||||
if (distanceSq < nearestDistanceSq) {
|
||||
nearestHitEntity = entity;
|
||||
nearestHitResult = hitResult;
|
||||
nearestDistanceSq = distanceSq;
|
||||
}
|
||||
}
|
||||
}
|
||||
RayTraceResult entities = nearestHitEntity == null ? null : new RayTraceResult(nearestHitResult.getHitPosition(), nearestHitEntity, nearestHitResult.getHitBlockFace());
|
||||
|
||||
if (blocks == null) {
|
||||
return entities;
|
||||
} else if (entities == null) {
|
||||
return blocks;
|
||||
} else {
|
||||
Vector startVec = startPos.toVector();
|
||||
double blockHitDistance = startVec.distance(blocks.getHitPosition());
|
||||
double entityHitDistanceSquared = startVec.distanceSquared(entities.getHitPosition());
|
||||
return entityHitDistanceSquared < blockHitDistance * blockHitDistance ? entities : blocks;
|
||||
}
|
||||
}
|
||||
|
||||
public static RRayTraceResult traceREntity(Player player, Location to, List<RFallingBlockEntity> entityList) {
|
||||
if (player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return null;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren