Skip to content

Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.

Take entity ids at creation for bolts, thrown potions, clouds, fireballs, eyes, tridents

HrafnaValkyrjac6dcaa6b46d2
diff --git a/crates/horizon-client/src/game/dragon.rs b/crates/horizon-client/src/game/dragon.rs
index 45ae1cc4a..1fc3ddd54 100644
--- a/crates/horizon-client/src/game/dragon.rs
+++ b/crates/horizon-client/src/game/dragon.rs
@@ -1814,8 +1814,9 @@ impl Game<'_> {
{
y -= 1.0;
}
+ let id = self.take_entity_id();
self.breath_clouds.push(Breath {
- id: 0,
+ id,
at: [x, y.floor() + 1.0, z],
radius: 5.0,
age: 0,
@@ -2291,8 +2292,9 @@ impl Game<'_> {
);
// assignDirectionalMovement: the direction times the acceleration power 0.1.
let velocity = Vec3::new(v.x * 0.1, v.y * 0.1, v.z * 0.1);
+ let id = self.take_entity_id();
self.dragon_fireballs.push(DragonFireball {
- id: 0,
+ id,
position: at,
previous: at,
velocity,
@@ -2338,8 +2340,9 @@ impl Game<'_> {
))
});
if hit_block || hit_player || b.age > 600 {
+ let id = self.take_entity_id();
self.breath_clouds.push(Breath {
- id: 0,
+ id,
at: [next.x, next.y, next.z],
radius: 3.0,
age: 0,
diff --git a/crates/horizon-client/src/game/end.rs b/crates/horizon-client/src/game/end.rs
index e33a274ba..a6bc8f340 100644
--- a/crates/horizon-client/src/game/end.rs
+++ b/crates/horizon-client/src/game/end.rs
@@ -1302,8 +1302,10 @@ impl Game<'_> {
target
};
let survive = self.world.random.next_int_bound(5).unwrap_or(0) > 0;
+ self.next_entity += 1;
+ let id = self.next_entity;
self.end.eyes.push(EyeOfEnder {
- id: 0,
+ id,
position: start,
previous: start,
velocity: glam::DVec3::ZERO,
diff --git a/crates/horizon-client/src/game/lan_entities.rs b/crates/horizon-client/src/game/lan_entities.rs
index b51f236b9..ed5a40e37 100644
--- a/crates/horizon-client/src/game/lan_entities.rs
+++ b/crates/horizon-client/src/game/lan_entities.rs
@@ -21,6 +21,14 @@ pub(super) fn assign_entity_id(next: &mut u32, id: &mut u32) -> u32 {
*id
}
+impl Game<'_> {
+ /// `Entity.nextEntityId`: the id a new entity takes from the one counter.
+ pub(super) fn take_entity_id(&mut self) -> u32 {
+ self.next_entity += 1;
+ self.next_entity
+ }
+}
+
fn state(id: u32, kind: &str, position: [f64; 3], yaw: f32, on_ground: bool) -> EntityState {
EntityState {
id: id as i32,
diff --git a/crates/horizon-client/src/game/lightning.rs b/crates/horizon-client/src/game/lightning.rs
index 5ed04b723..f241f4605 100644
--- a/crates/horizon-client/src/game/lightning.rs
+++ b/crates/horizon-client/src/game/lightning.rs
@@ -227,8 +227,9 @@ impl Game<'_> {
let seed = r.next_long();
let flashes = r.next_int_bound(3).unwrap_or(0) + 1;
self.lightning_seen[0] += 1;
+ let id = self.take_entity_id();
self.bolts.push(Bolt {
- id: 0,
+ id,
at,
life: 2,
flashes,
diff --git a/crates/horizon-client/src/game/potions.rs b/crates/horizon-client/src/game/potions.rs
index bfe40a158..2e5370c08 100644
--- a/crates/horizon-client/src/game/potions.rs
+++ b/crates/horizon-client/src/game/potions.rs
@@ -327,8 +327,9 @@ impl Game<'_> {
velocity: Vec3,
owner: Option<Text>,
) {
+ let id = self.take_entity_id();
self.potions.thrown.push(ThrownPotion {
- id: 0,
+ id,
stack,
previous: position,
position,
@@ -1270,8 +1271,9 @@ impl Game<'_> {
ambient: Vec<&'static str>,
color: u32,
) {
+ let id = self.take_entity_id();
self.breath_clouds.push(Breath {
- id: 0,
+ id,
at,
radius: 2.5,
age: 0,
@@ -1601,8 +1603,9 @@ impl Game<'_> {
// potion with no effects leaves none.
if !def.effects.is_empty() {
let at = mob.unwrap_or(at);
+ let id = self.take_entity_id();
self.breath_clouds.push(Breath {
- id: 0,
+ id,
at: [at.x, at.y, at.z],
radius: 3.0,
age: 0,
diff --git a/crates/horizon-client/src/game/trident.rs b/crates/horizon-client/src/game/trident.rs
index 8c6417061..25c4f83df 100644
--- a/crates/horizon-client/src/game/trident.rs
+++ b/crates/horizon-client/src/game/trident.rs
@@ -433,8 +433,9 @@ impl Game<'_> {
v,
on_ground,
);
+ let id = self.take_entity_id();
self.tridents.push(ThrownTrident {
- id: 0,
+ id,
loyalty: thrown.enchantment_level("minecraft:loyalty"),
stack: thrown,
position: start,