Search in sources :

Example 6 with TileEntity

use of com.loohp.interactionvisualizer.objectholders.TileEntity in project InteractionVisualizer by LOOHP.

the class V1_17 method getTileEntities.

@SuppressWarnings("unchecked")
@Override
public NMSTileEntitySet<?, ?> getTileEntities(ChunkPosition chunk, boolean load) {
    if (!chunk.isLoaded() && !load) {
        return null;
    }
    World world = chunk.getWorld();
    try {
        return new NMSTileEntitySet<net.minecraft.core.BlockPosition, net.minecraft.world.level.block.entity.TileEntity>((Map<net.minecraft.core.BlockPosition, net.minecraft.world.level.block.entity.TileEntity>) nmsChunkL.get(((CraftChunk) chunk.getChunk()).getHandle()), entry -> {
            net.minecraft.core.BlockPosition pos = entry.getKey();
            try {
                Material type = CraftMagicNumbers.getMaterial((net.minecraft.world.level.block.Block) blockDataGetBlock.invoke(tileEntityGetBlock.invoke(entry.getValue())));
                TileEntityType tileEntityType = TileEntity.getTileEntityType(type);
                if (tileEntityType != null) {
                    return new TileEntity(world, (int) blockPositionGetX.invoke(pos), (int) blockPositionGetY.invoke(pos), (int) blockPositionGetZ.invoke(pos), tileEntityType);
                } else {
                    return null;
                }
            } catch (Exception e) {
                return null;
            }
        });
    } catch (IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : BlockPosition(com.loohp.interactionvisualizer.objectholders.BlockPosition) Material(org.bukkit.Material) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) World(org.bukkit.World) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) InvocationTargetException(java.lang.reflect.InvocationTargetException) TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)

Example 7 with TileEntity

use of com.loohp.interactionvisualizer.objectholders.TileEntity in project InteractionVisualizer by LOOHP.

the class V1_18 method getTileEntities.

@Override
public NMSTileEntitySet<?, ?> getTileEntities(ChunkPosition chunk, boolean load) {
    if (!chunk.isLoaded() && !load) {
        return null;
    }
    World world = chunk.getWorld();
    return new NMSTileEntitySet<net.minecraft.core.BlockPosition, net.minecraft.world.level.block.entity.TileEntity>(((CraftChunk) chunk.getChunk()).getHandle().E(), entry -> {
        net.minecraft.core.BlockPosition pos = entry.getKey();
        Material type = CraftMagicNumbers.getMaterial(entry.getValue().q().b());
        TileEntityType tileEntityType = TileEntity.getTileEntityType(type);
        if (tileEntityType != null) {
            return new TileEntity(world, pos.u(), pos.v(), pos.w(), tileEntityType);
        } else {
            return null;
        }
    });
}
Also used : TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) Material(org.bukkit.Material) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) World(org.bukkit.World) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_18_R1.CraftChunk)

Example 8 with TileEntity

use of com.loohp.interactionvisualizer.objectholders.TileEntity in project InteractionVisualizer by LOOHP.

the class V1_18_2 method getTileEntities.

@Override
public NMSTileEntitySet<?, ?> getTileEntities(ChunkPosition chunk, boolean load) {
    if (!chunk.isLoaded() && !load) {
        return null;
    }
    World world = chunk.getWorld();
    return new NMSTileEntitySet<net.minecraft.core.BlockPosition, net.minecraft.world.level.block.entity.TileEntity>(((CraftChunk) chunk.getChunk()).getHandle().E(), entry -> {
        net.minecraft.core.BlockPosition pos = entry.getKey();
        Material type = CraftMagicNumbers.getMaterial(entry.getValue().q().b());
        TileEntityType tileEntityType = TileEntity.getTileEntityType(type);
        if (tileEntityType != null) {
            return new TileEntity(world, pos.u(), pos.v(), pos.w(), tileEntityType);
        } else {
            return null;
        }
    });
}
Also used : TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) Material(org.bukkit.Material) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) World(org.bukkit.World) CraftChunk(org.bukkit.craftbukkit.v1_18_R2.CraftChunk)

Example 9 with TileEntity

use of com.loohp.interactionvisualizer.objectholders.TileEntity in project InteractionVisualizer by LOOHP.

