diff --git a/src/block.rs b/src/block.rs index 98401e1..d41bfd7 100644 --- a/src/block.rs +++ b/src/block.rs @@ -1,6 +1,11 @@ +pub mod birch_leaves; +pub mod birch_log; pub mod deepslate; pub mod dirt; pub mod grass_block; +pub mod leaves; +pub mod logs; +pub mod oak_leaves; pub mod oak_log; pub mod stone; @@ -183,3 +188,22 @@ macro_rules! empty_block_state { } }; } + +#[macro_export] +macro_rules! block_def { + ($name:tt, $builder:expr) => { + pub struct $name { + pub builder: BlockBuilder, + } + impl Block for $name { + fn get_builder(&self) -> &BlockBuilder { + &self.builder + } + } + impl $name { + pub(crate) fn new() -> $name { + $name { builder: $builder } + } + } + }; +} diff --git a/src/block/birch_leaves.rs b/src/block/birch_leaves.rs new file mode 100644 index 0000000..079b86f --- /dev/null +++ b/src/block/birch_leaves.rs @@ -0,0 +1,11 @@ +use crate::block::leaves::LeavesProperties; +use crate::block::*; +use crate::{block_def, block_state}; +use serde_derive::Deserialize; + +pub const BIRCH_LEAVES: &str = "minecraft:birch_leaves"; +block_def! { + BirchLeaves, + BlockBuilder::new::(BIRCH_LEAVES, BlockSettings::new().strength(0.2)) +} +block_state!(BirchLeavesBlockState, LeavesProperties, BIRCH_LEAVES); diff --git a/src/block/birch_log.rs b/src/block/birch_log.rs new file mode 100644 index 0000000..d99102f --- /dev/null +++ b/src/block/birch_log.rs @@ -0,0 +1,27 @@ +use crate::block::logs::LogProperties; +use crate::block::*; +use crate::block_state; +use serde_derive::Deserialize; + +pub const BIRCH_LOG: &str = "minecraft:birch_log"; +pub struct BirchLog { + pub builder: BlockBuilder, +} +impl Block for BirchLog { + fn get_builder(&self) -> &BlockBuilder { + &self.builder + } +} + +impl BirchLog { + pub(crate) fn new() -> BirchLog { + BirchLog { + builder: BlockBuilder::new::( + BIRCH_LOG, + BlockSettings::new().strength(2.0), + ), + } + } +} + +block_state!(BirchLogBlockState, LogProperties, BIRCH_LOG); diff --git a/src/block/deepslate.rs b/src/block/deepslate.rs index c4f0653..7532c68 100644 --- a/src/block/deepslate.rs +++ b/src/block/deepslate.rs @@ -1,3 +1,4 @@ +use crate::block::logs::Axis; use crate::block::*; use crate::block_state; use serde_derive::Deserialize; @@ -24,7 +25,7 @@ impl DeepSlate { #[derive(Deserialize)] pub struct DeepSlateProperties { - axis: String, + axis: Axis, } block_state!(DeepSlateBlockState, DeepSlateProperties, DEEPSLATE); diff --git a/src/block/leaves.rs b/src/block/leaves.rs new file mode 100644 index 0000000..2ffc261 --- /dev/null +++ b/src/block/leaves.rs @@ -0,0 +1,28 @@ +use serde_derive::{Deserialize, Serialize}; + +#[derive(Serialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize)] +pub enum Distance { + #[serde(rename = "0")] + D0, + #[serde(rename = "1")] + D1, + #[serde(rename = "2")] + D2, + #[serde(rename = "3")] + D3, + #[serde(rename = "4")] + D4, + #[serde(rename = "5")] + D5, + #[serde(rename = "6")] + D6, + #[serde(rename = "7")] + D7, +} + +#[derive(Serialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize)] +pub struct LeavesProperties { + distance: Distance, + persistent: bool, + waterlogged: bool, +} diff --git a/src/block/logs.rs b/src/block/logs.rs new file mode 100644 index 0000000..f5d03e7 --- /dev/null +++ b/src/block/logs.rs @@ -0,0 +1,16 @@ +use serde_derive::{Deserialize, Serialize}; + +#[derive(Serialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize)] +pub enum Axis { + #[serde(rename = "x")] + X, + #[serde(rename = "y")] + Y, + #[serde(rename = "z")] + Z, +} + +#[derive(Serialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize)] +pub struct LogProperties { + axis: Axis, +} diff --git a/src/block/oak_leaves.rs b/src/block/oak_leaves.rs new file mode 100644 index 0000000..dc87a12 --- /dev/null +++ b/src/block/oak_leaves.rs @@ -0,0 +1,11 @@ +use crate::block::leaves::LeavesProperties; +use crate::block::*; +use crate::{block_def, block_state}; +use serde_derive::Deserialize; + +pub const OAK_LEAVES: &str = "minecraft:oak_leaves"; +block_def! { + OakLeaves, + BlockBuilder::new::(OAK_LEAVES, BlockSettings::new().strength(0.2)) +} +block_state!(OakLeavesBlockState, LeavesProperties, OAK_LEAVES); diff --git a/src/block/oak_log.rs b/src/block/oak_log.rs index 7a1ec49..af9291b 100644 --- a/src/block/oak_log.rs +++ b/src/block/oak_log.rs @@ -1,3 +1,4 @@ +use crate::block::logs::LogProperties; use crate::block::*; use crate::block_state; use serde_derive::Deserialize; @@ -23,8 +24,4 @@ impl OakLog { } } -block_state!(OakLogBlockState, OakLogProperties, OAK_LOG); -#[derive(Deserialize)] -pub struct OakLogProperties { - axis: String, -} +block_state!(OakLogBlockState, LogProperties, OAK_LOG); diff --git a/src/registry/registries.rs b/src/registry/registries.rs index a2a2b2c..e47ecf8 100644 --- a/src/registry/registries.rs +++ b/src/registry/registries.rs @@ -1,6 +1,9 @@ +use crate::block::birch_leaves::{BirchLeaves, BIRCH_LEAVES}; +use crate::block::birch_log::{BirchLog, BIRCH_LOG}; use crate::block::deepslate::{DeepSlate, DEEPSLATE}; use crate::block::dirt::{Dirt, DIRT}; use crate::block::grass_block::{GrassBlock, GRASS_BLOCK}; +use crate::block::oak_leaves::{OakLeaves, OAK_LEAVES}; use crate::block::oak_log::{OakLog, OAK_LOG}; use crate::block::register_block; use crate::block::stone::{Stone, STONE}; @@ -11,4 +14,7 @@ pub(crate) fn register_vanilla() { register_block(DIRT, Box::new(Dirt::new())); register_block(DEEPSLATE, Box::new(DeepSlate::new())); register_block(OAK_LOG, Box::new(OakLog::new())); + register_block(OAK_LEAVES, Box::new(OakLeaves::new())); + register_block(BIRCH_LOG, Box::new(BirchLog::new())); + register_block(BIRCH_LEAVES, Box::new(BirchLeaves::new())); }