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.

Selectors and /data see Tags on orbs, projectiles, crystals and the dragon

HrafnaValkyrja2b08d635d945
diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs
index 040fa712b..15da60254 100644
--- a/crates/horizon-client/src/entity_nbt.rs
+++ b/crates/horizon-client/src/entity_nbt.rs
@@ -2304,7 +2304,9 @@ pub fn fireball_to_nbt(
) -> Option<Tag> {
let power = match p.kind {
ProjectileKind::LargeFireball { power } => Some(power),
- ProjectileKind::SmallFireball => None,
+ ProjectileKind::SmallFireball
+ | ProjectileKind::WindCharge
+ | ProjectileKind::BreezeWindCharge => None,
_ => return None,
};
let base = Base {
diff --git a/crates/horizon-client/src/game/commands/data.rs b/crates/horizon-client/src/game/commands/data.rs
index 54b9bc273..383f4b121 100644
--- a/crates/horizon-client/src/game/commands/data.rs
+++ b/crates/horizon-client/src/game/commands/data.rs
@@ -149,7 +149,9 @@ impl Game<'_> {
self.other_to_nbt(&o, uuid)
}
Target::Orb(id) => {
- entity_nbt::orb_to_nbt(self.orbs.iter().find(|o| o.id == id)?, random_uuid())
+ let tag =
+ entity_nbt::orb_to_nbt(self.orbs.iter().find(|o| o.id == id)?, random_uuid());
+ crate::game::persist::with_raw(tag, self.persist.raw.get(&id))
}
Target::Projectile(id) => {
let p = self.creatures.projectiles.iter().find(|p| p.id == id)?;
@@ -163,19 +165,22 @@ impl Game<'_> {
.as_ref()
.and_then(|a| a.last_state)
.map(|s| self.state_to_nbt(s));
- entity_nbt::arrow_to_nbt(p, random_uuid(), owner, in_block, None)
- .or_else(|| entity_nbt::fireball_to_nbt(p, random_uuid(), owner, None))
- .or_else(|| entity_nbt::throwable_to_nbt(p, random_uuid(), owner, None))?
+ let raw = self.persist.raw.get(&id);
+ entity_nbt::arrow_to_nbt(p, random_uuid(), owner, in_block, raw)
+ .or_else(|| entity_nbt::fireball_to_nbt(p, random_uuid(), owner, raw))
+ .or_else(|| entity_nbt::throwable_to_nbt(p, random_uuid(), owner, raw))?
}
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)
+ let tag = c.to_nbt(uuid.unwrap_or_else(random_uuid), raw);
+ crate::game::persist::with_raw(tag, self.persist.raw.get(&id))
}
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)
+ let tag = d.to_nbt(uuid.unwrap_or_else(random_uuid), raw);
+ crate::game::persist::with_raw(tag, self.persist.raw.get(&id))
}
Target::Tnt(id) => {
let uuid = self.uuid_for(id);
@@ -301,6 +306,10 @@ impl Game<'_> {
// `tags_of` reads a primed TNT's compound; without this arm
// `/tag` wrote nothing and still reported success.
| Target::Tnt(id)
+ | Target::Orb(id)
+ | Target::Projectile(id)
+ | Target::Crystal(id)
+ | Target::Dragon(id)
| Target::Other(id) => Some(self.persist.raw.entry(id).or_insert_with(empty)),
_ => None,
}
diff --git a/crates/horizon-client/src/game/persist.rs b/crates/horizon-client/src/game/persist.rs
index 9578326df..390834d12 100644
--- a/crates/horizon-client/src/game/persist.rs
+++ b/crates/horizon-client/src/game/persist.rs
@@ -355,6 +355,7 @@ impl Game<'_> {
orb.id = self.next_entity;
let (id, p) = (orb.id, orb.position);
self.orbs.push(orb);
+ self.remember_tags(id, &tag);
let kind = "minecraft:experience_orb";
if !moved
&& !self.native_entity_joins(id, kind, [p.x, p.y, p.z], from_disk)
@@ -378,6 +379,7 @@ impl Game<'_> {
self.next_entity += 1;
p.id = self.next_entity;
self.restore_portal_cooldown(p.id, &tag);
+ self.remember_tags(p.id, &tag);
self.add_projectile(p);
}
}
@@ -388,12 +390,14 @@ impl Game<'_> {
if let Some(mut p) = entity_nbt::fireball_from_nbt(&tag, player_uuid) {
self.claim_owner(&mut p);
self.add_projectile(p);
+ self.remember_last_projectile_tags(&tag);
}
}
id if entity_nbt::throwable_kind(id).is_some() => {
if let Some(mut p) = entity_nbt::throwable_from_nbt(&tag, player_uuid) {
self.claim_owner(&mut p);
self.add_projectile(p);
+ self.remember_last_projectile_tags(&tag);
}
}
"minecraft:falling_block" => {
@@ -527,6 +531,7 @@ impl Game<'_> {
// parts' from the entity counter.
d.id = self.next_entity + 1;
self.next_entity += 9;
+ self.remember_tags(d.id, &tag);
self.dragon = Some(d);
}
}
@@ -537,6 +542,7 @@ impl Game<'_> {
// entity counter.
self.next_entity += 1;
c.id = self.next_entity;
+ self.remember_tags(c.id, &tag);
self.crystals.push(c);
}
}
@@ -1003,6 +1009,22 @@ impl Game<'_> {
&biome,
));
}
+ /// An entity Horizon keeps no compound for (orbs, projectiles, the
+ /// crystals and the dragon) still keeps its `Tags`, by entity id, so
+ /// `@e[tag=]`, `/tag` and `/data get` see them.
+ pub(super) fn remember_tags(&mut self, id: u32, tag: &Tag) {
+ if let Some(tags @ Tag::List(_)) = tag.get("Tags") {
+ let mut map = horizon_world::nbt::Compound::new();
+ map.insert("Tags".into(), tags.clone());
+ self.persist.raw.insert(id, Tag::Compound(map));
+ }
+ }
+ /// The `Tags` of the projectile `add_projectile` just pushed.
+ fn remember_last_projectile_tags(&mut self, tag: &Tag) {
+ if let Some(id) = self.creatures.projectiles.last().map(|p| p.id) {
+ self.remember_tags(id, tag);
+ }
+ }
fn remember(&mut self, id: u32, uuid: Option<[i32; 4]>, tag: Tag) {
self.restore_portal_cooldown(id, &tag);
if let Some(u) = uuid {
@@ -1083,9 +1105,10 @@ impl Game<'_> {
for o in &self.orbs {
if keys.contains(&chunk_of(o.position)) {
let (uuid, raw) = anon(&self.persist, "minecraft:experience_orb", o.position);
- out.entry(chunk_of(o.position))
- .or_default()
- .push(with_raw(entity_nbt::orb_to_nbt(o, uuid), raw.as_ref()));
+ out.entry(chunk_of(o.position)).or_default().push(with_raw(
+ with_raw(entity_nbt::orb_to_nbt(o, uuid), raw.as_ref()),
+ self.persist.raw.get(&o.id),
+ ));
}
}
for p in &self.creatures.projectiles {
@@ -1103,6 +1126,7 @@ impl Game<'_> {
.or_else(|| entity_nbt::fireball_to_nbt(p, uuid, owner, raw.as_ref()))
.or_else(|| entity_nbt::throwable_to_nbt(p, uuid, owner, raw.as_ref()));
if let Some(tag) = tag {
+ let tag = with_raw(tag, self.persist.raw.get(&p.id));
out.entry(chunk_of(p.position)).or_default().push(tag);
}
}
@@ -1417,6 +1441,11 @@ impl Game<'_> {
.chain(self.item_frames.iter().map(|e| e.id))
.chain(self.paintings.iter().map(|e| e.id))
.chain(self.others.iter().map(|e| e.id))
+ .chain(self.orbs.iter().map(|e| e.id))
+ .chain(self.creatures.projectiles.iter().map(|e| e.id))
+ .chain(self.crystals.iter().map(|e| e.id))
+ .chain(self.dragon.iter().map(|e| e.id))
+ .chain(self.tnts.iter().map(|e| e.id))
.collect();
self.persist.uuids.retain(|id, _| alive.contains(id));
self.persist.raw.retain(|id, _| alive.contains(id));
diff --git a/crates/horizon-client/src/game/scoreboard.rs b/crates/horizon-client/src/game/scoreboard.rs
index c237b43c8..98e4d35d8 100644
--- a/crates/horizon-client/src/game/scoreboard.rs
+++ b/crates/horizon-client/src/game/scoreboard.rs
@@ -220,6 +220,10 @@ impl Game<'_> {
| Target::Boat(id)
| Target::Cart(id)
| Target::Tnt(id)
+ | Target::Orb(id)
+ | Target::Projectile(id)
+ | Target::Crystal(id)
+ | Target::Dragon(id)
| Target::Other(id) => self.persist.raw.get(&id),
Target::Player => self.level.player_extra.as_ref(),
Target::Spawner(id) => self
@@ -232,11 +236,7 @@ impl Game<'_> {
.iter()
.find(|f| f.id == id)
.and_then(|f| f.saved.as_ref().map(|s| &s.1)),
- Target::Guest(_)
- | Target::Orb(_)
- | Target::Projectile(_)
- | Target::Crystal(_)
- | Target::Dragon(_) => None,
+ Target::Guest(_) => None,
};
match raw.and_then(|r| r.get("Tags")) {
Some(Tag::List(l)) => l
diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py
index fc224ce90..749ed32ef 100755
--- a/tools/lan_e2e.py
+++ b/tools/lan_e2e.py
@@ -11606,5 +11606,45 @@ CHECKS += ['blast-bystanders']
CHECK_FNS['blast-bystanders'] = check_blast_bystanders
+def check_selector_tags(host, guest, out):
+ """`@e[tag=]` and `/tag` find summoned experience orbs, arrows, thrown items, fireballs and wind
+ charges, and `/data get entity` reads a wind charge (vanilla 26.3, same scene: every kind is found
+ by its summoned Tags; sbs.py selkinds)."""
+ x, y, z = (int(v // 1) for v in pos_of(host))
+ kinds = ['experience_orb', 'arrow', 'snowball', 'egg', 'ender_pearl', 'fireball', 'small_fireball', 'wind_charge']
+ row = (x, y + 8, z + 4)
+ seen = {}
+
+ def marker(i, selector):
+ spot = (row[0] + i, row[1], row[2])
+ host('command', command=f'setblock {spot[0]} {spot[1]} {spot[2]} minecraft:air')
+ host('command', command=f'execute if {selector} run setblock {spot[0]} {spot[1]} {spot[2]} minecraft:gold_block')
+ host.wait(2)
+ return host.raw('block', *spot).get('block') == 'minecraft:gold_block'
+
+ try:
+ host('command', command='gamemode creative')
+ host('command', command='tick freeze')
+ for i, k in enumerate(kinds):
+ host('command', command=f'summon minecraft:{k} {x + 0.5 + i} {y + 20} {z + 0.5} '
+ f'{{NoGravity:1b,Tags:["sel_{k}"],Motion:[0.0d,0.0d,0.0d]}}')
+ host('command', command='summon minecraft:snowball ~ ~20 ~ {NoGravity:1b,Motion:[0.0d,0.0d,0.0d]}')
+ host('command', command='tag @e[type=minecraft:snowball,tag=!sel_snowball] add sel_late')
+ host.wait(4)
+ for i, k in enumerate(kinds):
+ seen[k] = marker(i, f'entity @e[tag=sel_{k}]')
+ seen['late'] = marker(len(kinds), 'entity @e[tag=sel_late]')
+ seen['data'] = marker(len(kinds) + 1, 'data entity @e[type=minecraft:wind_charge,limit=1] Pos')
+ finally:
+ host('command', command='tick unfreeze')
+ host('command', command='kill @e[type=!player]')
+ assert all(seen.values()), f'the selector cannot see these: {[k for k, v in seen.items() if not v]}'
+ return seen
+
+
+CHECKS += ['selector-tags']
+CHECK_FNS['selector-tags'] = check_selector_tags
+
+
if __name__ == '__main__':
main()