Skip to content

Commit

Permalink
feat: leaves and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Liyze09 committed Sep 24, 2024
1 parent 364de3c commit 20bcce1
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 6 deletions.
24 changes: 24 additions & 0 deletions src/block.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 }
}
}
};
}
11 changes: 11 additions & 0 deletions src/block/birch_leaves.rs
Original file line number Diff line number Diff line change
@@ -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::<BirchLeavesBlockState>(BIRCH_LEAVES, BlockSettings::new().strength(0.2))
}
block_state!(BirchLeavesBlockState, LeavesProperties, BIRCH_LEAVES);
27 changes: 27 additions & 0 deletions src/block/birch_log.rs
Original file line number Diff line number Diff line change
@@ -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::<BirchLogBlockState>(
BIRCH_LOG,
BlockSettings::new().strength(2.0),
),
}
}
}

block_state!(BirchLogBlockState, LogProperties, BIRCH_LOG);
3 changes: 2 additions & 1 deletion src/block/deepslate.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::block::logs::Axis;
use crate::block::*;
use crate::block_state;
use serde_derive::Deserialize;
Expand All @@ -24,7 +25,7 @@ impl DeepSlate {

#[derive(Deserialize)]
pub struct DeepSlateProperties {
axis: String,
axis: Axis,
}

block_state!(DeepSlateBlockState, DeepSlateProperties, DEEPSLATE);
28 changes: 28 additions & 0 deletions src/block/leaves.rs
Original file line number Diff line number Diff line change
@@ -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,
}
16 changes: 16 additions & 0 deletions src/block/logs.rs
Original file line number Diff line number Diff line change
@@ -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,
}
11 changes: 11 additions & 0 deletions src/block/oak_leaves.rs
Original file line number Diff line number Diff line change
@@ -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::<OakLeavesBlockState>(OAK_LEAVES, BlockSettings::new().strength(0.2))
}
block_state!(OakLeavesBlockState, LeavesProperties, OAK_LEAVES);
7 changes: 2 additions & 5 deletions src/block/oak_log.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::block::logs::LogProperties;
use crate::block::*;
use crate::block_state;
use serde_derive::Deserialize;
Expand All @@ -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);
6 changes: 6 additions & 0 deletions src/registry/registries.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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()));
}

0 comments on commit 20bcce1

Please sign in to comment.