diff options
| author | mat <github@matdoes.dev> | 2022-05-27 16:04:22 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-27 16:04:22 -0500 |
| commit | aac64d013546c8be3b992af63d70150155386c11 (patch) | |
| tree | 5241eda4c71ad5d6093b7759fc7ec8feab18863c | |
| parent | 86cc2a9b7c85b0cb412fa8cbe2ab6b9a7ae5fcfc (diff) | |
| download | azalea-drasl-aac64d013546c8be3b992af63d70150155386c11.tar.xz | |
Start making azalea-block
| -rwxr-xr-x | Cargo.lock | 4 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | azalea-block/Cargo.toml | 8 | ||||
| -rw-r--r-- | azalea-block/README.md | 8 | ||||
| -rw-r--r-- | azalea-block/src/behavior.rs | 3 | ||||
| -rw-r--r-- | azalea-block/src/blocks.rs | 88 | ||||
| -rw-r--r-- | azalea-block/src/lib.rs | 5 | ||||
| -rw-r--r-- | azalea-block/src/properties.rs | 20 |
8 files changed, 137 insertions, 0 deletions
@@ -79,6 +79,10 @@ dependencies = [ ] [[package]] +name = "azalea-block" +version = "0.1.0" + +[[package]] name = "azalea-brigadier" version = "0.1.0" @@ -11,6 +11,7 @@ members = [ "azalea-crypto", "azalea-world", "azalea-language", + "azalea-block", ] [profile.release] diff --git a/azalea-block/Cargo.toml b/azalea-block/Cargo.toml new file mode 100644 index 00000000..ea43e8ae --- /dev/null +++ b/azalea-block/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "azalea-block" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/azalea-block/README.md b/azalea-block/README.md new file mode 100644 index 00000000..39843ef4 --- /dev/null +++ b/azalea-block/README.md @@ -0,0 +1,8 @@ +# Azalea Block + +Representation of Minecraft block states. + +There's two main things here, the `BlockState` enum and the `Block` trait. +`BlockState` is a simple enum with every possible block state as variant, and `Block` is a heavier trait which lets you access information about a block more easily. + +Every block is a struct that implements `Block`. You can freely convert between `BlockState` and `Block` with .into(). diff --git a/azalea-block/src/behavior.rs b/azalea-block/src/behavior.rs new file mode 100644 index 00000000..974260f2 --- /dev/null +++ b/azalea-block/src/behavior.rs @@ -0,0 +1,3 @@ +pub struct BlockBehavior { + pub has_collision: bool, +} diff --git a/azalea-block/src/blocks.rs b/azalea-block/src/blocks.rs new file mode 100644 index 00000000..f6f33a89 --- /dev/null +++ b/azalea-block/src/blocks.rs @@ -0,0 +1,88 @@ +use crate::{behavior::BlockBehavior, properties}; + +// make_block_states! { +// acacia_button => BlockBehavior { has_collision: false }, { +// Face, +// Facing, +// Powered +// }; +// acacia_door => BlockBehavior { has_collision: true }, { +// Facing, +// Half, +// Hinge, +// Open, +// Powered +// }; +// } + +// the underscore makes it more readable, so i think it's fine to allow it +#[allow(non_camel_case_types)] +pub enum BlockState { + AcaciaButton_FloorNorthTrue, + AcaciaButton_WallNorthTrue, + AcaciaButton_CeilingNorthTrue, +} + +pub trait Block { + fn behavior(&self) -> BlockBehavior; +} + +#[derive(Debug)] +pub struct AcaciaButtonBlock { + pub face: properties::Face, + pub facing: properties::Facing, + pub powered: properties::Powered, +} + +impl Block for AcaciaButtonBlock { + fn behavior(&self) -> BlockBehavior { + BlockBehavior { + has_collision: false, + } + } +} + +pub struct AcaciaDoorBlock { + pub facing: properties::Facing, + // pub half: properties::Half, + // pub hinge: properties::Hinge, + // pub open: properties::Open, + pub powered: properties::Powered, +} + +impl From<BlockState> for &dyn Block { + fn from(b: BlockState) -> Self { + match b { + BlockState::AcaciaButton_FloorNorthTrue => &AcaciaButtonBlock { + face: properties::Face::Floor, + facing: properties::Facing::North, + powered: properties::Powered::True, + }, + // BlockState::AcaciaButton_WallNorthTrue => todo!(), + // BlockState::AcaciaButton_CeilingNorthTrue => todo!(), + _ => todo!(), + } + } +} +impl From<AcaciaButtonBlock> for BlockState { + fn from(b: AcaciaButtonBlock) -> Self { + match b { + AcaciaButtonBlock { + face: properties::Face::Floor, + facing: properties::Facing::North, + powered: properties::Powered::True, + } => BlockState::AcaciaButton_FloorNorthTrue, + // AcaciaButtonBlock { + // face: properties::Face::Wall, + // facing: properties::Facing::North, + // powered: properties::Powered::True, + // } => todo!(), + // AcaciaButtonBlock { + // face: properties::Face::Ceiling, + // facing: properties::Facing::North, + // powered: properties::Powered::True, + // } => todo!(), + _ => todo!(), + } + } +} diff --git a/azalea-block/src/lib.rs b/azalea-block/src/lib.rs new file mode 100644 index 00000000..db94d081 --- /dev/null +++ b/azalea-block/src/lib.rs @@ -0,0 +1,5 @@ +pub mod behavior; +pub mod blocks; +pub mod properties; + +use std::fmt::Debug; diff --git a/azalea-block/src/properties.rs b/azalea-block/src/properties.rs new file mode 100644 index 00000000..ac81fcb3 --- /dev/null +++ b/azalea-block/src/properties.rs @@ -0,0 +1,20 @@ +#[derive(Debug, Clone, Copy)] +pub enum Face { + Floor, + Wall, + Ceiling, +} + +#[derive(Debug, Clone, Copy)] +pub enum Facing { + North, + South, + West, + East, +} + +#[derive(Debug, Clone, Copy)] +pub enum Powered { + True, + False, +} |
