From d53f37d6640c1e598de098ea76cda2a5322ca1d2 Mon Sep 17 00:00:00 2001 From: Zoey Date: Wed, 24 Apr 2024 21:12:13 -0700 Subject: [PATCH] add support for CustomBlocks, closes #19 --- src/level/block.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++ src/packet.rs | 1 + 2 files changed, 50 insertions(+) diff --git a/src/level/block.rs b/src/level/block.rs index f38cd3f..b5faae9 100644 --- a/src/level/block.rs +++ b/src/level/block.rs @@ -98,6 +98,43 @@ pub static BLOCK_INFO: LazyLock> = LazyLock::new(|| { (0x2f, BlockInfo::new("bookshelf")), (0x30, BlockInfo::new("mossy_cobblestone")), (0x31, BlockInfo::new("obsidian")), + // CustomBlocks blocks + ( + 0x32, + BlockInfo::new("cobblestone_slab") + .block_type(BlockType::Slab) + .fallback(0x2c), + ), + ( + 0x33, + BlockInfo::new("rope") + .block_type(BlockType::Rope) + .fallback(0x27), + ), + (0x34, BlockInfo::new("sandstone").fallback(0x0c)), + ( + 0x35, + BlockInfo::new("snow") + .block_type(BlockType::NonSolid) + .fallback(0x00), + ), + ( + 0x36, + BlockInfo::new("fire") + .block_type(BlockType::NonSolid) + .fallback(0x0a), + ), + (0x37, BlockInfo::new("cloth_light_pink").fallback(0x21)), + (0x38, BlockInfo::new("cloth_forest_green").fallback(0x19)), + (0x39, BlockInfo::new("cloth_brown").fallback(0x03)), + (0x3a, BlockInfo::new("cloth_deep_blue").fallback(0x1d)), + (0x3b, BlockInfo::new("cloth_turquoise").fallback(0x1c)), + (0x3c, BlockInfo::new("ice").fallback(0x14)), + (0x3d, BlockInfo::new("ceramic_tile").fallback(0x2a)), + (0x3e, BlockInfo::new("magma").fallback(0x31)), + (0x3f, BlockInfo::new("pillar").fallback(0x24)), + (0x40, BlockInfo::new("crate").fallback(0x05)), + (0x41, BlockInfo::new("stone_brick").fallback(0x01)), ] .into() }); @@ -121,6 +158,8 @@ pub struct BlockInfo { pub place_permissions: PlayerType, /// permissions needed to break this block (includes replacing fluids) pub break_permissions: PlayerType, + /// the block used as fallback if the client doesn't support it + pub fallback: Option, } impl BlockInfo { @@ -131,6 +170,7 @@ impl BlockInfo { block_type: BlockType::Solid, place_permissions: PlayerType::Normal, break_permissions: PlayerType::Normal, + fallback: None, } } @@ -146,6 +186,13 @@ impl BlockInfo { self.break_permissions = brk; self } + + /// sets the block's fallback block + pub const fn fallback(mut self, fallback: u8) -> Self { + assert!(fallback <= 0x31, "fallback must be under 0x31!"); + self.fallback = Some(fallback); + self + } } /// types of blocks @@ -164,6 +211,8 @@ pub enum BlockType { }, /// fluid which is stationary FluidStationary { moving: u8 }, + /// a block which is climbable like the rope block + Rope, } impl BlockType { diff --git a/src/packet.rs b/src/packet.rs index 1aaf556..0160f9c 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -196,6 +196,7 @@ impl ExtBitmask { fn info(self) -> Option { // TODO: add entries as extensions are supported Some(match self { + Self::CustomBlocks => ExtInfo::new("CustomBlocks".to_string(), 1, Self::CustomBlocks), // this isn't actually used by the server at all, but it technically sort of implements it Self::HeldBlock => ExtInfo::new("HeldBlock".to_string(), 1, Self::HeldBlock), Self::EmoteFix => ExtInfo::new("EmoteFix".to_string(), 1, Self::EmoteFix),