Search in sources :

Example 1 with EntityComponentInventory

use of io.xol.chunkstories.api.entity.components.EntityComponentInventory in project chunkstories-api by Hugobros3.

the class InventoryTranslator method obtainInventoryHandle.

public static Inventory obtainInventoryHandle(DataInputStream in, PacketReceptionContext context) throws IOException {
    byte holderType = in.readByte();
    if (holderType == 0x01) {
        long uuid = in.readLong();
        short componentId = in.readShort();
        Entity entity = context.getWorld().getEntityByUUID(uuid);
        EntityComponent cpn = entity.getComponents().getComponentById(componentId);
        if (cpn != null && cpn instanceof EntityComponentInventory) {
            return ((EntityComponentInventory) cpn).getInventory();
        }
    } else if (holderType == 0x03) {
        int x = in.readInt();
        int y = in.readInt();
        int z = in.readInt();
        String componentName = in.readUTF();
        try {
            ChunkCell voxelContext = context.getWorld().peek(x, y, z);
            VoxelComponent com = voxelContext.components().get(componentName);
            if (com != null && com instanceof VoxelInventoryComponent) {
                VoxelInventoryComponent comp = (VoxelInventoryComponent) com;
                return comp.getInventory();
            }
        } catch (WorldException e) {
        // TODO log as warning
        // Ignore and return null
        }
    }
    return null;
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) WorldException(io.xol.chunkstories.api.exceptions.world.WorldException) VoxelComponent(io.xol.chunkstories.api.voxel.components.VoxelComponent) ChunkCell(io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell) EntityComponentInventory(io.xol.chunkstories.api.entity.components.EntityComponentInventory) EntityComponent(io.xol.chunkstories.api.entity.components.EntityComponent) VoxelInventoryComponent(io.xol.chunkstories.api.voxel.components.VoxelInventoryComponent)

Aggregations

Entity (io.xol.chunkstories.api.entity.Entity)1 EntityComponent (io.xol.chunkstories.api.entity.components.EntityComponent)1 EntityComponentInventory (io.xol.chunkstories.api.entity.components.EntityComponentInventory)1 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)1 VoxelComponent (io.xol.chunkstories.api.voxel.components.VoxelComponent)1 VoxelInventoryComponent (io.xol.chunkstories.api.voxel.components.VoxelInventoryComponent)1 ChunkCell (io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell)1