Keep unsimulated entities' UUIDs across saves and save player equipment as vanilla

save_entities forgot the UUID and compound of entities Horizon keeps but
does not simulate, so the save on quit gave them new UUIDs. The player's
equipment is written as LivingEntity does: omitted when empty, where
PlayerEquipment.isEmpty also counts the selected hotbar item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-12 13:26:18 +02:00
parent feb043fda6
commit e2b3f7b4e9
2 changed files with 11 additions and 2 deletions
@@ -815,6 +815,7 @@ impl Game<'_> {
.chain(self.armor_stands.iter().map(|e| e.id))
.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))
.collect();
self.persist.uuids.retain(|id, _| alive.contains(id));
self.persist.raw.retain(|id, _| alive.contains(id));
+10 -2
View File
@@ -1837,8 +1837,16 @@ impl Level {
}),
),
];
// Vanilla writes `equipment` even when empty and omits an empty effect list.
entries.push(("equipment", Tag::compound(equipment)));
// LivingEntity.addAdditionalSaveData omits empty equipment and an empty
// effect list. PlayerEquipment.isEmpty also counts the selected hotbar
// item, which the codec never writes: holding one saves `equipment: {}`.
let holding = self
.inventory
.iter()
.any(|(slot, _, count, _)| i32::from(*slot) == self.selected_slot && *count > 0);
if holding || !equipment.is_empty() {
entries.push(("equipment", Tag::compound(equipment)));
}
if self.active_effects.is_empty() {
entries.retain(|(key, _)| *key != "active_effects");
}