Search in sources :

Example 1 with AxisAlignedBB

use of net.minecraft.world.phys.AxisAlignedBB in project InteractionVisualizer by LOOHP.

the class V1_17 method getBoundingBoxes.

@SuppressWarnings("unchecked")
public List<BoundingBox> getBoundingBoxes(BlockPosition pos) {
    net.minecraft.core.BlockPosition blockpos = new net.minecraft.core.BlockPosition(pos.getX(), pos.getY(), pos.getZ());
    WorldServer world = ((CraftWorld) pos.getWorld()).getHandle();
    try {
        VoxelShape shape = (VoxelShape) blockDataGetShape.invoke(worldServerGetType.invoke(blockpos), world, blockpos);
        return ((List<AxisAlignedBB>) voxelShapeGetAABBList.invoke(shape)).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());
    } catch (Exception e) {
        List<BoundingBox> boxes = new ArrayList<>();
        boxes.add(BoundingBox.of(pos.getBlock()));
        return boxes;
    }
}
Also used : BlockData(net.minecraft.world.level.block.state.BlockBase.BlockData) WorldServer(net.minecraft.server.level.WorldServer) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) IBlockAccess(net.minecraft.world.level.IBlockAccess) Item(org.bukkit.entity.Item) PacketPlayOutEntityDestroy(net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy) PacketPlayOutEntityEquipment(net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) Chunk(net.minecraft.world.level.chunk.Chunk) CraftItem(org.bukkit.craftbukkit.v1_17_R1.entity.CraftItem) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) World(org.bukkit.World) Map(java.util.Map) WrappedIterable(com.loohp.interactionvisualizer.objectholders.WrappedIterable) Method(java.lang.reflect.Method) Material(org.bukkit.Material) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CraftChunk(org.bukkit.craftbukkit.v1_17_R1.CraftChunk) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) EntityItem(net.minecraft.world.entity.item.EntityItem) LevelEntityGetter(net.minecraft.world.level.entity.LevelEntityGetter) CraftMagicNumbers(org.bukkit.craftbukkit.v1_17_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) TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) AxisAlignedBB(net.minecraft.world.phys.AxisAlignedBB) PacketType(com.comphenix.protocol.PacketType) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) Pair(com.mojang.datafixers.util.Pair) ItemStack(org.bukkit.inventory.ItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) PacketContainer(com.comphenix.protocol.events.PacketContainer) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) EnumItemSlot(net.minecraft.world.entity.EnumItemSlot) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) InvocationTargetException(java.lang.reflect.InvocationTargetException) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 2 with AxisAlignedBB

use of net.minecraft.world.phys.AxisAlignedBB in project InteractionVisualizer by LOOHP.

the class V1_18 method getBoundingBoxes.

@SuppressWarnings("unchecked")
public List<BoundingBox> getBoundingBoxes(BlockPosition pos) {
    net.minecraft.core.BlockPosition blockpos = new net.minecraft.core.BlockPosition(pos.getX(), pos.getY(), pos.getZ());
    WorldServer world = ((CraftWorld) pos.getWorld()).getHandle();
    VoxelShape shape = world.a_(blockpos).j(world, blockpos);
    try {
        return ((List<AxisAlignedBB>) voxelShapeGetAABBList.invoke(shape)).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());
    } catch (Exception e) {
        List<BoundingBox> boxes = new ArrayList<>();
        boxes.add(BoundingBox.of(pos.getBlock()));
        return boxes;
    }
}
Also used : WorldServer(net.minecraft.server.level.WorldServer) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) Item(org.bukkit.entity.Item) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) PacketPlayOutEntityDestroy(net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy) PacketPlayOutEntityEquipment(net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) CraftMagicNumbers(org.bukkit.craftbukkit.v1_18_R1.util.CraftMagicNumbers) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) World(org.bukkit.World) WrappedIterable(com.loohp.interactionvisualizer.objectholders.WrappedIterable) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) Method(java.lang.reflect.Method) Material(org.bukkit.Material) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) CraftChunk(org.bukkit.craftbukkit.v1_18_R1.CraftChunk) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) EntityItem(net.minecraft.world.entity.item.EntityItem) InteractionVisualizer(com.loohp.interactionvisualizer.InteractionVisualizer) Entity(org.bukkit.entity.Entity) ValuePairs(com.loohp.interactionvisualizer.objectholders.ValuePairs) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) AxisAlignedBB(net.minecraft.world.phys.AxisAlignedBB) PacketType(com.comphenix.protocol.PacketType) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) Pair(com.mojang.datafixers.util.Pair) ItemStack(org.bukkit.inventory.ItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) PacketContainer(com.comphenix.protocol.events.PacketContainer) List(java.util.List) PersistentEntitySectionManager(net.minecraft.world.level.entity.PersistentEntitySectionManager) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) Collections(java.util.Collections) EnumItemSlot(net.minecraft.world.entity.EnumItemSlot) CraftItem(org.bukkit.craftbukkit.v1_18_R1.entity.CraftItem) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) InvocationTargetException(java.lang.reflect.InvocationTargetException) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 3 with AxisAlignedBB

