Interface BlockInventory

All Superinterfaces:
Container
All Known Subinterfaces:
BarrelInventory, ChestInventory, HopperInventory

public interface BlockInventory extends Container
The slots a block keeps in its block entity: those of a chest, of a barrel or of a hopper.

What is read is what the block holds, what is written is saved with its chunk and shows at once in the window of every player looking into it. Once the block is gone, the inventory reads as empty and ignores what is written to it.

A block still holding a loot table rolls it the first time its contents are read: when a player opens it, a comparator reads it, it is broken, or a plugin reads one of its slots.

Use it on the thread of the region owning the block.

Since:
0.1.0
See Also:
  • Method Details

    • world

      World world()
      Returns the world of the block.
      Returns:
      the world of the block
      Since:
      0.1.0
    • position

      BlockPosition position()
      Returns where the block is.
      Returns:
      where the block is
      Since:
      0.1.0
    • customName

      Optional<Component> customName()
      Returns the name shown at the top of the window, empty for the default one.
      Returns:
      the name shown at the top of the window, empty for the default one
      Since:
      0.1.0
    • setCustomName

      void setCustomName(@Nullable Component name)
      Names the block, as an item renamed in an anvil names the block it places.
      Parameters:
      name - the name shown at the top of the window, null for the default one
      Since:
      0.1.0
    • lootTable

      Optional<Key> lootTable()
      Returns the loot table the block has yet to roll, empty once rolled or for a block that never had one.

      Reading this never rolls the table.

      Returns:
      the loot table the block has yet to roll, empty once rolled or for a block that never had one
      Since:
      0.1.0
    • setLootTable

      void setLootTable(@Nullable Key table, long seed)
      Gives the block a loot table to roll the first time its contents are read, as the chests of dungeons have. What the block holds stays until then, the loot only filling its empty slots.
      Parameters:
      table - the loot table, such as minecraft:chests/simple_dungeon; null to forget the one it has
      seed - the seed of the roll, 0 for a random one
      Since:
      0.1.0