mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-31 08:22:33 +00:00
dynamically set entity eye height (#1503)
This commit is contained in:
@@ -42,7 +42,7 @@ fn get_anchor_position(entity: &crate::entity::Entity, anchor: EntityAnchor) ->
|
||||
let pos = entity.pos.load();
|
||||
match anchor {
|
||||
EntityAnchor::Eyes => {
|
||||
let eye_height = f64::from(entity.entity_type.eye_height);
|
||||
let eye_height = entity.get_eye_height();
|
||||
Vector3::new(pos.x, pos.y + eye_height, pos.z)
|
||||
}
|
||||
EntityAnchor::Feet => pos,
|
||||
@@ -134,7 +134,7 @@ impl CommandExecutor for RotateFacingLocationExecutor {
|
||||
let facing_pos = Position3DArgumentConsumer::find_arg(args, ARG_FACING_LOCATION)?;
|
||||
|
||||
let entity = target.get_entity();
|
||||
let eye_height = f64::from(entity.entity_type.eye_height);
|
||||
let eye_height = entity.get_eye_height();
|
||||
let pos = entity.pos.load();
|
||||
let looking_from = Vector3::new(pos.x, pos.y + eye_height, pos.z);
|
||||
|
||||
@@ -163,9 +163,8 @@ impl CommandExecutor for RotateFacingEntityExecutor {
|
||||
let target = EntityArgumentConsumer::find_arg(args, ARG_TARGET)?;
|
||||
let facing_entity = EntityArgumentConsumer::find_arg(args, ARG_FACING_ENTITY)?;
|
||||
let anchor = EntityAnchorArgumentConsumer::find_arg(args, ARG_FACING_ANCHOR)?;
|
||||
|
||||
let target_entity = target.get_entity();
|
||||
let eye_height = f64::from(target_entity.entity_type.eye_height);
|
||||
let eye_height = target_entity.get_eye_height();
|
||||
let pos = target_entity.pos.load();
|
||||
let looking_from = Vector3::new(pos.x, pos.y + eye_height, pos.z);
|
||||
|
||||
@@ -197,7 +196,7 @@ impl CommandExecutor for RotateFacingEntityNoAnchorExecutor {
|
||||
let facing_entity = EntityArgumentConsumer::find_arg(args, ARG_FACING_ENTITY)?;
|
||||
|
||||
let target_entity = target.get_entity();
|
||||
let eye_height = f64::from(target_entity.entity_type.eye_height);
|
||||
let eye_height = target_entity.get_eye_height();
|
||||
let pos = target_entity.pos.load();
|
||||
let looking_from = Vector3::new(pos.x, pos.y + eye_height, pos.z);
|
||||
|
||||
|
||||
@@ -754,10 +754,10 @@ impl LivingEntity {
|
||||
}
|
||||
|
||||
pub fn get_swim_height(&self) -> f64 {
|
||||
let eye_height = self.entity.entity_dimension.load().eye_height;
|
||||
let eye_height = self.entity.get_eye_height();
|
||||
|
||||
if self.entity.entity_type == &EntityType::BREEZE {
|
||||
f64::from(eye_height)
|
||||
eye_height
|
||||
} else if eye_height < 0.4 {
|
||||
0.0
|
||||
} else {
|
||||
|
||||
@@ -544,6 +544,10 @@ impl Entity {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_eye_height(&self) -> f64 {
|
||||
f64::from(Self::get_entity_dimensions(self.pose.load()).eye_height)
|
||||
}
|
||||
|
||||
/// Updates the entity's position, block position, and chunk position.
|
||||
///
|
||||
/// This function calculates the new position, block position, and chunk position based on the provided coordinates. If any of these values change, the corresponding fields are updated.
|
||||
@@ -885,7 +889,7 @@ impl Entity {
|
||||
let min = aabb.min_block_pos();
|
||||
let max = aabb.max_block_pos();
|
||||
|
||||
let eye_height = f64::from(self.entity_dimension.load().eye_height);
|
||||
let eye_height = self.get_eye_height();
|
||||
let mut eye_level_box = aabb;
|
||||
eye_level_box.min.y += eye_height;
|
||||
eye_level_box.max.y = eye_level_box.min.y;
|
||||
|
||||
@@ -1597,7 +1597,7 @@ impl Player {
|
||||
}
|
||||
|
||||
pub fn eye_position(&self) -> Vector3<f64> {
|
||||
let eye_height = f64::from(self.living_entity.entity.entity_dimension.load().eye_height);
|
||||
let eye_height = self.living_entity.entity.get_eye_height();
|
||||
Vector3::new(
|
||||
self.living_entity.entity.pos.load().x,
|
||||
self.living_entity.entity.pos.load().y + eye_height,
|
||||
@@ -1937,10 +1937,10 @@ impl Player {
|
||||
let d = self.block_interaction_range() + additional_range;
|
||||
let box_pos = BoundingBox::from_block(position);
|
||||
let entity_pos = self.living_entity.entity.pos.load();
|
||||
let standing_eye_height = self.living_entity.entity.entity_dimension.load().eye_height;
|
||||
let eye_height = self.living_entity.entity.get_eye_height();
|
||||
box_pos.squared_magnitude(Vector3 {
|
||||
x: entity_pos.x,
|
||||
y: entity_pos.y + f64::from(standing_eye_height),
|
||||
y: entity_pos.y + eye_height,
|
||||
z: entity_pos.z,
|
||||
}) < d * d
|
||||
}
|
||||
@@ -2226,7 +2226,7 @@ impl Player {
|
||||
|
||||
pub async fn drop_item(&self, item_stack: ItemStack) {
|
||||
let item_pos = self.living_entity.entity.pos.load()
|
||||
+ Vector3::new(0.0, f64::from(EntityType::PLAYER.eye_height) - 0.3, 0.0);
|
||||
+ Vector3::new(0.0, self.living_entity.entity.get_eye_height() - 0.3, 0.0);
|
||||
let entity = Entity::new(self.world(), item_pos, &EntityType::ITEM);
|
||||
|
||||
let pitch = f64::from(self.living_entity.entity.pitch.load()).to_radians();
|
||||
|
||||
@@ -32,7 +32,7 @@ pub struct ThrownItemEntity {
|
||||
impl ThrownItemEntity {
|
||||
pub fn new(entity: Entity, owner: &Entity) -> Self {
|
||||
let mut owner_pos = owner.pos.load();
|
||||
owner_pos.y = (owner_pos.y + f64::from(owner.entity_dimension.load().eye_height)) - 0.1;
|
||||
owner_pos.y = owner.get_eye_height() - 0.1;
|
||||
entity.pos.store(owner_pos);
|
||||
Self {
|
||||
entity,
|
||||
|
||||
Reference in New Issue
Block a user