use of net.minecraft.world.phys.AxisAlignedBB in project InteractionVisualizer by LOOHP.

the class V1_18_2 method getBoundingBoxes.

@SuppressWarnings("unchecked")
public List<BoundingBox> getBoundingBoxes(BlockPosition pos) {
    net.minecraft.core.BlockPosition blockpos = new net.minecraft.core.BlockPosition(pos.getX(), pos.getY(), pos.getZ());
    WorldServer world = ((CraftWorld) pos.getWorld()).getHandle();
    VoxelShape shape = world.a_(blockpos).j(world, blockpos);
    try {
        return ((List<AxisAlignedBB>) voxelShapeGetAABBList.invoke(shape)).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());
    } catch (Exception e) {
        List<BoundingBox> boxes = new ArrayList<>();
        boxes.add(BoundingBox.of(pos.getBlock()));
        return boxes;
    }
}
Also used : WorldServer(net.minecraft.server.level.WorldServer) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) Item(org.bukkit.entity.Item) PacketPlayOutEntityDestroy(net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy) PacketPlayOutEntityEquipment(net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk) 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) Method(java.lang.reflect.Method) Material(org.bukkit.Material) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) ChunkPosition(com.loohp.interactionvisualizer.objectholders.ChunkPosition) EntityItem(net.minecraft.world.entity.item.EntityItem) InteractionVisualizer(com.loohp.interactionvisualizer.InteractionVisualizer) Entity(org.bukkit.entity.Entity) ValuePairs(com.loohp.interactionvisualizer.objectholders.ValuePairs) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) CraftItem(org.bukkit.craftbukkit.v1_18_R2.entity.CraftItem) TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) AxisAlignedBB(net.minecraft.world.phys.AxisAlignedBB) PacketType(com.comphenix.protocol.PacketType) Collectors(java.util.stream.Collectors) Pair(com.mojang.datafixers.util.Pair) ItemStack(org.bukkit.inventory.ItemStack) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) PacketContainer(com.comphenix.protocol.events.PacketContainer) CraftMagicNumbers(org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers) List(java.util.List) CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) EnumItemSlot(net.minecraft.world.entity.EnumItemSlot) BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) BoundingBox(com.loohp.interactionvisualizer.objectholders.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

Example 4 with AxisAlignedBB

use of net.minecraft.world.phys.AxisAlignedBB in project Atlas by funkemunky.

the class BlockBox1_17_R1 method getCollisionBox.

@Override
public CollisionBox getCollisionBox(org.bukkit.block.Block block) {
    final World world = ((org.bukkit.craftbukkit.v1_17_R1.CraftWorld) block.getWorld()).getHandle();
    final int x = block.getX(), y = block.getY(), z = block.getZ();
    IBlockData iblockData = ((CraftBlock) block).getNMS();
    Block vblock = iblockData.getBlock();
    BlockPosition blockPos = new BlockPosition(x, y, z);
    VoxelShape shape = vblock.a(iblockData, world, blockPos, VoxelShapeCollision.a());
    List<AxisAlignedBB> boxes = shape.toList();
    if (boxes.size() == 0) {
        return BlockData.getData(block.getType()).getBox(block, ProtocolVersion.getGameVersion());
    } else if (boxes.size() == 1) {
        AxisAlignedBB box = boxes.get(0);
        return new SimpleCollisionBox(box.a, box.b, box.c, box.d, box.e, box.f);
    } else {
        ComplexCollisionBox complexBox = new ComplexCollisionBox();
        for (AxisAlignedBB box : boxes) {
            complexBox.add(new SimpleCollisionBox(box.a, box.b, box.c, box.d, box.e, box.f));
        }
        return complexBox;
    }
}
Also used : AxisAlignedBB(net.minecraft.world.phys.AxisAlignedBB) BlockPosition(net.minecraft.core.BlockPosition) ComplexCollisionBox(cc.funkemunky.api.utils.world.types.ComplexCollisionBox) CraftBlock(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock) World(net.minecraft.world.level.World) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) SimpleCollisionBox(cc.funkemunky.api.utils.world.types.SimpleCollisionBox) IBlockData(net.minecraft.world.level.block.state.IBlockData) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) CraftBlock(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock) Block(net.minecraft.world.level.block.Block) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 5 with AxisAlignedBB

