Skip to main content
Version: Minecraft 26.2

dev.polymodloader.api.content.block.entity

Generated

This page is generated from the source's Javadoc by ./gradlew apiReference. Do not edit it; fix the source comment and generate it again.

TypeKindDescription
BlockEntityDefinitionrecordGives a mod block per-position state that is saved with the world: a DataTree, an optional inventory, and an optional server tick.
BlockEntityDefinition.BuilderclassBuilds a BlockEntityDefinition.
BlockEntityTickerfunctional interfaceServer-side code run every tick for each loaded block entity.
BlockEntityViewinterfaceA mod block entity.
MenuLayoutrecordThe menu of a block entity with its own slot positions, like a furnace.
MenuLayout.BuilderclassBuilds a MenuLayout.
MenuLayout.MenuSlotrecordOne slot.
MenuLayout.ProgressBarrecordA bar filled in proportion to data().getInt(valueKey) / data().getInt(maxKey) of the block entity.
MenuLayout.ProgressStyleenumLooks of a ProgressBar, taken from the game's furnace.

BlockEntityDefinition​

record · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier

public record BlockEntityDefinition(int inventoryRows, String menuTitle, Optional<BlockEntityTicker> ticker, boolean syncToClients, Optional<MenuLayout> menu, int dataVersion, Optional<DataMigration> migration)

Gives a mod block per-position state that is saved with the world: a DataTree, an optional inventory, and an optional server tick.

ComponentTypeDescription
inventoryRowsintrows of 9 slots (1–6), or 0 for no inventory. Blocks with an inventory open the game's chest-style menu when used (unless the block behaviour returns something other than PASS), drop their contents when broken, and work with hoppers.
menuTitleStringtranslation key or plain text shown above the menu
tickerOptional<BlockEntityTicker>server-side code run every tick, or empty
syncToClientsbooleanwhether data changes reach clients (for rendering or client logic); the inventory is synchronised through the menu either way
menuOptional<MenuLayout>a menu with its own slot layout, or empty; when present the inventory has one slot per layout slot and inventoryRows is 0
dataVersionintthe current version of the data tree; older saved data runs migration
migrationOptional<DataMigration>upgrades older data, if any

inventorySize()​

public int inventorySize()

Since 0.1.0-alpha.4 or earlier

Number of inventory slots: from the layout, or rows × 9.

Returns int

builder()​

public static BlockEntityDefinition.Builder builder()

Since 0.1.0-alpha.4 or earlier

A builder for a block entity with data only.

Returns BlockEntityDefinition.Builder

BlockEntityDefinition.Builder​

class · Since 0.1.0-alpha.4 or earlier

public static final class Builder

Builds a BlockEntityDefinition.

inventory(int, String)​

public BlockEntityDefinition.Builder inventory(int rows, String title)

Since 0.1.0-alpha.4 or earlier

Adds an inventory of rows × 9 slots with a menu titled title.

ParameterTypeDescription
rowsint—
titleString—

Returns BlockEntityDefinition.Builder

menu(MenuLayout, String)​

public BlockEntityDefinition.Builder menu(MenuLayout layout, String title)

Since 0.1.0-alpha.4 or earlier

Adds an inventory with one slot per layout slot, shown in a menu with that layout.

ParameterTypeDescription
layoutMenuLayout—
titleString—

Returns BlockEntityDefinition.Builder

dataVersion(int, DataMigration)​

public BlockEntityDefinition.Builder dataVersion(int version, DataMigration upgrade)

Since 0.1.0-alpha.4 or earlier

Sets the data version; block entities saved with an older one run upgrade on load.

ParameterTypeDescription
versionint—
upgradeDataMigration—

Returns BlockEntityDefinition.Builder

ticker(BlockEntityTicker)​

public BlockEntityDefinition.Builder ticker(BlockEntityTicker ticker)

Since 0.1.0-alpha.4 or earlier

Runs ticker on the server every tick.

ParameterTypeDescription
tickerBlockEntityTicker—

Returns BlockEntityDefinition.Builder

syncToClients()​

public BlockEntityDefinition.Builder syncToClients()

Since 0.1.0-alpha.4 or earlier

Sends data changes to clients when BlockEntityView.markChanged() is called.

Returns BlockEntityDefinition.Builder

build()​

public BlockEntityDefinition build()

Since 0.1.0-alpha.4 or earlier

Creates the definition.

Returns BlockEntityDefinition

BlockEntityTicker​

functional interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier

public interface BlockEntityTicker

Server-side code run every tick for each loaded block entity. Keep it cheap.

tick(BlockEntityView)​

void tick(BlockEntityView entity)

Since 0.1.0-alpha.4 or earlier

Called on the server thread; entity is valid only during the call.

ParameterTypeDescription
entityBlockEntityView—

BlockEntityView​

interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier

public interface BlockEntityView

A mod block entity. The data tree and inventory live as long as the block; the view itself is valid only during the callback that handed it out.

world()​

