mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 23:47:38 +01:00
Creative Crate on contraptions
This commit is contained in:
parent
f58245158d
commit
d1c6352629
2 changed files with 57 additions and 13 deletions
|
@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement;
|
|||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.content.logistics.block.inventories.AdjustableCrateBlock;
|
||||
|
||||
import com.simibubi.create.content.logistics.block.inventories.CreativeCrateInventory;
|
||||
import net.minecraft.block.ChestBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
|
@ -85,14 +86,17 @@ public class MountedStorage {
|
|||
public MountedStorage(CompoundNBT nbt) {
|
||||
handler = new ItemStackHandler();
|
||||
working = nbt != null;
|
||||
if (working)
|
||||
if (working) {
|
||||
if (nbt.contains("isCreativeCrate") && nbt.getBoolean("isCreativeCrate"))
|
||||
handler = new CreativeCrateInventory();
|
||||
handler.deserializeNBT(nbt);
|
||||
}
|
||||
}
|
||||
|
||||
public void fill(TileEntity te) {
|
||||
IItemHandler teHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||
.orElse(dummyHandler);
|
||||
if (teHandler != dummyHandler && teHandler instanceof IItemHandlerModifiable) {
|
||||
if (teHandler != dummyHandler && teHandler instanceof IItemHandlerModifiable && !(teHandler instanceof CreativeCrateInventory)) {
|
||||
IItemHandlerModifiable inv = (IItemHandlerModifiable) teHandler;
|
||||
for (int slot = 0; slot < Math.min(inv.getSlots(), handler.getSlots()); slot++)
|
||||
inv.setStackInSlot(slot, handler.getStackInSlot(slot));
|
||||
|
@ -116,6 +120,8 @@ public class MountedStorage {
|
|||
return false;
|
||||
if (AllTileEntities.ADJUSTABLE_CRATE.is(te))
|
||||
return true;
|
||||
if (AllTileEntities.CREATIVE_CRATE.is(te))
|
||||
return true;
|
||||
if (te instanceof ShulkerBoxTileEntity)
|
||||
return true;
|
||||
if (te instanceof ChestTileEntity)
|
||||
|
|
|
@ -1,16 +1,30 @@
|
|||
package com.simibubi.create.content.logistics.block.inventories;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class CreativeCrateInventory implements IItemHandler {
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
private CreativeCrateTileEntity te;
|
||||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
public class CreativeCrateInventory extends ItemStackHandler {
|
||||
|
||||
public CreativeCrateInventory(CreativeCrateTileEntity te) {
|
||||
private ItemStack filter = null;
|
||||
private final CreativeCrateTileEntity te;
|
||||
|
||||
public CreativeCrateInventory(@Nullable CreativeCrateTileEntity te) {
|
||||
this.te = te;
|
||||
}
|
||||
|
||||
public CreativeCrateInventory() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return 2;
|
||||
|
@ -20,12 +34,13 @@ public class CreativeCrateInventory implements IItemHandler {
|
|||
public ItemStack getStackInSlot(int slot) {
|
||||
if (slot == 1)
|
||||
return ItemStack.EMPTY;
|
||||
ItemStack filter = te.filter.getFilter().copy();
|
||||
if (!filter.isEmpty())
|
||||
if (getFilter() == null)
|
||||
return ItemStack.EMPTY;
|
||||
if (!getFilter().isEmpty())
|
||||
filter.setCount(filter.getMaxStackSize());
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
return ItemStack.EMPTY;
|
||||
|
@ -33,10 +48,11 @@ public class CreativeCrateInventory implements IItemHandler {
|
|||
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
ItemStack filter = te.filter.getFilter().copy();
|
||||
if (!filter.isEmpty())
|
||||
filter.setCount(Math.min(filter.getMaxStackSize(), amount));
|
||||
return filter;
|
||||
if (getFilter() == null)
|
||||
return ItemStack.EMPTY;
|
||||
if (!getFilter().isEmpty())
|
||||
filter.setCount(Math.min(getFilter().getMaxStackSize(), amount));
|
||||
return getFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,4 +65,26 @@ public class CreativeCrateInventory implements IItemHandler {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT serializeNBT() {
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
nbt.putBoolean("isCreativeCrate", true);
|
||||
if (getFilter() != null)
|
||||
ItemStackHelper.saveAllItems(nbt, NonNullList.from(ItemStack.EMPTY, getFilter()));
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundNBT nbt) {
|
||||
NonNullList<ItemStack> filterList = NonNullList.withSize(1, ItemStack.EMPTY);
|
||||
ItemStackHelper.loadAllItems(nbt, filterList);
|
||||
filter = filterList.get(0);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getFilter() {
|
||||
if (te != null)
|
||||
filter = te.filter.getFilter();
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue