From 8909e0510c4700295514c83c5f61cbd5695d9db7 Mon Sep 17 00:00:00 2001 From: levzzz <86072227+levzzz5154@users.noreply.github.com> Date: Tue, 27 Oct 2026 03:55:39 +0500 Subject: [PATCH] commands: selectors find the End crystals and the Ender Dragon Horizon's command targets enumerated the ordinary entity collections only, so `@e[type=end_crystal]` and `@e[type=ender_dragon]` matched nothing: the End crystals and the dragon live in their own lists, and neither carried an entity id a command could name. The crystals and the dragon now take an id from the entity counter when they are created, as EndCrystal's and EnderDragon's constructors do; the selector offers them as candidates; `/data get entity` reads them and `/kill` removes them the way `Entity.kill` does. `/summon minecraft:end_crystal` creates one, as vanilla does. Fixes #1531 Co-Authored-By: minimax-m3.1-flash (Claude Code) --- crates/horizon-client/src/game/commands.rs | 49 +++++++++++++++++++ .../horizon-client/src/game/commands/data.rs | 10 ++++ crates/horizon-client/src/game/dragon.rs | 24 ++++++++- crates/horizon-client/src/game/persist.rs | 20 +++++++- crates/horizon-client/src/game/scoreboard.rs | 6 ++- tools/command_exec_corpus.py | 11 +++++ 6 files changed, 115 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index 22041c3b2..bb8ae68d6 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -53,6 +53,10 @@ pub(super) enum Target { /// An entity of a type Horizon does not simulate (markers, displays, /// interactions...): kept as its saved data at a position. Other(u32), + /// An End crystal, by its entity id (`minecraft:end_crystal`). + Crystal(u32), + /// The Ender Dragon, by its entity id (`minecraft:ender_dragon`). + Dragon(u32), } /// An entity of a type Horizon does not simulate: its compound lives in the /// entity memory (`persist.raw`), its position and rotation here. @@ -385,6 +389,16 @@ impl Game<'_> { .iter() .find(|o| o.id == id) .map(|o| [o.position.x, o.position.y, o.position.z]), + Target::Crystal(id) => self + .crystals + .iter() + .find(|c| c.id == id) + .map(|c| [c.position.x, c.position.y, c.position.z]), + Target::Dragon(id) => self + .dragon + .as_ref() + .filter(|d| d.id == id) + .map(|d| [d.position.x, d.position.y, d.position.z]), } } pub(super) fn target_type(&self, t: Target) -> String { @@ -428,6 +442,8 @@ impl Game<'_> { .iter() .find(|o| o.id == id) .map_or_else(String::new, |o| o.kind.clone()), + Target::Crystal(_) => "minecraft:end_crystal".into(), + Target::Dragon(_) => "minecraft:ender_dragon".into(), } } /// The name of the player the game acts for: a guest's own while their @@ -552,6 +568,12 @@ impl Game<'_> { candidates.extend(self.boats.iter().map(|b| Target::Boat(b.id))); candidates.extend(self.carts.iter().map(|c| Target::Cart(c.id))); candidates.extend(self.others.iter().map(|o| Target::Other(o.id))); + // The End crystals and the dragon (EndCrystal and EnderDragon + // are entities of their own). + candidates.extend(self.crystals.iter().map(|c| Target::Crystal(c.id))); + if let Some(d) = &self.dragon { + candidates.push(Target::Dragon(d.id)); + } } let level = self.experience.level; let creative = self.creative; @@ -1199,6 +1221,17 @@ impl Game<'_> { } } } + Target::Crystal(id) => { + if let Some(c) = self.crystals.iter_mut().find(|c| c.id == id) { + c.position = v; + } + } + Target::Dragon(id) => { + if let Some(d) = self.dragon.as_mut().filter(|d| d.id == id) { + d.position = v; + d.previous = v; + } + } // Wall-mounted entities do not move. Target::Frame(_) | Target::Painting(_) => {} } @@ -1594,6 +1627,8 @@ impl Game<'_> { Target::Boat(id) => self.boats.retain(|b| b.id != id), Target::Cart(id) => self.carts.retain(|c| c.id != id), Target::Other(id) => self.others.retain(|o| o.id != id), + Target::Crystal(id) => self.kill_crystal(id), + Target::Dragon(id) => self.kill_dragon(id), } } fn cmd_kill(&mut self, ctx: &Context) -> R { @@ -1706,6 +1741,20 @@ impl Game<'_> { self.spawn_bolt(pos, false); name = Text::translate("entity.minecraft.lightning_bolt", &[]); } + "end_crystal" => { + // EndCrystal's constructor takes an id from the entity + // counter, and the crystal is shown with its base. + self.next_entity += 1; + self.crystals.push(super::dragon::Crystal { + id: self.next_entity, + position: Vec3::new(pos[0], pos[1], pos[2]), + show_bottom: true, + time: self.world.random.next_int_bound(100_000).unwrap_or(0), + beam: None, + invulnerable: false, + }); + name = Text::translate("entity.minecraft.end_crystal", &[]); + } k if super::minecarts::CartKind::from_id(&kind).is_some() => { let cart_kind = super::minecarts::CartKind::from_id(&kind) .unwrap_or(super::minecarts::CartKind::Rideable); diff --git a/crates/horizon-client/src/game/commands/data.rs b/crates/horizon-client/src/game/commands/data.rs index ac16c5e7c..3964f73a1 100644 --- a/crates/horizon-client/src/game/commands/data.rs +++ b/crates/horizon-client/src/game/commands/data.rs @@ -129,6 +129,16 @@ impl Game<'_> { entity_nbt::arrow_to_nbt(p, random_uuid(), owner, in_block, None) .or_else(|| entity_nbt::fireball_to_nbt(p, random_uuid(), owner, None))? } + Target::Crystal(id) => { + let c = self.crystals.iter().find(|c| c.id == id)?; + let (uuid, raw) = self.persist_anon("minecraft:end_crystal", c.position); + c.to_nbt(uuid.unwrap_or_else(random_uuid), raw) + } + Target::Dragon(id) => { + let d = self.dragon.as_ref().filter(|d| d.id == id)?; + let (uuid, raw) = self.persist_anon("minecraft:ender_dragon", d.position); + d.to_nbt(uuid.unwrap_or_else(random_uuid), raw) + } }) } /// `Entity.load` of new data (`EntityDataAccessor.setData`): the entity is diff --git a/crates/horizon-client/src/game/dragon.rs b/crates/horizon-client/src/game/dragon.rs index fff03ef1c..7e1c90ac7 100644 --- a/crates/horizon-client/src/game/dragon.rs +++ b/crates/horizon-client/src/game/dragon.rs @@ -828,8 +828,10 @@ impl Game<'_> { continue; } let time = self.world.random.next_int_bound(100_000).unwrap_or(0); + // EndCrystal's constructor takes an id from the entity counter. + self.next_entity += 1; self.crystals.push(Crystal { - id: 0, + id: self.next_entity, position: at, show_bottom: true, time, @@ -2830,8 +2832,11 @@ impl Game<'_> { return false; } let time = self.world.random.next_int_bound(100_000).unwrap_or(0); + // EndCrystal's constructor takes an id from the entity counter, so + // the crystal is an entity a command can name (`@e[type=end_crystal]`). + self.next_entity += 1; self.crystals.push(Crystal { - id: 0, + id: self.next_entity, position: Vec3::new(x + 0.5, y, z + 0.5), show_bottom: false, time, @@ -2848,6 +2853,21 @@ impl Game<'_> { self.swing_arm(); true } + /// `EndCrystal.kill` (`/kill`): the crystal is removed, without a blast + /// (`Entity.kill` does not hurt it). + pub(super) fn kill_crystal(&mut self, id: u32) { + if let Some(i) = self.crystals.iter().position(|c| c.id == id) { + self.destroy_crystal(i, None, CrystalDamage::Explosion); + } + } + /// `EnderDragon.kill` (`/kill`): `Entity.kill` removes the entity, it + /// does not hurt it (the dragon flies its death flight when its health + /// runs out). + pub(super) fn kill_dragon(&mut self, id: u32) { + if self.dragon.as_ref().is_some_and(|d| d.id == id) { + self.dragon = None; + } + } /// Any entity touching `room` (`Level.getEntities(null, box)`). fn entity_in(&self, room: Aabb) -> bool { let touches = |lo: Vec3, hi: Vec3| { diff --git a/crates/horizon-client/src/game/persist.rs b/crates/horizon-client/src/game/persist.rs index b5e650e70..7b5a741b9 100644 --- a/crates/horizon-client/src/game/persist.rs +++ b/crates/horizon-client/src/game/persist.rs @@ -290,14 +290,22 @@ impl Game<'_> { "minecraft:ender_dragon" => { let seed = self.world.random.next_long(); if self.dragon.is_none() - && let Some(d) = super::dragon::Dragon::from_nbt(&tag, seed) + && let Some(mut d) = super::dragon::Dragon::from_nbt(&tag, seed) { + // EnderDragon's constructor takes its id and its + // parts' from the entity counter. + d.id = self.next_entity + 1; + self.next_entity += 9; self.dragon = Some(d); } } "minecraft:end_crystal" => { let time = self.world.random.next_int_bound(100_000).unwrap_or(0); - if let Some(c) = super::dragon::Crystal::from_nbt(&tag, time) { + if let Some(mut c) = super::dragon::Crystal::from_nbt(&tag, time) { + // EndCrystal's constructor takes an id from the + // entity counter. + self.next_entity += 1; + c.id = self.next_entity; self.crystals.push(c); } } @@ -531,6 +539,14 @@ impl Game<'_> { self.persist.uuids.remove(&id); self.persist.raw.remove(&id); } + /// The compound an entity without a Horizon entity ID was loaded with + /// (the crystals and the dragon), found again by type and position. + pub(super) fn persist_anon(&self, kind: &str, p: Vec3) -> (Option<[i32; 4]>, Option<&Tag>) { + self.persist + .anon + .get(&anon_key(kind, p)) + .map_or((None, None), |(_, uuid, raw)| (*uuid, Some(raw))) + } /// The compound an entity was loaded with (and commands have edited). pub(super) fn persist_raw(&self, id: u32) -> Option<&Tag> { self.persist.raw.get(&id) diff --git a/crates/horizon-client/src/game/scoreboard.rs b/crates/horizon-client/src/game/scoreboard.rs index 81c03e288..005446ed1 100644 --- a/crates/horizon-client/src/game/scoreboard.rs +++ b/crates/horizon-client/src/game/scoreboard.rs @@ -180,7 +180,11 @@ impl Game<'_> { | Target::Cart(id) | Target::Other(id) => self.persist.raw.get(&id), Target::Player => self.level.player_extra.as_ref(), - Target::Guest(_) | Target::Orb(_) | Target::Projectile(_) => None, + Target::Guest(_) + | Target::Orb(_) + | Target::Projectile(_) + | Target::Crystal(_) + | Target::Dragon(_) => None, }; match raw.and_then(|r| r.get("Tags")) { Some(Tag::List(l)) => l diff --git a/tools/command_exec_corpus.py b/tools/command_exec_corpus.py index d8f925ef0..1d346e002 100644 --- a/tools/command_exec_corpus.py +++ b/tools/command_exec_corpus.py @@ -327,6 +327,17 @@ def entities(): cmd('/data get entity @e[tag=attr,limit=1] Health'), cmd('/attribute @e[tag=attr,limit=1] minecraft:attack_damage base get'), cmd('/kill @e[tag=attr]'), + # An End crystal is an entity of its own: a type selector finds it, + # reads it and kills it (#1531). + cmd('/summon minecraft:end_crystal 4.5 210 8.5'), + cmd('/execute if entity @e[type=minecraft:end_crystal]'), + cmd('/data get entity @e[type=minecraft:end_crystal,limit=1] Pos'), + cmd('/kill @e[type=minecraft:end_crystal]'), + cmd('/execute if entity @e[type=minecraft:end_crystal]'), + cmd('/summon minecraft:ender_dragon 4.5 210 8.5'), + cmd('/execute if entity @e[type=minecraft:ender_dragon]'), + cmd('/data get entity @e[type=minecraft:ender_dragon,limit=1] Pos'), + cmd('/kill @e[type=minecraft:ender_dragon]'), *setup('/kill @e[type=minecraft:armor_stand]'), {'op': 'tick', 'n': 25}, cmd('/execute if entity @e[tag=h]'),