From 7232d8f2af6b32309efe46d88787101ea13ad458 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Thu, 14 Jan 2021 15:53:42 +0000 Subject: [PATCH] EntityLoadCrossbowEvent#shouldConsumeItem --- .../0251-Add-EntityLoadCrossbowEvent.patch | 21 ++++++++++++++-- .../0635-Add-EntityLoadCrossbowEvent.patch | 24 ++++++++++++++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Spigot-API-Patches/0251-Add-EntityLoadCrossbowEvent.patch b/Spigot-API-Patches/0251-Add-EntityLoadCrossbowEvent.patch index b96905bcd..f484d40cc 100644 --- a/Spigot-API-Patches/0251-Add-EntityLoadCrossbowEvent.patch +++ b/Spigot-API-Patches/0251-Add-EntityLoadCrossbowEvent.patch @@ -6,10 +6,10 @@ Subject: [PATCH] Add EntityLoadCrossbowEvent diff --git a/src/main/java/io/papermc/paper/event/entity/EntityLoadCrossbowEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityLoadCrossbowEvent.java new file mode 100644 -index 0000000000000000000000000000000000000000..8ba1c04af4058e70bf5925b9ccd36c3c8f8f8250 +index 0000000000000000000000000000000000000000..287f487b266d5c12fcf6f028452735e314d55636 --- /dev/null +++ b/src/main/java/io/papermc/paper/event/entity/EntityLoadCrossbowEvent.java -@@ -0,0 +1,84 @@ +@@ -0,0 +1,101 @@ +package io.papermc.paper.event.entity; + +import org.bukkit.entity.LivingEntity; @@ -30,6 +30,7 @@ index 0000000000000000000000000000000000000000..8ba1c04af4058e70bf5925b9ccd36c3c + private final ItemStack crossbow; + private final EquipmentSlot hand; + private boolean cancelled; ++ private boolean consumeItem = true; + + public EntityLoadCrossbowEvent(@NotNull LivingEntity entity, @Nullable ItemStack crossbow, @NotNull EquipmentSlot hand) { + super(entity); @@ -63,6 +64,22 @@ index 0000000000000000000000000000000000000000..8ba1c04af4058e70bf5925b9ccd36c3c + return hand; + } + ++ /** ++ * ++ * @return should the itemstack be consumed ++ */ ++ public boolean shouldConsumeItem() { ++ return consumeItem; ++ } ++ ++ /** ++ * ++ * @param consume should the item be consumed ++ */ ++ public void setConsumeItem(boolean consume) { ++ this.consumeItem = consume; ++ } ++ + @Override + public boolean isCancelled() { + return cancelled; diff --git a/Spigot-Server-Patches/0635-Add-EntityLoadCrossbowEvent.patch b/Spigot-Server-Patches/0635-Add-EntityLoadCrossbowEvent.patch index 125bbdaed..82f277001 100644 --- a/Spigot-Server-Patches/0635-Add-EntityLoadCrossbowEvent.patch +++ b/Spigot-Server-Patches/0635-Add-EntityLoadCrossbowEvent.patch @@ -5,34 +5,46 @@ Subject: [PATCH] Add EntityLoadCrossbowEvent diff --git a/src/main/java/net/minecraft/server/ItemCrossbow.java b/src/main/java/net/minecraft/server/ItemCrossbow.java -index 14c0e7382292b3d39858d4d957df8016c301c712..9bf5d77db3bca4073867139844fbcdcc4d3f7c83 100644 +index 14c0e7382292b3d39858d4d957df8016c301c712..ac60163117a52ea97b710fc93552dd1699e8a092 100644 --- a/src/main/java/net/minecraft/server/ItemCrossbow.java +++ b/src/main/java/net/minecraft/server/ItemCrossbow.java -@@ -1,6 +1,7 @@ +@@ -1,6 +1,10 @@ package net.minecraft.server; import com.google.common.collect.Lists; ++ ++import org.bukkit.inventory.EquipmentSlot; ++ +import io.papermc.paper.event.entity.EntityLoadCrossbowEvent; // Paper - EntityLoadCrossbowEvent namespace conflicts import java.util.List; import java.util.Random; import java.util.function.Predicate; -@@ -50,7 +51,10 @@ public class ItemCrossbow extends ItemProjectileWeapon implements ItemVanishable +@@ -50,7 +54,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)*/) { -+ if (!new EntityLoadCrossbowEvent(entityliving.getBukkitLivingEntity(), itemstack.asBukkitMirror(), entityliving.getRaisedHand() == EnumHand.MAIN_HAND ? org.bukkit.inventory.EquipmentSlot.HAND : org.bukkit.inventory.EquipmentSlot.OFF_HAND).callEvent() || !attemptProjectileLoad(entityliving, itemstack)) return; ++ 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; -@@ -59,6 +63,7 @@ public class ItemCrossbow extends ItemProjectileWeapon implements ItemVanishable +@@ -59,10 +67,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 a(EntityLiving entityliving, ItemStack itemstack) { ++ 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(); +