Skip to content

Commit 04036b6

Browse files
committed
implement BlockState::outline_shape
1 parent 6ccd44e commit 04036b6

File tree

6 files changed

+9514
-3013
lines changed

6 files changed

+9514
-3013
lines changed

azalea-physics/src/clip.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use azalea_block::BlockState;
1+
use azalea_block::{BlockState, FluidState};
22
use azalea_core::{
33
block_hit_result::BlockHitResult,
44
direction::Direction,
@@ -9,7 +9,7 @@ use azalea_inventory::ItemStack;
99
use azalea_world::ChunkStorage;
1010
use bevy_ecs::entity::Entity;
1111

12-
use crate::collision::{BlockWithShape, VoxelShape};
12+
use crate::collision::{BlockWithShape, VoxelShape, EMPTY_SHAPE};
1313

1414
#[derive(Debug, Clone)]
1515
pub struct ClipContext {
@@ -22,22 +22,37 @@ pub struct ClipContext {
2222
impl ClipContext {
2323
// minecraft passes in the world and blockpos here... but it doesn't actually
2424
// seem necessary?
25+
26+
/// Get the shape of given block, using the type of shape set in
27+
/// [`Self::block_shape_type`].
2528
pub fn block_shape(&self, block_state: BlockState) -> &VoxelShape {
26-
// TODO: implement the other shape getters
27-
// (see the ClipContext.Block class in the vanilla source)
2829
match self.block_shape_type {
29-
BlockShapeType::Collider => block_state.shape(),
30-
BlockShapeType::Outline => block_state.shape(),
31-
BlockShapeType::Visual => block_state.shape(),
32-
BlockShapeType::FallDamageResetting => block_state.shape(),
30+
BlockShapeType::Collider => block_state.collision_shape(),
31+
BlockShapeType::Outline => block_state.outline_shape(),
32+
BlockShapeType::Visual => block_state.collision_shape(),
33+
BlockShapeType::FallDamageResetting => {
34+
if azalea_registry::tags::blocks::FALL_DAMAGE_RESETTING
35+
.contains(&azalea_registry::Block::from(block_state))
36+
{
37+
block_state.collision_shape()
38+
} else {
39+
&EMPTY_SHAPE
40+
}
41+
}
3342
}
3443
}
3544
}
3645

3746
#[derive(Debug, Copy, Clone)]
3847
pub enum BlockShapeType {
48+
/// The shape that's used for collision.
3949
Collider,
50+
/// The block outline that renders when your cursor is over a block.
4051
Outline,
52+
/// Used by entities when considering their line of sight.
53+
///
54+
/// TODO: visual block shape isn't implemented (it'll just return the
55+
/// collider shape), that's correct for most blocks though
4156
Visual,
4257
FallDamageResetting,
4358
}
@@ -64,8 +79,11 @@ pub fn clip(chunk_storage: &ChunkStorage, context: ClipContext) -> BlockHitResul
6479
context,
6580
|ctx, block_pos| {
6681
let block_state = chunk_storage.get_block_state(block_pos).unwrap_or_default();
82+
let fluid_state = FluidState::from(block_state);
83+
6784
// TODO: add fluid stuff to this (see getFluidState in vanilla source)
6885
let block_shape = ctx.block_shape(block_state);
86+
6987
clip_with_interaction_override(&ctx.from, &ctx.to, block_pos, block_shape, &block_state)
7088
// let block_distance = if let Some(block_hit_result) =
7189
// block_hit_result { context.from.distance_squared_to(&
@@ -94,10 +112,9 @@ fn clip_with_interaction_override(
94112
let block_hit_result = block_shape.clip(from, to, block_pos);
95113
if let Some(block_hit_result) = block_hit_result {
96114
// TODO: minecraft calls .getInteractionShape here
97-
// some blocks (like tall grass) have a physics shape that's different from the
98-
// interaction shape, so we need to implement BlockState::interaction_shape. lol
99-
// have fun
100-
let interaction_shape = block_state.shape();
115+
// getInteractionShape is empty for almost every shape except cauldons,
116+
// compostors, hoppers, and scaffolding.
117+
let interaction_shape = &*EMPTY_SHAPE;
101118
let interaction_hit_result = interaction_shape.clip(from, to, block_pos);
102119
if let Some(interaction_hit_result) = interaction_hit_result {
103120
if interaction_hit_result.location.distance_squared_to(from)

0 commit comments

Comments
 (0)