Skip to content

Commit

Permalink
MOTION_BLOCKING heightmap (#523)
Browse files Browse the repository at this point in the history
# Objective
Aims to implement #104.

# Solution
The server needs to generate a heightmap when chunks are generated,
update them when blocks are changed, and send it in the `ChunkDataS2c`
packet.

I think the implementation should be done in the following order:
- [x] Encode (constant) heightmap and send it in the `ChunkDataS2c`
packet
- [x] Build heightmap in `write_init_packets`
- [x] Find out which blocks are "motion-blocking"
- [x] Implement a `blocks_motion` function
- [x] Change `weather.rs` to test the functionality`WORLD_SURFACE`
- [x] Find out why one needs to add 2 to the heightmap

---------

Co-authored-by: Ryan Johnson <[email protected]>
  • Loading branch information
tim-kt and rj00a authored Sep 17, 2023
1 parent c3d112d commit e38ab81
Show file tree
Hide file tree
Showing 5 changed files with 24,291 additions and 9 deletions.
20 changes: 20 additions & 0 deletions crates/valence_generated/build/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct State {
luminance: u8,
opaque: bool,
replaceable: bool,
blocks_motion: bool,
collision_shapes: Vec<u16>,
block_entity_type: Option<u32>,
}
Expand Down Expand Up @@ -149,6 +150,18 @@ pub fn build() -> anyhow::Result<TokenStream> {
})
.collect::<TokenStream>();

let state_to_blocks_motion_arms = blocks
.iter()
.flat_map(|b| {
b.states.iter().filter(|s| s.blocks_motion).map(|s| {
let id = s.id;
quote! {
#id => true,
}
})
})
.collect::<TokenStream>();

let shapes = shapes.iter().map(|s| {
let min_x = s.min_x;
let min_y = s.min_y;
Expand Down Expand Up @@ -672,6 +685,13 @@ pub fn build() -> anyhow::Result<TokenStream> {
}
}

pub const fn blocks_motion(self) -> bool {
match self.0 {
#state_to_blocks_motion_arms
_ => false,
}
}

const SHAPES: [Aabb; #shape_count] = [
#(#shapes,)*
];
Expand Down
Loading

0 comments on commit e38ab81

Please sign in to comment.