feat(block): implement structure block
This commit is contained in:
parent
56c3d6c134
commit
be279fa274
@ -118,6 +118,7 @@ pub mod fletching_table;
|
|||||||
pub mod loom;
|
pub mod loom;
|
||||||
pub mod smithing_table;
|
pub mod smithing_table;
|
||||||
pub mod sniffer_egg;
|
pub mod sniffer_egg;
|
||||||
|
pub mod structure_block;
|
||||||
pub mod trial_spawner;
|
pub mod trial_spawner;
|
||||||
pub mod turtle_egg;
|
pub mod turtle_egg;
|
||||||
pub mod vault;
|
pub mod vault;
|
||||||
|
|||||||
33
crates/pumpkin/src/block/blocks/structure_block.rs
Normal file
33
crates/pumpkin/src/block/blocks/structure_block.rs
Normal 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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -356,6 +356,10 @@ pub fn create_block_entity(
|
|||||||
"creaking_heart" => Some(Arc::new(creaking_heart::CreakingHeartBlockEntity::new(
|
"creaking_heart" => Some(Arc::new(creaking_heart::CreakingHeartBlockEntity::new(
|
||||||
position,
|
position,
|
||||||
))),
|
))),
|
||||||
|
"piston" => Some(Arc::new(piston::PistonBlockEntity::from_nbt(
|
||||||
|
&pumpkin_nbt::compound::NbtCompound::new(),
|
||||||
|
position,
|
||||||
|
))),
|
||||||
"brewing_stand" => Some(Arc::new(brewing_stand::BrewingStandBlockEntity::new(
|
"brewing_stand" => Some(Arc::new(brewing_stand::BrewingStandBlockEntity::new(
|
||||||
position,
|
position,
|
||||||
))),
|
))),
|
||||||
|
|||||||
@ -138,6 +138,7 @@ use crate::block::blocks::snow::LayeredSnowBlock;
|
|||||||
use crate::block::blocks::spawner::SpawnerBlock;
|
use crate::block::blocks::spawner::SpawnerBlock;
|
||||||
use crate::block::blocks::sponge::{SpongeBlock, WetSpongeBlock};
|
use crate::block::blocks::sponge::{SpongeBlock, WetSpongeBlock};
|
||||||
use crate::block::blocks::stairs::StairBlock;
|
use crate::block::blocks::stairs::StairBlock;
|
||||||
|
use crate::block::blocks::structure_block::StructureBlock;
|
||||||
use crate::block::blocks::tnt::TNTBlock;
|
use crate::block::blocks::tnt::TNTBlock;
|
||||||
use crate::block::blocks::torches::TorchBlock;
|
use crate::block::blocks::torches::TorchBlock;
|
||||||
use crate::block::blocks::trapdoor::TrapDoorBlock;
|
use crate::block::blocks::trapdoor::TrapDoorBlock;
|
||||||
@ -257,6 +258,7 @@ pub fn default_registry() -> Arc<BlockRegistry> {
|
|||||||
manager.register(CartographyTableBlock);
|
manager.register(CartographyTableBlock);
|
||||||
manager.register(SmithingTableBlock);
|
manager.register(SmithingTableBlock);
|
||||||
manager.register(FletchingTableBlock);
|
manager.register(FletchingTableBlock);
|
||||||
|
manager.register(StructureBlock);
|
||||||
manager.register(ShortPlantBlock);
|
manager.register(ShortPlantBlock);
|
||||||
manager.register(DryVegetationBlock);
|
manager.register(DryVegetationBlock);
|
||||||
manager.register(LilyPadBlock);
|
manager.register(LilyPadBlock);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user