feat(block): implement structure block

This commit is contained in:
Alexander Medvedev
2026-08-12 21:05:18 +02:00
parent 56c3d6c134
commit be279fa274
4 changed files with 40 additions and 0 deletions

View File

@@ -118,6 +118,7 @@ pub mod fletching_table;
pub mod loom;
pub mod smithing_table;
pub mod sniffer_egg;
pub mod structure_block;
pub mod trial_spawner;
pub mod turtle_egg;
pub mod vault;

View File

@@ -0,0 +1,33 @@
use crate::block::registry::BlockActionResult;
use crate::block::{BlockBehaviour, BlockFuture, NormalUseArgs, OnPlaceArgs};
use pumpkin_data::BlockStateId;
use pumpkin_data::block_properties::{BlockProperties, StructureBlockLikeProperties};
use pumpkin_macros::pumpkin_block;
use pumpkin_util::PermissionLvl;
#[pumpkin_block("minecraft:structure_block")]
pub struct StructureBlock;
impl BlockBehaviour for StructureBlock {
fn on_place<'a>(&'a self, args: OnPlaceArgs<'a>) -> BlockFuture<'a, BlockStateId> {
Box::pin(async move {
let props = StructureBlockLikeProperties::default(args.block);
props.to_state_id(args.block)
})
}
fn normal_use<'a>(&'a self, args: NormalUseArgs<'a>) -> BlockFuture<'a, BlockActionResult> {
Box::pin(async move {
if args.player.permission_lvl.load() < PermissionLvl::Two {
return BlockActionResult::Pass;
}
let Some(block_entity) = args.world.get_block_entity(args.position) else {
return BlockActionResult::Pass;
};
args.world.update_block_entity(&block_entity);
BlockActionResult::Success
})
}
}

View File

@@ -356,6 +356,10 @@ pub fn create_block_entity(
"creaking_heart" => Some(Arc::new(creaking_heart::CreakingHeartBlockEntity::new(
position,
))),
"piston" => Some(Arc::new(piston::PistonBlockEntity::from_nbt(
&pumpkin_nbt::compound::NbtCompound::new(),
position,
))),
"brewing_stand" => Some(Arc::new(brewing_stand::BrewingStandBlockEntity::new(
position,
))),

View File

@@ -138,6 +138,7 @@ use crate::block::blocks::snow::LayeredSnowBlock;
use crate::block::blocks::spawner::SpawnerBlock;
use crate::block::blocks::sponge::{SpongeBlock, WetSpongeBlock};
use crate::block::blocks::stairs::StairBlock;
use crate::block::blocks::structure_block::StructureBlock;
use crate::block::blocks::tnt::TNTBlock;
use crate::block::blocks::torches::TorchBlock;
use crate::block::blocks::trapdoor::TrapDoorBlock;
@@ -257,6 +258,7 @@ pub fn default_registry() -> Arc<BlockRegistry> {
manager.register(CartographyTableBlock);
manager.register(SmithingTableBlock);
manager.register(FletchingTableBlock);
manager.register(StructureBlock);
manager.register(ShortPlantBlock);
manager.register(DryVegetationBlock);
manager.register(LilyPadBlock);