Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
Honour NoGravity on arrows, orbs, TNT, items, boats and minecarts
HrafnaValkyrja50583c8b5397
diff --git a/crates/horizon-client/src/arrows.rs b/crates/horizon-client/src/arrows.rsindex daf913b08..1783907ee 100644--- a/crates/horizon-client/src/arrows.rs+++ b/crates/horizon-client/src/arrows.rs@@ -747,8 +747,8 @@ impl Ticker<'_, '_, '_, '_> {if !self.st.was_touching_water {self.p.velocity = self.p.velocity.scale(f64::from(0.99f32));}- if physics && !self.st.in_ground {- // Entity.applyGravity: AbstractArrow.getDefaultGravity.+ if physics && !self.st.in_ground && !self.p.no_gravity {+ // Entity.applyGravity: AbstractArrow.getDefaultGravity, none with NoGravity.self.add_velocity(-0.05);}// Projectile.tick, then Entity.baseTick's fluid and fire phases.diff --git a/crates/horizon-client/src/entities.rs b/crates/horizon-client/src/entities.rsindex 398149827..01aa61c98 100644--- a/crates/horizon-client/src/entities.rs+++ b/crates/horizon-client/src/entities.rs@@ -88,6 +88,8 @@ pub struct ItemEntity {/// `Entity.stuckSpeedMultiplier`: set after a move by the cobweb or powder snow/// the item is in, scales (and stops) the next one.pub stuck: Vec3,+ /// `Entity.noGravity` (`NoGravity` in its save): `applyGravity` does nothing.+ pub no_gravity: bool,}/// Environment results needed by the entity owner, including lethal lava damage.#[derive(Debug)]@@ -228,7 +230,9 @@ impl ItemEntity {self.velocity.z * 0.95,);} else {- self.velocity.y -= 0.04;+ if !self.no_gravity {+ self.velocity.y -= 0.04;+ }}let horizontal = self.velocity.x * self.velocity.x + self.velocity.z * self.velocity.z;// ItemEntity.tick: skip move 3 of 4 ticks while grounded with no@@ -658,6 +662,8 @@ pub struct ExperienceOrb {pub ticks: u32,/// `ExperienceOrb.health`: damage wears it down from 5 (`hurtServer`).pub health: i32,+ /// `Entity.noGravity`: `ExperienceOrb.tick`'s `applyGravity` does nothing.+ pub no_gravity: bool,}impl ExperienceOrb {/// `ExperienceOrb.hurtServer`: the damage comes off the health as an@@ -774,7 +780,7 @@ impl ExperienceOrb {(self.velocity.y + 5.0e-4).min(0.06),self.velocity.z * 0.99,);- } else if !colliding {+ } else if !colliding && !self.no_gravity {self.velocity.y -= 0.03;}if facts.get(block).fluid == Fluid::Lava {@@ -1481,6 +1487,7 @@ mod fire_environment_tests {).unwrap();let make = |id: &str| ItemEntity {+ no_gravity: false,id: 1,thrower: None,target: None,@@ -1627,6 +1634,7 @@ mod merge_tests {fn item(id: &str, count: u32, x: f64, age: u32) -> ItemEntity {let at = Vec3::new(x, 64.0, 0.5);ItemEntity {+ no_gravity: false,id: 0,thrower: None,target: None,@@ -1918,6 +1926,7 @@ mod honey_slide_tests {pub(super) fn falling_item(x: f64, y: f64, z: f64, vx: f64, vy: f64, vz: f64) -> ItemEntity {let at = Vec3::new(x, y, z);ItemEntity {+ no_gravity: false,id: 1,thrower: None,target: None,@@ -2047,6 +2056,7 @@ mod slime_bounce_tests {fn grounded_item() -> ItemEntity {let at = Vec3::new(0.5, 2.0, 0.5);ItemEntity {+ no_gravity: false,id: 1,thrower: None,target: None,diff --git a/crates/horizon-client/src/entities/fluids.rs b/crates/horizon-client/src/entities/fluids.rsindex 89caf1a37..67e9346ad 100644--- a/crates/horizon-client/src/entities/fluids.rs+++ b/crates/horizon-client/src/entities/fluids.rs@@ -224,6 +224,7 @@ mod tests {}let at = Vec3::new(20.5, 4.0, 20.5);let item = ItemEntity {+ no_gravity: false,id: 1,health: 5,fire_ticks: 0,diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rsindex 040fa712b..06c4387e6 100644--- a/crates/horizon-client/src/entity_nbt.rs+++ b/crates/horizon-client/src/entity_nbt.rs@@ -41,7 +41,7 @@ pub fn motion(tag: &Tag) -> Vec3 {pub fn rotation(tag: &Tag) -> [f32; 2] {read_doubles::<2>(tag.get("Rotation")).map_or([0.0; 2], |r| [r[0] as f32, r[1] as f32])}-fn flag(tag: &Tag, key: &str) -> bool {+pub fn flag(tag: &Tag, key: &str) -> bool {number(tag.get(key)).unwrap_or(0) != 0}/// `Entity.saveWithoutId` fields every entity has, over the loaded compound.@@ -2079,6 +2079,7 @@ pub fn item_entity_from_nbt(tag: &Tag, id: u32, bob_offset: f32) -> Option<ItemElet stack = item_from_nbt(tag.get("Item")?)?;let position = position(tag)?;Some(ItemEntity {+ no_gravity: flag(tag, "NoGravity"),health: number(tag.get("Health")).unwrap_or(5) as i32,fire_ticks: number(tag.get("Fire")).unwrap_or(0) as i32,id,@@ -2167,6 +2168,10 @@ pub fn orb_to_nbt(o: &ExperienceOrb, uuid: [i32; 4]) -> Tag {] {put(&mut tag, key, value);}+ // Entity.saveWithoutId writes NoGravity only when set.+ if o.no_gravity {+ put(&mut tag, "NoGravity", Tag::Byte(1));+ }tag}/// One orb with its merged `Count`.@@ -2176,6 +2181,7 @@ pub fn orbs_from_nbt(tag: &Tag) -> Vec<ExperienceOrb> {};let count = number(tag.get("Count")).unwrap_or(1).max(1) as u32;let orb = ExperienceOrb {+ no_gravity: flag(tag, "NoGravity"),id: 0,position,previous: position,@@ -2249,6 +2255,10 @@ pub fn arrow_to_nbt(if let Some(state) = in_block {put(&mut tag, "inBlockState", state);}+ // Entity.saveWithoutId writes NoGravity only when set.+ if p.no_gravity {+ put(&mut tag, "NoGravity", Tag::Byte(1));+ }if let Some(owner) = owner {put(&mut tag, "Owner", Tag::IntArray(owner.to_vec()));}@@ -2279,6 +2289,7 @@ pub fn arrow_from_nbt([p.yaw, p.pitch] = rotation(tag);p.left_owner = flag(tag, "LeftOwner");p.owner_uuid = owner;+ p.no_gravity = flag(tag, "NoGravity");let a = p.arrow.as_mut()?;a.life = number(tag.get("life")).unwrap_or(0) as i16 as i32;a.shake = (number(tag.get("shake")).unwrap_or(0) as i8 as u8).into();@@ -2339,6 +2350,10 @@ fn put_projectile(tag: &mut Tag, p: &Projectile, owner: Option<[i32; 4]>) {if p.left_owner {put(tag, "LeftOwner", Tag::Byte(1));}+ // Entity.saveWithoutId writes NoGravity only when set.+ if p.no_gravity {+ put(tag, "NoGravity", Tag::Byte(1));+ }if p.age > 0 || tag.get("HasBeenShot").is_none() {put(tag, "HasBeenShot", Tag::Byte(i8::from(p.age > 0)));}@@ -2454,6 +2469,7 @@ pub fn fireball_from_nbt(tag: &Tag, player: Option<[i32; 4]>) -> Option<Projecti[p.yaw, p.pitch] = rotation(tag);p.left_owner = flag(tag, "LeftOwner");p.owner_uuid = owner;+ p.no_gravity = flag(tag, "NoGravity");p.acceleration = float(tag.get("acceleration_power")).unwrap_or(0.1);Some(p)}@@ -3159,6 +3175,7 @@ mod tests {#[test]fn item_entities_round_trip() {let e = ItemEntity {+ no_gravity: false,health: 2,fire_ticks: 73,thrower: Some([5, 6, 7, 8]),@@ -3217,6 +3234,7 @@ mod tests {#[test]fn orbs_keep_their_count() {let o = ExperienceOrb {+ no_gravity: false,id: 0,position: Vec3::new(1.0, 2.0, 3.0),previous: Vec3::ZERO,@@ -4732,4 +4750,19 @@ mod mod_thrown_nbt_tests {// a type no mod declares now is not a thrown kind.assert!(throwable_kind("gone:bolt").is_none());}+ #[test]+ fn no_gravity_survives_save_and_load_for_orbs() {+ // Entity.saveWithoutId / load: NoGravity round-trips on a kind that+ // fall by their own tick (orb, item, arrow, fireball).+ let mut orb = orbs_from_nbt(&Tag::compound([+ ("Pos", doubles(&[0.0, 10.0, 0.0])),+ ("NoGravity", Tag::Byte(1)),+ ]))+ .remove(0);+ assert!(orb.no_gravity);+ let back = orbs_from_nbt(&orb_to_nbt(&orb, [1; 4])).remove(0);+ assert!(back.no_gravity);+ orb.no_gravity = false;+ assert!(orb_to_nbt(&orb, [1; 4]).get("NoGravity").is_none());+ }}diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rsindex eeca27743..747515cc1 100644--- a/crates/horizon-client/src/game.rs+++ b/crates/horizon-client/src/game.rs@@ -3645,6 +3645,7 @@ impl Game<'_> {// ItemEntity.bobOffs comes from the entity's own random, not the level's.let bob = self.particles.random().next_float() * std::f32::consts::PI * 2.0;self.dropped.push(ItemEntity {+ no_gravity: false,health: 5,fire_ticks: 0,thrower: None,@@ -13124,6 +13125,7 @@ impl Game<'_> {let p = Vec3::new(at[0], at[1], at[2]);self.next_entity += 1;self.orbs.push(ExperienceOrb {+ no_gravity: false,id: self.next_entity,position: p,previous: p,diff --git a/crates/horizon-client/src/game/boats.rs b/crates/horizon-client/src/game/boats.rsindex 342a31b62..3e1279977 100644--- a/crates/horizon-client/src/game/boats.rs+++ b/crates/horizon-client/src/game/boats.rs@@ -70,6 +70,8 @@ pub(super) struct Boat {pub hurt_time: i32,pub hurt_dir: i32,pub damage: f32,+ /// `Entity.noGravity` (`NoGravity` in its save).+ pub no_gravity: bool,pub paddles: [f32; 2],pub paddling: [bool; 2],/// left, right, up, down@@ -138,6 +140,7 @@ impl Boat {hurt_time: 0,hurt_dir: 1,damage: 0.0,+ no_gravity: false,paddles: [0.0; 2],paddling: [false; 2],input: [false; 4],@@ -578,7 +581,8 @@ impl Game<'_> {b.input = [false; 4];}// floatBoat- let mut vspeed = -0.04;+ // `-getGravity()`: none with NoGravity.+ let mut vspeed = if b.no_gravity { 0.0 } else { -0.04 };let mut buoyancy = 0.0;let inv_friction: f32;let obstacles = self.boat_move_obstacles(&b);diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rsindex d7704e2c3..4e0e5dd95 100644--- a/crates/horizon-client/src/game/commands.rs+++ b/crates/horizon-client/src/game/commands.rs@@ -2156,6 +2156,7 @@ impl Game<'_> {let at = self.unstuck_orb(pos);self.next_entity += 1;self.orbs.push(horizon_client::entities::ExperienceOrb {+ no_gravity: false,id: self.next_entity,position: Vec3::new(at[0], at[1], at[2]),previous: Vec3::new(at[0], at[1], at[2]),diff --git a/crates/horizon-client/src/game/machines.rs b/crates/horizon-client/src/game/machines.rsindex fed8942f6..94b7e5f92 100644--- a/crates/horizon-client/src/game/machines.rs+++ b/crates/horizon-client/src/game/machines.rs@@ -1392,6 +1392,7 @@ mod item_column_tests {fn item(id: u32, x: f64, y: f64, z: f64) -> ItemEntity {let at = Vec3::new(x, y, z);ItemEntity {+ no_gravity: false,health: 5,fire_ticks: 0,id,diff --git a/crates/horizon-client/src/game/minecarts.rs b/crates/horizon-client/src/game/minecarts.rsindex d5bfbdf80..03e8bb542 100644--- a/crates/horizon-client/src/game/minecarts.rs+++ b/crates/horizon-client/src/game/minecarts.rs@@ -106,6 +106,8 @@ pub(super) struct Minecart {pub hurt_time: i32,pub hurt_dir: i32,pub damage: f32,+ /// `Entity.noGravity` (`NoGravity` in its save).+ pub no_gravity: bool,pub items: Vec<Option<ItemStack>>,/// Furnace minecarts: fuel ticks and `MinecartFurnace.push`. Its y part/// stays between ticks (it sets the push's length), only saving drops it.@@ -260,6 +262,7 @@ impl Minecart {hurt_time: 0,hurt_dir: 1,damage: 0.0,+ no_gravity: false,items: vec![None; kind.slots()],fuel: 0,push: Vec3::ZERO,@@ -923,7 +926,9 @@ impl Game<'_> {c.hurt_time = (c.hurt_time - 1).max(0);c.damage = (c.damage - 1.0).max(0.0);// applyGravity- c.velocity.y -= if self.cart_in_water(c) { 0.005 } else { 0.04 };+ if !c.no_gravity {+ c.velocity.y -= if self.cart_in_water(c) { 0.005 } else { 0.04 };+ }let pos = self.rail_block(c.position);if let Some(rail) = self.rail(pos[0], pos[1], pos[2]) {if self.minecart_improvements() {@@ -2216,6 +2221,7 @@ impl Minecart {c.velocity = velocity;c.yaw = yaw;c.previous_yaw = yaw;+ c.no_gravity = horizon_client::entity_nbt::flag(tag, "NoGravity");let int = |k: &str| match tag.get(k) {Some(Tag::Byte(v)) => Some(i32::from(*v)),Some(Tag::Short(v)) => Some(i32::from(*v)),diff --git a/crates/horizon-client/src/game/persist.rs b/crates/horizon-client/src/game/persist.rsindex 9578326df..566ffb78e 100644--- a/crates/horizon-client/src/game/persist.rs+++ b/crates/horizon-client/src/game/persist.rs@@ -452,6 +452,7 @@ impl Game<'_> {_ => 80,};self.tnts.push(super::tnt::PrimedTnt {+ no_gravity: entity_nbt::flag(&tag, "NoGravity"),id,position,previous: position,@@ -484,6 +485,7 @@ impl Game<'_> {position,yaw,);+ b.no_gravity = entity_nbt::flag(&tag, "NoGravity");if chest {b = b.with_chest();b.items = horizon_client::save::decode_items(diff --git a/crates/horizon-client/src/game/pickups.rs b/crates/horizon-client/src/game/pickups.rsindex 0e1a9a168..674a4b90f 100644--- a/crates/horizon-client/src/game/pickups.rs+++ b/crates/horizon-client/src/game/pickups.rs@@ -162,6 +162,7 @@ mod tests {fn orb_at(x: f64, y: f64, z: f64) -> Taken {let at = horizon_core::geometry::Vec3::new(x, y, z);Taken::Orb(Box::new(ExperienceOrb {+ no_gravity: false,id: 0,position: at,previous: at,diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rsindex 3c2b01fdd..61ed345eb 100644--- a/crates/horizon-client/src/game/remote.rs+++ b/crates/horizon-client/src/game/remote.rs@@ -2391,6 +2391,7 @@ impl Game<'_> {// Its value (ExperienceOrb.DATA_VALUE) follows in SetEntityData.self.orbs.retain(|o| o.id != id as u32);self.orbs.push(ExperienceOrb {+ no_gravity: false,id: id as u32,position: at,previous: at,@@ -5190,6 +5191,7 @@ impl Game<'_> {let at = Vec3::new(p[0], p[1], p[2]);let bob_offset = self.world.random.next_float() * std::f32::consts::PI * 2.0;self.dropped.push(ItemEntity {+ no_gravity: false,health: 5,fire_ticks: 0,thrower: None,diff --git a/crates/horizon-client/src/game/remote_projectiles.rs b/crates/horizon-client/src/game/remote_projectiles.rsindex 412379e93..099e125bd 100644--- a/crates/horizon-client/src/game/remote_projectiles.rs+++ b/crates/horizon-client/src/game/remote_projectiles.rs@@ -316,6 +316,7 @@ impl Game<'_> {match kind {"minecraft:evoker_fangs" => self.insert_fangs(id, position, yaw, 0, 0),"minecraft:tnt" => self.tnts.push(super::tnt::PrimedTnt {+ no_gravity: false,id,position: at,previous: at,diff --git a/crates/horizon-client/src/game/tnt.rs b/crates/horizon-client/src/game/tnt.rsindex 3534be890..dd6ae4022 100644--- a/crates/horizon-client/src/game/tnt.rs+++ b/crates/horizon-client/src/game/tnt.rs@@ -23,6 +23,8 @@ pub(super) struct PrimedTnt {pub on_ground: bool,pub owner: Option<Who>,pub guest: Option<u32>,+ /// `Entity.noGravity` (`NoGravity` in its save).+ pub no_gravity: bool,}impl PrimedTnt {const SIZE: f64 = 0.98;@@ -45,7 +47,9 @@ impl PrimedTnt {facts: &horizon_client::blocks::BlockFacts,) -> Result<()> {self.previous = self.position;- self.velocity.y -= 0.04;+ if !self.no_gravity {+ self.velocity.y -= 0.04;+ }let mut scene = SceneCollisions {world,binding: collision,@@ -170,6 +174,7 @@ impl Game<'_> {// An id from the entity counter at once, so a command can name it.self.next_entity += 1;self.tnts.push(PrimedTnt {+ no_gravity: false,id: self.next_entity,position,previous: position,@@ -584,6 +589,7 @@ mod tests {use horizon_core::geometry::Direction;use horizon_world::piston_push::bounce_velocity;let mut tnt = PrimedTnt {+ no_gravity: false,id: 0,position: Vec3::new(0.5, 1.0, 0.5),previous: Vec3::new(0.5, 1.0, 0.5),@@ -626,6 +632,7 @@ mod tests {world.set(21, 4, 20, flowing).unwrap();let at = Vec3::new(20.5, 4.0, 20.5);let mut tnt = PrimedTnt {+ no_gravity: false,id: 0,position: at,previous: at,@@ -720,6 +727,7 @@ mod tests {// (Entity.handleOnInsideBubbleColumn / handleOnAboveBubbleColumn).let at = Vec3::new(20.5, 6.0, 20.5);let mut tnt = PrimedTnt {+ no_gravity: false,id: 0,position: at,previous: at,