Search in sources :

Example 11 with BlockPosition

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;
}
Also used : BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) Material(org.bukkit.Material) LinkedHashMap(java.util.LinkedHashMap) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) List(java.util.List) ArrayList(java.util.ArrayList) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 12 with BlockPosition

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());
}
Also used : BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) Item(org.bukkit.entity.Item) CraftChunk(org.bukkit.craftbukkit.v1_13_R1.CraftChunk) Block(org.bukkit.block.Block) CraftWorld(org.bukkit.craftbukkit.v1_13_R1.CraftWorld) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) World(org.bukkit.World) VoxelShape(net.minecraft.server.v1_13_R1.VoxelShape) WrappedIterable(com.loohp.interactionvisualizer.objectholders.WrappedIterable) WorldServer(net.minecraft.server.v1_13_R1.WorldServer) Material(org.bukkit.Material) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) CraftMagicNumbers(org.bukkit.craftbukkit.v1_13_R1.util.CraftMagicNumbers) InteractionVisualizer(com.loohp.interactionvisualizer.InteractionVisualizer) Entity(org.bukkit.entity.Entity) ValuePairs(com.loohp.interactionvisualizer.objectholders.ValuePairs) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) ItemSlot(com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot) TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) PacketType(com.comphenix.protocol.PacketType) EntityItem(net.minecraft.server.v1_13_R1.EntityItem) Collectors(java.util.stream.Collectors) ItemStack(org.bukkit.inventory.ItemStack) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) PacketContainer(com.comphenix.protocol.events.PacketContainer) List(java.util.List) CraftItem(org.bukkit.craftbukkit.v1_13_R1.entity.CraftItem) VoxelShape(net.minecraft.server.v1_13_R1.VoxelShape) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) WorldServer(net.minecraft.server.v1_13_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_13_R1.CraftWorld)

Example 13 with BlockPosition

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());
}
Also used : BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) EntityItem(net.minecraft.server.v1_16_R1.EntityItem) Item(org.bukkit.entity.Item) CraftChunk(org.bukkit.craftbukkit.v1_16_R1.CraftChunk) CraftWorld(org.bukkit.craftbukkit.v1_16_R1.CraftWorld) VoxelShape(net.minecraft.server.v1_16_R1.VoxelShape) CraftItem(org.bukkit.craftbukkit.v1_16_R1.entity.CraftItem) WorldServer(net.minecraft.server.v1_16_R1.WorldServer) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) World(org.bukkit.World) WrappedIterable(com.loohp.interactionvisualizer.objectholders.WrappedIterable) Material(org.bukkit.Material) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) Entity(org.bukkit.entity.Entity) ValuePairs(com.loohp.interactionvisualizer.objectholders.ValuePairs) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) Collectors(java.util.stream.Collectors) Pair(com.mojang.datafixers.util.Pair) CraftItemStack(org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) PacketContainer(com.comphenix.protocol.events.PacketContainer) List(java.util.List) EnumItemSlot(net.minecraft.server.v1_16_R1.EnumItemSlot) PacketPlayOutEntityEquipment(net.minecraft.server.v1_16_R1.PacketPlayOutEntityEquipment) CraftMagicNumbers(org.bukkit.craftbukkit.v1_16_R1.util.CraftMagicNumbers) VoxelShape(net.minecraft.server.v1_16_R1.VoxelShape) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) WorldServer(net.minecraft.server.v1_16_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_16_R1.CraftWorld)

Aggregations

BlockPosition (com.loohp.interactionvisualizer.objectholders.BlockPosition)13 BoundingBox (com.loohp.interactionvisualizer.objectholders.BoundingBox)13 List (java.util.List)11 Material (org.bukkit.Material)11 PacketContainer (com.comphenix.protocol.events.PacketContainer)10 ChunkPosition (com.loohp.interactionvisualizer.objectholders.ChunkPosition)10 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)10 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)10 TileEntityType (com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)10 ValuePairs (com.loohp.interactionvisualizer.objectholders.ValuePairs)10 WrappedIterable (com.loohp.interactionvisualizer.objectholders.WrappedIterable)10 Collectors (java.util.stream.Collectors)10 World (org.bukkit.World)10 Block (org.bukkit.block.Block)10 Entity (org.bukkit.entity.Entity)10 Item (org.bukkit.entity.Item)10 EquipmentSlot (org.bukkit.inventory.EquipmentSlot)10 ItemStack (org.bukkit.inventory.ItemStack)10 ArrayList (java.util.ArrayList)9 PacketType (com.comphenix.protocol.PacketType)7