Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
LivingEquipmentChangeEvent covers the server's players
Federico Tagliani89ca25c574aa
diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rsindex 110edc20c..652b3c37a 100644--- a/crates/horizon-client/src/game/lan_actions.rs+++ b/crates/horizon-client/src/game/lan_actions.rs@@ -95,6 +95,9 @@ pub(super) struct GuestPlay {pub(super) lectern: Option<super::lan_stations::GuestLectern>,/// The menu the mods last heard this guest open (`tick_player_menus`).pub(super) menu_heard: Option<super::native_menus::HeardMenu>,+ /// The equipment the mods last heard this guest wear (`native_players_equipment`), by+ /// `EquipmentSlot`: main hand, off hand, feet, legs, chest, head.+ pub(super) equipment_heard: Option<Box<[Option<crate::items::ItemStack>; 6]>>,/// What the guest's body was given for its effects and enchantments.potions: super::potions::BodyPotions,/// `ServerPlayer.getStats` and the inventory `inventory_changed` last saw.@@ -3294,6 +3297,7 @@ impl Game<'_> {self.lan_containers_tick(host);self.tick_lan_mount_menus(host);self.tick_player_menus(host);+ self.native_players_equipment(host);self.announce_guest_advancements(host);let conns: Vec<u32> = host.hubdiff --git a/crates/horizon-client/src/game/native_mobs.rs b/crates/horizon-client/src/game/native_mobs.rsindex 7a23b6f75..bb562a9e8 100644--- a/crates/horizon-client/src/game/native_mobs.rs+++ b/crates/horizon-client/src/game/native_mobs.rs@@ -55,6 +55,57 @@ impl Game<'_> {}}+impl Game<'_> {+ /// `LivingEntity.collectEquipmentChanges` for the server's players (they are living entities+ /// too): each slot whose stack differs from what the mods last heard is told, the previous+ /// stack with it, so a hotbar selection that moves the main hand counts. A player new to the+ /// level counts from empty, as for mobs, and only while a mod listens.+ pub(super) fn native_players_equipment(&mut self, host: &mut super::lan::LanHost) {+ let mut listened = false;+ self.native_living_equipment_listened(&mut listened);+ if !listened {+ return;+ }+ let mut changes = Vec::new();+ for g in host.hub.guests.iter().filter(|g| host.hub.here(g)) {+ let now: [Option<crate::items::ItemStack>; 6] = [+ g.inventory.get(g.selected).cloned().flatten(),+ g.offhand.clone(),+ g.armor[3].clone(),+ g.armor[2].clone(),+ g.armor[1].clone(),+ g.armor[0].clone(),+ ];+ let Some(play) = host.play.get_mut(&g.conn) else {+ continue;+ };+ let heard = play.equipment_heard.get_or_insert_with(Default::default);+ if **heard == now {+ continue;+ }+ for (slot, name) in PLAYER_SLOTS.into_iter().enumerate() {+ if now[slot] != heard[slot] {+ let from = heard[slot].take();+ changes.push((g.entity_id as u32, name, from, now[slot].clone()));+ }+ }+ **heard = now;+ }+ for (id, slot, from, to) in changes {+ self.native_living_equipment_change(+ id,+ "minecraft:player",+ slot,+ from.as_ref(),+ to.as_ref(),+ );+ }+ }+}++/// The `EquipmentSlot` names of a player's equipment, in the order of `native_players_equipment`.+const PLAYER_SLOTS: [&str; 6] = ["mainhand", "offhand", "feet", "legs", "chest", "head"];+/// A mob as a native mod reads it.#[allow(dead_code)]#[derive(Clone, Debug, PartialEq)]