mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
EntityLoadCrossbowEvent#shouldConsumeItem
This commit is contained in:
parent
d0d21ba718
commit
2da0e4a287
2 changed files with 31 additions and 2 deletions
|
@ -30,6 +30,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ private final ItemStack crossbow;
|
+ private final ItemStack crossbow;
|
||||||
+ private final EquipmentSlot hand;
|
+ private final EquipmentSlot hand;
|
||||||
+ private boolean cancelled;
|
+ private boolean cancelled;
|
||||||
|
+ private boolean consumeItem = true;
|
||||||
+
|
+
|
||||||
+ public EntityLoadCrossbowEvent(@NotNull LivingEntity entity, @Nullable ItemStack crossbow, @NotNull EquipmentSlot hand) {
|
+ public EntityLoadCrossbowEvent(@NotNull LivingEntity entity, @Nullable ItemStack crossbow, @NotNull EquipmentSlot hand) {
|
||||||
+ super(entity);
|
+ super(entity);
|
||||||
|
@ -63,6 +64,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ return hand;
|
+ 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
|
+ @Override
|
||||||
+ public boolean isCancelled() {
|
+ public boolean isCancelled() {
|
||||||
+ return cancelled;
|
+ return cancelled;
|
||||||
|
|
|
@ -12,6 +12,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
+
|
||||||
|
+import org.bukkit.inventory.EquipmentSlot;
|
||||||
|
+
|
||||||
+import io.papermc.paper.event.entity.EntityLoadCrossbowEvent; // Paper - EntityLoadCrossbowEvent namespace conflicts
|
+import io.papermc.paper.event.entity.EntityLoadCrossbowEvent; // Paper - EntityLoadCrossbowEvent namespace conflicts
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -23,7 +26,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
- if (f >= 1.0F && !d(itemstack) && a(entityliving, itemstack)) {
|
- if (f >= 1.0F && !d(itemstack) && a(entityliving, itemstack)) {
|
||||||
+ // Paper start - EntityLoadCrossbowEvent
|
+ // Paper start - EntityLoadCrossbowEvent
|
||||||
+ if (f >= 1.0F && !d(itemstack) /*&& a(entityliving, itemstack)*/) {
|
+ 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
|
+ // Paper end
|
||||||
a(itemstack, true);
|
a(itemstack, true);
|
||||||
SoundCategory soundcategory = entityliving instanceof EntityHuman ? SoundCategory.PLAYERS : SoundCategory.HOSTILE;
|
SoundCategory soundcategory = entityliving instanceof EntityHuman ? SoundCategory.PLAYERS : SoundCategory.HOSTILE;
|
||||||
|
@ -32,7 +36,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- 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) { 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 i = EnchantmentManager.getEnchantmentLevel(Enchantments.MULTISHOT, itemstack);
|
||||||
int j = i == 0 ? 1 : 3;
|
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();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue