2019-03-20 02:46:00 +01:00
|
|
|
From d80a4b17e1c8d28526426a21fd09a901b298b40b Mon Sep 17 00:00:00 2001
|
2018-06-18 06:39:04 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sat, 15 Jun 2013 19:51:17 -0400
|
|
|
|
Subject: [PATCH] EntityShootBowEvent consumeArrow and getArrowItem API
|
|
|
|
|
|
|
|
Adds ability to get what arrow was shot, and control if it should be consumed.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java b/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java
|
2019-03-20 02:46:00 +01:00
|
|
|
index 749a8a527..6e2ee04c7 100644
|
2018-06-18 06:39:04 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java
|
2019-01-15 22:12:19 +01:00
|
|
|
@@ -152,7 +152,7 @@ public abstract class EntitySkeletonAbstract extends EntityMonster implements IR
|
2018-06-18 06:39:04 +02:00
|
|
|
|
|
|
|
entityarrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - this.world.getDifficulty().a() * 4));
|
|
|
|
// CraftBukkit start
|
|
|
|
- org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(this, this.getItemInMainHand(), entityarrow, 0.8F);
|
|
|
|
+ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(this, this.getItemInMainHand(), this.getItemInOffHand(), entityarrow, 0.8F); // Paper
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
event.getProjectile().remove();
|
|
|
|
return;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ItemBow.java b/src/main/java/net/minecraft/server/ItemBow.java
|
2019-03-20 02:46:00 +01:00
|
|
|
index 693411400..52bc68e6a 100644
|
2018-06-18 06:39:04 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ItemBow.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ItemBow.java
|
2019-01-15 22:12:19 +01:00
|
|
|
@@ -55,6 +55,7 @@ public class ItemBow extends Item {
|
2018-06-18 06:39:04 +02:00
|
|
|
if ((double) f >= 0.1D) {
|
|
|
|
boolean flag1 = flag && itemstack1.getItem() == Items.ARROW;
|
|
|
|
|
|
|
|
+ boolean consumeArrow = true; // Paper
|
|
|
|
if (!world.isClientSide) {
|
|
|
|
ItemArrow itemarrow = (ItemArrow) ((ItemArrow) (itemstack1.getItem() instanceof ItemArrow ? itemstack1.getItem() : Items.ARROW));
|
|
|
|
EntityArrow entityarrow = itemarrow.a(world, itemstack1, (EntityLiving) entityhuman);
|
2019-01-15 22:12:19 +01:00
|
|
|
@@ -80,7 +81,7 @@ public class ItemBow extends Item {
|
|
|
|
entityarrow.setOnFire(100);
|
2018-06-18 06:39:04 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit start
|
|
|
|
- org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityhuman, itemstack, entityarrow, f);
|
|
|
|
+ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityhuman, itemstack, itemstack1, entityarrow, f); // Paper
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
event.getProjectile().remove();
|
|
|
|
return;
|
2019-01-15 22:12:19 +01:00
|
|
|
@@ -88,7 +89,8 @@ public class ItemBow extends Item {
|
|
|
|
// CraftBukkit end
|
2018-06-18 06:39:04 +02:00
|
|
|
|
|
|
|
itemstack.damage(1, entityhuman);
|
|
|
|
- if (flag1 || entityhuman.abilities.canInstantlyBuild && (itemstack1.getItem() == Items.SPECTRAL_ARROW || itemstack1.getItem() == Items.TIPPED_ARROW)) {
|
|
|
|
+ consumeArrow = event.getConsumeArrow(); // Paper
|
|
|
|
+ if (!consumeArrow || flag1 || (entityhuman.abilities.canInstantlyBuild && ((itemstack1.getItem() == Items.SPECTRAL_ARROW) || (itemstack1.getItem() == Items.TIPPED_ARROW)))) { // Paper - add !consumeArrow
|
|
|
|
entityarrow.fromPlayer = EntityArrow.PickupStatus.CREATIVE_ONLY;
|
|
|
|
}
|
|
|
|
|
2019-01-15 22:12:19 +01:00
|
|
|
@@ -105,7 +107,7 @@ public class ItemBow extends Item {
|
2018-06-18 06:39:04 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 20:11:49 +02:00
|
|
|
world.a((EntityHuman) null, entityhuman.locX, entityhuman.locY, entityhuman.locZ, SoundEffects.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (ItemBow.i.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
|
2018-06-18 06:39:04 +02:00
|
|
|
- if (!flag1 && !entityhuman.abilities.canInstantlyBuild) {
|
|
|
|
+ if (!flag1 && !entityhuman.abilities.canInstantlyBuild && consumeArrow) { // Paper
|
|
|
|
itemstack1.subtract(1);
|
|
|
|
if (itemstack1.isEmpty()) {
|
|
|
|
entityhuman.inventory.f(itemstack1);
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2019-03-20 02:46:00 +01:00
|
|
|
index 0c57b36c8..e75c188b5 100644
|
2018-06-18 06:39:04 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2019-01-30 14:26:12 +01:00
|
|
|
@@ -332,7 +332,7 @@ public class CraftEventFactory {
|
2018-06-18 06:39:04 +02:00
|
|
|
/**
|
|
|
|
* EntityShootBowEvent
|
|
|
|
*/
|
|
|
|
- public static EntityShootBowEvent callEntityShootBowEvent(EntityLiving who, ItemStack itemstack, EntityArrow entityArrow, float force) {
|
|
|
|
+ public static EntityShootBowEvent callEntityShootBowEvent(EntityLiving who, /*bow*/ItemStack itemstack, /*arrow*/ ItemStack arrowItem, EntityArrow entityArrow, float force) { // Paper
|
|
|
|
LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
|
|
|
|
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
|
|
|
|
Arrow arrow = (Arrow) entityArrow.getBukkitEntity();
|
2019-01-30 14:26:12 +01:00
|
|
|
@@ -341,7 +341,7 @@ public class CraftEventFactory {
|
2018-06-18 06:39:04 +02:00
|
|
|
itemInHand = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
- EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force);
|
|
|
|
+ EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, CraftItemStack.asCraftMirror(arrowItem), arrow, force); // Paper
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
--
|
2019-03-20 02:46:00 +01:00
|
|
|
2.21.0
|
2018-06-18 06:39:04 +02:00
|
|
|
|