use of io.xol.chunkstories.api.voxel.components.VoxelInventoryComponent 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;
}
use of io.xol.chunkstories.api.voxel.components.VoxelInventoryComponent in project chunkstories-api by Hugobros3.
the class InventoryTranslator method writeInventoryHandle.
public static void writeInventoryHandle(DataOutputStream out, Inventory inventory) throws IOException {
/*if(inventory instanceof InventoryLocalCreativeMenu)
out.writeByte(0x02); else */
if (inventory == null || inventory.getHolder() == null)
out.writeByte(0x00);
else if (inventory instanceof EntityComponentInventory.EntityInventory) {
EntityComponentInventory.EntityInventory entityInventory = (EntityComponentInventory.EntityInventory) inventory;
out.writeByte(0x01);
out.writeLong(((Entity) inventory.getHolder()).getUUID());
out.writeShort(entityInventory.asComponent().getEntityComponentId());
} else if (inventory.getHolder() instanceof VoxelInventoryComponent) {
VoxelInventoryComponent component = (VoxelInventoryComponent) inventory.getHolder();
out.writeByte(0x03);
out.writeInt(component.holder().getX());
out.writeInt(component.holder().getY());
out.writeInt(component.holder().getZ());
out.writeUTF(component.holder().name(component));
} else
out.writeByte(0x00);
// throw new RuntimeException("Untranslatable and Unknown Inventory : "+inventory+", can't describe it in outgoing packets");
}
use of io.xol.chunkstories.api.voxel.components.VoxelInventoryComponent in project chunkstories-core by Hugobros3.
the class VoxelChest method whenPlaced.
@Override
public void whenPlaced(FreshChunkCell cell) {
// Create a new component and insert it into the chunk
VoxelInventoryComponent component = new VoxelInventoryComponent(cell.components(), 10, 6);
cell.registerComponent("chestInventory", component);
}
use of io.xol.chunkstories.api.voxel.components.VoxelInventoryComponent in project chunkstories-core by Hugobros3.
the class VoxelChest method getInventory.
private Inventory getInventory(ChunkCell context) {
VoxelComponent comp = context.components().get("chestInventory");
VoxelInventoryComponent component = (VoxelInventoryComponent) comp;
return component.getInventory();
}
Aggregations