public abstract class InventoryHandler extends Syncable implements net.minecraftforge.items.IItemHandlerModifiable
Nucleus - Java is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License: http://creativecommons.org/licenses/by-nc-sa/4.0/
Modifier and Type | Field and Description |
---|---|
net.minecraft.util.NonNullList<net.minecraft.item.ItemStack> |
inventoryContents |
Constructor and Description |
---|
InventoryHandler(net.minecraft.tileentity.TileEntityType<?> tileEntityTypeIn) |
Modifier and Type | Method and Description |
---|---|
InventoryHandler |
addCallback(IInventoryCallback iInventoryCallback)
Add a callback to this inventory
|
void |
copyFrom(net.minecraftforge.items.IItemHandler inventory)
Used to copy from an existing inventory
|
net.minecraft.item.ItemStack |
extractItem(int slot,
int amount,
boolean simulate)
Extracts an ItemStack from the given slot.
|
<T> net.minecraftforge.common.util.LazyOptional<T> |
getCapability(net.minecraftforge.common.capabilities.Capability<T> capability,
net.minecraft.util.Direction facing)
Used to access the capability
|
protected abstract int |
getInventorySize()
The initial size of the inventory
|
int |
getSlotLimit(int slot)
Retrieves the maximum stack size allowed to exist in the given slot.
|
int |
getSlots()
Returns the number of slots available
|
net.minecraft.item.ItemStack |
getStackInSlot(int slot)
Returns the ItemStack in a given slot.
|
net.minecraft.item.ItemStack |
insertItem(int slot,
net.minecraft.item.ItemStack stack,
boolean simulate)
Inserts an ItemStack into the given slot and return the remainder.
|
protected abstract boolean |
isItemValidForSlot(int index,
net.minecraft.item.ItemStack stack)
Used to define if an item is valid for a slot
|
protected boolean |
isValidSlot(int slot)
Makes sure this slot is within our range
|
protected void |
onInventoryChanged(int slot)
Called when the inventory has a change
|
void |
read(net.minecraft.nbt.CompoundNBT compound)
Used to read the inventory from an NBT tag compound
|
void |
setStackInSlot(int slot,
net.minecraft.item.ItemStack stack)
Overrides the stack in the given slot.
|
net.minecraft.nbt.CompoundNBT |
write(net.minecraft.nbt.CompoundNBT compound)
Used to save the inventory to an NBT tag
|
getVariable, sendValueToClient, sendValueToServer, setVariable, updateClientValueFromServer
getUpdatePacket, getUpdateTag, markForUpdate, onClientTick, onDataPacket, onServerTick, tick
addInfoToCrashReport, create, getBlockState, getDistanceSq, getMaxRenderDistanceSquared, getPos, getTileData, getType, getWorld, hasWorld, isRemoved, markDirty, mirror, onlyOpsCanSetNbt, receiveClientEvent, remove, rotate, setPos, setWorld, updateContainingBlockInfo, validate, warnInvalidBlock
areCapsCompatible, areCapsCompatible, deserializeCaps, gatherCapabilities, gatherCapabilities, getCapabilities, invalidateCaps, reviveCaps, serializeCaps
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public net.minecraft.util.NonNullList<net.minecraft.item.ItemStack> inventoryContents
public InventoryHandler(net.minecraft.tileentity.TileEntityType<?> tileEntityTypeIn)
protected abstract int getInventorySize()
protected abstract boolean isItemValidForSlot(int index, net.minecraft.item.ItemStack stack)
index
- The slot idstack
- The stack to checkpublic InventoryHandler addCallback(IInventoryCallback iInventoryCallback)
iInventoryCallback
- The callback you wish to addprotected void onInventoryChanged(int slot)
slot
- The slot that changedpublic void copyFrom(net.minecraftforge.items.IItemHandler inventory)
inventory
- The inventory to copy fromprotected boolean isValidSlot(int slot)
slot
- Which slotpublic net.minecraft.nbt.CompoundNBT write(net.minecraft.nbt.CompoundNBT compound)
write
in class net.minecraft.tileentity.TileEntity
compound
- The tag to save topublic void read(net.minecraft.nbt.CompoundNBT compound)
read
in class net.minecraft.tileentity.TileEntity
compound
- The tag to read frompublic <T> net.minecraftforge.common.util.LazyOptional<T> getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.Direction facing)
getCapability
in interface net.minecraftforge.common.capabilities.ICapabilityProvider
getCapability
in class net.minecraftforge.common.capabilities.CapabilityProvider<net.minecraft.tileentity.TileEntity>
T
- The object to casecapability
- The capabilityfacing
- Which facepublic void setStackInSlot(int slot, net.minecraft.item.ItemStack stack)
setStackInSlot
in interface net.minecraftforge.items.IItemHandlerModifiable
slot
- Slot to modifystack
- ItemStack to set slot to (may be null)java.lang.RuntimeException
- if the handler is called in a way that the handler
was not expecting.public int getSlots()
getSlots
in interface net.minecraftforge.items.IItemHandler
@Nonnull public net.minecraft.item.ItemStack getStackInSlot(int slot)
The result's stack size may be greater than the itemstacks max size.
If the result is null, then the slot is empty. If the result is not null but the stack size is zero, then it represents an empty slot that will only accept* a specific itemstack.
IMPORTANT: This ItemStack MUST NOT be modified. This method is not for altering an inventories contents. Any implementers who are able to detect modification through this method should throw an exception. p SERIOUSLY: DO NOT MODIFY THE RETURNED ITEMSTACK
getStackInSlot
in interface net.minecraftforge.items.IItemHandler
slot
- Slot to query@Nonnull public net.minecraft.item.ItemStack insertItem(int slot, net.minecraft.item.ItemStack stack, boolean simulate)
insertItem
in interface net.minecraftforge.items.IItemHandler
slot
- Slot to insert into.stack
- ItemStack to insert.simulate
- If true, the insertion is only simulated@Nonnull public net.minecraft.item.ItemStack extractItem(int slot, int amount, boolean simulate)
extractItem
in interface net.minecraftforge.items.IItemHandler
slot
- Slot to extract from.amount
- Amount to extract (may be greater than the current stacks max limit)simulate
- If true, the extraction is only simulatedpublic int getSlotLimit(int slot)
getSlotLimit
in interface net.minecraftforge.items.IItemHandler
slot
- Slot to query.