aboutsummaryrefslogtreecommitdiff
path: root/azalea-physics/src/clip.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2024-11-27 19:31:40 -0600
committerGitHub <noreply@github.com>2024-11-27 19:31:40 -0600
commit08958c2278b15ebeac8a964f392ebb792e479b61 (patch)
tree4ae3664cea38d7fd1a8f1e95ed06fac04ffe519e /azalea-physics/src/clip.rs
parent139d77d3c2b0922fba5e9d4fa2bd9819d78bd773 (diff)
downloadazalea-drasl-08958c2278b15ebeac8a964f392ebb792e479b61.tar.xz
Refactor azalea-protocol (#190)
* start updating to 1.21.4 * fix block codegen and stop using block data from burger * rename packet related modules and structs to be simpler * ItemSlot -> ItemStack for more consistency with mojmap * .get() -> .into_packet() * simplify declare_state_packets by removing packet ids * rename read_from and write_into to azalea_read and azalea_write * rename McBufReadable and McBufWritable to AzaleaRead and AzaleaWrite * McBuf -> AzBuf * remove most uses of into_variant * update codegen and use resourcelocation names for packets * implement #[limit(i)] attribute for AzBuf derive macro * fixes for 1.21.4 * fix examples * update some physics code and fix ChatType * remove unused imports in codegen * re-add some things to migrate.py and update +mc version numbers automatically * downgrade to 1.21.3 lol
Diffstat (limited to 'azalea-physics/src/clip.rs')
-rw-r--r--azalea-physics/src/clip.rs37
1 files changed, 9 insertions, 28 deletions
diff --git a/azalea-physics/src/clip.rs b/azalea-physics/src/clip.rs
index 30b46a8e..f24721c5 100644
--- a/azalea-physics/src/clip.rs
+++ b/azalea-physics/src/clip.rs
@@ -5,7 +5,7 @@ use azalea_core::{
math::{self, lerp, EPSILON},
position::{BlockPos, Vec3},
};
-use azalea_inventory::ItemSlot;
+use azalea_inventory::ItemStack;
use azalea_world::ChunkStorage;
use bevy_ecs::entity::Entity;
@@ -52,7 +52,7 @@ pub enum FluidPickType {
pub struct EntityCollisionContext {
pub descending: bool,
pub entity_bottom: f64,
- pub held_item: ItemSlot,
+ pub held_item: ItemStack,
// pub can_stand_on_fluid: Box<dyn Fn(&FluidState) -> bool>,
pub entity: Entity,
}
@@ -62,21 +62,15 @@ pub fn clip(chunk_storage: &ChunkStorage, context: ClipContext) -> BlockHitResul
context.from,
context.to,
context,
- |context, block_pos| {
+ |ctx, block_pos| {
let block_state = chunk_storage.get_block_state(block_pos).unwrap_or_default();
// TODO: add fluid stuff to this (see getFluidState in vanilla source)
- let block_shape = context.block_shape(block_state);
- clip_with_interaction_override(
- &context.from,
- &context.to,
- block_pos,
- block_shape,
- &block_state,
- )
+ let block_shape = ctx.block_shape(block_state);
+ clip_with_interaction_override(&ctx.from, &ctx.to, block_pos, block_shape, &block_state)
// let block_distance = if let Some(block_hit_result) =
- // block_hit_result { context.from.distance_to_sqr(&
+ // block_hit_result { context.from.distance_squared_to(&
// block_hit_result.location) } else {
- // f64::MAX
+ // f64::INFINITY
// };
},
|context| {
@@ -90,19 +84,6 @@ pub fn clip(chunk_storage: &ChunkStorage, context: ClipContext) -> BlockHitResul
)
}
-// default BlockHitResult clipWithInteractionOverride(Vec3 world, Vec3 from,
-// BlockPos to, VoxelShape shape, BlockState block) {
-// BlockHitResult blockHitResult = shape.clip(world, from, to);
-// if (blockHitResult != null) {
-// BlockHitResult var7 = block.getInteractionShape(this, to).clip(world,
-// from, to); if (var7 != null
-// && var7.getLocation().subtract(world).lengthSqr() <
-// blockHitResult.getLocation().subtract(world).lengthSqr()) { return
-// blockHitResult.withDirection(var7.getDirection()); }
-// }
-
-// return blockHitResult;
-// }
fn clip_with_interaction_override(
from: &Vec3,
to: &Vec3,
@@ -119,8 +100,8 @@ fn clip_with_interaction_override(
let interaction_shape = block_state.shape();
let interaction_hit_result = interaction_shape.clip(from, to, block_pos);
if let Some(interaction_hit_result) = interaction_hit_result {
- if interaction_hit_result.location.distance_to_sqr(from)
- < block_hit_result.location.distance_to_sqr(from)
+ if interaction_hit_result.location.distance_squared_to(from)
+ < block_hit_result.location.distance_squared_to(from)
{
return Some(block_hit_result.with_direction(interaction_hit_result.direction));
}