Search in sources :

Example 1 with BottomlessItemHandler

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;
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) BottomlessItemHandler(com.simibubi.create.content.logistics.block.inventories.BottomlessItemHandler) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with BottomlessItemHandler

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));
}
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)

Example 3 with BottomlessItemHandler

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;
}
Also used : BottomlessItemHandler(com.simibubi.create.content.logistics.block.inventories.BottomlessItemHandler) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

BottomlessItemHandler (com.simibubi.create.content.logistics.block.inventories.BottomlessItemHandler)3 CompoundTag (net.minecraft.nbt.CompoundTag)2 ItemStack (net.minecraft.world.item.ItemStack)2 ItemVaultTileEntity (com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity)1 ChestBlockEntity (net.minecraft.world.level.block.entity.ChestBlockEntity)1 IItemHandler (net.minecraftforge.items.IItemHandler)1 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)1 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)1