Paper/patches/server/0526-Add-EntityLoadCrossbowEvent.patch
2023-06-08 21:29:58 -07:00

45 lines
2.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JRoy <joshroy126@gmail.com>
Date: Wed, 7 Oct 2020 12:04:01 -0400
Subject: [PATCH] Add EntityLoadCrossbowEvent
diff --git a/src/main/java/net/minecraft/world/item/CrossbowItem.java b/src/main/java/net/minecraft/world/item/CrossbowItem.java
index 9bea5e94c246d843f3d67680ffb57075bd9d3467..a433910fb4d0bd8d7b6b0d66c8fc88d62a0e4879 100644
--- a/src/main/java/net/minecraft/world/item/CrossbowItem.java
+++ b/src/main/java/net/minecraft/world/item/CrossbowItem.java
@@ -89,7 +89,14 @@ public class CrossbowItem extends ProjectileWeaponItem implements Vanishable {
int j = this.getUseDuration(stack) - remainingUseTicks;
float f = CrossbowItem.getPowerForTime(j, stack);
- if (f >= 1.0F && !CrossbowItem.isCharged(stack) && CrossbowItem.tryLoadProjectiles(user, stack)) {
+ // Paper start - EntityLoadCrossbowEvent
+ if (f >= 1.0F && !CrossbowItem.isCharged(stack) /*&& CrossbowItem.tryLoadProjectiles(entityliving, itemstack)*/) {
+ final io.papermc.paper.event.entity.EntityLoadCrossbowEvent event = new io.papermc.paper.event.entity.EntityLoadCrossbowEvent(user.getBukkitLivingEntity(), stack.asBukkitMirror(), user.getUsedItemHand() == InteractionHand.MAIN_HAND ? org.bukkit.inventory.EquipmentSlot.HAND : org.bukkit.inventory.EquipmentSlot.OFF_HAND);
+ if (!event.callEvent() || !tryLoadProjectiles(user, stack, event.shouldConsumeItem())) {
+ if (user instanceof ServerPlayer player) player.containerMenu.sendAllDataToRemote();
+ return;
+ }
+ // Paper end
CrossbowItem.setCharged(stack, true);
SoundSource soundcategory = user instanceof Player ? SoundSource.PLAYERS : SoundSource.HOSTILE;
@@ -98,10 +105,16 @@ public class CrossbowItem extends ProjectileWeaponItem implements Vanishable {
}
+ @io.papermc.paper.annotation.DoNotUse // Paper
private static boolean tryLoadProjectiles(LivingEntity shooter, ItemStack crossbow) {
+ // Paper start
+ return CrossbowItem.tryLoadProjectiles(shooter, crossbow, true);
+ }
+ private static boolean tryLoadProjectiles(LivingEntity shooter, ItemStack crossbow, boolean consume) {
+ // Paper end
int i = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.MULTISHOT, crossbow);
int j = i == 0 ? 1 : 3;
- boolean flag = shooter instanceof Player && ((Player) shooter).getAbilities().instabuild;
+ boolean flag = !consume || shooter instanceof Player && ((Player) shooter).getAbilities().instabuild; // Paper - add consume
ItemStack itemstack1 = shooter.getProjectile(crossbow);
ItemStack itemstack2 = itemstack1.copy();