[PR #6190] [MERGED] Save a wandering trader's visit timer and target #6708

Closed
opened 2026-11-03 06:25:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6190
Author: @MSedgeMC
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: fix/trader-save


📝 Commits (1)

  • 802ab62 Save a wandering trader's visit timer and target

📊 Changes

1 file changed (+71 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/entity_nbt.rs (+71 -1)

📄 Description

WanderingTrader.addAdditionalSaveData writes two fields Horizon left out:

// javap -p -c on WanderingTrader
 6: ldc "DespawnDelay"; 9: getfield despawnDelay; 12: ValueOutput.putInt
18: ldc "wander_target"; 20: getstatic BlockPos.CODEC; 24: getfield wanderTarget
27: ValueOutput.storeNullable

and readAdditionalSaveData reads them back with getIntOr("DespawnDelay", 0) and a null
default for the target.

Horizon keeps the countdown in ints[5] (WanderingTraderSpawner sets it to 48000 and
trader::tick counts it down to the despawn) and the target in extra.point, which the
spawner sets and WanderToPositionGoal walks to — but neither reached the save, so a
world reload reset the visit and dropped the target.

Proven: on the build VM, cargo test -q -p horizon-client --lib a_wandering_traders_countdown
→ 1 passed: a trader with 48000 and a target round-trips through mob_to_nbt/mob_from_nbt
with both fields intact, and a save with neither reads back as idle.

Not proven: not checked in game. The in-game check: /data get entity @e[type=wandering_trader,limit=1]
shows DespawnDelay and wander_target before and after a reload.

One deliberate conversion: vanilla stores the target as a BlockPos (an int array) while
extra.point is a position, so the save writes the block the point is in (floor) and the load
reads it back as whole coordinates. That is the same block, which is all every reader of
extra.point uses.


🔄 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/6190 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/trader-save` --- ### 📝 Commits (1) - [`802ab62`](https://github.com/horizon-rust/horizon/commit/802ab62f2b2cc2982e15698d064712f7cea4f398) Save a wandering trader's visit timer and target ### 📊 Changes **1 file changed** (+71 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/entity_nbt.rs` (+71 -1) </details> ### 📄 Description `WanderingTrader.addAdditionalSaveData` writes two fields Horizon left out: ```java // javap -p -c on WanderingTrader 6: ldc "DespawnDelay"; 9: getfield despawnDelay; 12: ValueOutput.putInt 18: ldc "wander_target"; 20: getstatic BlockPos.CODEC; 24: getfield wanderTarget 27: ValueOutput.storeNullable ``` and `readAdditionalSaveData` reads them back with `getIntOr("DespawnDelay", 0)` and a null default for the target. Horizon keeps the countdown in `ints[5]` (`WanderingTraderSpawner` sets it to 48000 and `trader::tick` counts it down to the despawn) and the target in `extra.point`, which the spawner sets and `WanderToPositionGoal` walks to — but neither reached the save, so a world reload reset the visit and dropped the target. **Proven:** on the build VM, `cargo test -q -p horizon-client --lib a_wandering_traders_countdown` → `1 passed`: a trader with 48000 and a target round-trips through `mob_to_nbt`/`mob_from_nbt` with both fields intact, and a save with neither reads back as idle. **Not proven:** not checked in game. The in-game check: `/data get entity @e[type=wandering_trader,limit=1]` shows `DespawnDelay` and `wander_target` before and after a reload. One deliberate conversion: vanilla stores the target as a `BlockPos` (an int array) while `extra.point` is a position, so the save writes the block the point is in (`floor`) and the load reads it back as whole coordinates. That is the same block, which is all every reader of `extra.point` uses. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:25:13 +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#6708
No description provided.