use of com.simibubi.create.content.logistics.block.inventories.BottomlessItemHandler in project Create by Creators-of-Create.
the class MountedStorage method deserialize.
public static MountedStorage deserialize(CompoundTag nbt) {
MountedStorage storage = new MountedStorage(null);
storage.handler = new ItemStackHandler();
if (nbt == null)
return storage;
storage.valid = true;
if (nbt.contains("Bottomless")) {
ItemStack providedStack = ItemStack.of(nbt.getCompound("ProvidedStack"));
storage.handler = new BottomlessItemHandler(() -> providedStack);
return storage;
}
storage.handler.deserializeNBT(nbt);
return storage;
}
use of com.simibubi.create.content.logistics.block.inventories.BottomlessItemHandler in project Create by Creators-of-Create.
the class MountedStorage method addStorageToWorld.
public void addStorageToWorld(BlockEntity te) {
// FIXME: More dynamic mounted storage in .4
if (handler instanceof BottomlessItemHandler)
return;
if (te instanceof ChestBlockEntity) {
CompoundTag tag = te.saveWithFullMetadata();
tag.remove("Items");
NonNullList<ItemStack> items = NonNullList.withSize(handler.getSlots(), ItemStack.EMPTY);
for (int i = 0; i < items.size(); i++) items.set(i, handler.getStackInSlot(i));
ContainerHelper.saveAllItems(tag, items);
te.load(tag);
return;
}
if (te instanceof ItemVaultTileEntity) {
((ItemVaultTileEntity) te).applyInventoryToBlock(handler);
return;
}
LazyOptional<IItemHandler> capability = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
IItemHandler teHandler = capability.orElse(null);
if (!(teHandler instanceof IItemHandlerModifiable))
return;
IItemHandlerModifiable inv = (IItemHandlerModifiable) teHandler;
for (int slot = 0; slot < Math.min(inv.getSlots(), handler.getSlots()); slot++) inv.setStackInSlot(slot, handler.getStackInSlot(slot));
}
use of com.simibubi.create.content.logistics.block.inventories.BottomlessItemHandler in project Create by Creators-of-Create.
the class MountedStorage method serialize.
public CompoundTag serialize() {
if (!valid)
return null;
CompoundTag tag = handler.serializeNBT();
if (handler instanceof BottomlessItemHandler) {
NBTHelper.putMarker(tag, "Bottomless");
tag.put("ProvidedStack", handler.getStackInSlot(0).serializeNBT());
}
return tag;
}
Aggregations