dev.polymodloader.api.content.block.entity
This page is generated from the source's Javadoc by ./gradlew apiReference. Do not edit it; fix the source comment and generate it again.
| Type | Kind | Description |
|---|---|---|
BlockEntityDefinition | record | Gives a mod block per-position state that is saved with the world: a DataTree, an optional inventory, and an optional server tick. |
BlockEntityDefinition.Builder | class | Builds a BlockEntityDefinition. |
BlockEntityTicker | functional interface | Server-side code run every tick for each loaded block entity. |
BlockEntityView | interface | A mod block entity. |
MenuLayout | record | The menu of a block entity with its own slot positions, like a furnace. |
MenuLayout.Builder | class | Builds a MenuLayout. |
MenuLayout.MenuSlot | record | One slot. |
MenuLayout.ProgressBar | record | A bar filled in proportion to data().getInt(valueKey) / data().getInt(maxKey) of the block entity. |
MenuLayout.ProgressStyle | enum | Looks 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.
| Component | Type | Description |
|---|---|---|
inventoryRows | int | rows 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. |
menuTitle | String | translation key or plain text shown above the menu |
ticker | Optional<BlockEntityTicker> | server-side code run every tick, or empty |
syncToClients | boolean | whether data changes reach clients (for rendering or client logic); the inventory is synchronised through the menu either way |
menu | Optional<MenuLayout> | a menu with its own slot layout, or empty; when present the inventory has one slot per layout slot and inventoryRows is 0 |
dataVersion | int | the current version of the data tree; older saved data runs migration |
migration | Optional<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.
| Parameter | Type | Description |
|---|---|---|
rows | int | — |
title | String | — |
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.
| Parameter | Type | Description |
|---|---|---|
layout | MenuLayout | — |
title | String | — |
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.
| Parameter | Type | Description |
|---|---|---|
version | int | — |
upgrade | DataMigration | — |
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.
| Parameter | Type | Description |
|---|---|---|
ticker | BlockEntityTicker | — |
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.
| Parameter | Type | Description |
|---|---|---|
entity | BlockEntityView | — |
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.
MenuLayout
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.
| Component | Type | Description |
|---|---|---|
width | int | menu width (176 for the game's menus) |
height | int | menu height (166 for the game's menus) |
slots | List<MenuLayout.MenuSlot> | the block entity's slots, in inventory order |
inventoryX | int | left of the player's inventory |
inventoryY | int | top of the player's inventory |
background | Optional<ResourceId> | texture, or empty for the plain panel |
progressBars | List<MenuLayout.ProgressBar> | bars filled from block entity data |
builder(int, int)
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.
| Parameter | Type | Description |
|---|---|---|
width | int | — |
height | int | — |
Returns MenuLayout.Builder
MenuLayout.Builder
class · Since 0.1.0-alpha.4 or earlier
public static final class Builder
Builds a MenuLayout.
slot(int, int)
public MenuLayout.Builder slot(int x, int y)
Since 0.1.0-alpha.4 or earlier
Adds a slot.
| Parameter | Type | Description |
|---|---|---|
x | int | — |
y | int | — |
Returns MenuLayout.Builder
outputSlot(int, int)
public MenuLayout.Builder outputSlot(int x, int y)
Since 0.1.0-alpha.4 or earlier
Adds a slot players can only take from.
| Parameter | Type | Description |
|---|---|---|
x | int | — |
y | int | — |
Returns MenuLayout.Builder
grid(int, int, int, int)
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.
| Parameter | Type | Description |
|---|---|---|
x | int | — |
y | int | — |
columns | int | — |
rows | int | — |
Returns MenuLayout.Builder
playerInventory(int, int)
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).
| Parameter | Type | Description |
|---|---|---|
x | int | — |
y | int | — |
Returns MenuLayout.Builder
background(ResourceId)
public MenuLayout.Builder background(ResourceId texture)
Since 0.1.0-alpha.4 or earlier
Draws texture instead of the plain panel.
| Parameter | Type | Description |
|---|---|---|
texture | ResourceId | — |
Returns MenuLayout.Builder
progressBar(int, int, MenuLayout.ProgressStyle, String, String)
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.
| Parameter | Type | Description |
|---|---|---|
x | int | — |
y | int | — |
style | MenuLayout.ProgressStyle | — |
valueKey | String | — |
maxKey | String | — |
Returns MenuLayout.Builder
build()
public MenuLayout build()
Since 0.1.0-alpha.4 or earlier
Creates the layout; invalid values throw IllegalArgumentException.
Returns MenuLayout
MenuLayout.MenuSlot
record · Since 0.1.0-alpha.4 or earlier
public static record MenuSlot(int x, int y, boolean outputOnly)
One slot.
| Component | Type | Description |
|---|---|---|
x | int | left of the 16×16 item area |
y | int | top of the item area |
outputOnly | boolean | players can take items out but not put them in |
MenuLayout.ProgressBar
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.
| Component | Type | Description |
|---|---|---|
x | int | left |
y | int | top |
style | MenuLayout.ProgressStyle | how it looks |
valueKey | String | data key of the current value |
maxKey | String | data key of the full value; the bar is empty while it is 0 |
MenuLayout.ProgressStyle
enum · Since 0.1.0-alpha.4 or earlier
public static enum ProgressStyle
Looks of a ProgressBar, taken from the game's furnace.
| Constant | Description |
|---|---|
ARROW | 24×16 arrow filling left to right. |
FLAME | 14×14 flame filling bottom to top. |