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.

A saved fireball carries its Item, as vanilla's Fireball does

Akirabane9de27c4e0882
diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs
index 40c98b84c..c93e08692 100644
--- a/crates/horizon-client/src/entity_nbt.rs
+++ b/crates/horizon-client/src/entity_nbt.rs
@@ -2343,6 +2343,20 @@ pub fn fireball_to_nbt(
if let Some(power) = power {
put(&mut tag, "ExplosionPower", Tag::Byte(power as i8));
}
+ // Fireball.addAdditionalSaveData: the item it is drawn as, one of the loaded
+ // item or else a fire charge (`setItem` refuses an empty stack and keeps one).
+ if matches!(
+ p.kind,
+ ProjectileKind::LargeFireball { .. } | ProjectileKind::SmallFireball
+ ) {
+ let mut item = tag
+ .get("Item")
+ .and_then(item_from_nbt)
+ .filter(|i| i.count > 0 && &*i.item != "minecraft:air")
+ .unwrap_or_else(|| crate::items::ItemStack::new("minecraft:fire_charge", 1));
+ item.count = 1;
+ put(&mut tag, "Item", item_to_nbt(&item));
+ }
Some(tag)
}
@@ -4673,6 +4687,61 @@ mod fireball_nbt_tests {
}
}
+ /// `Fireball.addAdditionalSaveData` / `readAdditionalSaveData`: both fireballs save
+ /// `Item`, a fire charge by default, and a loaded one stays, as one item.
+ #[test]
+ fn a_fireball_saves_its_item() {
+ let item_of = |tag: &Tag| {
+ let item = tag.get("Item").and_then(item_from_nbt).unwrap();
+ (item.item.to_string(), item.count)
+ };
+ for id in ["minecraft:fireball", "minecraft:small_fireball"] {
+ let plain = Tag::compound([
+ ("id", Tag::String(id.into())),
+ ("Pos", doubles(&[0.0, 0.0, 0.0])),
+ ]);
+ let p = fireball_from_nbt(&plain, None).unwrap();
+ let back = fireball_to_nbt(&p, [1, 2, 3, 4], None, Some(&plain)).unwrap();
+ assert_eq!(
+ item_of(&back),
+ ("minecraft:fire_charge".to_owned(), 1),
+ "{id}"
+ );
+ // A loaded item stays, as a single one.
+ let mut loaded = plain.clone();
+ put(
+ &mut loaded,
+ "Item",
+ item_to_nbt(&crate::items::ItemStack::new("minecraft:diamond", 5)),
+ );
+ let p = fireball_from_nbt(&loaded, None).unwrap();
+ let back = fireball_to_nbt(&p, [1, 2, 3, 4], None, Some(&loaded)).unwrap();
+ assert_eq!(item_of(&back), ("minecraft:diamond".to_owned(), 1), "{id}");
+ // An empty one falls back to the fire charge.
+ let mut empty = plain.clone();
+ put(
+ &mut empty,
+ "Item",
+ item_to_nbt(&crate::items::ItemStack::new("minecraft:air", 1)),
+ );
+ let p = fireball_from_nbt(&empty, None).unwrap();
+ let back = fireball_to_nbt(&p, [1, 2, 3, 4], None, Some(&empty)).unwrap();
+ assert_eq!(
+ item_of(&back),
+ ("minecraft:fire_charge".to_owned(), 1),
+ "{id}"
+ );
+ }
+ // The wind charges are not `Fireball`s: they save no item.
+ let wind = Tag::compound([
+ ("id", Tag::String("minecraft:wind_charge".into())),
+ ("Pos", doubles(&[0.0, 0.0, 0.0])),
+ ]);
+ let p = fireball_from_nbt(&wind, None).unwrap();
+ let back = fireball_to_nbt(&p, [1, 2, 3, 4], None, Some(&wind)).unwrap();
+ assert!(back.get("Item").is_none());
+ }
+
#[test]
fn thrown_item_projectiles_round_trip_their_flight_item_and_owner() {
let player = Some([5, 6, 7, 8]);
diff --git a/crates/horizon-client/src/game/persist.rs b/crates/horizon-client/src/game/persist.rs
index 7082adcbd..b30896c39 100644
--- a/crates/horizon-client/src/game/persist.rs
+++ b/crates/horizon-client/src/game/persist.rs
@@ -1031,11 +1031,17 @@ impl Game<'_> {
}
/// 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.
+ /// `@e[tag=]`, `/tag` and `/data get` see them, and the `Item` a
+ /// fireball or a thrown item projectile was loaded with.
pub(super) fn remember_tags(&mut self, id: u32, tag: &Tag) {
+ let mut map = horizon_world::nbt::Compound::new();
if let Some(tags @ Tag::List(_)) = tag.get("Tags") {
- let mut map = horizon_world::nbt::Compound::new();
map.insert("Tags".into(), tags.clone());
+ }
+ if let Some(item @ Tag::Compound(_)) = tag.get("Item") {
+ map.insert("Item".into(), item.clone());
+ }
+ if !map.is_empty() {
self.persist.raw.insert(id, Tag::Compound(map));
}
}
diff --git a/docs/server.md b/docs/server.md
index 1133d9e6b..d3c9387bb 100644
--- a/docs/server.md
+++ b/docs/server.md
@@ -475,7 +475,8 @@ runtime or new dependency. Server-sent events can replace the polling later if a
`RconThread.create` does: no password or a port outside 1 to 65535 leaves it off with vanilla's warning. The
packets are `RconClient`'s: login (3), command (2), the output in packets of 4096 characters, `-1` for a refused
login, `Unknown request <hex>` for another type, `Error executing: <command> (<reason>)` for a command that failed.
- A command goes to the game as `horizon-server cmd` sends it (`console <line>` on the control endpoint), so the
+ A command goes to the game as an `rcon <line>` request on the control endpoint (`horizon-server cmd` sends
+ `console <line>`, the same console under the `Server` source), so the
output is what the console prints, its messages joined as `RconConsoleSource` joins them. Differences, each one
named in `rcon.rs`: the packets are read from the stream, the password is compared in constant time, a
connection that hasn't logged in within 30 seconds is closed and at most 16 are open. A command runs as