public abstract class InventoryHandlerItem
extends java.lang.Object
implements net.minecraftforge.items.IItemHandlerModifiable, net.minecraftforge.common.capabilities.ICapabilityProvider
Nucleus 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 |
---|
InventoryHandlerItem(net.minecraft.item.ItemStack stack,
net.minecraft.nbt.CompoundNBT compound)
Creates a handler with given stack
|
Modifier and Type | Method and Description |
---|---|
InventoryHandlerItem |
addCallback(IInventoryCallback iInventoryCallback)
Add a callback to this inventory
|
protected void |
checkStackTag()
Makes sure we always have a valid tag
|
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)
Retrieves the handler for the capability requested on the specific side.
|
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 |
readFromNBT(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 |
writeToNBT(net.minecraft.nbt.CompoundNBT compound)
Used to save the inventory to an NBT tag
|
public net.minecraft.util.NonNullList<net.minecraft.item.ItemStack> inventoryContents
public InventoryHandlerItem(net.minecraft.item.ItemStack stack, net.minecraft.nbt.CompoundNBT compound)
stack
- Stack to attach toprotected abstract int getInventorySize()
protected abstract boolean isItemValidForSlot(int index, net.minecraft.item.ItemStack stack)
index
- The slot idstack
- The stack to checkpublic InventoryHandlerItem 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 slotprotected void checkStackTag()
public net.minecraft.nbt.CompoundNBT writeToNBT(net.minecraft.nbt.CompoundNBT compound)
compound
- The tag to save topublic void readFromNBT(net.minecraft.nbt.CompoundNBT compound)
compound
- The tag to read frompublic 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. 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.@Nullable public <T> net.minecraftforge.common.util.LazyOptional<T> getCapability(@Nonnull net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.Direction facing)
getCapability
in interface net.minecraftforge.common.capabilities.ICapabilityProvider
capability
- The capability to checkfacing
- The Side to check from:
CAN BE NULL. Null is defined to represent 'internal' or 'self'