Item cooldowns: the sweep on a slot, and no use while one runs
Nothing tracked `ItemCooldowns`: `draw_item_decorations` passed a cooldown of 0.0 with a note that there was none to shade, and ender pearls were held back by an ad-hoc `pearl_cooldown` counter. `horizon_client::cooldowns` keeps the `use_cooldown` component's entries by cooldown group the way `Player.getCooldowns` does (start and end ticks, the percent `getCooldownPercent` returns), `ItemInfo` now carries the item's `use_cooldown`, and the game uses it where vanilla does: `ServerPlayerGameMode.useItem`/useItemOn refuse a stack on cooldown, `ItemStack.applyAfterUseComponentSideEffects` starts the entry when a use finishes (a thrown pearl, a wind charge, an eaten chorus fruit), `GuiGraphicsExtractor.itemCooldown` shades the slot, and a server's guests keep their own and are sent `ClientboundCooldownPacket` (started, and 0 when it ends), which a client applies. Fixes #1763 Co-Authored-By: [CC] <deepseek-v4.1-flash> <noreply@deepseek.com>
This commit is contained in:
@@ -2561,6 +2561,16 @@ impl Game<'_> {
|
||||
r.commands = Some(tree);
|
||||
}
|
||||
}
|
||||
C::Cooldown(p) => {
|
||||
// ClientPacketListener.handleItemCooldown: the server starts
|
||||
// (or confirms) a group's cooldown; 0 ends it.
|
||||
let group: Arc<str> = Arc::from(p.group.as_str());
|
||||
if p.duration == 0 {
|
||||
self.cooldowns.remove(&group);
|
||||
} else {
|
||||
self.cooldowns.add(group, p.duration);
|
||||
}
|
||||
}
|
||||
C::SystemChat(p) => {
|
||||
// The component as sent, translated in the client's own
|
||||
// language. ChatListener.handleOverlay for the action bar.
|
||||
@@ -4303,8 +4313,12 @@ impl Game<'_> {
|
||||
let Some(info) = self.res.items().get(&held.item).cloned() else {
|
||||
return false;
|
||||
};
|
||||
// MultiPlayerGameMode.useItem runs the use here too: food starts
|
||||
// being eaten (Consumable.startConsuming), a book and quill opens.
|
||||
// MultiPlayerGameMode.useItem runs the use here too (inside
|
||||
// startPrediction): the `use_cooldown` component starts its entry, and
|
||||
// the server's ClientboundCooldownPacket confirms it.
|
||||
self.apply_use_cooldown(&held);
|
||||
// Food starts being eaten (Consumable.startConsuming), a book and
|
||||
// quill opens.
|
||||
self.with_hand(hand, |g| g.start_eating(&info));
|
||||
if self.with_hand(hand, |g| g.remote_use_book(&held)) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user