1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

start adding shapes

This commit is contained in:
mat 2022-09-05 17:37:18 -05:00
parent eb6328ddc6
commit 3364b82a1e
9 changed files with 68 additions and 44 deletions

1
Cargo.lock generated
View file

@ -226,6 +226,7 @@ dependencies = [
"azalea-block",
"azalea-core",
"azalea-world",
"lazy_static",
"uuid",
]

View file

@ -426,38 +426,38 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
quote! { BlockState::#block_name_pascal_case }
};
let block_struct = quote! {
#[derive(Debug)]
pub struct #block_struct_name {
#block_struct_fields
}
let block_struct = quote! {
#[derive(Debug)]
pub struct #block_struct_name {
#block_struct_fields
}
impl Block for #block_struct_name {
fn behavior(&self) -> BlockBehavior {
#block_behavior
}
fn id(&self) -> &'static str {
#block_id
impl Block for #block_struct_name {
fn behavior(&self) -> BlockBehavior {
#block_behavior
}
fn id(&self) -> &'static str {
#block_id
}
}
impl From<#block_struct_name> for BlockState {
fn from(b: #block_struct_name) -> Self {
#from_block_to_state_match
}
}
impl Default for #block_struct_name {
fn default() -> Self {
Self {
#block_default_fields
}
}
}
};
impl From<#block_struct_name> for BlockState {
fn from(b: #block_struct_name) -> Self {
#from_block_to_state_match
}
}
impl Default for #block_struct_name {
fn default() -> Self {
Self {
#block_default_fields
}
}
}
};
block_structs.extend(block_struct);
}
block_structs.extend(block_struct);
}
let last_state_id = (state_id - 1) as u32;
let mut generated = quote! {
@ -478,19 +478,19 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
}
};
generated.extend(quote! {
#block_structs
generated.extend(quote! {
#block_structs
impl From<BlockState> for Box<dyn Block> {
fn from(b: BlockState) -> Self {
let b = b as usize;
match b {
#from_state_to_block_match
_ => panic!("Invalid block state: {}", b),
}
impl From<BlockState> for Box<dyn Block> {
fn from(b: BlockState) -> Self {
let b = b as usize;
match b {
#from_state_to_block_match
_ => panic!("Invalid block state: {}", b),
}
}
});
}
});
generated.into()
}

View file

@ -7,5 +7,5 @@ pub mod message;
pub mod modifier;
pub mod parse_results;
pub mod string_reader;
pub mod tree;
pub mod suggestion;
pub mod tree;

View file

@ -53,4 +53,4 @@ impl McBufWritable for BitSet {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
self.data.write_into(buf)
}
}
}

View file

@ -11,6 +11,7 @@ version = "0.1.0"
azalea-block = {path = "../azalea-block", version = "^0.1.0"}
azalea-core = {path = "../azalea-core", version = "^0.1.0"}
azalea-world = {path = "../azalea-world", version = "^0.1.0"}
lazy_static = "1.4.0"
[dev-dependencies]
uuid = "^1.1.2"

View file

@ -0,0 +1,22 @@
//! Autogenerated block collisions for every block
use super::{BitSetDiscreteVoxelShape, CubeVoxelShape, VoxelShape};
use lazy_static::lazy_static;
trait BlockWithShape {
fn shape(&self) -> &'static dyn VoxelShape;
}
lazy_static! {
static ref SHAPE1: CubeVoxelShape = {
let mut shape = BitSetDiscreteVoxelShape::new(1, 1, 1);
shape.fill(0, 0, 0);
CubeVoxelShape::new(Box::new(shape))
};
}
impl BlockWithShape for azalea_block::StoneSlabBlock {
fn shape(&self) -> &'static dyn VoxelShape {
&*SHAPE1
}
}

View file

@ -2,7 +2,7 @@ use azalea_core::{Axis, AxisCycle, BitSet};
// TODO: every impl of DiscreteVoxelShape could be turned into a single enum as an optimization
pub trait DiscreteVoxelShape {
pub trait DiscreteVoxelShape: Send + Sync {
fn size(&self, axis: Axis) -> u32;
fn first_full_x(&self) -> u32;

View file

@ -1,3 +1,4 @@
mod blocks;
mod dimension_collisions;
mod discrete_voxel_shape;
mod shape;

View file

@ -35,7 +35,7 @@ impl Shapes {
}
}
pub trait VoxelShape {
pub trait VoxelShape: Send + Sync {
fn shape(&self) -> Box<dyn DiscreteVoxelShape>;
fn get_coords(&self, axis: Axis) -> Vec<f64>;
@ -47,7 +47,6 @@ pub trait VoxelShape {
return empty_shape();
}
Box::new(ArrayVoxelShape::new(
self.shape(),
self.get_coords(Axis::X).iter().map(|c| c + x).collect(),
@ -202,7 +201,7 @@ impl ArrayVoxelShape {
}
impl CubeVoxelShape {
pub fn new(shape: Box<dyn DiscreteVoxelShape>) -> Self {
pub fn new(shape: Box<dyn DiscreteVoxelShape + Send + Sync>) -> Self {
Self { shape, faces: None }
}
}