Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Add try_move
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubelotix committed Nov 13, 2023
1 parent 51ecd33 commit f10ffe2
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions minecraft-server/src/world/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,23 @@ impl WorldMap {
inner_get_block(self, position, block).await;
}

pub async fn test_move(&self, object: CollisionShape, movement: Translation) -> Translation {
todo!()
pub async fn try_move(&self, object: CollisionShape, movement: Translation) -> Translation {
// TODO(perf): Optimize Map.try_move by preventing block double-checking
// Also lock the map only once
let movement_fragments = movement.clone().fragment(&object);
let mut validated = Translation{ x: 0.0, y: 0.0, z: 0.0 };
for fragment in movement_fragments {
let validating = validated.clone() + fragment;
let translated_object = object.clone() + &validating;
for block in translated_object.containing_blocks() {
let block = self.get_block(block).await;
if block.block_id() != 0 {
return validated;
}
}
validated = validating;
}
movement
}

pub async fn load(&self, position: ChunkColumnPosition) {
Expand Down

0 comments on commit f10ffe2

Please sign in to comment.