2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/EntityItem.java
|
|
|
|
+++ b/net/minecraft/server/EntityItem.java
|
2018-12-27 02:02:17 +01:00
|
|
|
@@ -3,16 +3,21 @@
|
2018-07-15 02:00:00 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.UUID;
|
2016-05-10 13:47:39 +02:00
|
|
|
import javax.annotation.Nullable;
|
2017-07-28 09:47:59 +02:00
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.event.entity.EntityPickupItemEvent;
|
|
|
|
+import org.bukkit.event.player.PlayerPickupItemEvent;
|
|
|
|
+// CraftBukkit end
|
2015-06-06 11:33:48 +02:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
public class EntityItem extends Entity {
|
|
|
|
|
2018-12-27 02:02:17 +01:00
|
|
|
private static final DataWatcherObject<ItemStack> b = DataWatcher.a(EntityItem.class, DataWatcherRegistry.g);
|
|
|
|
- private int age;
|
|
|
|
+ public int age; // PAIL
|
|
|
|
public int pickupDelay;
|
|
|
|
private int e;
|
2018-07-15 02:00:00 +02:00
|
|
|
private UUID f;
|
|
|
|
private UUID g;
|
2014-11-25 22:32:16 +01:00
|
|
|
public float a;
|
2016-11-25 00:31:53 +01:00
|
|
|
+ private int lastTick = MinecraftServer.currentTick - 1; // CraftBukkit
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
public EntityItem(World world) {
|
|
|
|
super(EntityTypes.ITEM, world);
|
|
|
|
@@ -48,9 +53,12 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
this.die();
|
|
|
|
} else {
|
2018-07-15 02:00:00 +02:00
|
|
|
super.tick();
|
2014-11-25 22:32:16 +01:00
|
|
|
- if (this.pickupDelay > 0 && this.pickupDelay != 32767) {
|
|
|
|
- --this.pickupDelay;
|
|
|
|
- }
|
|
|
|
+ // CraftBukkit start - Use wall time for pickup and despawn timers
|
|
|
|
+ int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
|
2015-02-26 23:41:06 +01:00
|
|
|
+ if (this.pickupDelay != 32767) this.pickupDelay -= elapsedTicks;
|
|
|
|
+ if (this.age != -32768) this.age += elapsedTicks;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ this.lastTick = MinecraftServer.currentTick;
|
|
|
|
+ // CraftBukkit end
|
|
|
|
|
|
|
|
this.lastX = this.locX;
|
|
|
|
this.lastY = this.locY;
|
2018-07-15 02:00:00 +02:00
|
|
|
@@ -100,9 +108,11 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
this.motY *= -0.5D;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ /* Craftbukkit start - moved up
|
|
|
|
if (this.age != -32768) {
|
|
|
|
++this.age;
|
|
|
|
}
|
|
|
|
+ // Craftbukkit end */
|
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
this.impulse |= this.at();
|
2016-11-17 02:41:03 +01:00
|
|
|
if (!this.world.isClientSide) {
|
2018-07-15 02:00:00 +02:00
|
|
|
@@ -117,6 +127,12 @@
|
2016-11-17 02:41:03 +01:00
|
|
|
}
|
|
|
|
|
2015-02-26 23:41:06 +01:00
|
|
|
if (!this.world.isClientSide && this.age >= 6000) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - fire ItemDespawnEvent
|
|
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
|
|
|
|
+ this.age = 0;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
this.die();
|
|
|
|
}
|
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
@@ -165,6 +181,7 @@
|
2016-11-17 02:41:03 +01:00
|
|
|
} else if (itemstack1.getCount() + itemstack.getCount() > itemstack1.getMaxStackSize()) {
|
2015-06-26 11:55:33 +02:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemMergeEvent(this, entityitem).isCancelled()) return false; // CraftBukkit
|
2016-11-17 02:41:03 +01:00
|
|
|
itemstack1.add(itemstack.getCount());
|
2015-06-26 11:55:33 +02:00
|
|
|
entityitem.pickupDelay = Math.max(entityitem.pickupDelay, this.pickupDelay);
|
|
|
|
entityitem.age = Math.min(entityitem.age, this.age);
|
2018-07-15 02:00:00 +02:00
|
|
|
@@ -197,6 +214,11 @@
|
2016-11-17 02:41:03 +01:00
|
|
|
} else if (!this.getItemStack().isEmpty() && this.getItemStack().getItem() == Items.NETHER_STAR && damagesource.isExplosion()) {
|
2015-01-06 23:58:56 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2018-07-15 02:00:00 +02:00
|
|
|
this.aA();
|
|
|
|
this.e = (int) ((float) this.e - f);
|
|
|
|
if (this.e <= 0) {
|
|
|
|
@@ -255,6 +277,35 @@
|
2016-11-17 02:41:03 +01:00
|
|
|
Item item = itemstack.getItem();
|
|
|
|
int i = itemstack.getCount();
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start - fire PlayerPickupItemEvent
|
|
|
|
+ int canHold = entityhuman.inventory.canHold(itemstack);
|
2016-11-17 02:41:03 +01:00
|
|
|
+ int remaining = i - canHold;
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ if (this.pickupDelay <= 0 && canHold > 0) {
|
2016-11-17 02:41:03 +01:00
|
|
|
+ itemstack.setCount(canHold);
|
2017-07-28 09:47:59 +02:00
|
|
|
+ // Call legacy event
|
|
|
|
+ PlayerPickupItemEvent playerEvent = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining);
|
|
|
|
+ playerEvent.setCancelled(!entityhuman.canPickUpLoot);
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(playerEvent);
|
|
|
|
+ if (playerEvent.isCancelled()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2017-07-28 09:47:59 +02:00
|
|
|
+ // Call newer event afterwards
|
|
|
|
+ EntityPickupItemEvent entityEvent = new EntityPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining);
|
|
|
|
+ entityEvent.setCancelled(!entityhuman.canPickUpLoot);
|
|
|
|
+ this.world.getServer().getPluginManager().callEvent(entityEvent);
|
|
|
|
+ if (entityEvent.isCancelled()) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
2017-07-28 09:47:59 +02:00
|
|
|
+ itemstack.setCount(canHold + remaining);
|
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // Possibly < 0; fix here so we do not have to modify code below
|
|
|
|
+ this.pickupDelay = 0;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2018-07-15 02:00:00 +02:00
|
|
|
if (this.pickupDelay == 0 && (this.g == null || 6000 - this.age <= 200 || this.g.equals(entityhuman.getUniqueID())) && entityhuman.inventory.pickup(itemstack)) {
|
2017-05-14 04:00:00 +02:00
|
|
|
entityhuman.receive(this, i);
|
|
|
|
if (itemstack.isEmpty()) {
|
2019-01-25 10:54:56 +01:00
|
|
|
@@ -294,7 +345,9 @@
|
2018-07-15 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setItemStack(ItemStack itemstack) {
|
|
|
|
+ com.google.common.base.Preconditions.checkArgument(!itemstack.isEmpty(), "Cannot drop air"); // CraftBukkit
|
|
|
|
this.getDataWatcher().set(EntityItem.b, itemstack);
|
2019-01-25 10:54:56 +01:00
|
|
|
+ this.getDataWatcher().markDirty(EntityItem.b); // CraftBukkit - SPIGOT-4591, must mark dirty
|
2018-07-15 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
2019-01-25 10:54:56 +01:00
|
|
|
@Nullable
|