the class TileEntityManager method addTileEntities.

private static synchronized void addTileEntities(ChunkPosition chunk) {
    NMSTileEntitySet<?, ?> list = NMS.getInstance().getTileEntities(chunk, false);
    Set<Block> blocks = byChunk.get(chunk);
    if (blocks == null) {
        blocks = new LinkedHashSet<>();
        byChunk.put(chunk, blocks);
    }
    Map<Block, TileEntityType> newBlocks = new LinkedHashMap<>();
    if (list != null) {
        for (TileEntity tile : list) {
            if (tile != null) {
                Block block = tile.getBlock();
                TileEntityType type = tile.getType();
                active.get(type).add(block);
                newBlocks.put(block, type);
                blocks.add(block);
            }
        }
    }
    Iterator<Block> itr = blocks.iterator();
    while (itr.hasNext()) {
        Block block = itr.next();
        TileEntityType type = newBlocks.get(block);
        if (type == null) {
            itr.remove();
            for (TileEntityType t : tileEntityTypes) {
                if (active.get(t).remove(block)) {
                    Bukkit.getPluginManager().callEvent(new TileEntityRemovedEvent(block, t));
                }
            }
        } else {
            for (TileEntityType t : tileEntityTypes) {
                if (!t.equals(type)) {
                    if (active.get(t).remove(block)) {
                        Bukkit.getPluginManager().callEvent(new TileEntityRemovedEvent(block, t));
                    }
                }
            }
        }
    }
}
Also used : TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) TileEntityRemovedEvent(com.loohp.interactionvisualizer.api.events.TileEntityRemovedEvent) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) Block(org.bukkit.block.Block) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with TileEntity

use of com.loohp.interactionvisualizer.objectholders.TileEntity in project InteractionVisualizer by LOOHP.

the class V1_11 method getTileEntities.

@Override
public NMSTileEntitySet<?, ?> getTileEntities(ChunkPosition chunk, boolean load) {
    if (!chunk.isLoaded() && !load) {
        return null;
    }
    World world = chunk.getWorld();
    return new NMSTileEntitySet<net.minecraft.server.v1_11_R1.BlockPosition, net.minecraft.server.v1_11_R1.TileEntity>(((CraftChunk) chunk.getChunk()).getHandle().tileEntities, entry -> {
        net.minecraft.server.v1_11_R1.BlockPosition pos = entry.getKey();
        Material type = CraftMagicNumbers.getMaterial(entry.getValue().getBlock());
        TileEntityType tileEntityType = TileEntity.getTileEntityType(type);
        if (tileEntityType != null) {
            return new TileEntity(world, pos.getX(), pos.getY(), pos.getZ(), tileEntityType);
        } else {
            return null;
        }
    });
}
Also used : TileEntity(com.loohp.interactionvisualizer.objectholders.TileEntity) TileEntityType(com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType) Material(org.bukkit.Material) NMSTileEntitySet(com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet) World(org.bukkit.World) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_11_R1.CraftChunk)

Aggregations

TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)13 TileEntityType (com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType)13 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)12 Material (org.bukkit.Material)12 World (org.bukkit.World)12 TileEntityRemovedEvent (com.loohp.interactionvisualizer.api.events.TileEntityRemovedEvent)1 BlockPosition (com.loohp.interactionvisualizer.objectholders.BlockPosition)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedHashMap (java.util.LinkedHashMap)1 Block (org.bukkit.block.Block)1 CraftChunk (org.bukkit.craftbukkit.v1_11_R1.CraftChunk)1 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)1 CraftChunk (org.bukkit.craftbukkit.v1_12_R1.CraftChunk)1 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)1 CraftChunk (org.bukkit.craftbukkit.v1_13_R1.CraftChunk)1 CraftWorld (org.bukkit.craftbukkit.v1_13_R1.CraftWorld)1 CraftChunk (org.bukkit.craftbukkit.v1_13_R2.CraftChunk)1 CraftWorld (org.bukkit.craftbukkit.v1_13_R2.CraftWorld)1 CraftChunk (org.bukkit.craftbukkit.v1_14_R1.CraftChunk)1 CraftWorld (org.bukkit.craftbukkit.v1_14_R1.CraftWorld)1