use of net.minecraft.world.phys.AxisAlignedBB in project Atlas by funkemunky.

the class BlockBox1_18_R1 method getCollisionBox.

@Override
public CollisionBox getCollisionBox(org.bukkit.block.Block block) {
    final World world = ((org.bukkit.craftbukkit.v1_18_R1.CraftWorld) block.getWorld()).getHandle();
    final int x = block.getX(), y = block.getY(), z = block.getZ();
    IBlockData iblockData = ((CraftBlock) block).getNMS();
    Block vblock = iblockData.b();
    BlockPosition blockPos = new BlockPosition(x, y, z);
    VoxelShape shape = vblock.a(iblockData, world, blockPos, VoxelShapeCollision.a());
    List<AxisAlignedBB> boxes = shape.d();
    if (boxes.size() == 0) {
        return BlockData.getData(block.getType()).getBox(block, ProtocolVersion.getGameVersion());
    } else if (boxes.size() == 1) {
        AxisAlignedBB box = boxes.get(0);
        return new SimpleCollisionBox(box.a, box.b, box.c, box.d, box.e, box.f);
    } else {
        ComplexCollisionBox complexBox = new ComplexCollisionBox();
        for (AxisAlignedBB box : boxes) {
            complexBox.add(new SimpleCollisionBox(box.a, box.b, box.c, box.d, box.e, box.f));
        }
        return complexBox;
    }
}
Also used : AxisAlignedBB(net.minecraft.world.phys.AxisAlignedBB) BlockPosition(net.minecraft.core.BlockPosition) ComplexCollisionBox(cc.funkemunky.api.utils.world.types.ComplexCollisionBox) CraftBlock(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock) World(net.minecraft.world.level.World) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) SimpleCollisionBox(cc.funkemunky.api.utils.world.types.SimpleCollisionBox) IBlockData(net.minecraft.world.level.block.state.IBlockData) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) CraftBlock(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock) Block(net.minecraft.world.level.block.Block) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Aggregations

AxisAlignedBB (net.minecraft.world.phys.AxisAlignedBB)5 VoxelShape (net.minecraft.world.phys.shapes.VoxelShape)5 PacketType (com.comphenix.protocol.PacketType)3 PacketContainer (com.comphenix.protocol.events.PacketContainer)3 InteractionVisualizer (com.loohp.interactionvisualizer.InteractionVisualizer)3 BlockPosition (com.loohp.interactionvisualizer.objectholders.BlockPosition)3 BoundingBox (com.loohp.interactionvisualizer.objectholders.BoundingBox)3 ChunkPosition (com.loohp.interactionvisualizer.objectholders.ChunkPosition)3 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)3 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)3 TileEntityType (com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)3 ValuePairs (com.loohp.interactionvisualizer.objectholders.ValuePairs)3 WrappedIterable (com.loohp.interactionvisualizer.objectholders.WrappedIterable)3 Pair (com.mojang.datafixers.util.Pair)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 PacketPlayOutEntityDestroy (net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy)3 PacketPlayOutEntityEquipment (net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment)3