fix: gravity for couple of projectile entities (#2161)

* fix: gravity for couple of projectile entities

* fix: clippy warning

* fix: rerun actions
This commit is contained in:
Greened
2026-05-20 13:24:12 +04:00
committed by GitHub
parent 7d15f6e7a1
commit 6b7628962d
12 changed files with 42 additions and 15 deletions

View File

@@ -21,6 +21,7 @@ use tokio::sync::RwLock;
use uuid::Uuid;
const MAX_EGG_HATCH_EVENT_SPAWNS: usize = 16;
const GRAVITY: f64 = 0.03;
pub struct EggEntity {
pub thrown: ThrownItemEntity,
@@ -36,6 +37,7 @@ impl EggEntity {
owner_id: None,
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity: GRAVITY,
};
Self {
@@ -45,7 +47,7 @@ impl EggEntity {
}
pub fn new_shot(entity: Entity, shooter: &Entity) -> Self {
let thrown = ThrownItemEntity::new(entity, shooter);
let thrown = ThrownItemEntity::new(entity, shooter, GRAVITY);
// Default slight upward velocity
thrown.entity.set_velocity(Vector3::new(0.0, 0.1, 0.0));

View File

@@ -10,6 +10,8 @@ use pumpkin_data::particle::Particle;
use pumpkin_data::sound::{Sound, SoundCategory};
use pumpkin_util::math::vector3::Vector3;
const GRAVITY: f64 = 0.03;
pub struct EnderPearlEntity {
pub thrown: ThrownItemEntity,
}
@@ -23,13 +25,14 @@ impl EnderPearlEntity {
owner_id: None,
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity: GRAVITY,
};
Self { thrown }
}
pub fn new_shot(entity: Entity, shooter: &Entity) -> Self {
let thrown = ThrownItemEntity::new(entity, shooter);
let thrown = ThrownItemEntity::new(entity, shooter, GRAVITY);
thrown.entity.set_velocity(Vector3::new(0.0, 0.1, 0.0));
Self { thrown }
}

View File

@@ -10,6 +10,7 @@ use crate::{
};
const EXPLOSION_POWER: f32 = 1.0;
const GRAVITY: f64 = 0.0;
pub struct FireballEntity {
pub thrown: ThrownItemEntity,
@@ -24,6 +25,7 @@ impl FireballEntity {
owner_id: None,
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity: GRAVITY,
};
Self {
@@ -34,7 +36,7 @@ impl FireballEntity {
#[must_use]
pub fn new_shot(entity: Entity, shooter: &Entity) -> Self {
let thrown = ThrownItemEntity::new(entity, shooter);
let thrown = ThrownItemEntity::new(entity, shooter, GRAVITY);
Self {
thrown,
explosion_power: EXPLOSION_POWER,

View File

@@ -15,6 +15,8 @@ use std::sync::{
atomic::{AtomicU32, Ordering},
};
const GRAVITY: f64 = 0.0;
pub struct FireworkRocketEntity {
entity: ThrownItemEntity,
shooter_id: Option<i32>,
@@ -37,6 +39,7 @@ impl FireworkRocketEntity {
owner_id: None,
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity: GRAVITY,
},
shooter_id: None,
life: 0.into(),
@@ -51,7 +54,7 @@ impl FireworkRocketEntity {
// Set random initial velocity
// Set on the inner entity after constructing ThrownItemEntity
let thrown = ThrownItemEntity::new(entity, shooter);
let thrown = ThrownItemEntity::new(entity, shooter, GRAVITY);
thrown.entity.set_velocity(Vector3::new(
random.next_triangular(0.0, 0.002_297),
0.05,

View File

@@ -14,6 +14,8 @@ use pumpkin_util::math::vector3::Vector3;
use tokio::sync::RwLock;
use uuid::Uuid;
const GRAVITY: f64 = 0.05;
pub struct LingeringPotionEntity {
pub thrown: ThrownItemEntity,
pub item_stack: RwLock<ItemStack>,
@@ -27,6 +29,7 @@ impl LingeringPotionEntity {
owner_id: None,
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity: GRAVITY,
};
Self {
@@ -39,7 +42,7 @@ impl LingeringPotionEntity {
}
pub fn new_shot(entity: Entity, shooter: &Entity) -> Self {
let thrown = ThrownItemEntity::new(entity, shooter);
let thrown = ThrownItemEntity::new(entity, shooter, GRAVITY);
thrown.entity.set_velocity(Vector3::new(0.0, 0.1, 0.0));
Self {
thrown,

View File

@@ -44,10 +44,11 @@ pub struct ThrownItemEntity {
pub owner_id: Option<i32>,
pub collides_with_projectiles: bool,
pub has_hit: AtomicBool,
pub gravity: f64,
}
impl ThrownItemEntity {
pub fn new(entity: Entity, owner: &Entity) -> Self {
pub fn new(entity: Entity, owner: &Entity, gravity: f64) -> Self {
let mut owner_pos = owner.pos.load();
owner_pos.y += owner.get_eye_height() - 0.1;
entity.pos.store(owner_pos);
@@ -56,6 +57,7 @@ impl ThrownItemEntity {
owner_id: Some(owner.entity_id),
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity,
}
}
@@ -257,9 +259,8 @@ impl ThrownItemEntity {
const fn as_nbt_storage(&self) -> &dyn NBTStorage {
self
}
#[allow(clippy::unused_self)]
const fn get_gravity(&self) -> f64 {
0.03
self.gravity
}
}

View File

@@ -9,6 +9,8 @@ use crate::{
server::Server,
};
const GRAVITY: f64 = 0.0;
pub struct SmallFireballEntity {
pub thrown: ThrownItemEntity,
}
@@ -21,6 +23,7 @@ impl SmallFireballEntity {
owner_id: None,
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity: GRAVITY,
};
Self { thrown }
@@ -28,7 +31,7 @@ impl SmallFireballEntity {
#[must_use]
pub fn new_shot(entity: Entity, shooter: &Entity) -> Self {
let thrown = ThrownItemEntity::new(entity, shooter);
let thrown = ThrownItemEntity::new(entity, shooter, GRAVITY);
Self { thrown }
}
}

View File

@@ -10,6 +10,8 @@ use pumpkin_data::damage::DamageType;
use pumpkin_data::entity::{EntityStatus, EntityType};
use pumpkin_util::math::vector3::Vector3;
const GRAVITY: f64 = 0.03;
pub struct SnowballEntity {
pub thrown: ThrownItemEntity,
}
@@ -25,13 +27,14 @@ impl SnowballEntity {
owner_id: None,
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity: GRAVITY,
};
Self { thrown }
}
pub fn new_shot(entity: Entity, shooter: &Entity) -> Self {
let thrown = ThrownItemEntity::new(entity, shooter);
let thrown = ThrownItemEntity::new(entity, shooter, GRAVITY);
thrown.entity.set_velocity(Vector3::new(0.0, 0.1, 0.0));
Self { thrown }
}

View File

@@ -14,6 +14,8 @@ use pumpkin_util::math::vector3::Vector3;
use pumpkin_world::world::BlockFlags;
use tokio::sync::RwLock;
const GRAVITY: f64 = 0.05;
pub struct SplashPotionEntity {
pub thrown: ThrownItemEntity,
pub item_stack: RwLock<ItemStack>,
@@ -27,6 +29,7 @@ impl SplashPotionEntity {
owner_id: None,
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity: GRAVITY,
};
Self {
@@ -36,7 +39,7 @@ impl SplashPotionEntity {
}
pub fn new_shot(entity: Entity, shooter: &Entity) -> Self {
let thrown = ThrownItemEntity::new(entity, shooter);
let thrown = ThrownItemEntity::new(entity, shooter, GRAVITY);
thrown.entity.set_velocity(Vector3::new(0.0, 0.1, 0.0));
Self {
thrown,

View File

@@ -17,6 +17,7 @@ use crate::{
const EXPLOSION_POWER: f32 = 1.2;
const DEFAULT_DEFLECT_COOLDOWN: u8 = 5;
pub const WIND_CHARGE_GRAVITY: f64 = 0.0;
pub struct WindChargeEntity {
deflect_cooldown: AtomicU8,

View File

@@ -105,7 +105,7 @@ use crate::entity::projectile::shulker_bullet::ShulkerBulletEntity;
use crate::entity::projectile::small_fireball::SmallFireballEntity;
use crate::entity::projectile::snowball::SnowballEntity;
use crate::entity::projectile::splash_potion::SplashPotionEntity;
use crate::entity::projectile::wind_charge::WindChargeEntity;
use crate::entity::projectile::wind_charge::{WIND_CHARGE_GRAVITY, WindChargeEntity};
use crate::entity::tnt::TNTEntity;
use crate::entity::vehicle::boat::BoatEntity;
use crate::entity::{Entity, EntityBase, mob};
@@ -250,6 +250,7 @@ pub fn from_type(
owner_id: None,
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity: WIND_CHARGE_GRAVITY,
};
Arc::new(WindChargeEntity::new(thrown))
}
@@ -259,6 +260,7 @@ pub fn from_type(
owner_id: None,
collides_with_projectiles: false,
has_hit: AtomicBool::new(false),
gravity: WIND_CHARGE_GRAVITY,
};
Arc::new(WindChargeEntity::new(thrown))
}

View File

@@ -8,7 +8,7 @@ use pumpkin_data::sound::Sound;
use crate::entity::Entity;
use crate::entity::projectile::ThrownItemEntity;
use crate::entity::projectile::wind_charge::WindChargeEntity;
use crate::entity::projectile::wind_charge::{WIND_CHARGE_GRAVITY, WindChargeEntity};
use crate::item::{ItemBehaviour, ItemMetadata};
pub struct WindChargeItem;
@@ -41,7 +41,8 @@ impl ItemBehaviour for WindChargeItem {
let entity = Entity::new(world.clone(), position, &EntityType::WIND_CHARGE);
let wind_charge = ThrownItemEntity::new(entity, &player.living_entity.entity);
let wind_charge =
ThrownItemEntity::new(entity, &player.living_entity.entity, WIND_CHARGE_GRAVITY);
let yaw = player.living_entity.entity.yaw.load();
let pitch = player.living_entity.entity.pitch.load();
@@ -55,7 +56,7 @@ impl ItemBehaviour for WindChargeItem {
);
// TODO: player.incrementStat(Stats.USED)
// TODO: Implement that the projectile will explode on impact on ground
// TODO: Implement that the projectile will explode on impact
world
.spawn_entity(Arc::new(WindChargeEntity::new(wind_charge)))
.await;