dev.polymodloader.api.content.block
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 |
|---|---|---|
BlockBehavior | interface | Code that runs when something happens to a mod block. |
BlockDefinition | record | Properties of a mod block. |
BlockDefinition.Builder | class | Builds a BlockDefinition. |
BlockHandle | interface | A declared block. |
BlockShape | record | The solid part of a block: boxes in pixels, where a full block spans 0..16 on each axis, like the from/to of a block model element. |
BlockShape.Box | record | A box from (minX, minY, minZ) to (maxX, maxY, maxZ) in pixels. |
BlockSound | enum | Sounds a block makes when placed, broken, and walked on; each maps to the game's sound type. |
BlockUse | record | A player using (right-clicking) a block with an empty hand. |
BlockBehavior
interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface BlockBehavior
Code that runs when something happens to a mod block. Every method has a default that keeps the game's normal behaviour, so implement only what the block needs.
Thread: the world's thread. Callbacks run on both the client and the server copy of the world unless stated otherwise; check WorldView.isClientSide() before changing state. Failure: exceptions propagate into the game like exceptions from the game's own blocks.
onUse(BlockUse)
default InteractionResult onUse(BlockUse use)
Since 0.1.0-alpha.4 or earlier
A player used the block with an empty hand.
| Parameter | Type | Description |
|---|---|---|
use | BlockUse | — |
Returns InteractionResult
onSteppedOn(WorldView, BlockPos, EntityView)
default void onSteppedOn(WorldView world, BlockPos pos, EntityView entity)
Since 0.1.0-alpha.4 or earlier
An entity walks on top of the block.
| Parameter | Type | Description |
|---|---|---|
world | WorldView | — |
pos | BlockPos | — |
entity | EntityView | — |
onPlaced(WorldView, BlockPos, EntityView)
default void onPlaced(WorldView world, BlockPos pos, EntityView placer)
Since 0.1.0-alpha.4 or earlier
The block was placed by an entity (server and client).
| Parameter | Type | Description |
|---|---|---|
world | WorldView | — |
pos | BlockPos | — |
placer | EntityView | — |
onRandomTick(WorldView, BlockPos)
default void onRandomTick(WorldView world, BlockPos pos)
Since 0.1.0-alpha.4 or earlier
A random tick reached the block (server only, about every 68 seconds per block at the default randomTickSpeed). Requires BlockDefinition.Builder.randomTicks().
| Parameter | Type | Description |
|---|---|---|
world | WorldView | — |
pos | BlockPos | — |
onNeighborChanged(WorldView, BlockPos)
default void onNeighborChanged(WorldView world, BlockPos pos)
Since 0.1.0-alpha.4 or earlier
A neighbouring block changed (server and client); typical for redstone-like reactions.
| Parameter | Type | Description |
|---|---|---|
world | WorldView | — |
pos | BlockPos | — |
BlockDefinition
record · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public record BlockDefinition(float hardness, float explosionResistance, boolean requiresCorrectTool, BlockSound sound, int lightLevel, float friction, boolean collision, boolean occludes, BlockBehavior behavior, Optional<ItemDefinition> item, List<BlockProperty<?>> properties, Optional<BlockProperty.DirectionProperty> placementFacing, boolean randomTicks, Optional<BlockEntityDefinition> blockEntity, Optional<ToIntFunction<BlockStateView>> lightByState, Optional<Function<BlockStateView,BlockShape>> shape, Optional<Function<BlockStateView,BlockShape>> collisionShape)
Properties of a mod block. Created with builder(); immutable.
| Component | Type | Description |
|---|---|---|
hardness | float | time factor to break the block; -1 is unbreakable |
explosionResistance | float | resistance to explosions |
requiresCorrectTool | boolean | whether the block drops only when mined with the right tool (tool tags such as minecraft:mineable/pickaxe come from the mod's data pack) |
sound | BlockSound | sound type |
lightLevel | int | emitted light, 0–15 |
friction | float | slipperiness; the game's default is 0.6, ice is 0.98 |
collision | boolean | whether entities collide with the block |
occludes | boolean | whether the block hides the faces of its neighbours; turn off for see-through blocks |
behavior | BlockBehavior | interaction callbacks |
item | Optional<ItemDefinition> | the block item to declare with the same ID, or empty for no item |
properties | List<BlockProperty<?>> | block state properties, in order |
placementFacing | Optional<BlockProperty.DirectionProperty> | a horizontal direction property set on placement so the block faces the player, or empty |
randomTicks | boolean | whether the block receives random ticks (BlockBehavior.onRandomTick) |
blockEntity | Optional<BlockEntityDefinition> | per-position saved state, or empty |
lightByState | Optional<ToIntFunction<BlockStateView>> | emitted light computed from the state (0–15), overriding lightLevel; for example a lamp that glows only when lit=true |
shape | Optional<Function<BlockStateView,BlockShape>> | the outline the player aims at, by state, or empty for a full block |
collisionShape | Optional<Function<BlockStateView,BlockShape>> | what entities collide with, by state, or empty for the same as shape; ignored without collision |
builder()
public static BlockDefinition.Builder builder()
Since 0.1.0-alpha.4 or earlier
A builder with the game's defaults for a plain stone-like block that has a block item.
Returns BlockDefinition.Builder
BlockDefinition.Builder
class · Since 0.1.0-alpha.4 or earlier
public static final class Builder
Builds a BlockDefinition.
strength(float, float)
public BlockDefinition.Builder strength(float hardness, float explosionResistance)
Since 0.1.0-alpha.4 or earlier
Sets hardness and explosion resistance (stone is 1.5 / 6.0).
| Parameter | Type | Description |
|---|---|---|
hardness | float | — |
explosionResistance | float | — |
Returns BlockDefinition.Builder
requiresCorrectTool()
public BlockDefinition.Builder requiresCorrectTool()
Since 0.1.0-alpha.4 or earlier
The block drops only when mined with the correct tool.
Returns BlockDefinition.Builder
sound(BlockSound)
public BlockDefinition.Builder sound(BlockSound sound)
Since 0.1.0-alpha.4 or earlier
Sets the sound type.
| Parameter | Type | Description |
|---|---|---|
sound | BlockSound | — |
Returns BlockDefinition.Builder
lightLevel(int)
public BlockDefinition.Builder lightLevel(int lightLevel)
Since 0.1.0-alpha.4 or earlier
Sets the emitted light level, 0–15.
| Parameter | Type | Description |
|---|---|---|
lightLevel | int | — |
Returns BlockDefinition.Builder
lightLevel(ToIntFunction<BlockStateView>)
public BlockDefinition.Builder lightLevel(ToIntFunction<BlockStateView> byState)
Since 0.1.0-alpha.4 or earlier
Computes the emitted light from each state, for example state -> state.get(LIT) ? 15 : 0. The game evaluates it once per state while the block is created; results outside 0–15 are clamped.
| Parameter | Type | Description |
|---|---|---|
byState | ToIntFunction<BlockStateView> | — |
Returns BlockDefinition.Builder
friction(float)
public BlockDefinition.Builder friction(float friction)
Since 0.1.0-alpha.4 or earlier
Sets the friction (0.6 default, 0.98 ice).
| Parameter | Type | Description |
|---|---|---|
friction | float | — |
Returns BlockDefinition.Builder
noCollision()
public BlockDefinition.Builder noCollision()
Since 0.1.0-alpha.4 or earlier
Entities pass through the block.
Returns BlockDefinition.Builder
noOcclusion()
public BlockDefinition.Builder noOcclusion()
Since 0.1.0-alpha.4 or earlier
The block does not hide its neighbours' faces (glass-like blocks).
Returns BlockDefinition.Builder
behavior(BlockBehavior)
public BlockDefinition.Builder behavior(BlockBehavior behavior)
Since 0.1.0-alpha.4 or earlier
Sets the interaction callbacks.
| Parameter | Type | Description |
|---|---|---|
behavior | BlockBehavior | — |
Returns BlockDefinition.Builder
item(ItemDefinition)
public BlockDefinition.Builder item(ItemDefinition item)
Since 0.1.0-alpha.4 or earlier
Sets the properties of the block item declared with the block.
| Parameter | Type | Description |
|---|---|---|
item | ItemDefinition | — |
Returns BlockDefinition.Builder
noItem()
public BlockDefinition.Builder noItem()
Since 0.1.0-alpha.4 or earlier
Declares no block item.
Returns BlockDefinition.Builder
properties(BlockProperty<?>[])
public BlockDefinition.Builder properties(BlockProperty<?>... added)
Since 0.1.0-alpha.4 or earlier
Adds block state properties; their default values form the default state.
| Parameter | Type | Description |
|---|---|---|
added | BlockProperty<?>[] | — |
Returns BlockDefinition.Builder
facesPlayerWhenPlaced(BlockProperty.DirectionProperty)
public BlockDefinition.Builder facesPlayerWhenPlaced(BlockProperty.DirectionProperty facing)
Since 0.1.0-alpha.4 or earlier
Adds facing as a property and sets it on placement so the block faces the player.
| Parameter | Type | Description |
|---|---|---|
facing | BlockProperty.DirectionProperty | — |
Returns BlockDefinition.Builder
randomTicks()
public BlockDefinition.Builder randomTicks()
Since 0.1.0-alpha.4 or earlier
The block receives random ticks.
Returns BlockDefinition.Builder
blockEntity(BlockEntityDefinition)
public BlockDefinition.Builder blockEntity(BlockEntityDefinition definition)
Since 0.1.0-alpha.4 or earlier
Gives the block per-position saved state.
| Parameter | Type | Description |
|---|---|---|
definition | BlockEntityDefinition | — |
Returns BlockDefinition.Builder
shape(BlockShape)
public BlockDefinition.Builder shape(BlockShape shape)
Since 0.1.0-alpha.4 or earlier
The block's outline and collision: a slab, a post, a pipe. The game also uses it to hide only the neighbour faces the shape covers. Block models are not changed; draw the model to match.
| Parameter | Type | Description |
|---|---|---|
shape | BlockShape | — |
Returns BlockDefinition.Builder
shape(Function<BlockStateView,BlockShape>)
public BlockDefinition.Builder shape(Function<BlockStateView,BlockShape> byState)
Since 0.1.0-alpha.4 or earlier
The block's outline and collision computed from the state, for example turned with BlockShape.facing by a facing property. Called once per state when the game starts.
| Parameter | Type | Description |
|---|---|---|
byState | Function<BlockStateView,BlockShape> | — |
Returns BlockDefinition.Builder
collisionShape(BlockShape)
public BlockDefinition.Builder collisionShape(BlockShape shape)
Since 0.1.0-alpha.4 or earlier
What entities collide with, when it differs from shape: a low fence-like box, for example.
| Parameter | Type | Description |
|---|---|---|
shape | BlockShape | — |
Returns BlockDefinition.Builder
collisionShape(Function<BlockStateView,BlockShape>)
public BlockDefinition.Builder collisionShape(Function<BlockStateView,BlockShape> byState)
Since 0.1.0-alpha.4 or earlier
What entities collide with, computed from the state. Called once per state when the game starts.
| Parameter | Type | Description |
|---|---|---|
byState | Function<BlockStateView,BlockShape> | — |
Returns BlockDefinition.Builder
build()
public BlockDefinition build()
Since 0.1.0-alpha.4 or earlier
Creates the definition; invalid values throw IllegalArgumentException.
Returns BlockDefinition
BlockHandle
interface · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public interface BlockHandle extends ContentHandle
A declared block.
Supertypes: ContentHandle
BlockShape
record · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public record BlockShape(List<BlockShape.Box> boxes)
The solid part of a block: boxes in pixels, where a full block spans 0..16 on each axis, like the from/to of a block model element. Used for the outline the player aims at and for what entities collide with.
| Component | Type | Description |
|---|---|---|
boxes | List<BlockShape.Box> | the boxes; empty for no shape at all |
| Constant or field | Type | Description |
|---|---|---|
FULL | BlockShape | The whole block. |
EMPTY | BlockShape | Nothing: the block cannot be aimed at or collided with. |
box(double, double, double, double, double, double)
public static BlockShape box(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)
Since 0.1.0-alpha.4 or earlier
One box, in pixels.
| Parameter | Type | Description |
|---|---|---|
minX | double | — |
minY | double | — |
minZ | double | — |
maxX | double | — |
maxY | double | — |
maxZ | double | — |
Returns BlockShape
or(BlockShape)
public BlockShape or(BlockShape other)
Since 0.1.0-alpha.4 or earlier
This shape together with other.
| Parameter | Type | Description |
|---|---|---|
other | BlockShape | — |
Returns BlockShape
facing(Direction)
public BlockShape facing(Direction facing)
Since 0.1.0-alpha.4 or earlier
This shape, drawn facing north, turned around the block's vertical axis to face facing. For example a box along the north edge ends up along the east edge for Direction.EAST.
| Parameter | Type | Description |
|---|---|---|
facing | Direction | — |
Returns BlockShape
Throws IllegalArgumentException — if facing is up or down
BlockShape.Box
record · Since 0.1.0-alpha.4 or earlier
public static record Box(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)
A box from (minX, minY, minZ) to (maxX, maxY, maxZ) in pixels.
| Component | Type | Description |
|---|---|---|
minX | double | lowest x, 0..16 |
minY | double | lowest y |
minZ | double | lowest z (north side) |
maxX | double | highest x, greater than minX |
maxY | double | highest y |
maxZ | double | highest z (south side) |
BlockSound
enum · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public enum BlockSound
Sounds a block makes when placed, broken, and walked on; each maps to the game's sound type.
| Constant | Description |
|---|---|
STONE | — |
WOOD | — |
GRAVEL | — |
GRASS | — |
METAL | — |
GLASS | — |
WOOL | — |
SAND | — |
COPPER | — |
AMETHYST | — |
BlockUse
record · Stability PREVIEW · Since 0.1.0-alpha.4 or earlier
public record BlockUse(WorldView world, BlockPos pos, PlayerView player)
A player using (right-clicking) a block with an empty hand.
| Component | Type | Description |
|---|---|---|
world | WorldView | the world, client or server copy |
pos | BlockPos | the block's position |
player | PlayerView | the player |