diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-10-02 12:29:47 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-02 12:29:47 -0500 |
| commit | c9b4dccd7eaeed68ce96cf5167916417d0baa6a7 (patch) | |
| tree | 0b381ee72a1486ccb22fe22158b5d7d3edaf3f99 /azalea-physics/src/collision/dimension_collisions.rs | |
| parent | aa78491ee09ec0c6879e6edde349ca67cf809daf (diff) | |
| download | azalea-drasl-c9b4dccd7eaeed68ce96cf5167916417d0baa6a7.tar.xz | |
All block shapes & collisions (#22)
* start adding shapes
* add more collision stuff
* DiscreteCubeMerger
* more mergers
* start adding BitSetDiscreteVoxelShape::join
* i love rust :smiley: :smiley: :smiley:
* r
* IT COMPILES????
* fix warning
* fix error
* fix more clippy issues
* add box_shape
* more shape stuff
* make DiscreteVoxelShape an enum
* Update shape.rs
* also make VoxelShape an enum
* implement BitSet::clear
* add more missing things
* it compiles
W
* start block shape codegen
* optimize shape codegen
* make az-block/blocks.rs look better (broken)
* almost new block macro
* make the codegen not generate 'type'
* try to fix
* work more on the blocks macro
* wait it compiles
* fix clippy issues
* shapes codegen works
* well it's almost working
* simplify some shape codegen
* enum type names are correct
* W it compiles
* cargo check no longer warns
* fix some clippy issues
* start making it so the shape impl is on BlockStates
* insane code
* new impl compiles
* fix wrong find_bits + TESTS PASS!
* add a test for slab collision
* fix clippy issues
* ok rust
* fix error that happens when on stairs
* add test for top slabs
* start adding join_is_not_empty
* add more to join_is_not_empty
* top slabs still don't work!!
* x..=0 doesn't work in rust :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley:
* remove comment since i added more useful names
* remove some printlns
* fix walls in some configurations erroring
* fix some warnings
* change comment to \`\`\`ignore instead of \`\`\`no_run
* players are .6 wide not .8
* fix clippy's complaints
* i missed one clippy warning
Diffstat (limited to 'azalea-physics/src/collision/dimension_collisions.rs')
| -rw-r--r-- | azalea-physics/src/collision/dimension_collisions.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/azalea-physics/src/collision/dimension_collisions.rs b/azalea-physics/src/collision/dimension_collisions.rs index 5f9fa039..9d807b62 100644 --- a/azalea-physics/src/collision/dimension_collisions.rs +++ b/azalea-physics/src/collision/dimension_collisions.rs @@ -1,10 +1,12 @@ -use crate::collision::{VoxelShape, AABB}; +use crate::collision::{BlockWithShape, VoxelShape, AABB}; use azalea_block::BlockState; use azalea_core::{ChunkPos, ChunkSectionPos, Cursor3d, CursorIterationType, EPSILON}; use azalea_world::entity::EntityData; use azalea_world::{Chunk, Dimension}; use std::sync::{Arc, Mutex}; +use super::Shapes; + pub trait CollisionGetter { fn get_block_collisions<'a>( &'a self, @@ -27,12 +29,13 @@ pub struct BlockCollisions<'a> { pub dimension: &'a Dimension, // context: CollisionContext, pub aabb: AABB, - + pub entity_shape: VoxelShape, pub cursor: Cursor3d, pub only_suffocating_blocks: bool, } impl<'a> BlockCollisions<'a> { + // TODO: the entity is stored in the context pub fn new(dimension: &'a Dimension, _entity: Option<&EntityData>, aabb: AABB) -> Self { let origin_x = (aabb.min_x - EPSILON) as i32 - 1; let origin_y = (aabb.min_y - EPSILON) as i32 - 1; @@ -47,6 +50,7 @@ impl<'a> BlockCollisions<'a> { Self { dimension, aabb, + entity_shape: VoxelShape::from(aabb), cursor, only_suffocating_blocks: false, } @@ -75,7 +79,7 @@ impl<'a> BlockCollisions<'a> { } impl<'a> Iterator for BlockCollisions<'a> { - type Item = Box<dyn VoxelShape>; + type Item = VoxelShape; fn next(&mut self) -> Option<Self::Item> { while let Some(item) = self.cursor.next() { @@ -92,19 +96,13 @@ impl<'a> Iterator for BlockCollisions<'a> { let pos = item.pos; let block_state: BlockState = chunk_lock.get(&(&pos).into(), self.dimension.min_y()); - // let block: Box<dyn Block> = block_state.into(); // TODO: continue if self.only_suffocating_blocks and the block is not suffocating - let block_shape = if block_state == BlockState::Air { - crate::collision::empty_shape() - } else { - crate::collision::block_shape() - }; - // let block_shape = block.get_collision_shape(); - // if block_shape == Shapes::block() { - if true { - // TODO: this can be optimized + let block_shape = block_state.shape(); + + // if it's a full block do a faster collision check + if block_shape == &crate::collision::block_shape() { if !self.aabb.intersects_aabb(&AABB { min_x: item.pos.x as f64, min_y: item.pos.y as f64, @@ -123,12 +121,14 @@ impl<'a> Iterator for BlockCollisions<'a> { )); } - // let block_shape = block_shape.move_relative(item.pos.x, item.pos.y, item.pos.z); - // if (!Shapes.joinIsNotEmpty(block_shape, this.entityShape, BooleanOp.AND)) { - // continue; - // } + let block_shape = + block_shape.move_relative(item.pos.x as f64, item.pos.y as f64, item.pos.z as f64); + // if the entity shape and block shape don't collide, continue + if !Shapes::matches_anywhere(&block_shape, &self.entity_shape, |a, b| a && b) { + continue; + } - // return block_shape; + return Some(block_shape); } None |
