mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-06 00:07:56 +01:00
SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync
By: Doc <nachito94@msn.com>
This commit is contained in:
parent
616ec5f700
commit
deb7197a64
@ -1049,14 +1049,14 @@
|
|||||||
int j = (Byte) this.entityData.get(EntityLiving.DATA_LIVING_ENTITY_FLAGS);
|
int j = (Byte) this.entityData.get(EntityLiving.DATA_LIVING_ENTITY_FLAGS);
|
||||||
|
|
||||||
if (flag) {
|
if (flag) {
|
||||||
@@ -3346,7 +3846,26 @@
|
@@ -3346,7 +3846,29 @@
|
||||||
} else {
|
} else {
|
||||||
if (!this.useItem.isEmpty() && this.isUsingItem()) {
|
if (!this.useItem.isEmpty() && this.isUsingItem()) {
|
||||||
this.triggerItemUseEffects(this.useItem, 16);
|
this.triggerItemUseEffects(this.useItem, 16);
|
||||||
- ItemStack itemstack = this.useItem.finishUsingItem(this.level(), this);
|
- ItemStack itemstack = this.useItem.finishUsingItem(this.level(), this);
|
||||||
+ // CraftBukkit start - fire PlayerItemConsumeEvent
|
+ // CraftBukkit start - fire PlayerItemConsumeEvent
|
||||||
+ ItemStack itemstack;
|
+ ItemStack itemstack;
|
||||||
+ if (this instanceof EntityPlayer) {
|
+ if (this instanceof EntityPlayer entityPlayer) {
|
||||||
+ org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.useItem);
|
+ org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.useItem);
|
||||||
+ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(enumhand);
|
+ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(enumhand);
|
||||||
+ PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem, hand);
|
+ PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem, hand);
|
||||||
@ -1064,8 +1064,11 @@
|
|||||||
+
|
+
|
||||||
+ if (event.isCancelled()) {
|
+ if (event.isCancelled()) {
|
||||||
+ // Update client
|
+ // Update client
|
||||||
+ ((EntityPlayer) this).getBukkitEntity().updateInventory();
|
+ if (this.useItem.getItem() instanceof net.minecraft.world.item.ItemSuspiciousStew itemSuspiciousStew) {
|
||||||
+ ((EntityPlayer) this).getBukkitEntity().updateScaledHealth();
|
+ itemSuspiciousStew.cancelUsingItem(entityPlayer, this.useItem);
|
||||||
|
+ }
|
||||||
|
+ entityPlayer.getBukkitEntity().updateInventory();
|
||||||
|
+ entityPlayer.getBukkitEntity().updateScaledHealth();
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
@ -1077,7 +1080,7 @@
|
|||||||
|
|
||||||
if (itemstack != this.useItem) {
|
if (itemstack != this.useItem) {
|
||||||
this.setItemInHand(enumhand, itemstack);
|
this.setItemInHand(enumhand, itemstack);
|
||||||
@@ -3424,6 +3943,12 @@
|
@@ -3424,6 +3946,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean randomTeleport(double d0, double d1, double d2, boolean flag) {
|
public boolean randomTeleport(double d0, double d1, double d2, boolean flag) {
|
||||||
@ -1090,7 +1093,7 @@
|
|||||||
double d3 = this.getX();
|
double d3 = this.getX();
|
||||||
double d4 = this.getY();
|
double d4 = this.getY();
|
||||||
double d5 = this.getZ();
|
double d5 = this.getZ();
|
||||||
@@ -3448,16 +3973,41 @@
|
@@ -3448,16 +3976,41 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag2) {
|
if (flag2) {
|
||||||
@ -1135,7 +1138,7 @@
|
|||||||
} else {
|
} else {
|
||||||
if (flag) {
|
if (flag) {
|
||||||
world.broadcastEntityEvent(this, (byte) 46);
|
world.broadcastEntityEvent(this, (byte) 46);
|
||||||
@@ -3469,7 +4019,7 @@
|
@@ -3469,7 +4022,7 @@
|
||||||
entitycreature.getNavigation().stop();
|
entitycreature.getNavigation().stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1144,7 +1147,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3562,7 +4112,7 @@
|
@@ -3562,7 +4115,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopSleeping() {
|
public void stopSleeping() {
|
||||||
@ -1153,7 +1156,7 @@
|
|||||||
World world = this.level();
|
World world = this.level();
|
||||||
|
|
||||||
java.util.Objects.requireNonNull(world);
|
java.util.Objects.requireNonNull(world);
|
||||||
@@ -3596,7 +4146,7 @@
|
@@ -3596,7 +4149,7 @@
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public EnumDirection getBedOrientation() {
|
public EnumDirection getBedOrientation() {
|
||||||
@ -1162,7 +1165,7 @@
|
|||||||
|
|
||||||
return blockposition != null ? BlockBed.getBedOrientation(this.level(), blockposition) : null;
|
return blockposition != null ? BlockBed.getBedOrientation(this.level(), blockposition) : null;
|
||||||
}
|
}
|
||||||
@@ -3633,7 +4183,7 @@
|
@@ -3633,7 +4186,7 @@
|
||||||
FoodInfo.b foodinfo_b = (FoodInfo.b) iterator.next();
|
FoodInfo.b foodinfo_b = (FoodInfo.b) iterator.next();
|
||||||
|
|
||||||
if (this.random.nextFloat() < foodinfo_b.probability()) {
|
if (this.random.nextFloat() < foodinfo_b.probability()) {
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
--- a/net/minecraft/world/item/ItemSuspiciousStew.java
|
||||||
|
+++ b/net/minecraft/world/item/ItemSuspiciousStew.java
|
||||||
|
@@ -53,4 +53,15 @@
|
||||||
|
|
||||||
|
return super.finishUsingItem(itemstack, world, entityliving);
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ // CraftBukkit start
|
||||||
|
+ public void cancelUsingItem(net.minecraft.server.level.EntityPlayer entityplayer, ItemStack itemstack) {
|
||||||
|
+ SuspiciousStewEffects suspicioussteweffects = (SuspiciousStewEffects) itemstack.getOrDefault(DataComponents.SUSPICIOUS_STEW_EFFECTS, SuspiciousStewEffects.EMPTY);
|
||||||
|
+
|
||||||
|
+ for (SuspiciousStewEffects.a suspicioussteweffects_a : suspicioussteweffects.effects()) {
|
||||||
|
+ entityplayer.connection.send(new net.minecraft.network.protocol.game.PacketPlayOutRemoveEntityEffect(entityplayer.getId(), suspicioussteweffects_a.effect()));
|
||||||
|
+ }
|
||||||
|
+ entityplayer.server.getPlayerList().sendActivePlayerEffects(entityplayer);
|
||||||
|
+ }
|
||||||
|
+ // CraftBukkit end
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user