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:
levzzz
2026-10-26 01:50:12 +05:00
parent 7fd1f3118f
commit b71623dfd7
9 changed files with 306 additions and 29 deletions
+5
View File
@@ -77,6 +77,8 @@ pub struct ItemInfo {
pub consumable: Option<horizon_world::consumable::Consumable<String, ConsumeEffect>>,
/// `use_remainder`: what a finished use leaves (`UseRemainder`).
pub use_remainder: Option<String>,
/// `use_cooldown`: the cooldown a use starts (`UseCooldown`).
pub use_cooldown: Option<crate::cooldowns::UseCooldown>,
pub model: String,
/// Main-hand `attack_damage` / `attack_speed` modifier amounts.
pub attack_damage: f32,
@@ -568,6 +570,9 @@ impl Items {
use_remainder: c["minecraft:use_remainder"]["id"]
.as_str()
.map(str::to_owned),
use_cooldown: c
.get("minecraft:use_cooldown")
.and_then(crate::cooldowns::UseCooldown::from_json),
model: c["minecraft:item_model"]
.as_str()
.unwrap_or(name)