aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0299-Prevent-consuming-the-wrong-itemstack.patch
blob: 9f1185976526ff96dc508da26f7d5c9e9afb32a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: kickash32 <kickash32@gmail.com>
Date: Mon, 19 Aug 2019 19:42:35 +0500
Subject: [PATCH] Prevent consuming the wrong itemstack


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 6bac6b338302ff0e0e93d5b66d2fd3ea0e666114..3a9c823193e939a6bbf6a43cd440d3fae129a252 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3827,9 +3827,14 @@ public abstract class LivingEntity extends Entity implements Attackable {
     }
 
     public void startUsingItem(InteractionHand hand) {
+        // Paper start - Prevent consuming the wrong itemstack
+        this.startUsingItem(hand, false);
+    }
+    public void startUsingItem(InteractionHand hand, boolean forceUpdate) {
+        // Paper end - Prevent consuming the wrong itemstack
         ItemStack itemstack = this.getItemInHand(hand);
 
-        if (!itemstack.isEmpty() && !this.isUsingItem()) {
+        if (!itemstack.isEmpty() && !this.isUsingItem() || forceUpdate) { // Paper - Prevent consuming the wrong itemstack
             this.useItem = itemstack;
             this.useItemRemaining = itemstack.getUseDuration(this);
             if (!this.level().isClientSide) {
@@ -3914,6 +3919,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
                 this.releaseUsingItem();
             } else {
                 if (!this.useItem.isEmpty() && this.isUsingItem()) {
+                    this.startUsingItem(this.getUsedItemHand(), true); // Paper - Prevent consuming the wrong itemstack
                     this.triggerItemUseEffects(this.useItem, 16);
                     // CraftBukkit start - fire PlayerItemConsumeEvent
                     ItemStack itemstack;
@@ -3948,8 +3954,8 @@ public abstract class LivingEntity extends Entity implements Attackable {
                     }
 
                     this.stopUsingItem();
-                    // Paper start - if the replacement is anything but the default, update the client inventory
-                    if (this instanceof ServerPlayer && !com.google.common.base.Objects.equal(defaultReplacement, itemstack)) {
+                    // Paper start
+                    if (this instanceof ServerPlayer) {
                         ((ServerPlayer) this).getBukkitEntity().updateInventory();
                     }
                     // Paper end