feat(plugin-api): expand block state

This commit is contained in:
Alexander Medvedev 2026-05-17 21:22:05 +02:00
parent 4a4b72c83c
commit 5daee97744
2 changed files with 139 additions and 1 deletions

View File

@ -93,6 +93,75 @@ interface %world {
piston-behavior: piston-behavior, piston-behavior: piston-behavior,
/// Whether this block receives random ticks. /// Whether this block receives random ticks.
has-random-ticks: bool, has-random-ticks: bool,
/// Whether this block can catch fire.
burnable: bool,
/// Whether a specific tool is required to mine this block and get drops.
tool-required: bool,
/// Whether this block has transparency on its sides.
sided-transparency: bool,
/// Whether this block can be replaced by another block (e.g., grass).
replaceable: bool,
/// Whether this block is considered a solid block for redstone purposes.
is-solid-block: bool,
/// The numerical ID of the block entity type, if any.
block-entity-type: u16,
/// The instrument used for note blocks when placed on top of this block.
instrument: noteblock-instrument,
/// The collision shapes of this block.
collision-shapes: list<bounding-box>,
/// The outline shapes of this block.
outline-shapes: list<bounding-box>,
/// Whether the bottom side of the block is solid.
down-side-solid: bool,
/// Whether the top side of the block is solid.
up-side-solid: bool,
/// Whether the north side of the block is solid.
north-side-solid: bool,
/// Whether the south side of the block is solid.
south-side-solid: bool,
/// Whether the west side of the block is solid.
west-side-solid: bool,
/// Whether the east side of the block is solid.
east-side-solid: bool,
/// Whether the center of the bottom side is solid.
down-center-solid: bool,
/// Whether the center of the top side is solid.
up-center-solid: bool,
/// The color of this block when displayed on a map.
map-color: u8,
}
/// Musical instruments used by note blocks.
enum noteblock-instrument {
harp,
basedrum,
snare,
hat,
bass,
flute,
bell,
guitar,
chime,
xylophone,
iron-xylophone,
cow-bell,
didgeridoo,
bit,
banjo,
pling,
trumpet,
trumpet-exposed,
trumpet-oxidized,
trumpet-weathered,
zombie,
skeleton,
creeper,
dragon,
wither-skeleton,
piglin,
custom-head,
} }
/// A simple wrapper for a block state ID. /// A simple wrapper for a block state ID.

View File

