use of com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity in project Create by Creators-of-Create.
the class Contraption method getTileEntityNBT.
@Nullable
protected CompoundTag getTileEntityNBT(Level world, BlockPos pos) {
BlockEntity tileentity = world.getBlockEntity(pos);
if (tileentity == null)
return null;
CompoundTag nbt = tileentity.saveWithFullMetadata();
nbt.remove("x");
nbt.remove("y");
nbt.remove("z");
if ((tileentity instanceof FluidTankTileEntity || tileentity instanceof ItemVaultTileEntity) && nbt.contains("Controller"))
nbt.put("Controller", NbtUtils.writeBlockPos(toLocalPos(NbtUtils.readBlockPos(nbt.getCompound("Controller")))));
return nbt;
}
use of com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity in project Create by Creators-of-Create.
the class MountedStorage method canUseAsStorage.
public static boolean canUseAsStorage(BlockEntity te) {
if (te == null)
return false;
if (te instanceof MechanicalCrafterTileEntity)
return false;
if (AllTileEntities.CREATIVE_CRATE.is(te))
return true;
if (te instanceof ShulkerBoxBlockEntity)
return true;
if (te instanceof ChestBlockEntity)
return true;
if (te instanceof BarrelBlockEntity)
return true;
if (te instanceof ItemVaultTileEntity)
return true;
LazyOptional<IItemHandler> capability = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
IItemHandler handler = capability.orElse(null);
return handler instanceof ItemStackHandler && !(handler instanceof ProcessingInventory);
}
use of com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity in project Create by Creators-of-Create.
the class MountedStorage method removeStorageFromWorld.
public void removeStorageFromWorld() {
valid = false;
if (te == null)
return;
if (te instanceof ChestBlockEntity) {
CompoundTag tag = te.saveWithFullMetadata();
if (tag.contains("LootTable", 8))
return;
handler = new ItemStackHandler(((ChestBlockEntity) te).getContainerSize());
NonNullList<ItemStack> items = NonNullList.withSize(handler.getSlots(), ItemStack.EMPTY);
ContainerHelper.loadAllItems(tag, items);
for (int i = 0; i < items.size(); i++) handler.setStackInSlot(i, items.get(i));
valid = true;
return;
}
IItemHandler teHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(dummyHandler);
if (teHandler == dummyHandler)
return;
// multiblock vaults need to provide individual invs
if (te instanceof ItemVaultTileEntity) {
handler = ((ItemVaultTileEntity) te).getInventoryOfBlock();
valid = true;
return;
}
// te uses ItemStackHandler
if (teHandler instanceof ItemStackHandler) {
handler = (ItemStackHandler) teHandler;
valid = true;
return;
}
// serialization not accessible -> fill into a serializable handler
if (teHandler instanceof IItemHandlerModifiable) {
IItemHandlerModifiable inv = (IItemHandlerModifiable) teHandler;
handler = new ItemStackHandler(teHandler.getSlots());
for (int slot = 0; slot < handler.getSlots(); slot++) {
handler.setStackInSlot(slot, inv.getStackInSlot(slot));
inv.setStackInSlot(slot, ItemStack.EMPTY);
}
valid = true;
return;
}
}
use of com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity 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));
}
Aggregations