Skip to main content
Version: Minecraft 26.2

dev.polymodloader.api.content.block

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
BlockBehaviorinterfaceCode that runs when something happens to a mod block.
BlockDefinitionrecordProperties of a mod block.
BlockDefinition.BuilderclassBuilds a BlockDefinition.
BlockHandleinterfaceA declared block.
BlockShaperecordThe 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.BoxrecordA box from (minX, minY, minZ) to (maxX, maxY, maxZ) in pixels.
BlockSoundenumSounds a block makes when placed, broken, and walked on; each maps to the game's sound type.
BlockUserecordA 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.

ParameterTypeDescription
useBlockUse—

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.

ParameterTypeDescription
worldWorldView—
posBlockPos—
entityEntityView—

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).

ParameterTypeDescription
worldWorldView—
posBlockPos—
placerEntityView—

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().

ParameterTypeDescription
worldWorldView—
posBlockPos—

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.

ParameterTypeDescription
worldWorldView—
posBlockPos—

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.

ComponentTypeDescription
hardnessfloattime factor to break the block; -1 is unbreakable
explosionResistancefloatresistance to explosions
requiresCorrectToolbooleanwhether the block drops only when mined with the right tool (tool tags such as minecraft:mineable/pickaxe come from the mod's data pack)
soundBlockSoundsound type
lightLevelintemitted light, 0–15
frictionfloatslipperiness; the game's default is 0.6, ice is 0.98
collisionbooleanwhether entities collide with the block
occludesbooleanwhether the block hides the faces of its neighbours; turn off for see-through blocks
behaviorBlockBehaviorinteraction callbacks
itemOptional<ItemDefinition>the block item to declare with the same ID, or empty for no item
propertiesList<BlockProperty<?>>block state properties, in order
placementFacingOptional<BlockProperty.DirectionProperty>a horizontal direction property set on placement so the block faces the player, or empty
randomTicksbooleanwhether the block receives random ticks (BlockBehavior.onRandomTick)
blockEntityOptional<BlockEntityDefinition>per-position saved state, or empty
lightByStateOptional<ToIntFunction<BlockStateView>>emitted light computed from the state (0–15), overriding lightLevel; for example a lamp that glows only when lit=true
shapeOptional<Function<BlockStateView,BlockShape>>the outline the player aims at, by state, or empty for a full block
collisionShapeOptional<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).

ParameterTypeDescription
hardnessfloat—
explosionResistancefloat—

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.

ParameterTypeDescription
soundBlockSound—

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.

ParameterTypeDescription
lightLevelint—

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.

ParameterTypeDescription
byStateToIntFunction<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).

ParameterTypeDescription
frictionfloat—

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.

ParameterTypeDescription
behaviorBlockBehavior—

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.

ParameterTypeDescription
itemItemDefinition—

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.

ParameterTypeDescription
addedBlockProperty<?>[]—

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.

ParameterTypeDescription
facingBlockProperty.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.

ParameterTypeDescription
definitionBlockEntityDefinition—

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.

ParameterTypeDescription
shapeBlockShape—

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.

ParameterTypeDescription
byStateFunction<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.

ParameterTypeDescription
shapeBlockShape—

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.

ParameterTypeDescription
byStateFunction<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.

ComponentTypeDescription
boxesList<BlockShape.Box>the boxes; empty for no shape at all
Constant or fieldTypeDescription
FULLBlockShapeThe whole block.
EMPTYBlockShapeNothing: 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.

ParameterTypeDescription
minXdouble—
minYdouble—
minZdouble—
maxXdouble—
maxYdouble—
maxZdouble—

Returns BlockShape

or(BlockShape)​

public BlockShape or(BlockShape other)

Since 0.1.0-alpha.4 or earlier

This shape together with other.

ParameterTypeDescription
otherBlockShape—

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.

ParameterTypeDescription
facingDirection—

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.

ComponentTypeDescription
minXdoublelowest x, 0..16
minYdoublelowest y
minZdoublelowest z (north side)
maxXdoublehighest x, greater than minX
maxYdoublehighest y
maxZdoublehighest 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.

ConstantDescription
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.

ComponentTypeDescription
worldWorldViewthe world, client or server copy
posBlockPosthe block's position
playerPlayerViewthe player
Buy me a coffee