server.block
Constants #
const custom_block_runtime_id_start = 10000
Runtime ids for custom blocks start above the vanilla palette so they never collide with it.
const dye_colors = ['white', 'orange', 'magenta', 'light_blue', 'yellow', 'lime', 'pink', 'gray',
'light_gray', 'cyan', 'purple', 'blue', 'brown', 'green', 'red', 'black']
Decorative-components family: wool, carpet, concrete, terracotta, stained glass(and pane), candles, signs, banners, bed.
const random_tick_speed = 3
Each loaded 16x16x16 subchunk contains 4096 block positions. On every game tick, vanilla selects random_tick_speed positions from each subchunk for random ticking. Therefore, any individual position has a random_tick_speed / 4096 chance of being selected per tick.
const random_tick_chance_denominator = 4096
fn combat_progression_blocks #
fn combat_progression_blocks() []Block
fn container_blocks #
fn container_blocks() []Block
fn decorative_blocks #
fn decorative_blocks() []Block
fn farming_blocks #
fn farming_blocks() []Block
fn new_andesite #
fn new_andesite() AndesiteBlock
fn new_bedrock_block #
fn new_bedrock_block() BedrockBlock
fn new_blue_ice #
fn new_blue_ice() BlueIceBlock
fn new_calcite #
fn new_calcite() CalciteBlock
fn new_clay #
fn new_clay() ClayBlock
fn new_coal_block #
fn new_coal_block() CoalBlock
fn new_coal_ore #
fn new_coal_ore() CoalOreBlock
fn new_cobbled_deepslate #
fn new_cobbled_deepslate() CobbledDeepslateBlock
fn new_cobblestone #
fn new_cobblestone() CobblestoneBlock
fn new_copper_block #
fn new_copper_block() CopperBlock
fn new_copper_ore #
fn new_copper_ore() CopperOreBlock
fn new_custom_registry #
fn new_custom_registry() CustomRegistry
fn new_diamond_block #
fn new_diamond_block() DiamondBlock
fn new_diamond_ore #
fn new_diamond_ore() DiamondOreBlock
fn new_diorite #
fn new_diorite() DioriteBlock
fn new_dirt_block #
fn new_dirt_block() DirtBlock
fn new_dripstone_block #
fn new_dripstone_block() DripstoneBlock
fn new_emerald_block #
fn new_emerald_block() EmeraldBlock
fn new_emerald_ore #
fn new_emerald_ore() EmeraldOreBlock
fn new_end_bricks #
fn new_end_bricks() EndBricksBlock
fn new_end_stone #
fn new_end_stone() EndStoneBlock
fn new_fern_block #
fn new_fern_block() FernBlock
fn new_glowstone #
fn new_glowstone() GlowstoneBlock
fn new_gold_block #
fn new_gold_block() GoldBlock
fn new_gold_ore #
fn new_gold_ore() GoldOreBlock
fn new_granite #
fn new_granite() GraniteBlock
fn new_grass_block #
fn new_grass_block() GrassBlock
fn new_gravel #
fn new_gravel() GravelBlock
fn new_ice #
fn new_ice() IceBlock
fn new_iron_block #
fn new_iron_block() IronBlock
fn new_iron_ore #
fn new_iron_ore() IronOreBlock
fn new_lapis_block #
fn new_lapis_block() LapisBlock
fn new_lapis_ore #
fn new_lapis_ore() LapisOreBlock
fn new_magma_block #
fn new_magma_block() MagmaBlock
fn new_mossy_cobblestone #
fn new_mossy_cobblestone() MossyCobblestoneBlock
fn new_netherrack #
fn new_netherrack() NetherrackBlock
fn new_obsidian #
fn new_obsidian() ObsidianBlock
fn new_packed_ice #
fn new_packed_ice() PackedIceBlock
fn new_polished_andesite #
fn new_polished_andesite() PolishedAndesiteBlock
fn new_polished_diorite #
fn new_polished_diorite() PolishedDioriteBlock
fn new_polished_granite #
fn new_polished_granite() PolishedGraniteBlock
fn new_purpur_block #
fn new_purpur_block() PurpurBlock
fn new_red_sand #
fn new_red_sand() RedSandBlock
fn new_redstone_block #
fn new_redstone_block() RedstoneBlock
fn new_redstone_ore #
fn new_redstone_ore() RedstoneOreBlock
fn new_registry #
fn new_registry() Registry
new_registry builds a Registry pre-populated with the built-in block classes.
fn new_sand #
fn new_sand() SandBlock
fn new_sandstone #
fn new_sandstone() SandstoneBlock
fn new_short_grass_block #
fn new_short_grass_block() ShortGrassBlock
fn new_smooth_basalt #
fn new_smooth_basalt() SmoothBasaltBlock
fn new_snow #
fn new_snow() SnowBlock
fn new_soul_sand #
fn new_soul_sand() SoulSandBlock
fn new_soul_soil #
fn new_soul_soil() SoulSoilBlock
fn new_stone_block #
fn new_stone_block() StoneBlock
fn new_tuff #
fn new_tuff() TuffBlock
fn redstone_component_blocks #
fn redstone_component_blocks() []Block
fn replaceable_plant_blocks #
fn replaceable_plant_blocks() []Block
fn wood_blocks #
fn wood_blocks() []Block
interface Block #
interface Block {
// identifier returns the namespaced block id.
identifier() string
// runtime_id is the network runtime id sent on the wire.
runtime_id() int
// hardness is how long the block resists breaking, in vanilla units.
hardness() f32
// breakable reports whether survival players can destroy this block.
breakable() bool
}
Block is the behaviour contract every block class implements. Every block is its own class built on a family base struct (SimpleBlock, UnbreakableBlock) and registered in the Registry so the session layer can look it up by its runtime id or namespaced identifier.
interface Interactable #
interface Interactable {
// interact runs this block's right click behaviour at (x, y, z).
// Returns whether it did anything, false means fall through, letting
// the session layer treat the click as an ordinary placement attempt.
interact(x int, y int, z int, click_face int, mut w TickWorld) bool
}
Interactable is implemented by blocks with a behaviour on right click.
interface Punchable #
interface Punchable {
// punch runs this block's left click behaviour at (x, y, z). Unlike
// interact() there's no fall through decision to make, punching a
// block always proceeds to the normal start break animation regardless.
punch(x int, y int, z int, click_face int, mut w TickWorld)
}
Punchable is implemented by blocks with a behaviour on left click. the moment a player starts breaking it, separate from Interactable's right click behaviour and from anything that happens once the break actually completes.
interface RandomTicker #
interface RandomTicker {
random_tick(x int, y int, z int, mut w TickWorld)
}
RandomTicker is implemented by blocks that may receive random updates. On each game tick, every eligible block position has a random_tick_speed / random_tick_chance_denominator chance of having random_tick called.
Examples include crop growth and leaf decay.
interface Replaceable #
interface Replaceable {
replaceable() bool
}
Replaceable is implemented by blocks that get silently overwritten by a placement instead of blocking it.
interface ScheduledTicker #
interface ScheduledTicker {
scheduled_tick(x int, y int, z int, mut w TickWorld)
}
ScheduledTicker is implemented by blocks that need to perform a one time update after a delay. scheduled_tick is called delay game ticks after the block position is queued using TickWorld.schedule_tick.
Examples include liquid spreading and delayed redstone propagation.
interface TickWorld #
interface TickWorld {
block_id(x int, y int, z int) int
mut:
set_block(x int, y int, z int, id int)
schedule_tick(x int, y int, z int, delay int)
}
TickWorld provides the world operations available during block ticks. It allows tick handlers to read blocks, including neighbouring positions, update blocks and schedule a future tick for a position.
struct AndesiteBlock #
struct AndesiteBlock {
SimpleBlock
}
AndesiteBlock is the class for 'minecraft:andesite'.
struct BedrockBlock #
struct BedrockBlock {
UnbreakableBlock
}
BedrockBlock is the class for 'minecraft:bedrock'.
struct BlueIceBlock #
struct BlueIceBlock {
SimpleBlock
}
BlueIceBlock is the class for 'minecraft:blue_ice'.
struct BoxComponent #
struct BoxComponent {
pub:
origin_x f32 = -8.0
origin_y f32
origin_z f32 = -8.0
size_x f32 = 16.0
size_y f32 = 16.0
size_z f32 = 16.0
}
BoxComponent is a collision or selection box: origin is the corner offset from the block origin (-8..8), size the extent in pixels (0..16).
struct CalciteBlock #
struct CalciteBlock {
SimpleBlock
}
CalciteBlock is the class for 'minecraft:calcite'.
struct ClayBlock #
struct ClayBlock {
SimpleBlock
}
ClayBlock is the class for 'minecraft:clay'.
struct CoalBlock #
struct CoalBlock {
SimpleBlock
}
CoalBlock is the class for 'minecraft:coal_block'.
struct CoalOreBlock #
struct CoalOreBlock {
SimpleBlock
}
CoalOreBlock is the class for 'minecraft:coal_ore'.
struct CobbledDeepslateBlock #
struct CobbledDeepslateBlock {
SimpleBlock
}
CobbledDeepslateBlock is the class for 'minecraft:cobbled_deepslate'.
struct CobblestoneBlock #
struct CobblestoneBlock {
SimpleBlock
}
CobblestoneBlock is the class for 'minecraft:cobblestone'.
struct CopperBlock #
struct CopperBlock {
SimpleBlock
}
CopperBlock is the class for 'minecraft:copper_block'.
struct CopperOreBlock #
struct CopperOreBlock {
SimpleBlock
}
CopperOreBlock is the class for 'minecraft:copper_ore'.
struct CustomBlockDefinition #
struct CustomBlockDefinition {
pub mut:
id string
display_name string
texture string
geometry string
materials []MaterialInstance
friction f32 = 0.4
break_hardness f32 = 1.0
explosion_resistance int = 5
light_emission int
light_dampening int = 15
map_color string
creative_category string = 'construction'
creative_group string
collision ?BoxComponent
selection ?BoxComponent
runtime_id int
}
CustomBlockDefinition describes a data-driven block a plugin registers. It is serialized to block property NBT and shipped in the StartGamePacket blocks list so the client can build render state for it.
fn (CustomBlockDefinition) network_entry #
fn (d &CustomBlockDefinition) network_entry() NetworkEntry
network_entry builds the block property NBT: a components compound, menu_category, molang version and the allocated runtime id under vanilla_block_data.
struct CustomRegistry #
struct CustomRegistry {
mut:
defs []CustomBlockDefinition
ids map[string]int
next_id int = custom_block_runtime_id_start
}
CustomRegistry owns every registered custom block definition and hands out runtime ids sequentially, starting at custom_block_runtime_id_start.
fn (CustomRegistry) register #
fn (mut r CustomRegistry) register(def CustomBlockDefinition) int
register allocates a runtime id for def and stores it. Registering the same id again returns the previously allocated runtime id unchanged.
fn (CustomRegistry) all #
fn (r &CustomRegistry) all() []CustomBlockDefinition
fn (CustomRegistry) len #
fn (r &CustomRegistry) len() int
fn (CustomRegistry) runtime_id #
fn (r &CustomRegistry) runtime_id(id string) ?int
fn (CustomRegistry) names #
fn (r &CustomRegistry) names() []string
struct DiamondBlock #
struct DiamondBlock {
SimpleBlock
}
DiamondBlock is the class for 'minecraft:diamond_block'.
struct DiamondOreBlock #
struct DiamondOreBlock {
SimpleBlock
}
DiamondOreBlock is the class for 'minecraft:diamond_ore'.
struct DioriteBlock #
struct DioriteBlock {
SimpleBlock
}
DioriteBlock is the class for 'minecraft:diorite'.
struct DirtBlock #
struct DirtBlock {
SimpleBlock
}
DirtBlock is the class for 'minecraft:dirt'.
struct DripstoneBlock #
struct DripstoneBlock {
SimpleBlock
}
DripstoneBlock is the class for 'minecraft:dripstone_block'.
struct EmeraldBlock #
struct EmeraldBlock {
SimpleBlock
}
EmeraldBlock is the class for 'minecraft:emerald_block'.
struct EmeraldOreBlock #
struct EmeraldOreBlock {
SimpleBlock
}
EmeraldOreBlock is the class for 'minecraft:emerald_ore'.
struct EndBricksBlock #
struct EndBricksBlock {
SimpleBlock
}
EndBricksBlock is the class for 'minecraft:end_bricks'.
struct EndStoneBlock #
struct EndStoneBlock {
SimpleBlock
}
EndStoneBlock is the class for 'minecraft:end_stone'.
struct FernBlock #
struct FernBlock {
SimpleBlock
}
fn (FernBlock) replaceable #
fn (b FernBlock) replaceable() bool
struct GlowstoneBlock #
struct GlowstoneBlock {
SimpleBlock
}
GlowstoneBlock is the class for 'minecraft:glowstone'.
struct GoldBlock #
struct GoldBlock {
SimpleBlock
}
GoldBlock is the class for 'minecraft:gold_block'.
struct GoldOreBlock #
struct GoldOreBlock {
SimpleBlock
}
GoldOreBlock is the class for 'minecraft:gold_ore'.
struct GraniteBlock #
struct GraniteBlock {
SimpleBlock
}
GraniteBlock is the class for 'minecraft:granite'.
struct GrassBlock #
struct GrassBlock {
SimpleBlock
}
GrassBlock is the class for 'minecraft:grass_block'.
struct GravelBlock #
struct GravelBlock {
SimpleBlock
}
GravelBlock is the class for 'minecraft:gravel'.
struct IceBlock #
struct IceBlock {
SimpleBlock
}
IceBlock is the class for 'minecraft:ice'.
struct IronBlock #
struct IronBlock {
SimpleBlock
}
IronBlock is the class for 'minecraft:iron_block'.
struct IronOreBlock #
struct IronOreBlock {
SimpleBlock
}
IronOreBlock is the class for 'minecraft:iron_ore'.
struct LapisBlock #
struct LapisBlock {
SimpleBlock
}
LapisBlock is the class for 'minecraft:lapis_block'.
struct LapisOreBlock #
struct LapisOreBlock {
SimpleBlock
}
LapisOreBlock is the class for 'minecraft:lapis_ore'.
struct MagmaBlock #
struct MagmaBlock {
SimpleBlock
}
MagmaBlock is the class for 'minecraft:magma'.
struct MaterialInstance #
struct MaterialInstance {
pub:
face string = '*'
texture string
render_method string = 'opaque'
}
MaterialInstance is the render description for one face (or '*' for all).
struct MossyCobblestoneBlock #
struct MossyCobblestoneBlock {
SimpleBlock
}
MossyCobblestoneBlock is the class for 'minecraft:mossy_cobblestone'.
struct NetherrackBlock #
struct NetherrackBlock {
SimpleBlock
}
NetherrackBlock is the class for 'minecraft:netherrack'.
struct NetworkEntry #
struct NetworkEntry {
pub:
name string
properties nbt.RootTag
}
NetworkEntry is the wire form of a custom block: the name plus the block property NBT the session layer wraps into a protocol.BlockEntry.
struct ObsidianBlock #
struct ObsidianBlock {
SimpleBlock
}
ObsidianBlock is the class for 'minecraft:obsidian'.
struct PackedIceBlock #
struct PackedIceBlock {
SimpleBlock
}
PackedIceBlock is the class for 'minecraft:packed_ice'.
struct PaletteEntry #
struct PaletteEntry {
pub:
name string
network_id int
}
PaletteEntry is one block state from the wire palette, in palette order.
struct PolishedAndesiteBlock #
struct PolishedAndesiteBlock {
SimpleBlock
}
PolishedAndesiteBlock is the class for 'minecraft:polished_andesite'.
struct PolishedDioriteBlock #
struct PolishedDioriteBlock {
SimpleBlock
}
PolishedDioriteBlock is the class for 'minecraft:polished_diorite'.
struct PolishedGraniteBlock #
struct PolishedGraniteBlock {
SimpleBlock
}
PolishedGraniteBlock is the class for 'minecraft:polished_granite'.
struct PurpurBlock #
struct PurpurBlock {
SimpleBlock
}
PurpurBlock is the class for 'minecraft:purpur_block'.
struct RedSandBlock #
struct RedSandBlock {
SimpleBlock
}
RedSandBlock is the class for 'minecraft:red_sand'.
struct RedstoneBlock #
struct RedstoneBlock {
SimpleBlock
}
RedstoneBlock is the class for 'minecraft:redstone_block'.
struct RedstoneOreBlock #
struct RedstoneOreBlock {
SimpleBlock
}
RedstoneOreBlock is the class for 'minecraft:redstone_ore'.
struct Registry #
struct Registry {
mut:
by_runtime map[int]Block
by_name map[string]Block
}
Registry maps block runtime ids and namespaced ids to their concrete Block class. The session layer holds one Registry and queries it for per-block behaviour (breakability, hardness, ...) instead of hard-coding runtime ids.
fn (Registry) register #
fn (mut r Registry) register(b Block)
register adds or overrides the class for a block.
fn (Registry) register_fallbacks #
fn (mut r Registry) register_fallbacks(entries []PaletteEntry)
fn (Registry) get #
fn (r &Registry) get(runtime_id int) ?Block
get returns the registered class for a runtime id, or none if unregistered.
fn (Registry) get_by_name #
fn (r &Registry) get_by_name(id string) ?Block
get_by_name returns the registered class for a namespaced id, or none if unregistered.
fn (Registry) breakable #
fn (r &Registry) breakable(runtime_id int) bool
breakable reports whether survival players may destroy the block with the given runtime id. Unregistered blocks fall back to breakable.
fn (Registry) hardness #
fn (r &Registry) hardness(runtime_id int) f32
hardness returns the break hardness for a runtime id, falling back to 1.0 for unregistered blocks.
fn (Registry) len #
fn (r &Registry) len() int
len is the number of registered block classes.
struct RepeaterBlock #
struct RepeaterBlock {
SimpleBlock
next_delay_id int
}
RepeaterBlock is the class for 'minecraft:unpowered_repeater'/ 'minecraft:powered_repeater'.
fn (RepeaterBlock) interact #
fn (b RepeaterBlock) interact(x int, y int, z int, click_face int, mut w TickWorld) bool
struct SandBlock #
struct SandBlock {
SimpleBlock
}
SandBlock is the class for 'minecraft:sand'.
struct SandstoneBlock #
struct SandstoneBlock {
SimpleBlock
}
SandstoneBlock is the class for 'minecraft:sandstone'.
struct ShortGrassBlock #
struct ShortGrassBlock {
SimpleBlock
}
fn (ShortGrassBlock) replaceable #
fn (b ShortGrassBlock) replaceable() bool
struct SimpleBlock #
struct SimpleBlock {
pub:
id string
block_runtime int
break_hardness f32 = 1.0
}
SimpleBlock is the base class for blocks that carry no special behaviour beyond a hardness value. Concrete blocks embed it and fill in their identity; anything unregistered behaves like a default SimpleBlock.
fn (SimpleBlock) identifier #
fn (b SimpleBlock) identifier() string
fn (SimpleBlock) runtime_id #
fn (b SimpleBlock) runtime_id() int
fn (SimpleBlock) hardness #
fn (b SimpleBlock) hardness() f32
fn (SimpleBlock) breakable #
fn (b SimpleBlock) breakable() bool
struct SmoothBasaltBlock #
struct SmoothBasaltBlock {
SimpleBlock
}
SmoothBasaltBlock is the class for 'minecraft:smooth_basalt'.
struct SnowBlock #
struct SnowBlock {
SimpleBlock
}
SnowBlock is the class for 'minecraft:snow'.
struct SoulSandBlock #
struct SoulSandBlock {
SimpleBlock
}
SoulSandBlock is the class for 'minecraft:soul_sand'.
struct SoulSoilBlock #
struct SoulSoilBlock {
SimpleBlock
}
SoulSoilBlock is the class for 'minecraft:soul_soil'.
struct StoneBlock #
struct StoneBlock {
SimpleBlock
}
StoneBlock is the class for 'minecraft:stone'.
struct TuffBlock #
struct TuffBlock {
SimpleBlock
}
TuffBlock is the class for 'minecraft:tuff'.
struct UnbreakableBlock #
struct UnbreakableBlock {
pub:
id string
block_runtime int
}
UnbreakableBlock is the base class for blocks survival players can never destroy (bedrock, barriers). Creative mode bypasses the check in the session layer. Concrete blocks embed it, one class per block.
fn (UnbreakableBlock) identifier #
fn (b UnbreakableBlock) identifier() string
fn (UnbreakableBlock) runtime_id #
fn (b UnbreakableBlock) runtime_id() int
fn (UnbreakableBlock) hardness #
fn (b UnbreakableBlock) hardness() f32
fn (UnbreakableBlock) breakable #
fn (b UnbreakableBlock) breakable() bool
- Constants
- fn combat_progression_blocks
- fn container_blocks
- fn decorative_blocks
- fn farming_blocks
- fn new_andesite
- fn new_bedrock_block
- fn new_blue_ice
- fn new_calcite
- fn new_clay
- fn new_coal_block
- fn new_coal_ore
- fn new_cobbled_deepslate
- fn new_cobblestone
- fn new_copper_block
- fn new_copper_ore
- fn new_custom_registry
- fn new_diamond_block
- fn new_diamond_ore
- fn new_diorite
- fn new_dirt_block
- fn new_dripstone_block
- fn new_emerald_block
- fn new_emerald_ore
- fn new_end_bricks
- fn new_end_stone
- fn new_fern_block
- fn new_glowstone
- fn new_gold_block
- fn new_gold_ore
- fn new_granite
- fn new_grass_block
- fn new_gravel
- fn new_ice
- fn new_iron_block
- fn new_iron_ore
- fn new_lapis_block
- fn new_lapis_ore
- fn new_magma_block
- fn new_mossy_cobblestone
- fn new_netherrack
- fn new_obsidian
- fn new_packed_ice
- fn new_polished_andesite
- fn new_polished_diorite
- fn new_polished_granite
- fn new_purpur_block
- fn new_red_sand
- fn new_redstone_block
- fn new_redstone_ore
- fn new_registry
- fn new_sand
- fn new_sandstone
- fn new_short_grass_block
- fn new_smooth_basalt
- fn new_snow
- fn new_soul_sand
- fn new_soul_soil
- fn new_stone_block
- fn new_tuff
- fn redstone_component_blocks
- fn replaceable_plant_blocks
- fn wood_blocks
- interface Block
- interface Interactable
- interface Punchable
- interface RandomTicker
- interface Replaceable
- interface ScheduledTicker
- interface TickWorld
- struct AndesiteBlock
- struct BedrockBlock
- struct BlueIceBlock
- struct BoxComponent
- struct CalciteBlock
- struct ClayBlock
- struct CoalBlock
- struct CoalOreBlock
- struct CobbledDeepslateBlock
- struct CobblestoneBlock
- struct CopperBlock
- struct CopperOreBlock
- struct CustomBlockDefinition
- struct CustomRegistry
- struct DiamondBlock
- struct DiamondOreBlock
- struct DioriteBlock
- struct DirtBlock
- struct DripstoneBlock
- struct EmeraldBlock
- struct EmeraldOreBlock
- struct EndBricksBlock
- struct EndStoneBlock
- struct FernBlock
- struct GlowstoneBlock
- struct GoldBlock
- struct GoldOreBlock
- struct GraniteBlock
- struct GrassBlock
- struct GravelBlock
- struct IceBlock
- struct IronBlock
- struct IronOreBlock
- struct LapisBlock
- struct LapisOreBlock
- struct MagmaBlock
- struct MaterialInstance
- struct MossyCobblestoneBlock
- struct NetherrackBlock
- struct NetworkEntry
- struct ObsidianBlock
- struct PackedIceBlock
- struct PaletteEntry
- struct PolishedAndesiteBlock
- struct PolishedDioriteBlock
- struct PolishedGraniteBlock
- struct PurpurBlock
- struct RedSandBlock
- struct RedstoneBlock
- struct RedstoneOreBlock
- struct Registry
- struct RepeaterBlock
- struct SandBlock
- struct SandstoneBlock
- struct ShortGrassBlock
- struct SimpleBlock
- struct SmoothBasaltBlock
- struct SnowBlock
- struct SoulSandBlock
- struct SoulSoilBlock
- struct StoneBlock
- struct TuffBlock
- struct UnbreakableBlock