aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches-Unmapped/0633-Add-EntityLoadCrossbowEvent.patch
blob: 5e9ae2150b3356f8778eae3b63f843607fdcd4f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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/ItemCrossbow.java b/src/main/java/net/minecraft/world/item/ItemCrossbow.java
index ec6c0836f02e7ac5b72fd224a3022a844dce55cb..4e1e819c8535e8a6b9aa5f76afe568ea171b939f 100644
--- a/src/main/java/net/minecraft/world/item/ItemCrossbow.java
+++ b/src/main/java/net/minecraft/world/item/ItemCrossbow.java
@@ -3,6 +3,8 @@ package net.minecraft.world.item;
 import com.google.common.collect.Lists;
 import com.mojang.math.Quaternion;
 import com.mojang.math.Vector3fa;
+import org.bukkit.inventory.EquipmentSlot; // Paper
+import io.papermc.paper.event.entity.EntityLoadCrossbowEvent; // Paper - EntityLoadCrossbowEvent namespace conflicts
 import java.util.List;
 import java.util.Random;
 import java.util.function.Predicate;
@@ -73,7 +75,11 @@ public class ItemCrossbow extends ItemProjectileWeapon implements ItemVanishable
         int j = this.e_(itemstack) - i;
         float f = a(j, itemstack);
 
-        if (f >= 1.0F && !d(itemstack) && a(entityliving, itemstack)) {
+        // Paper start - EntityLoadCrossbowEvent
+        if (f >= 1.0F && !d(itemstack) /*&& a(entityliving, itemstack)*/) {
+            final EntityLoadCrossbowEvent event = new EntityLoadCrossbowEvent(entityliving.getBukkitLivingEntity(), itemstack.asBukkitMirror(), entityliving.getRaisedHand() == EnumHand.MAIN_HAND ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND);
+            if (!event.callEvent() || !attemptProjectileLoad(entityliving, itemstack, event.shouldConsumeItem())) return;
+        // Paper end
             a(itemstack, true);
             SoundCategory soundcategory = entityliving instanceof EntityHuman ? SoundCategory.PLAYERS : SoundCategory.HOSTILE;
 
@@ -82,10 +88,13 @@ public class ItemCrossbow extends ItemProjectileWeapon implements ItemVanishable
 
     }
 
-    private static boolean a(EntityLiving entityliving, ItemStack itemstack) {
+    private static boolean attemptProjectileLoad(EntityLiving ent, ItemStack bow) { return a(ent, bow); } // Paper - EntityLoadCrossbowEvent - OBFHELPER
+    private static boolean attemptProjectileLoad(EntityLiving ent, ItemStack bow, boolean consume) { return a(ent, bow, consume); } // Paper - EntityLoadCrossbowEvent - OBFHELPER
+    private static boolean a(EntityLiving entityliving, ItemStack itemstack) { return a(entityliving, itemstack, true); };// Paper - add consume
+    private static boolean a(EntityLiving entityliving, ItemStack itemstack, boolean consume) { // Paper - add consume
         int i = EnchantmentManager.getEnchantmentLevel(Enchantments.MULTISHOT, itemstack);
         int j = i == 0 ? 1 : 3;
-        boolean flag = entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.canInstantlyBuild;
+        boolean flag = !consume || entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.canInstantlyBuild; // Paper - add consme
         ItemStack itemstack1 = entityliving.f(itemstack);
         ItemStack itemstack2 = itemstack1.cloneItemStack();