WorldView world()

Since 0.1.0-alpha.4 or earlier

The world it is in.

Returns WorldView

pos()​

BlockPos pos()

Since 0.1.0-alpha.4 or earlier

Its position.

Returns BlockPos

data()​

DataTree data()

Since 0.1.0-alpha.4 or earlier

Its saved data; call markChanged() after changing it.

Returns DataTree

inventory()​

Optional<InventoryView> inventory()

Since 0.1.0-alpha.4 or earlier

Its inventory, when the definition has one.

Returns Optional<InventoryView>

markChanged()​

void markChanged()

Since 0.1.0-alpha.4 or earlier

Marks the data for saving and, for synchronised block entities, sends it to clients.

record · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier

public record MenuLayout(int width, int height, List<MenuLayout.MenuSlot> slots, int inventoryX, int inventoryY, Optional<ResourceId> background, List<MenuLayout.ProgressBar> progressBars)

The menu of a block entity with its own slot positions, like a furnace. Coordinates are GUI pixels from the menu's top-left corner; a slot is 16×16 with its frame one pixel outside. The player's inventory (27 + 9 slots) is placed at inventoryX, inventoryY.

Without a background texture Poly Mod Loader draws a plain panel with slot frames. With one, the texture (<namespace>:textures/gui/...png, 256×256 canvas) is drawn as is and must include the slot frames.

ComponentTypeDescription
widthintmenu width (176 for the game's menus)
heightintmenu height (166 for the game's menus)
slotsList<MenuLayout.MenuSlot>the block entity's slots, in inventory order
inventoryXintleft of the player's inventory
inventoryYinttop of the player's inventory
backgroundOptional<ResourceId>texture, or empty for the plain panel
progressBarsList<MenuLayout.ProgressBar>bars filled from block entity data
public static MenuLayout.Builder builder(int width, int height)

Since 0.1.0-alpha.4 or earlier

A builder for a width × height menu with the inventory at the game's usual place.

ParameterTypeDescription
widthint—
heightint—

Returns MenuLayout.Builder

class · Since 0.1.0-alpha.4 or earlier

public static final class Builder

Builds a MenuLayout.

public MenuLayout.Builder slot(int x, int y)

Since 0.1.0-alpha.4 or earlier

Adds a slot.

ParameterTypeDescription
xint—
yint—

Returns MenuLayout.Builder

public MenuLayout.Builder outputSlot(int x, int y)

Since 0.1.0-alpha.4 or earlier

Adds a slot players can only take from.

ParameterTypeDescription
xint—
yint—

Returns MenuLayout.Builder

public MenuLayout.Builder grid(int x, int y, int columns, int rows)

Since 0.1.0-alpha.4 or earlier

Adds a columns × rows grid of slots with 18-pixel spacing.

ParameterTypeDescription
xint—
yint—
columnsint—
rowsint—

Returns MenuLayout.Builder

public MenuLayout.Builder playerInventory(int x, int y)

Since 0.1.0-alpha.4 or earlier

Moves the player's inventory (default 8, height - 82).

ParameterTypeDescription
xint—
yint—

Returns MenuLayout.Builder

public MenuLayout.Builder background(ResourceId texture)

Since 0.1.0-alpha.4 or earlier

Draws texture instead of the plain panel.

ParameterTypeDescription
textureResourceId—

Returns MenuLayout.Builder

public MenuLayout.Builder progressBar(int x, int y, MenuLayout.ProgressStyle style, String valueKey, String maxKey)

Since 0.1.0-alpha.4 or earlier

Adds a progress bar.

ParameterTypeDescription
xint—
yint—
styleMenuLayout.ProgressStyle—
valueKeyString—
maxKeyString—

Returns MenuLayout.Builder

public MenuLayout build()

Since 0.1.0-alpha.4 or earlier

Creates the layout; invalid values throw IllegalArgumentException.

Returns MenuLayout

record · Since 0.1.0-alpha.4 or earlier

public static record MenuSlot(int x, int y, boolean outputOnly)

One slot.

ComponentTypeDescription
xintleft of the 16×16 item area
yinttop of the item area
outputOnlybooleanplayers can take items out but not put them in

record · Since 0.1.0-alpha.4 or earlier

public static record ProgressBar(int x, int y, MenuLayout.ProgressStyle style, String valueKey, String maxKey)

A bar filled in proportion to data().getInt(valueKey) / data().getInt(maxKey) of the block entity. Values reach the client while the menu is open; they must fit in -32768..32767.

ComponentTypeDescription
xintleft
yinttop
styleMenuLayout.ProgressStylehow it looks
valueKeyStringdata key of the current value
maxKeyStringdata key of the full value; the bar is empty while it is 0

enum · Since 0.1.0-alpha.4 or earlier

public static enum ProgressStyle

Looks of a ProgressBar, taken from the game's furnace.

ConstantDescription
ARROW24×16 arrow filling left to right.
FLAME14×14 flame filling bottom to top.
Buy me a coffee