2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 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
|
2020-05-06 11:48:49 +02:00
|
|
|
index fb9656afde07a871216a4c5e414777603be590d1..3c95c0428b211b14db65be16a95446debda789e6 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-04-30 03:20:24 +02:00
|
|
|
@@ -157,7 +157,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
|
2020-05-06 11:48:49 +02:00
|
|
|
index 83aa70c295f93b1c19d81fb0b90876e62fe58c23..26899916d3f5274691386685d13d18f587e4ec28 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-04-30 03:20:24 +02:00
|
|
|
@@ -36,6 +36,7 @@ public class ItemBow extends ItemProjectileWeapon {
|
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-04-30 03:20:24 +02:00
|
|
|
@@ -61,7 +62,7 @@ public class ItemBow extends ItemProjectileWeapon {
|
2019-01-15 22:12:19 +01:00
|
|
|
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-04-30 03:20:24 +02:00
|
|
|
@@ -71,7 +72,8 @@ public class ItemBow extends ItemProjectileWeapon {
|
|
|
|
itemstack.damage(1, entityhuman, (entityhuman1) -> {
|
2020-01-22 03:02:07 +01:00
|
|
|
entityhuman1.broadcastItemBreak(entityhuman.getRaisedHand());
|
2019-04-30 03:20:24 +02:00
|
|
|
});
|
2018-06-18 06:39:04 +02:00
|
|
|
- if (flag1 || entityhuman.abilities.canInstantlyBuild && (itemstack1.getItem() == Items.SPECTRAL_ARROW || itemstack1.getItem() == Items.TIPPED_ARROW)) {
|
|
|
|
+ consumeArrow = event.getConsumeArrow(); // Paper
|
2019-04-30 03:20:24 +02:00
|
|
|
+ if (!consumeArrow || flag1 || (entityhuman.abilities.canInstantlyBuild && ((itemstack1.getItem() == Items.SPECTRAL_ARROW) || (itemstack1.getItem() == Items.TIPPED_ARROW)))) { // Paper - add
|
2018-06-18 06:39:04 +02:00
|
|
|
entityarrow.fromPlayer = EntityArrow.PickupStatus.CREATIVE_ONLY;
|
|
|
|
}
|
|
|
|
|
2019-04-30 03:20:24 +02:00
|
|
|
@@ -88,7 +90,7 @@ public class ItemBow extends ItemProjectileWeapon {
|
2018-06-18 06:39:04 +02:00
|
|
|
}
|
|
|
|
|
2019-12-12 00:43:22 +01:00
|
|
|
world.playSound((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);
|
2019-04-30 03:20:24 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ItemCrossbow.java b/src/main/java/net/minecraft/server/ItemCrossbow.java
|
2020-05-06 11:48:49 +02:00
|
|
|
index 7be41c8698e86727978db7d72b3dd3fbfe6b7272..60a47bccca5bc77039c0bec94eb329b3f2f0937f 100644
|
2019-04-30 03:20:24 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ItemCrossbow.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ItemCrossbow.java
|
2019-07-24 05:12:40 +02:00
|
|
|
@@ -221,7 +221,7 @@ public class ItemCrossbow extends ItemProjectileWeapon {
|
2019-04-30 03:20:24 +02:00
|
|
|
((IProjectile) object).shoot((double) vector3fa.a(), (double) vector3fa.b(), (double) vector3fa.c(), f1, f2);
|
|
|
|
}
|
|
|
|
// CraftBukkit start
|
|
|
|
- org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityliving, itemstack, (Entity) object, f);
|
|
|
|
+ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityliving, itemstack, itemstack1, (IProjectile) object, f); // Paper // TODO: consume??
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
event.getProjectile().remove();
|
|
|
|
return;
|
2018-06-18 06:39:04 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2020-05-06 12:05:22 +02:00
|
|
|
index 43965bea87e5884fa0f6b7838abbade08ce5c536..3a897cf5903539e1099f1a9ec98f1e157437fee0 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
|
2020-05-02 00:03:47 +02:00
|
|
|
@@ -52,6 +52,7 @@ import net.minecraft.server.GeneratorAccess;
|
2019-04-30 03:20:24 +02:00
|
|
|
import net.minecraft.server.IBlockData;
|
|
|
|
import net.minecraft.server.IChatBaseComponent;
|
|
|
|
import net.minecraft.server.IInventory;
|
|
|
|
+import net.minecraft.server.IProjectile;
|
|
|
|
import net.minecraft.server.ItemActionContext;
|
|
|
|
import net.minecraft.server.ItemStack;
|
|
|
|
import net.minecraft.server.Items;
|
2020-05-06 12:05:22 +02:00
|
|
|
@@ -478,16 +479,16 @@ public class CraftEventFactory {
|
2018-06-18 06:39:04 +02:00
|
|
|
/**
|
|
|
|
* EntityShootBowEvent
|
|
|
|
*/
|
2019-04-30 03:20:24 +02:00
|
|
|
- public static EntityShootBowEvent callEntityShootBowEvent(EntityLiving who, ItemStack itemstack, Entity entityArrow, float force) {
|
|
|
|
+ public static EntityShootBowEvent callEntityShootBowEvent(EntityLiving who, ItemStack itemstack, ItemStack arrowItem, IProjectile entityArrow, float force) { // paper
|
2018-06-18 06:39:04 +02:00
|
|
|
LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
|
|
|
|
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
|
2019-04-30 03:20:24 +02:00
|
|
|
- org.bukkit.entity.Entity arrow = entityArrow.getBukkitEntity();
|
|
|
|
+ org.bukkit.entity.Entity arrow = ((Entity) entityArrow).getBukkitEntity(); // Paper
|
|
|
|
|
|
|
|
if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
|
2018-06-18 06:39:04 +02:00
|
|
|
itemInHand = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
- EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force);
|
2019-05-07 20:56:32 +02:00
|
|
|
+ EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, CraftItemStack.asCraftMirror(arrowItem), arrow, force); // Paper
|
2018-06-18 06:39:04 +02:00
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|