Skip to content

Commit

Permalink
Fix client visual desync if cooldown events are cancelled (#11892)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doc94 authored Jan 12, 2025
1 parent 2ea6aee commit ad74b67
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
--- a/net/minecraft/world/item/ServerItemCooldowns.java
+++ b/net/minecraft/world/item/ServerItemCooldowns.java
@@ -11,6 +_,39 @@
@@ -11,6 +_,50 @@
this.player = player;
}

+ // Paper start - Add PlayerItemCooldownEvent
+ private int getCurrentCooldown(final ResourceLocation groupId) {
+ final net.minecraft.world.item.ItemCooldowns.CooldownInstance cooldownInstance = this.cooldowns.get(groupId);
+ if (cooldownInstance == null) {
+ return 0;
+ }
+ return Math.max(0, cooldownInstance.endTime() - this.tickCount);
+ }
+
+ @Override
+ public void addCooldown(ItemStack item, int duration) {
+ final ResourceLocation cooldownGroup = this.getCooldownGroup(item);
Expand All @@ -15,7 +23,9 @@
+ duration
+ );
+ if (event.callEvent()) {
+ super.addCooldown(cooldownGroup, event.getCooldown(), false);
+ this.addCooldown(cooldownGroup, event.getCooldown(), false);
+ } else {
+ this.player.connection.send(new ClientboundCooldownPacket(cooldownGroup, this.getCurrentCooldown(cooldownGroup)));
+ }
+ }
+
Expand All @@ -28,6 +38,7 @@
+ duration
+ );
+ if (!event.callEvent()) {
+ this.player.connection.send(new ClientboundCooldownPacket(groupId, this.getCurrentCooldown(groupId)));
+ return;
+ }
+
Expand Down

0 comments on commit ad74b67

Please sign in to comment.