--- a/net/minecraft/world/item/CrossbowItem.java +++ b/net/minecraft/world/item/CrossbowItem.java @@ -90,7 +_,14 @@ public boolean releaseUsing(ItemStack stack, Level level, LivingEntity entity, int timeLeft) { int i = this.getUseDuration(stack, entity) - timeLeft; float powerForTime = getPowerForTime(i, stack, entity); - if (powerForTime >= 1.0F && !isCharged(stack) && tryLoadProjectiles(entity, stack)) { + // Paper start - Add EntityLoadCrossbowEvent + if (powerForTime >= 1.0F && !isCharged(stack)) { + final io.papermc.paper.event.entity.EntityLoadCrossbowEvent event = new io.papermc.paper.event.entity.EntityLoadCrossbowEvent(entity.getBukkitLivingEntity(), stack.asBukkitMirror(), org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(entity.getUsedItemHand())); + if (!event.callEvent() || !tryLoadProjectiles(entity, stack, event.shouldConsumeItem()) || !event.shouldConsumeItem()) { + if (entity instanceof ServerPlayer player) player.containerMenu.sendAllDataToRemote(); + return false; + } + // Paper end - Add EntityLoadCrossbowEvent CrossbowItem.ChargingSounds chargingSounds = this.getChargingSounds(stack); chargingSounds.end() .ifPresent( @@ -111,8 +_,14 @@ } } + @io.papermc.paper.annotation.DoNotUse // Paper - Add EntityLoadCrossbowEvent private static boolean tryLoadProjectiles(LivingEntity shooter, ItemStack crossbowStack) { - List list = draw(crossbowStack, shooter.getProjectile(crossbowStack), shooter); + // Paper start - Add EntityLoadCrossbowEvent + return CrossbowItem.tryLoadProjectiles(shooter, crossbowStack, true); + } + private static boolean tryLoadProjectiles(LivingEntity shooter, ItemStack crossbowStack, boolean consume) { + List list = draw(crossbowStack, shooter.getProjectile(crossbowStack), shooter, consume); + // Paper end - Add EntityLoadCrossbowEvent if (!list.isEmpty()) { crossbowStack.set(DataComponents.CHARGED_PROJECTILES, ChargedProjectiles.of(list)); return true; @@ -164,7 +_,11 @@ @Override protected Projectile createProjectile(Level level, LivingEntity shooter, ItemStack weapon, ItemStack ammo, boolean isCrit) { if (ammo.is(Items.FIREWORK_ROCKET)) { - return new FireworkRocketEntity(level, ammo, shooter, shooter.getX(), shooter.getEyeY() - 0.15F, shooter.getZ(), true); + // Paper start + FireworkRocketEntity entity = new FireworkRocketEntity(level, ammo, shooter, shooter.getX(), shooter.getEyeY() - 0.15F, shooter.getZ(), true); + entity.spawningEntity = shooter.getUUID(); // Paper + return entity; + // Paper end } else { Projectile projectile = super.createProjectile(level, shooter, weapon, ammo, isCrit); if (projectile instanceof AbstractArrow abstractArrow) {