mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-11 04:22:00 +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.AllTileEntities;
|
||||||
import com.simibubi.create.content.logistics.block.inventories.AdjustableCrateBlock;
|
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.block.ChestBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
@ -85,14 +86,17 @@ public class MountedStorage {
|
||||||
public MountedStorage(CompoundNBT nbt) {
|
public MountedStorage(CompoundNBT nbt) {
|
||||||
handler = new ItemStackHandler();
|
handler = new ItemStackHandler();
|
||||||
working = nbt != null;
|
working = nbt != null;
|
||||||
if (working)
|
if (working) {
|
||||||
|
if (nbt.contains("isCreativeCrate") && nbt.getBoolean("isCreativeCrate"))
|
||||||
|
handler = new CreativeCrateInventory();
|
||||||
handler.deserializeNBT(nbt);
|
handler.deserializeNBT(nbt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fill(TileEntity te) {
|
public void fill(TileEntity te) {
|
||||||
IItemHandler teHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
IItemHandler teHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
||||||
.orElse(dummyHandler);
|
.orElse(dummyHandler);
|
||||||
if (teHandler != dummyHandler && teHandler instanceof IItemHandlerModifiable) {
|
if (teHandler != dummyHandler && teHandler instanceof IItemHandlerModifiable && !(teHandler instanceof CreativeCrateInventory)) {
|
||||||
IItemHandlerModifiable inv = (IItemHandlerModifiable) teHandler;
|
IItemHandlerModifiable inv = (IItemHandlerModifiable) teHandler;
|
||||||
for (int slot = 0; slot < Math.min(inv.getSlots(), handler.getSlots()); slot++)
|
for (int slot = 0; slot < Math.min(inv.getSlots(), handler.getSlots()); slot++)
|
||||||
inv.setStackInSlot(slot, handler.getStackInSlot(slot));
|
inv.setStackInSlot(slot, handler.getStackInSlot(slot));
|
||||||
|
@ -116,6 +120,8 @@ public class MountedStorage {
|
||||||
return false;
|
return false;
|
||||||
if (AllTileEntities.ADJUSTABLE_CRATE.is(te))
|
if (AllTileEntities.ADJUSTABLE_CRATE.is(te))
|
||||||
return true;
|
return true;
|
||||||
|
if (AllTileEntities.CREATIVE_CRATE.is(te))
|
||||||
|
return true;
|
||||||
if (te instanceof ShulkerBoxTileEntity)
|
if (te instanceof ShulkerBoxTileEntity)
|
||||||
return true;
|
return true;
|
||||||
if (te instanceof ChestTileEntity)
|
if (te instanceof ChestTileEntity)
|
||||||
|
|
|
@ -1,16 +1,30 @@
|
||||||
package com.simibubi.create.content.logistics.block.inventories;
|
package com.simibubi.create.content.logistics.block.inventories;
|
||||||
|
|
||||||
|
import mcp.MethodsReturnNonnullByDefault;
|
||||||
|
import net.minecraft.inventory.ItemStackHelper;
|
||||||
import net.minecraft.item.ItemStack;
|
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;
|
this.te = te;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CreativeCrateInventory() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSlots() {
|
public int getSlots() {
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -20,12 +34,13 @@ public class CreativeCrateInventory implements IItemHandler {
|
||||||
public ItemStack getStackInSlot(int slot) {
|
public ItemStack getStackInSlot(int slot) {
|
||||||
if (slot == 1)
|
if (slot == 1)
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
ItemStack filter = te.filter.getFilter().copy();
|
if (getFilter() == null)
|
||||||
if (!filter.isEmpty())
|
return ItemStack.EMPTY;
|
||||||
|
if (!getFilter().isEmpty())
|
||||||
filter.setCount(filter.getMaxStackSize());
|
filter.setCount(filter.getMaxStackSize());
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
|
@ -33,10 +48,11 @@ public class CreativeCrateInventory implements IItemHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||||
ItemStack filter = te.filter.getFilter().copy();
|
if (getFilter() == null)
|
||||||
if (!filter.isEmpty())
|
return ItemStack.EMPTY;
|
||||||
filter.setCount(Math.min(filter.getMaxStackSize(), amount));
|
if (!getFilter().isEmpty())
|
||||||
return filter;
|
filter.setCount(Math.min(getFilter().getMaxStackSize(), amount));
|
||||||
|
return getFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,4 +65,26 @@ public class CreativeCrateInventory implements IItemHandler {
|
||||||
return true;
|
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