port PlayerLaunchProjectileEvent patch to 1.15 (#2758)

This commit is contained in:
Omer Uddin 2019-12-15 13:25:10 -05:00 committed by Shane Freeder
parent f3c55f239a
commit a133980223

View file

@ -1,26 +1,26 @@
git From 264d17e1439c26acd197336ce546e691460d1ebd Mon Sep 17 00:00:00 2001 From acafe8ad3e296235f669e51c4cc8a07aa1a3a485 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com> From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 21 Jul 2018 03:11:03 -0500 Date: Sat, 21 Jul 2018 03:11:03 -0500
Subject: [PATCH] PlayerLaunchProjectileEvent Subject: [PATCH] PlayerLaunchProjectileEvent
diff --git a/src/main/java/net/minecraft/server/InteractionResultWrapper.java b/src/main/java/net/minecraft/server/InteractionResultWrapper.java
index a6b96456b..712bda122 100644
--- a/src/main/java/net/minecraft/server/InteractionResultWrapper.java
+++ b/src/main/java/net/minecraft/server/InteractionResultWrapper.java
@@ -10,6 +10,7 @@ public class InteractionResultWrapper<T> {
this.b = t0;
}
+ public EnumInteractionResult getResult() { return this.a(); } // Paper - OBFHELPER
public EnumInteractionResult a() {
return this.a;
}
diff --git a/src/main/java/net/minecraft/server/ItemEgg.java b/src/main/java/net/minecraft/server/ItemEgg.java diff --git a/src/main/java/net/minecraft/server/ItemEgg.java b/src/main/java/net/minecraft/server/ItemEgg.java
index 7cc3c33b0..b92d39600 100644 index 89d399c9f..15a536dab 100644
--- a/src/main/java/net/minecraft/server/ItemEgg.java --- a/src/main/java/net/minecraft/server/ItemEgg.java
+++ b/src/main/java/net/minecraft/server/ItemEgg.java +++ b/src/main/java/net/minecraft/server/ItemEgg.java
@@ -10,17 +10,35 @@ public class ItemEgg extends Item { @@ -16,13 +16,32 @@ public class ItemEgg extends Item {
public InteractionResultWrapper<ItemStack> a(World world, EntityHuman entityhuman, EnumHand enumhand) {
ItemStack itemstack = entityhuman.b(enumhand);
+ /* // Paper start - moved down
if (!entityhuman.abilities.canInstantlyBuild) {
itemstack.subtract(1);
}
world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (ItemEgg.i.nextFloat() * 0.4F + 0.8F));
+ */ // Paper end
if (!world.isClientSide) {
EntityEgg entityegg = new EntityEgg(world, entityhuman);
entityegg.setItem(itemstack); entityegg.setItem(itemstack);
entityegg.a(entityhuman, entityhuman.pitch, entityhuman.yaw, 0.0F, 1.5F, 1.0F); entityegg.a(entityhuman, entityhuman.pitch, entityhuman.yaw, 0.0F, 1.5F, 1.0F);
@ -34,28 +34,37 @@ index 7cc3c33b0..b92d39600 100644
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ } + }
+ +
+ world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F)); + world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ entityhuman.b(StatisticList.ITEM_USED.b(this));
+ } else { + } else {
+ if (entityhuman instanceof EntityPlayer) { + if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ } + }
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack); + return new InteractionResultWrapper<ItemStack>(EnumInteractionResult.FAIL, itemstack);
+ } + }
+ // Paper end + // Paper end
} }
+ /* // Paper start - moved up
entityhuman.b(StatisticList.ITEM_USED.b(this)); entityhuman.b(StatisticList.ITEM_USED.b(this));
if (!entityhuman.abilities.canInstantlyBuild) {
itemstack.subtract(1);
}
+ */ // Paper end
return InteractionResultWrapper.a(itemstack);
}
diff --git a/src/main/java/net/minecraft/server/ItemEnderPearl.java b/src/main/java/net/minecraft/server/ItemEnderPearl.java diff --git a/src/main/java/net/minecraft/server/ItemEnderPearl.java b/src/main/java/net/minecraft/server/ItemEnderPearl.java
index e4a9e4b7b..570abc8b2 100644 index 315e01274..34ad0c119 100644
--- a/src/main/java/net/minecraft/server/ItemEnderPearl.java --- a/src/main/java/net/minecraft/server/ItemEnderPearl.java
+++ b/src/main/java/net/minecraft/server/ItemEnderPearl.java +++ b/src/main/java/net/minecraft/server/ItemEnderPearl.java
@@ -16,7 +16,19 @@ public class ItemEnderPearl extends Item { @@ -16,22 +16,37 @@ public class ItemEnderPearl extends Item {
entityenderpearl.setItem(itemstack); entityenderpearl.setItem(itemstack);
entityenderpearl.a(entityhuman, entityhuman.pitch, entityhuman.yaw, 0.0F, 1.5F, 1.0F); entityenderpearl.a(entityhuman, entityhuman.pitch, entityhuman.yaw, 0.0F, 1.5F, 1.0F);
- if (!world.addEntity(entityenderpearl)) { - if (!world.addEntity(entityenderpearl)) {
+ // Paper start + // Paper start
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entityenderpearl.getBukkitEntity()); + com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entityenderpearl.getBukkitEntity());
+ if (event.callEvent() && world.addEntity(entityenderpearl)) { + if (event.callEvent() && world.addEntity(entityenderpearl)) {
+ if (event.shouldConsume() && !entityhuman.abilities.canInstantlyBuild) { + if (event.shouldConsume() && !entityhuman.abilities.canInstantlyBuild) {
+ itemstack.subtract(1); + itemstack.subtract(1);
@ -63,52 +72,50 @@ index e4a9e4b7b..570abc8b2 100644
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ } + }
+ +
+ world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F)); + world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ entityhuman.b(StatisticList.ITEM_USED.b(this));
+ entityhuman.getCooldownTracker().setCooldown(this, 20); + entityhuman.getCooldownTracker().setCooldown(this, 20);
+ } else { + } else {
+ // Paper end + // Paper end
if (entityhuman instanceof EntityPlayer) { if (entityhuman instanceof EntityPlayer) {
((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
} }
@@ -24,13 +36,15 @@ public class ItemEnderPearl extends Item { - return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
+ return new InteractionResultWrapper<ItemStack>(EnumInteractionResult.FAIL, itemstack);
} }
} }
- world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemEnderPearl.i.nextFloat() * 0.4F + 0.8F));
- entityhuman.getCooldownTracker().setCooldown(this, 20);
- // CraftBukkit end
-
- entityhuman.b(StatisticList.ITEM_USED.b(this));
- if (!entityhuman.abilities.canInstantlyBuild) { - if (!entityhuman.abilities.canInstantlyBuild) {
- itemstack.subtract(1); - itemstack.subtract(1);
- } - }
- + // Paper start - moved up
- world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemEnderPearl.i.nextFloat() * 0.4F + 0.8F)); +// world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemEnderPearl.i.nextFloat() * 0.4F + 0.8F));
- entityhuman.getCooldownTracker().a(this, 20); +// entityhuman.getCooldownTracker().setCooldown(this, 20);
- // CraftBukkit end +// // CraftBukkit end
+// // Paper start - moved up +//
+// entityhuman.b(StatisticList.ITEM_USED.b(this));
+// if (!entityhuman.abilities.canInstantlyBuild) { +// if (!entityhuman.abilities.canInstantlyBuild) {
+// itemstack.subtract(1); +// itemstack.subtract(1);
+// } +// }
+// + // Paper end
+// world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemEnderPearl.i.nextFloat() * 0.4F + 0.8F));
+// entityhuman.getCooldownTracker().a(this, 20);
+// // CraftBukkit end
+// // Paper end
entityhuman.b(StatisticList.ITEM_USED.b(this)); return InteractionResultWrapper.a(itemstack);
return new InteractionResultWrapper<>(EnumInteractionResult.SUCCESS, itemstack); }
diff --git a/src/main/java/net/minecraft/server/ItemExpBottle.java b/src/main/java/net/minecraft/server/ItemExpBottle.java diff --git a/src/main/java/net/minecraft/server/ItemExpBottle.java b/src/main/java/net/minecraft/server/ItemExpBottle.java
index 8d557cd85..2a0aded65 100644 index f83eb5c45..1bcf58292 100644
--- a/src/main/java/net/minecraft/server/ItemExpBottle.java --- a/src/main/java/net/minecraft/server/ItemExpBottle.java
+++ b/src/main/java/net/minecraft/server/ItemExpBottle.java +++ b/src/main/java/net/minecraft/server/ItemExpBottle.java
@@ -9,18 +9,35 @@ public class ItemExpBottle extends Item { @@ -15,19 +15,38 @@ public class ItemExpBottle extends Item {
@Override
public InteractionResultWrapper<ItemStack> a(World world, EntityHuman entityhuman, EnumHand enumhand) { public InteractionResultWrapper<ItemStack> a(World world, EntityHuman entityhuman, EnumHand enumhand) {
ItemStack itemstack = entityhuman.b(enumhand); ItemStack itemstack = entityhuman.b(enumhand);
-
+ /* // Paper start
if (!entityhuman.abilities.canInstantlyBuild) {
itemstack.subtract(1);
}
world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_EXPERIENCE_BOTTLE_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemExpBottle.i.nextFloat() * 0.4F + 0.8F)); - world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_EXPERIENCE_BOTTLE_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemExpBottle.i.nextFloat() * 0.4F + 0.8F));
+ */ // Paper end +// world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_EXPERIENCE_BOTTLE_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemExpBottle.i.nextFloat() * 0.4F + 0.8F)); // Paper - moved down
if (!world.isClientSide) { if (!world.isClientSide) {
EntityThrownExpBottle entitythrownexpbottle = new EntityThrownExpBottle(world, entityhuman); EntityThrownExpBottle entitythrownexpbottle = new EntityThrownExpBottle(world, entityhuman);
@ -124,41 +131,51 @@ index 8d557cd85..2a0aded65 100644
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ } + }
+ +
+ world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_EXPERIENCE_BOTTLE_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F)); + world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_EXPERIENCE_BOTTLE_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ entityhuman.b(StatisticList.ITEM_USED.b(this));
+ } else { + } else {
+ if (entityhuman instanceof EntityPlayer) { + if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ } + }
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack); + return new InteractionResultWrapper<ItemStack>(EnumInteractionResult.FAIL, itemstack);
+ } + }
+ // Paper end + // Paper end
} }
+ /* // Paper start - moved up
entityhuman.b(StatisticList.ITEM_USED.b(this)); entityhuman.b(StatisticList.ITEM_USED.b(this));
if (!entityhuman.abilities.canInstantlyBuild) {
itemstack.subtract(1);
}
+ */ // Paper end
return InteractionResultWrapper.a(itemstack);
}
diff --git a/src/main/java/net/minecraft/server/ItemLingeringPotion.java b/src/main/java/net/minecraft/server/ItemLingeringPotion.java diff --git a/src/main/java/net/minecraft/server/ItemLingeringPotion.java b/src/main/java/net/minecraft/server/ItemLingeringPotion.java
index 1bddb7801..ca3f9f8cc 100644 index c19b678cf..7672e31fc 100644
--- a/src/main/java/net/minecraft/server/ItemLingeringPotion.java --- a/src/main/java/net/minecraft/server/ItemLingeringPotion.java
+++ b/src/main/java/net/minecraft/server/ItemLingeringPotion.java +++ b/src/main/java/net/minecraft/server/ItemLingeringPotion.java
@@ -9,15 +9,40 @@ public class ItemLingeringPotion extends ItemPotion { @@ -8,7 +8,11 @@ public class ItemLingeringPotion extends ItemPotionThrowable {
@Override @Override
public InteractionResultWrapper<ItemStack> a(World world, EntityHuman entityhuman, EnumHand enumhand) { public InteractionResultWrapper<ItemStack> a(World world, EntityHuman entityhuman, EnumHand enumhand) {
ItemStack itemstack = entityhuman.b(enumhand); - world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_LINGERING_POTION_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemLingeringPotion.i.nextFloat() * 0.4F + 0.8F));
+ /* // Paper start - return super.a(world, entityhuman, enumhand);
ItemStack itemstack1 = entityhuman.abilities.canInstantlyBuild ? itemstack.cloneItemStack() : itemstack.cloneAndSubtract(1); + // Paper start
+ InteractionResultWrapper<ItemStack> wrapper = super.a(world, entityhuman, enumhand);
+ if (wrapper.getResult() != EnumInteractionResult.FAIL)
+ world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_LINGERING_POTION_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemLingeringPotion.i.nextFloat() * 0.4F + 0.8F));
+ return wrapper;
+ // Paper end
}
}
diff --git a/src/main/java/net/minecraft/server/ItemPotionThrowable.java b/src/main/java/net/minecraft/server/ItemPotionThrowable.java
index 8f8f31b26..72dcf109f 100644
--- a/src/main/java/net/minecraft/server/ItemPotionThrowable.java
+++ b/src/main/java/net/minecraft/server/ItemPotionThrowable.java
@@ -15,13 +15,31 @@ public class ItemPotionThrowable extends ItemPotion {
world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_LINGERING_POTION_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemLingeringPotion.i.nextFloat() * 0.4F + 0.8F)); entitypotion.setItem(itemstack);
+ */ // Paper end
if (!world.isClientSide) {
+
+ // Paper start - ensure stack count matches vanilla behavior without modifying original stack yet
+ ItemStack itemstack1 = itemstack.cloneItemStack();
+ if (!entityhuman.abilities.canInstantlyBuild) {
+ itemstack1.setCount(1);
+ }
+ // Paper end
EntityPotion entitypotion = new EntityPotion(world, entityhuman);
entitypotion.setItem(itemstack1);
entitypotion.a(entityhuman, entityhuman.pitch, entityhuman.yaw, -20.0F, 0.5F, 1.0F); entitypotion.a(entityhuman, entityhuman.pitch, entityhuman.yaw, -20.0F, 0.5F, 1.0F);
- world.addEntity(entitypotion); - world.addEntity(entitypotion);
+ // Paper start + // Paper start
@ -170,22 +187,30 @@ index 1bddb7801..ca3f9f8cc 100644
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ } + }
+ +
+ world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_LINGERING_POTION_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F)); + entityhuman.b(StatisticList.ITEM_USED.b(this));
+ } else { + } else {
+ if (entityhuman instanceof EntityPlayer) { + if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ } + }
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack); + return new InteractionResultWrapper<ItemStack>(EnumInteractionResult.FAIL, itemstack);
+ } + }
+ // Paper end + // Paper end
} }
+ /* // Paper start - moved up
entityhuman.b(StatisticList.ITEM_USED.b(this)); entityhuman.b(StatisticList.ITEM_USED.b(this));
if (!entityhuman.abilities.canInstantlyBuild) {
itemstack.subtract(1);
}
+ */ // Paper end
return InteractionResultWrapper.a(itemstack);
}
diff --git a/src/main/java/net/minecraft/server/ItemSnowball.java b/src/main/java/net/minecraft/server/ItemSnowball.java diff --git a/src/main/java/net/minecraft/server/ItemSnowball.java b/src/main/java/net/minecraft/server/ItemSnowball.java
index f5387a74a..bbd22596e 100644 index abbf2b788..4ad285696 100644
--- a/src/main/java/net/minecraft/server/ItemSnowball.java --- a/src/main/java/net/minecraft/server/ItemSnowball.java
+++ b/src/main/java/net/minecraft/server/ItemSnowball.java +++ b/src/main/java/net/minecraft/server/ItemSnowball.java
@@ -23,14 +23,21 @@ public class ItemSnowball extends Item { @@ -17,18 +17,27 @@ public class ItemSnowball extends Item {
entitysnowball.setItem(itemstack); entitysnowball.setItem(itemstack);
entitysnowball.a(entityhuman, entityhuman.pitch, entityhuman.yaw, 0.0F, 1.5F, 1.0F); entitysnowball.a(entityhuman, entityhuman.pitch, entityhuman.yaw, 0.0F, 1.5F, 1.0F);
@ -200,63 +225,42 @@ index f5387a74a..bbd22596e 100644
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
} }
- world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemSnowball.i.nextFloat() * 0.4F + 0.8F)); - world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (ItemSnowball.i.nextFloat() * 0.4F + 0.8F)); } else if (entityhuman instanceof EntityPlayer) {
- } else if (entityhuman instanceof EntityPlayer) {
- ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); - ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F)); + world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ entityhuman.b(StatisticList.ITEM_USED.b(this));
+ } else { + } else {
+ if (entityhuman instanceof EntityPlayer) { + if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ } + }
+ return new InteractionResultWrapper<>(EnumInteractionResult.FAIL, itemstack); + return new InteractionResultWrapper<ItemStack>(EnumInteractionResult.FAIL, itemstack);
} }
} }
// CraftBukkit end // CraftBukkit end
- entityhuman.b(StatisticList.ITEM_USED.b(this));
+// entityhuman.b(StatisticList.ITEM_USED.b(this)); // Paper - moved up
// CraftBukkit start - moved up
/*
if (!entityhuman.abilities.canInstantlyBuild) {
diff --git a/src/main/java/net/minecraft/server/ItemSplashPotion.java b/src/main/java/net/minecraft/server/ItemSplashPotion.java diff --git a/src/main/java/net/minecraft/server/ItemSplashPotion.java b/src/main/java/net/minecraft/server/ItemSplashPotion.java
index bb9e60659..4460ddc6d 100644 index 18bd846ce..e71e933ff 100644
--- a/src/main/java/net/minecraft/server/ItemSplashPotion.java --- a/src/main/java/net/minecraft/server/ItemSplashPotion.java
+++ b/src/main/java/net/minecraft/server/ItemSplashPotion.java +++ b/src/main/java/net/minecraft/server/ItemSplashPotion.java
@@ -9,15 +9,39 @@ public class ItemSplashPotion extends ItemPotion { @@ -8,7 +8,11 @@ public class ItemSplashPotion extends ItemPotionThrowable {
@Override @Override
public InteractionResultWrapper<ItemStack> a(World world, EntityHuman entityhuman, EnumHand enumhand) { public InteractionResultWrapper<ItemStack> a(World world, EntityHuman entityhuman, EnumHand enumhand) {
ItemStack itemstack = entityhuman.b(enumhand); - world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (ItemSplashPotion.i.nextFloat() * 0.4F + 0.8F));
+ /* // Paper start - return super.a(world, entityhuman, enumhand);
ItemStack itemstack1 = entityhuman.abilities.canInstantlyBuild ? itemstack.cloneItemStack() : itemstack.cloneAndSubtract(1); + // Paper start
+ InteractionResultWrapper<ItemStack> wrapper = super.a(world, entityhuman, enumhand);
world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (ItemSplashPotion.i.nextFloat() * 0.4F + 0.8F)); + if (wrapper.getResult() != EnumInteractionResult.FAIL)
+ */ // Paper end + world.playSound((EntityHuman) null, entityhuman.locX(), entityhuman.locY(), entityhuman.locZ(), SoundEffects.ENTITY_SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (ItemSplashPotion.i.nextFloat() * 0.4F + 0.8F));
if (!world.isClientSide) { + return wrapper;
EntityPotion entitypotion = new EntityPotion(world, entityhuman); + // Paper end
+ // Paper start - ensure stack count matches vanilla behavior without modifying original stack yet }
+ ItemStack itemstack1 = itemstack.cloneItemStack(); }
+ if (!entityhuman.abilities.canInstantlyBuild) {
+ itemstack1.setCount(1);
+ }
+ // Paper end
entitypotion.setItem(itemstack1);
entitypotion.a(entityhuman, entityhuman.pitch, entityhuman.yaw, -20.0F, 0.5F, 1.0F);
- world.addEntity(entitypotion);
+ // Paper start
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack), (org.bukkit.entity.Projectile) entitypotion.getBukkitEntity());
+ if (event.callEvent() && world.addEntity(entitypotion)) {
+ if (event.shouldConsume() && !entityhuman.abilities.canInstantlyBuild) {
+ itemstack.subtract(1);
+ } else if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ }
+
+ world.playSound((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_SPLASH_POTION_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (Entity.SHARED_RANDOM.nextFloat() * 0.4F + 0.8F));
+ } else {
+ if (entityhuman instanceof EntityPlayer) {
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
+ }
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
+ }
+ // Paper end
}
entityhuman.b(StatisticList.ITEM_USED.b(this));
-- --
2.20.1 2.22.0