mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 03:52:45 +01:00
c4c6bf8a92
This pr reverts a change made in 2012 which allowed CraftItem to be a also other entities such as an arrow. I don't see any practical reason why the original change was done, other than to allow plugin developers to do some stuff in a cursed way. With the introduction of the PlayerPickupArrowEvent in 2016 there is also a way to access the arrow involved in a better way. Generally I think the current behavior is a bit strange and should be reverted. By: DerFrZocker <derrieple@gmail.com>
63 lines
3 KiB
Diff
63 lines
3 KiB
Diff
--- a/net/minecraft/world/entity/projectile/EntityArrow.java
|
|
+++ b/net/minecraft/world/entity/projectile/EntityArrow.java
|
|
@@ -46,6 +46,12 @@
|
|
import net.minecraft.world.phys.Vec3D;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
+// CraftBukkit start
|
|
+import net.minecraft.world.entity.item.EntityItem;
|
|
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
|
+import org.bukkit.event.player.PlayerPickupArrowEvent;
|
|
+// CraftBukkit end
|
|
+
|
|
public abstract class EntityArrow extends IProjectile {
|
|
|
|
private static final double ARROW_BASE_DAMAGE = 2.0D;
|
|
@@ -212,7 +218,7 @@
|
|
}
|
|
|
|
if (object != null && !flag) {
|
|
- this.onHit((MovingObjectPosition) object);
|
|
+ this.preOnHit((MovingObjectPosition) object); // CraftBukkit - projectile hit event
|
|
this.hasImpulse = true;
|
|
}
|
|
|
|
@@ -359,7 +365,13 @@
|
|
int k = entity.getRemainingFireTicks();
|
|
|
|
if (this.isOnFire() && !flag) {
|
|
- entity.setSecondsOnFire(5);
|
|
+ // CraftBukkit start
|
|
+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 5);
|
|
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
|
|
+ if (!combustEvent.isCancelled()) {
|
|
+ entity.setSecondsOnFire(combustEvent.getDuration(), false);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
if (entity.hurt(damagesource, (float) i)) {
|
|
@@ -522,7 +534,22 @@
|
|
@Override
|
|
public void playerTouch(EntityHuman entityhuman) {
|
|
if (!this.level().isClientSide && (this.inGround || this.isNoPhysics()) && this.shakeTime <= 0) {
|
|
- if (this.tryPickup(entityhuman)) {
|
|
+ // CraftBukkit start
|
|
+ ItemStack itemstack = this.getPickupItem();
|
|
+ if (this.pickup == PickupStatus.ALLOWED && !itemstack.isEmpty() && entityhuman.getInventory().canHold(itemstack) > 0) {
|
|
+ EntityItem item = new EntityItem(this.level(), this.getX(), this.getY(), this.getZ(), itemstack);
|
|
+ PlayerPickupArrowEvent event = new PlayerPickupArrowEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), new org.bukkit.craftbukkit.entity.CraftItem(this.level().getCraftServer(), item), (org.bukkit.entity.AbstractArrow) this.getBukkitEntity());
|
|
+ // event.setCancelled(!entityhuman.canPickUpLoot); TODO
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ itemstack = item.getItem();
|
|
+ }
|
|
+
|
|
+ if ((this.pickup == EntityArrow.PickupStatus.ALLOWED && entityhuman.getInventory().add(itemstack)) || (this.pickup == EntityArrow.PickupStatus.CREATIVE_ONLY && entityhuman.getAbilities().instabuild)) {
|
|
+ // CraftBukkit end
|
|
entityhuman.take(this, 1);
|
|
this.discard();
|
|
}
|