Search in sources :

Example 1 with ItemVaultTileEntity

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;
}
Also used : FluidTankTileEntity(com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity) ItemVaultTileEntity(com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity) CompoundTag(net.minecraft.nbt.CompoundTag) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Nullable(javax.annotation.Nullable)

Example 2 with ItemVaultTileEntity

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);
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) ShulkerBoxBlockEntity(net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity) ChestBlockEntity(net.minecraft.world.level.block.entity.ChestBlockEntity) IItemHandler(net.minecraftforge.items.IItemHandler) ItemVaultTileEntity(com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity) BarrelBlockEntity(net.minecraft.world.level.block.entity.BarrelBlockEntity) MechanicalCrafterTileEntity(com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterTileEntity) ProcessingInventory(com.simibubi.create.content.contraptions.processing.ProcessingInventory)

Example 3 with ItemVaultTileEntity

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;
    }
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) ChestBlockEntity(net.minecraft.world.level.block.entity.ChestBlockEntity) IItemHandler(net.minecraftforge.items.IItemHandler) ItemVaultTileEntity(com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity) ItemStack(net.minecraft.world.item.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 4 with ItemVaultTileEntity

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));
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) ChestBlockEntity(net.minecraft.world.level.block.entity.ChestBlockEntity) IItemHandler(net.minecraftforge.items.IItemHandler) ItemVaultTileEntity(com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity) BottomlessItemHandler(com.simibubi.create.content.logistics.block.inventories.BottomlessItemHandler) ItemStack(net.minecraft.world.item.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

ItemVaultTileEntity (com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity)4 CompoundTag (net.minecraft.nbt.CompoundTag)3 ChestBlockEntity (net.minecraft.world.level.block.entity.ChestBlockEntity)3 IItemHandler (net.minecraftforge.items.IItemHandler)3 ItemStack (net.minecraft.world.item.ItemStack)2 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)2 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)2 MechanicalCrafterTileEntity (com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterTileEntity)1 FluidTankTileEntity (com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity)1 ProcessingInventory (com.simibubi.create.content.contraptions.processing.ProcessingInventory)1 BottomlessItemHandler (com.simibubi.create.content.logistics.block.inventories.BottomlessItemHandler)1 Nullable (javax.annotation.Nullable)1 BarrelBlockEntity (net.minecraft.world.level.block.entity.BarrelBlockEntity)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 ShulkerBoxBlockEntity (net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity)1