PaperMC/paper-server/patches/sources/net/minecraft/world/item/ThrowablePotionItem.java.patch
2018-07-21 03:11:03 -05:00

34 lines
2.1 KiB
Diff

--- a/net/minecraft/world/item/ThrowablePotionItem.java
+++ b/net/minecraft/world/item/ThrowablePotionItem.java
@@ -22,11 +22,28 @@
public InteractionResult use(Level world, Player user, InteractionHand hand) {
ItemStack itemStack = user.getItemInHand(hand);
if (world instanceof ServerLevel serverLevel) {
- Projectile.spawnProjectileFromRotation(ThrownPotion::new, serverLevel, itemStack, user, -20.0F, PROJECTILE_SHOOT_POWER, 1.0F);
+ // Paper start - PlayerLaunchProjectileEvent
+ final Projectile.Delayed<ThrownPotion> thrownPotion = Projectile.spawnProjectileFromRotationDelayed(ThrownPotion::new, serverLevel, itemStack, user, -20.0F, PROJECTILE_SHOOT_POWER, 1.0F);
+ // Paper start - PlayerLaunchProjectileEvent
+ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Projectile) thrownPotion.projectile().getBukkitEntity());
+ if (event.callEvent() && thrownPotion.attemptSpawn()) {
+ if (event.shouldConsume()) {
+ itemStack.consume(1, user);
+ } else if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+
+ user.awardStat(Stats.ITEM_USED.get(this));
+ } else {
+ if (user instanceof net.minecraft.server.level.ServerPlayer) {
+ ((net.minecraft.server.level.ServerPlayer) user).getBukkitEntity().updateInventory();
+ }
+ return InteractionResult.FAIL;
+ }
+ // Paper end - PlayerLaunchProjectileEvent
}
- user.awardStat(Stats.ITEM_USED.get(this));
- itemStack.consume(1, user);
+ // Paper - PlayerLaunchProjectileEvent - move up
return InteractionResult.SUCCESS;
}