Fix items with use durations of 0 being repeatedly used when use button is held down. Fixed #10150

This commit is contained in:
LexManos committed 2024-10-28 14:54:39 -07:00
1 parent 40220600b0
commit 7d0b07e858
2 files changed
+3 -5

No files matched your search

@@ -518,14 +518,12 @@
this.completeUsingItem();
}
}
@@ -3134,8 +_,12 @@
@@ -3134,8 +_,10 @@
public void startUsingItem(InteractionHand p_21159_) {
ItemStack itemstack = this.getItemInHand(p_21159_);
if (!itemstack.isEmpty() && !this.isUsingItem()) {
+ int duration = net.minecraftforge.event.ForgeEventFactory.onItemUseStart(this, itemstack, itemstack.getUseDuration(this));
+ if (duration <= 0) {
+ return;
+ }
+ if (duration < 0) return;
this.useItem = itemstack;
- this.useItemRemaining = itemstack.getUseDuration(this);
+ this.useItemRemaining = duration;
@@ -46,7 +46,7 @@ public class LivingEntityUseItemEvent extends LivingEvent
* Drinking Potions/Milk
* Guarding with a sword
*
* Cancel the event, or set the duration or {@literal <=} 0 to prevent it from processing.
* Cancel the event, or set the duration or {@literal <} 0 to prevent it from processing.
*
*/
@Cancelable