@ -1,4 +1,5 @@
use pumpkin_data::BlockDirection as InternalBlockDirection; use pumpkin_data::BlockDirection as InternalBlockDirection;
use pumpkin_data::block_properties::NoteblockInstrument as InternalNoteblockInstrument;
use pumpkin_data::block_state::PistonBehavior; use pumpkin_data::block_state::PistonBehavior;
use pumpkin_util::math::position::BlockPos; use pumpkin_util::math::position::BlockPos;
use pumpkin_world::chunk::ChunkHeightmapType; use pumpkin_world::chunk::ChunkHeightmapType;
@ -13,7 +14,8 @@ use crate::block::entities::mob_spawner::MobSpawnerBlockEntity as InternalMobSpa
use crate::block::entities::sign::SignBlockEntity as InternalSignBlockEntity; use crate::block::entities::sign::SignBlockEntity as InternalSignBlockEntity;
use crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::world::{ use crate::plugin::loader::wasm::wasm_host::wit::v0_1::pumpkin::plugin::world::{
BlockDirection as WitBlockDirection, BlockEntity, BlockEntityType, BlockFlags as WitBlockFlags, BlockDirection as WitBlockDirection, BlockEntity, BlockEntityType, BlockFlags as WitBlockFlags,
BlockPos as WitBlockPos, BlockState as WitBlockState, PistonBehavior as WitPistonBehavior, BlockPos as WitBlockPos, BlockState as WitBlockState, BoundingBox as WitBoundingBox,
NoteblockInstrument as WitNoteblockInstrument, PistonBehavior as WitPistonBehavior,
}; };
use crate::plugin::loader::wasm::wasm_host::{ use crate::plugin::loader::wasm::wasm_host::{
state::{PluginHostState, TextComponentResource, WorldResource}, state::{PluginHostState, TextComponentResource, WorldResource},
@ -32,6 +34,49 @@ pub(crate) const fn to_wasm_block_direction(dir: InternalBlockDirection) -> WitB
} }
} }
pub(crate) const fn to_wit_noteblock_instrument(
instr: InternalNoteblockInstrument,
) -> WitNoteblockInstrument {
match instr {
InternalNoteblockInstrument::Harp => WitNoteblockInstrument::Harp,
InternalNoteblockInstrument::Basedrum => WitNoteblockInstrument::Basedrum,
InternalNoteblockInstrument::Snare => WitNoteblockInstrument::Snare,
InternalNoteblockInstrument::Hat => WitNoteblockInstrument::Hat,
InternalNoteblockInstrument::Bass => WitNoteblockInstrument::Bass,
InternalNoteblockInstrument::Flute => WitNoteblockInstrument::Flute,
InternalNoteblockInstrument::Bell => WitNoteblockInstrument::Bell,
InternalNoteblockInstrument::Guitar => WitNoteblockInstrument::Guitar,
InternalNoteblockInstrument::Chime => WitNoteblockInstrument::Chime,
InternalNoteblockInstrument::Xylophone => WitNoteblockInstrument::Xylophone,
InternalNoteblockInstrument::IronXylophone => WitNoteblockInstrument::IronXylophone,
InternalNoteblockInstrument::CowBell => WitNoteblockInstrument::CowBell,
InternalNoteblockInstrument::Didgeridoo => WitNoteblockInstrument::Didgeridoo,
InternalNoteblockInstrument::Bit => WitNoteblockInstrument::Bit,
InternalNoteblockInstrument::Banjo => WitNoteblockInstrument::Banjo,
InternalNoteblockInstrument::Pling => WitNoteblockInstrument::Pling,
InternalNoteblockInstrument::Trumpet => WitNoteblockInstrument::Trumpet,
InternalNoteblockInstrument::TrumpetExposed => WitNoteblockInstrument::TrumpetExposed,
InternalNoteblockInstrument::TrumpetOxidized => WitNoteblockInstrument::TrumpetOxidized,
InternalNoteblockInstrument::TrumpetWeathered => WitNoteblockInstrument::TrumpetWeathered,
InternalNoteblockInstrument::Zombie => WitNoteblockInstrument::Zombie,
InternalNoteblockInstrument::Skeleton => WitNoteblockInstrument::Skeleton,
InternalNoteblockInstrument::Creeper => WitNoteblockInstrument::Creeper,
InternalNoteblockInstrument::Dragon => WitNoteblockInstrument::Dragon,
InternalNoteblockInstrument::WitherSkeleton => WitNoteblockInstrument::WitherSkeleton,
InternalNoteblockInstrument::Piglin => WitNoteblockInstrument::Piglin,
InternalNoteblockInstrument::CustomHead => WitNoteblockInstrument::CustomHead,
}
}
pub(crate) const fn to_wit_bounding_box(
bb: pumpkin_util::math::boundingbox::BoundingBox,
) -> WitBoundingBox {
WitBoundingBox {
min: (bb.min.x, bb.min.y, bb.min.z),
max: (bb.max.x, bb.max.y, bb.max.z),
}
}
// --- Trapping Helpers --- // --- Trapping Helpers ---
impl PluginHostState { impl PluginHostState {
fn get_world_res(&self, res: &Resource<World>) -> wasmtime::Result<&WorldResource> { fn get_world_res(&self, res: &Resource<World>) -> wasmtime::Result<&WorldResource> {
@ -102,6 +147,30 @@ impl pumpkin::plugin::world::HostWorld for PluginHostState {
PistonBehavior::Ignore => WitPistonBehavior::Ignore, PistonBehavior::Ignore => WitPistonBehavior::Ignore,
PistonBehavior::PushOnly => WitPistonBehavior::PushOnly, PistonBehavior::PushOnly => WitPistonBehavior::PushOnly,
}, },
burnable: state.burnable(),
tool_required: state.tool_required(),
sided_transparency: state.sided_transparency(),
replaceable: state.replaceable(),
is_solid_block: state.is_solid_block(),
block_entity_type: state.block_entity_type,
instrument: to_wit_noteblock_instrument(state.instrument),
collision_shapes: state
.get_block_collision_shapes()
.map(to_wit_bounding_box)
.collect(),
outline_shapes: state
.get_block_outline_shapes()
.map(to_wit_bounding_box)
.collect(),
down_side_solid: state.is_side_solid(InternalBlockDirection::Down),
up_side_solid: state.is_side_solid(InternalBlockDirection::Up),
north_side_solid: state.is_side_solid(InternalBlockDirection::North),
south_side_solid: state.is_side_solid(InternalBlockDirection::South),
west_side_solid: state.is_side_solid(InternalBlockDirection::West),
east_side_solid: state.is_side_solid(InternalBlockDirection::East),
down_center_solid: state.is_center_solid(InternalBlockDirection::Down),
up_center_solid: state.is_center_solid(InternalBlockDirection::Up),
map_color: pumpkin_data::Block::from_state_id(state.id).map_color,
}) })
} }