Package top.girlkisser.lazuli.api.block
Interface IInventoryBE<T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>>
- Type Parameters:
T- The item stack handler (inventory) that the implementing block entity uses.
- All Superinterfaces:
net.minecraft.world.Clearable,net.minecraft.world.Container,IBE,net.minecraft.world.inventory.StackedContentsCompatible,net.minecraft.world.WorldlyContainer
- All Known Implementing Classes:
AbstractCapacitorBE,AbstractInventoryBE,AbstractSingleTankAndInventoryBE
public interface IInventoryBE<T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>>
extends IBE, net.minecraft.world.WorldlyContainer, net.minecraft.world.inventory.StackedContentsCompatible
Provides a large number of helper functions for block entities with inventories.
-
Field Summary
Fields inherited from interface net.minecraft.world.Container
DEFAULT_DISTANCE_BUFFER -
Method Summary
Modifier and TypeMethodDescriptiondefault booleancanEjectSlot(int slot) Returns true if the item in the given slot can be ejected.default booleancanPlaceItemThroughFace(int index, net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Direction direction) Controls whether an item can be inserted into the given slot through the given face.default booleancanTakeItemThroughFace(int index, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction direction) Controls whether an item can be taken from the given slot through the given face.default voidClear all items from the inventory.static voidejectFrom(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, int slot, int maxCount) Ejects anItemStackinto the world or into a valid container from anIInventoryBE.static <T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>>
voidejectFrom(IInventoryBE<T> be, int maxAmount) Ejects anItemStackinto the world or into a valid container from anIInventoryBE.static <T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>>
voidejectFrom(IInventoryBE<T> be, int slot, int maxAmount) Ejects anItemStackinto the world or into a valid container from anIInventoryBE.static net.minecraft.world.item.ItemStackejectStack(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, net.minecraft.world.item.ItemStack toEject) Ejects anItemStackinto the world or into a valid container.default voidfillStackedContents(net.minecraft.world.entity.player.StackedContents contents) default intdefault net.minecraft.core.DirectiongetEjectDirection(net.minecraft.world.level.block.state.BlockState state) Get theDirectionto eject items at.default intReturns the index to the first non-emptyItemStackin the inventory or-1if no such item exists.Get the block entity's inventorydefault TgetInventory(net.minecraft.core.Direction side) Get the inventory on the given side, by default the inventory is non-sided, so this returns the main inventory.default net.minecraft.world.item.ItemStackgetItem(int slot) Get the item in the given slot index.default intgetRandomUsedSlot(net.minecraft.util.RandomSource random) Gets a random slot with at least 1 item in it.default intgetRandomUsedSlot(net.minecraft.util.RandomSource random, int minimumCount) Gets a random slot with at leastminimumCountitems in it, or a slot where the maximum stack size equals 1.default int[]getSlotsForFace(net.minecraft.core.Direction side) Gets the indexes to any slots accessible on the given side.default net.minecraft.world.item.ItemStackgiveItem(net.minecraft.world.item.ItemStack stack) Add an item to the inventory, returning the remainder.static net.minecraft.world.item.ItemStackinsertItemInto(net.neoforged.neoforge.items.IItemHandler itemHandler, net.minecraft.world.item.ItemStack stack) Inserts an item into the provided item handler.static net.minecraft.world.item.ItemStackinsertItemInto(net.neoforged.neoforge.items.IItemHandler itemHandler, net.minecraft.world.item.ItemStack stack, int startIndex, int endIndex) Inserts an item into the provided item handler.default booleanisEmpty()static booleanisFull(net.neoforged.neoforge.items.IItemHandler handler) Returns true if the given handler has no empty slots.default booleanGets whether the inventory has no empty slots.default net.minecraft.world.item.ItemStackremoveItem(int slot, int amount) Removes `amount` items from the given slot and returns the takenItemStack.default net.minecraft.world.item.ItemStackremoveItemNoUpdate(int slot) Removes the item from the given slot without updating the container.default voidsetItem(int slot, net.minecraft.world.item.ItemStack stack) Set theItemStackin the given slot.default booleanWhether the inventory should eject any items inside its inventory.default booleanstillValid(net.minecraft.world.entity.player.Player player) Returns true if the container is still valid for the player to interact with.Methods inherited from interface net.minecraft.world.Container
canPlaceItem, canTakeItem, countItem, getMaxStackSize, getMaxStackSize, hasAnyMatching, hasAnyOf, setChanged, startOpen, stopOpenMethods inherited from interface top.girlkisser.lazuli.api.block.IBE
getBlockPos, getBlockState, getLevel, setChanged
-
Method Details
-
getInventory
T getInventory()Get the block entity's inventory- Returns:
- The inventory.
-
getInventory
Get the inventory on the given side, by default the inventory is non-sided, so this returns the main inventory.- Parameters:
side- The side to access.- Returns:
- The inventory for that side.
-
getSlotsForFace
default int[] getSlotsForFace(net.minecraft.core.Direction side) Gets the indexes to any slots accessible on the given side.- Specified by:
getSlotsForFacein interfacenet.minecraft.world.WorldlyContainer- Parameters:
side- The side to access.- Returns:
- An array of slot indexes.
-
canPlaceItemThroughFace
default boolean canPlaceItemThroughFace(int index, net.minecraft.world.item.ItemStack stack, @Nullable @Nullable net.minecraft.core.Direction direction) Controls whether an item can be inserted into the given slot through the given face.- Specified by:
canPlaceItemThroughFacein interfacenet.minecraft.world.WorldlyContainer- Parameters:
index- The slot to check.stack- The item attempting to be inserted.direction- The direction the item is being inserted on.- Returns:
- `true` if the item can be inserted.
-
canTakeItemThroughFace
default boolean canTakeItemThroughFace(int index, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction direction) Controls whether an item can be taken from the given slot through the given face.- Specified by:
canTakeItemThroughFacein interfacenet.minecraft.world.WorldlyContainer- Parameters:
index- The slot to check.stack- The item attempting to be inserted.direction- The direction the item is being inserted on.- Returns:
- `true` if the item can be inserted.
-
fillStackedContents
default void fillStackedContents(net.minecraft.world.entity.player.StackedContents contents) - Specified by:
fillStackedContentsin interfacenet.minecraft.world.inventory.StackedContentsCompatible
-
isInventoryFull
default boolean isInventoryFull()Gets whether the inventory has no empty slots.- Returns:
- Whether the inventory has no empty slots or not.
-
getContainerSize
default int getContainerSize()- Specified by:
getContainerSizein interfacenet.minecraft.world.Container- Returns:
- The amount of slots in the inventory.
-
isEmpty
default boolean isEmpty()- Specified by:
isEmptyin interfacenet.minecraft.world.Container- Returns:
- `true` if all slots in the inventory are empty.
-
getItem
default net.minecraft.world.item.ItemStack getItem(int slot) Get the item in the given slot index.- Specified by:
getItemin interfacenet.minecraft.world.Container- Parameters:
slot- The index to access.- Returns:
- The item stack contained in the slot.
-
removeItem
default net.minecraft.world.item.ItemStack removeItem(int slot, int amount) Removes `amount` items from the given slot and returns the takenItemStack.- Specified by:
removeItemin interfacenet.minecraft.world.Container- Parameters:
slot- The slot to remove items from.amount- The amount to remove.- Returns:
- An
ItemStackcontaining the item removed and the amount removed.
-
removeItemNoUpdate
default net.minecraft.world.item.ItemStack removeItemNoUpdate(int slot) Removes the item from the given slot without updating the container.- Specified by:
removeItemNoUpdatein interfacenet.minecraft.world.Container- Parameters:
slot- The slot to remove the item from.- Returns:
- The item removed.
-
setItem
default void setItem(int slot, net.minecraft.world.item.ItemStack stack) Set theItemStackin the given slot.- Specified by:
setItemin interfacenet.minecraft.world.Container- Parameters:
slot- The slot index.stack- The stack.
-
stillValid
default boolean stillValid(net.minecraft.world.entity.player.Player player) Returns true if the container is still valid for the player to interact with. The default implementation checks if the player is within range of the block entity.
**This method will throw an exception if the level is null.**- Specified by:
stillValidin interfacenet.minecraft.world.Container- Parameters:
player- The player to check.- Returns:
- `true` if the player is still able to access the inventory.
-
clearContent
default void clearContent()Clear all items from the inventory.- Specified by:
clearContentin interfacenet.minecraft.world.Clearable
-
getFirstStackIndex
default int getFirstStackIndex()Returns the index to the first non-emptyItemStackin the inventory or-1if no such item exists.- Returns:
- The index.
-
giveItem
default net.minecraft.world.item.ItemStack giveItem(net.minecraft.world.item.ItemStack stack) Add an item to the inventory, returning the remainder. The provided stack is not mutated.- Parameters:
stack- The stack to insert.- Returns:
- The remainder, if the stack could not be fully inserted.
-
shouldEjectItems
default boolean shouldEjectItems()Whether the inventory should eject any items inside its inventory.- Returns:
- Whether the inventory should eject any items inside its inventory.
-
canEjectSlot
default boolean canEjectSlot(int slot) Returns true if the item in the given slot can be ejected.- Parameters:
slot- The slot to check.- Returns:
- Whether the item in the slot can be ejected.
-
getEjectDirection
default net.minecraft.core.Direction getEjectDirection(net.minecraft.world.level.block.state.BlockState state) Get theDirectionto eject items at.- Parameters:
state- TheBlockStateof the implementing block entity.- Returns:
- The direction to eject items at.
-
getRandomUsedSlot
default int getRandomUsedSlot(net.minecraft.util.RandomSource random) Gets a random slot with at least 1 item in it.- Parameters:
random- Random source to use.- Returns:
- The index to the random slot.
-
getRandomUsedSlot
default int getRandomUsedSlot(net.minecraft.util.RandomSource random, int minimumCount) Gets a random slot with at leastminimumCountitems in it, or a slot where the maximum stack size equals 1.- Parameters:
random- Random source to use.minimumCount- The minimum count for a stack to be picked.- Returns:
- The index to the random slot. Returns to -1 if no slots match.
-
ejectStack
static net.minecraft.world.item.ItemStack ejectStack(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, net.minecraft.world.item.ItemStack toEject) Ejects anItemStackinto the world or into a valid container. This method does not care what the ejecting block is.- Parameters:
level- The level.pos- The position of the block ejecting the stack.direction- The direction to eject in.toEject- The stack to eject.- Returns:
- If the stack could not be ejected (i.e, there is a block in the way or the container was full), this is the remainder.
-
ejectFrom
static void ejectFrom(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, int slot, int maxCount) Ejects anItemStackinto the world or into a valid container from anIInventoryBE.- Parameters:
level- The level.pos- The position of the block ejecting the stack.direction- The direction to eject in.slot- The slot to eject from.maxCount- The maximum amount of items to eject.
-
ejectFrom
static <T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>> void ejectFrom(IInventoryBE<T> be, int maxAmount) Ejects anItemStackinto the world or into a valid container from anIInventoryBE.- Type Parameters:
T- The container type of the block entity.- Parameters:
be- The block entity to eject an item from.maxAmount- The maximum amount of items to eject.
-
ejectFrom
static <T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>> void ejectFrom(IInventoryBE<T> be, int slot, int maxAmount) Ejects anItemStackinto the world or into a valid container from anIInventoryBE.- Type Parameters:
T- The container type of the block entity.- Parameters:
be- The block entity to eject an item from.slot- The slot to eject from.maxAmount- The maximum amount of items to eject.
-
insertItemInto
static net.minecraft.world.item.ItemStack insertItemInto(net.neoforged.neoforge.items.IItemHandler itemHandler, net.minecraft.world.item.ItemStack stack, int startIndex, int endIndex) Inserts an item into the provided item handler. UsestartIndexandendIndexto only insert into a specific range of slots.- Parameters:
itemHandler- The item handler to insert into.stack- The stack to insert.startIndex- The first index to check (inclusive).endIndex- The last index to check (exclusive).- Returns:
- The remainder item stack if not all items could be inserted.
-
insertItemInto
static net.minecraft.world.item.ItemStack insertItemInto(net.neoforged.neoforge.items.IItemHandler itemHandler, net.minecraft.world.item.ItemStack stack) Inserts an item into the provided item handler. UsestartIndexandendIndexto only insert into a specific range of slots.- Parameters:
itemHandler- The item handler to insert into.stack- The stack to insert.- Returns:
- The remainder item stack if not all items could be inserted.
-
isFull
static boolean isFull(net.neoforged.neoforge.items.IItemHandler handler) Returns true if the given handler has no empty slots.- Parameters:
handler- The handler to check.- Returns:
- Whether the provided inventory is full.
-