Class InventoryBlockEntity<T extends net.minecraft.world.Container>
- Type Parameters:
T- The type of inventory held by the BlockEntity.
- All Implemented Interfaces:
net.fabricmc.fabric.api.blockview.v2.RenderDataBlockEntity,net.fabricmc.fabric.api.screenhandler.v1.FabricScreenHandlerFactory,net.minecraft.world.Clearable,net.minecraft.world.Container,net.minecraft.world.inventory.MenuConstructor,net.minecraft.world.MenuProvider,net.minecraft.world.Nameable
- Direct Known Subclasses:
WorldlyInventoryBlockEntity
-
Field Summary
Fields inherited from class net.minecraft.world.level.block.entity.BlockEntity
level, remove, worldPositionFields inherited from interface net.minecraft.world.Container
DEFAULT_DISTANCE_LIMIT, LARGE_MAX_STACK_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionInventoryBlockEntity(net.minecraft.world.level.block.entity.BlockEntityType<?> type, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state) -
Method Summary
Modifier and TypeMethodDescriptionfinal booleancanPlaceItem(int slot, net.minecraft.world.item.ItemStack stack) final voidfinal intcountItem(net.minecraft.world.item.Item toCount) abstract TCreates a new instance of the inventory held by the block entity.protected net.minecraft.world.inventory.AbstractContainerMenucreateMenu(int i, net.minecraft.world.entity.player.Inventory inventory) voiddropContents(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos) Drops the contents of the held inventory into the world.final intfinal TGets the inventory currently held by the block entity.final net.minecraft.world.item.ItemStackgetItem(int slot) final intfinal booleanfinal booleanisEmpty()voidload(net.minecraft.nbt.CompoundTag tag) voidNotifies the world that the tile has been updated and requires re-saving.voidreadInventory(net.minecraft.nbt.CompoundTag tag) Update the state of the held inventory using state data read from NBT.final net.minecraft.world.item.ItemStackremoveItem(int slot, int amount) final net.minecraft.world.item.ItemStackremoveItemNoUpdate(int slot) voidsaveAdditional(net.minecraft.nbt.CompoundTag tag) net.minecraft.nbt.CompoundTagStores the state of the currently held inventory in an NBT tag.final voidfinal voidsetItem(int slot, net.minecraft.world.item.ItemStack stack) final voidstartOpen(net.minecraft.world.entity.player.Player player) final booleanstillValid(net.minecraft.world.entity.player.Player player) final voidstopOpen(net.minecraft.world.entity.player.Player player) Methods inherited from class net.minecraft.world.level.block.entity.BaseContainerBlockEntity
canOpen, canUnlock, createMenu, getCustomName, getDefaultName, getDisplayName, getName, setCustomNameMethods inherited from class net.minecraft.world.level.block.entity.BlockEntity
addEntityType, clearRemoved, fillCrashReportCategory, getBlockPos, getBlockState, getLevel, getPosFromTag, getType, getUpdatePacket, getUpdateTag, hasLevel, isRemoved, loadStatic, onlyOpCanSetNbt, saveToItem, saveWithFullMetadata, saveWithId, saveWithoutMetadata, setBlockState, setChanged, setLevel, setRemoved, triggerEventMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.world.Container
canTakeItem, hasAnyMatchingMethods inherited from interface net.fabricmc.fabric.api.screenhandler.v1.FabricScreenHandlerFactory
shouldCloseCurrentScreenMethods inherited from interface net.minecraft.world.Nameable
hasCustomNameMethods inherited from interface net.fabricmc.fabric.api.blockview.v2.RenderDataBlockEntity
getRenderData
-
Constructor Details
-
InventoryBlockEntity
public InventoryBlockEntity(net.minecraft.world.level.block.entity.BlockEntityType<?> type, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
-
-
Method Details
-
getInventory
Gets the inventory currently held by the block entity.- Returns:
- The inventory currently held by the block entity.
-
createInventory
Creates a new instance of the inventory held by the block entity. The resulting inventory should be effectively a clean slate that represents the default state for the inventory. Persisting the state of the inventory is managed byload(net.minecraft.nbt.CompoundTag)andsaveAdditional(net.minecraft.nbt.CompoundTag).This method should only be invoked once per tile entity instance. The resulting value is stored with
inventory.- Returns:
- A new inventory to be held by the block entity.
-
dropContents
public void dropContents(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos) Drops the contents of the held inventory into the world. This is used in situations where the block has been removed from the world and allows the inventory to drop the contents before they are destroyed.The default behaviour will drop the entire contents of the inventory onto the ground.
- Parameters:
state- The state of the block.world- The level the block is in.pos- The position of the block.
-
readInventory
public void readInventory(net.minecraft.nbt.CompoundTag tag) Update the state of the held inventory using state data read from NBT.Implementations of this method must be capable of reading from the result of
saveInventory().The inventory instance should always be accessed using
getInventory(). While each instance of the block entity will have their own unique instance of the inventory, that instance will be reused across multiple read and write cycles. You must ensure that the entire state of the inventory is properly reinitialized on read.- Parameters:
tag- A tag containing the inventory state data.
-
saveInventory
public net.minecraft.nbt.CompoundTag saveInventory()Stores the state of the currently held inventory in an NBT tag.Implementations of this method must be capable of writing a tag that can be read by
readInventory(CompoundTag).The inventory instance should always be accessed using
getInventory().- Returns:
- A tag holding the state of the current inventory.
-
markDirty
public void markDirty()Notifies the world that the tile has been updated and requires re-saving. This has the same behaviour asBlockEntity.setChanged()but avoids invokingContainer.setChanged()unintentionally. -
load
public void load(net.minecraft.nbt.CompoundTag tag) - Overrides:
loadin classnet.minecraft.world.level.block.entity.BaseContainerBlockEntity
-
saveAdditional
public void saveAdditional(net.minecraft.nbt.CompoundTag tag) - Overrides:
saveAdditionalin classnet.minecraft.world.level.block.entity.BaseContainerBlockEntity
-
createMenu
protected net.minecraft.world.inventory.AbstractContainerMenu createMenu(int i, net.minecraft.world.entity.player.Inventory inventory) - Specified by:
createMenuin classnet.minecraft.world.level.block.entity.BaseContainerBlockEntity
-
getContainerSize
public final int getContainerSize() -
isEmpty
public final boolean isEmpty() -
getItem
public final net.minecraft.world.item.ItemStack getItem(int slot) -
removeItem
public final net.minecraft.world.item.ItemStack removeItem(int slot, int amount) -
removeItemNoUpdate
public final net.minecraft.world.item.ItemStack removeItemNoUpdate(int slot) -
setItem
public final void setItem(int slot, net.minecraft.world.item.ItemStack stack) -
getMaxStackSize
public final int getMaxStackSize() -
setChanged
public final void setChanged()- Specified by:
setChangedin interfacenet.minecraft.world.Container- Overrides:
setChangedin classnet.minecraft.world.level.block.entity.BlockEntity
-
stillValid
public final boolean stillValid(net.minecraft.world.entity.player.Player player) -
startOpen
public final void startOpen(net.minecraft.world.entity.player.Player player) -
stopOpen
public final void stopOpen(net.minecraft.world.entity.player.Player player) -
canPlaceItem
public final boolean canPlaceItem(int slot, net.minecraft.world.item.ItemStack stack) -
countItem
public final int countItem(net.minecraft.world.item.Item toCount) -
hasAnyOf
-
clearContent
public final void clearContent()
-