use of io.xol.chunkstories.api.entity.components.EntityComponent 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;
}
Aggregations