Merge pull request #1933 from levzzz5154/fix/item-cooldowns

🤖 Agent: Thanks levzzz5154! Matches ItemCooldowns and the slot sweep in Gui.renderSlot; thrown, eat and shield pass on both hosts. I merged main and dropped orphaned doc comments. Tested together with the other wave 2 contributor PRs: fmt, clippy -D warnings, and the horizon-client, horizon-world and horizon-protocol tests pass. Of the 127 harnesses the batch affects, 124 pass; the other three are a player-head mismatch fixed in #1934 and two worldgen timeouts on a loaded machine with no chunk differing. lan_e2e chat, fireball, cursor, looks, thrown, eat, shield, lava, contacts, projectiles and mobs pass with the host in-frame and on its server thread.
This commit is contained in:
Ludovic Marie
2026-10-26 04:58:42 +01:00
committed by GitHub
9 changed files with 306 additions and 32 deletions
@@ -176,6 +176,9 @@ packet!(
}
);
packet!(ContainerSetData { container: i32 => VarInt, id: i16 => Short, value: i16 => Short });
// ClientboundCooldownPacket: the cooldown group (an identifier) and the ticks
// its entry lasts (0 ends it).
packet!(Cooldown { group: String => Ident, duration: i32 => VarInt });
packet!(ContainerSetSlot { container: i32 => VarInt, state: i32 => VarInt, slot: i16 => Short, item: Option<Stack> => Slot });
/// A holder reference: registry id + 1, or 0 for an inline value (unsupported).
pub struct HolderId;
@@ -1790,6 +1793,7 @@ packet_enum!(Clientbound, crate::ids::play::clientbound {
ContainerSetData(ContainerSetData) = CONTAINER_SET_DATA,
ContainerSetSlot(ContainerSetSlot) = CONTAINER_SET_SLOT,
CookieRequest(CookieRequest) = COOKIE_REQUEST,
Cooldown(Cooldown) = COOLDOWN,
CustomPayload(CustomPayload) = CUSTOM_PAYLOAD,
Disconnect(Disconnect) = DISCONNECT,
DisguisedChat(DisguisedChat) = DISGUISED_CHAT,
@@ -2926,6 +2930,24 @@ mod tests {
round_trip(beacon, Serverbound::encode, Serverbound::decode);
}
#[test]
fn a_cooldown_packet_carries_its_group_and_ticks() {
let packet = Clientbound::Cooldown(Cooldown {
group: "minecraft:ender_pearl".into(),
duration: 20,
});
round_trip(packet, Clientbound::encode, Clientbound::decode);
// The group is an identifier, the ticks a VarInt; a duration of 0
// removes the entry.
let body = Clientbound::encode(&Clientbound::Cooldown(Cooldown {
group: "minecraft:ender_pearl".into(),
duration: 0,
}));
assert_eq!(body[0], crate::ids::play::clientbound::COOLDOWN as u8);
assert_eq!(&body[1..3], [21, b'm']);
assert_eq!(body[body.len() - 1], 0);
}
#[test]
fn change_game_mode_uses_the_game_type_varint() {
for mode in 0..=3 {