[PR #5081] [MERGED] Let a spawn egg carry entity data, as vanilla's does #6048

Closed
opened 2026-11-03 05:16:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5081
Author: @MSedgeMC
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/egg-entity-data


📝 Commits (1)

  • a6d66cd Let a spawn egg carry entity data, as vanilla's does

📊 Changes

4 files changed (+140 additions, -10 deletions)

View changed files

📝 crates/horizon-client/src/block_entity_item.rs (+63 -8)
📝 crates/horizon-client/src/entity_nbt.rs (+54 -0)
📝 crates/horizon-client/src/game/commands/data.rs (+3 -2)
📝 crates/horizon-client/src/game/creatures.rs (+20 -0)

📄 Description

Fixes the EntityType.appendCustomEntityStackConfig / updateCustomEntityTag rows in the port ledger. (No issue.)

Vanilla chains two processors when a mob is spawned from a stack: the item's implicit components, then the minecraft:entity_data component. EntityType.updateCustomEntityTag loads the latter into the entity it just created, with two guards — the data's type must match the spawned type, and a type in EntityTypes.OP_ONLY_CUSTOM_DATA (falling block, command-block minecart, spawner minecart) needs an op — and TypedEntityData.loadInto is saveWithoutId, merge the data over it, load, restore the UUID. That is exactly what /data merge entity does.

Horizon applied the egg's components (the custom name, and the per-species variant and sound variant, from an earlier PR) and never this one, so /give @s zombie_spawn_egg[minecraft:entity_data={NoAI:1b,Silent:1b}] spawned an ordinary zombie.

Proven: cargo test -p horizon-client --lib spawn_egg → 7 passed on a build box with the prepared data: a zombie egg carrying {NoAI:1b} spawns a mob with AI off, one whose entity_data.id names another type spawns the egg's own type with the data skipped, a plain egg is unchanged, and the guard alone refuses a mismatched type and an op-only type without an op.

Not proven: nothing in a game. Two honest notes for a reviewer: the loader is reused rather than new, so a merged egg compound also lands in persist.raw and is deep-merged where vanilla's CompoundTag.merge is shallow — both inherited from /data merge, now reachable from an egg; and the data lands just after the mob is registered rather than inside EntityType.create, which is the same ordering the components call already had, so a LAN guest could see one tick of the un-dated mob.

One divergence left untouched deliberately: vanilla takes the spawned type from the data's own id (SpawnEggItem.getType(stack)), where Horizon spawns the item's type and skips mismatched data. Changing type selection is its own PR.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5081 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/egg-entity-data` --- ### 📝 Commits (1) - [`a6d66cd`](https://github.com/horizon-rust/horizon/commit/a6d66cd98ed8770f88e1f5649b7156c99688ed08) Let a spawn egg carry entity data, as vanilla's does ### 📊 Changes **4 files changed** (+140 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/block_entity_item.rs` (+63 -8) 📝 `crates/horizon-client/src/entity_nbt.rs` (+54 -0) 📝 `crates/horizon-client/src/game/commands/data.rs` (+3 -2) 📝 `crates/horizon-client/src/game/creatures.rs` (+20 -0) </details> ### 📄 Description Fixes the `EntityType.appendCustomEntityStackConfig` / `updateCustomEntityTag` rows in the port ledger. (No issue.) Vanilla chains two processors when a mob is spawned from a stack: the item's implicit components, then the `minecraft:entity_data` component. `EntityType.updateCustomEntityTag` loads the latter into the entity it just created, with two guards — the data's type must match the spawned type, and a type in `EntityTypes.OP_ONLY_CUSTOM_DATA` (falling block, command-block minecart, spawner minecart) needs an op — and `TypedEntityData.loadInto` is `saveWithoutId`, merge the data over it, `load`, restore the UUID. That is exactly what `/data merge entity` does. Horizon applied the egg's components (the custom name, and the per-species variant and sound variant, from an earlier PR) and never this one, so `/give @s zombie_spawn_egg[minecraft:entity_data={NoAI:1b,Silent:1b}]` spawned an ordinary zombie. **Proven:** `cargo test -p horizon-client --lib spawn_egg` → 7 passed on a build box with the prepared data: a zombie egg carrying `{NoAI:1b}` spawns a mob with AI off, one whose `entity_data.id` names another type spawns the egg's own type with the data skipped, a plain egg is unchanged, and the guard alone refuses a mismatched type and an op-only type without an op. **Not proven:** nothing in a game. Two honest notes for a reviewer: the loader is reused rather than new, so a merged egg compound also lands in `persist.raw` and is deep-merged where vanilla's `CompoundTag.merge` is shallow — both inherited from `/data merge`, now reachable from an egg; and the data lands just after the mob is registered rather than inside `EntityType.create`, which is the same ordering the components call already had, so a LAN guest could see one tick of the un-dated mob. One divergence left untouched deliberately: vanilla takes the spawned type from the data's own `id` (`SpawnEggItem.getType(stack)`), where Horizon spawns the item's type and skips mismatched data. Changing type selection is its own PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:16:51 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6048
No description provided.