use of com.loohp.interactionvisualizer.objectholders.BlockPosition in project InteractionVisualizer by LOOHP.
the class LineOfSightUtils method hasLineOfSight.
@SuppressWarnings("deprecation")
public static boolean hasLineOfSight(Location from, Location to, double accuracy) {
if (!from.getWorld().equals(to.getWorld())) {
return false;
}
Vector direction = to.toVector().subtract(from.toVector()).normalize();
double distance = from.distance(to);
Map<BlockPosition, List<Location>> blocks = new LinkedHashMap<>();
for (double d = 0; d <= distance; d += accuracy) {
Location pos = from.clone().add(direction.clone().multiply(d));
BlockPosition blockPos = new BlockPosition(pos);
List<Location> list = blocks.get(blockPos);
if (list == null) {
list = new ArrayList<>();
blocks.put(blockPos, list);
}
list.add(pos);
}
for (Entry<BlockPosition, List<Location>> entry : blocks.entrySet()) {
BlockPosition blockPos = entry.getKey();
List<Location> pos = entry.getValue();
if (blockPos.getWorld().isChunkLoaded(blockPos.getX() >> 4, blockPos.getZ() >> 4)) {
List<BoundingBox> box = BoundingBoxUtils.getBoundingBoxes(blockPos);
Material type = blockPos.getBlock().getType();
if (!type.isTransparent() && !type.toString().contains("GLASS") && !InteractionVisualizer.exemptBlocks.contains(type.toString())) {
for (Location point : pos) {
if (box.stream().anyMatch(each -> each.contains(point.getX(), point.getY(), point.getZ()))) {
return false;
}
}
}
}
}
return true;
}
use of com.loohp.interactionvisualizer.objectholders.BlockPosition in project InteractionVisualizer by LOOHP.
the class V1_13 method getBoundingBoxes.
public List<BoundingBox> getBoundingBoxes(BlockPosition pos) {
net.minecraft.server.v1_13_R1.BlockPosition blockpos = new net.minecraft.server.v1_13_R1.BlockPosition(pos.getX(), pos.getY(), pos.getZ());
WorldServer world = ((CraftWorld) pos.getWorld()).getHandle();
VoxelShape shape = world.getType(blockpos).g(world, blockpos);
return shape.d().stream().map(each -> new BoundingBox(each.a + pos.getX(), each.b + pos.getY(), each.c + pos.getZ(), each.d + pos.getX(), each.e + pos.getY(), each.f + pos.getZ())).collect(Collectors.toList());
}
use of com.loohp.interactionvisualizer.objectholders.BlockPosition in project InteractionVisualizer by LOOHP.
the class V1_16 method getBoundingBoxes.
public List<BoundingBox> getBoundingBoxes(BlockPosition pos) {
net.minecraft.server.v1_16_R1.BlockPosition blockpos = new net.minecraft.server.v1_16_R1.BlockPosition(pos.getX(), pos.getY(), pos.getZ());
WorldServer world = ((CraftWorld) pos.getWorld()).getHandle();
VoxelShape shape = world.getType(blockpos).getShape(world, blockpos);
return shape.d().stream().map(each -> new BoundingBox(each.minX + pos.getX(), each.minY + pos.getY(), each.minZ + pos.getZ(), each.maxX + pos.getX(), each.maxY + pos.getY(), each.maxZ + pos.getZ())).collect(Collectors.toList());
}
Aggregations