Class InventoryBlockEntity<T extends net.minecraft.world.Container>

java.lang.Object
net.minecraft.world.level.block.entity.BlockEntity
net.minecraft.world.level.block.entity.BaseContainerBlockEntity
net.darkhax.bookshelf.api.block.entity.InventoryBlockEntity<T>
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

public abstract class InventoryBlockEntity<T extends net.minecraft.world.Container> extends net.minecraft.world.level.block.entity.BaseContainerBlockEntity
An implementation of BlockEntity that holds an inventory. The inventory is persisted and synced to the client.
  • Field Summary

    Fields inherited from class net.minecraft.world.level.block.entity.BlockEntity

    level, remove, worldPosition

    Fields inherited from interface net.minecraft.world.Container

    DEFAULT_DISTANCE_LIMIT, LARGE_MAX_STACK_SIZE
  • Constructor Summary

    Constructors
    Constructor
    Description
    InventoryBlockEntity(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 Type
    Method
    Description
    final boolean
    canPlaceItem(int slot, net.minecraft.world.item.ItemStack stack)
     
    final void
     
    final int
    countItem(net.minecraft.world.item.Item toCount)
     
    abstract T
    Creates a new instance of the inventory held by the block entity.
    protected net.minecraft.world.inventory.AbstractContainerMenu
    createMenu(int i, net.minecraft.world.entity.player.Inventory inventory)
     
    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.
    final int
     
    final T
    Gets the inventory currently held by the block entity.
    final net.minecraft.world.item.ItemStack
    getItem(int slot)
     
    final int
     
    final boolean
    hasAnyOf(Set<net.minecraft.world.item.Item> toFind)
     
    final boolean
     
    void
    load(net.minecraft.nbt.CompoundTag tag)
     
    void
    Notifies the world that the tile has been updated and requires re-saving.
    void
    readInventory(net.minecraft.nbt.CompoundTag tag)
    Update the state of the held inventory using state data read from NBT.
    final net.minecraft.world.item.ItemStack
    removeItem(int slot, int amount)
     
    final net.minecraft.world.item.ItemStack
     
    void
    saveAdditional(net.minecraft.nbt.CompoundTag tag)
     
    net.minecraft.nbt.CompoundTag
    Stores the state of the currently held inventory in an NBT tag.
    final void
     
    final void
    setItem(int slot, net.minecraft.world.item.ItemStack stack)
     
    final void
    startOpen(net.minecraft.world.entity.player.Player player)
     
    final boolean
    stillValid(net.minecraft.world.entity.player.Player player)
     
    final void
    stopOpen(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, setCustomName

    Methods 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, triggerEvent

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.minecraft.world.Container

    canTakeItem, hasAnyMatching

    Methods inherited from interface net.fabricmc.fabric.api.screenhandler.v1.FabricScreenHandlerFactory

    shouldCloseCurrentScreen

    Methods inherited from interface net.minecraft.world.Nameable

    hasCustomName

    Methods 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

      public final T getInventory()
      Gets the inventory currently held by the block entity.
      Returns:
      The inventory currently held by the block entity.
    • createInventory

      public abstract T 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 by load(net.minecraft.nbt.CompoundTag) and saveAdditional(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 as BlockEntity.setChanged() but avoids invoking Container.setChanged() unintentionally.
    • load

      public void load(net.minecraft.nbt.CompoundTag tag)
      Overrides:
      load in class net.minecraft.world.level.block.entity.BaseContainerBlockEntity
    • saveAdditional

      public void saveAdditional(net.minecraft.nbt.CompoundTag tag)
      Overrides:
      saveAdditional in class net.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:
      createMenu in class net.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:
      setChanged in interface net.minecraft.world.Container
      Overrides:
      setChanged in class net.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

      public final boolean hasAnyOf(Set<net.minecraft.world.item.Item> toFind)
    • clearContent

      public final void clearContent()