--- a/net/minecraft/world/item/ProjectileWeaponItem.java +++ b/net/minecraft/world/item/ProjectileWeaponItem.java @@ -62,12 +_,25 @@ float f4 = f2 + f3 * ((i + 1) / 2) * f1; f3 = -f3; int i1 = i; - Projectile.spawnProjectile( - this.createProjectile(level, shooter, weapon, itemStack, isCrit), - level, - itemStack, - projectile -> this.shootProjectile(shooter, projectile, i1, velocity, inaccuracy, f4, target) - ); + // CraftBukkit start + Projectile projectile = this.createProjectile(level, shooter, weapon, itemStack, isCrit); + this.shootProjectile(shooter, projectile, i1, velocity, inaccuracy, f4, target); + + org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(shooter, weapon, itemStack, projectile, hand, velocity, true); + if (event.isCancelled()) { + event.getProjectile().remove(); + return; + } + + if (event.getProjectile() == projectile.getBukkitEntity()) { + if (Projectile.spawnProjectile(projectile, level, itemStack).isRemoved()) { + if (shooter instanceof net.minecraft.server.level.ServerPlayer) { + ((net.minecraft.server.level.ServerPlayer) shooter).getBukkitEntity().updateInventory(); + } + return; + } + } + // CraftBukkit end weapon.hurtAndBreak(this.getDurabilityUse(itemStack), shooter, LivingEntity.getSlotForHand(hand)); if (weapon.isEmpty()) { break; @@ -95,6 +_,11 @@ } protected static List draw(ItemStack weapon, ItemStack ammo, LivingEntity shooter) { + // Paper start + return draw(weapon, ammo, shooter, true); + } + protected static List draw(ItemStack weapon, ItemStack ammo, LivingEntity shooter, boolean consume) { + // Paper end if (ammo.isEmpty()) { return List.of(); } else { @@ -103,7 +_,7 @@ ItemStack itemStack = ammo.copy(); for (int i1 = 0; i1 < i; i1++) { - ItemStack itemStack1 = useAmmo(weapon, i1 == 0 ? ammo : itemStack, shooter, i1 > 0); + ItemStack itemStack1 = useAmmo(weapon, i1 == 0 ? ammo : itemStack, shooter, i1 > 0 || !consume); // Paper if (!itemStack1.isEmpty()) { list.add(itemStack1); }