2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/entity/item/EntityItem.java
|
|
|
|
+++ b/net/minecraft/world/entity/item/EntityItem.java
|
2021-11-21 23:00:00 +01:00
|
|
|
@@ -32,6 +32,12 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
2021-03-15 23:00:00 +01:00
|
|
|
import net.minecraft.world.phys.Vec3D;
|
2021-03-08 22:47:33 +01:00
|
|
|
|
2017-07-28 09:47:59 +02:00
|
|
|
+// CraftBukkit start
|
2021-03-15 23:00:00 +01:00
|
|
|
+import net.minecraft.server.MinecraftServer;
|
2017-07-28 09:47:59 +02:00
|
|
|
+import org.bukkit.event.entity.EntityPickupItemEvent;
|
|
|
|
+import org.bukkit.event.player.PlayerPickupItemEvent;
|
|
|
|
+// CraftBukkit end
|
2021-03-08 22:47:33 +01:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
public class EntityItem extends Entity {
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
private static final DataWatcherObject<ItemStack> DATA_ITEM = DataWatcher.defineId(EntityItem.class, DataWatcherRegistry.ITEM_STACK);
|
|
|
|
@@ -46,6 +52,7 @@
|
|
|
|
@Nullable
|
2019-04-23 04:00:00 +02:00
|
|
|
private UUID owner;
|
2021-06-11 07:00:00 +02:00
|
|
|
public final float bobOffs;
|
2016-11-25 00:31:53 +01:00
|
|
|
+ private int lastTick = MinecraftServer.currentTick - 1; // CraftBukkit
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
public EntityItem(EntityTypes<? extends EntityItem> entitytypes, World world) {
|
|
|
|
super(entitytypes, world);
|
2021-11-21 23:00:00 +01:00
|
|
|
@@ -95,9 +102,12 @@
|
|
|
|
this.discard();
|
2014-11-25 22:32:16 +01:00
|
|
|
} 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
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
this.xo = this.getX();
|
|
|
|
this.yo = this.getY();
|
|
|
|
@@ -147,9 +157,11 @@
|
|
|
|
this.mergeWithNeighbours();
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2020-02-02 01:18:17 +01:00
|
|
|
+ /* CraftBukkit start - moved up
|
2014-11-25 22:32:16 +01:00
|
|
|
if (this.age != -32768) {
|
|
|
|
++this.age;
|
|
|
|
}
|
2020-02-02 01:18:17 +01:00
|
|
|
+ // CraftBukkit end */
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
|
2021-06-11 07:00:00 +02:00
|
|
|
if (!this.level.isClientSide) {
|
2021-11-21 23:00:00 +01:00
|
|
|
@@ -161,6 +173,12 @@
|
2016-11-17 02:41:03 +01:00
|
|
|
}
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
if (!this.level.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
|
2021-11-21 23:00:00 +01:00
|
|
|
this.discard();
|
2014-11-25 22:32:16 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
@@ -236,10 +254,11 @@
|
|
|
|
private static void merge(EntityItem entityitem, ItemStack itemstack, ItemStack itemstack1) {
|
|
|
|
ItemStack itemstack2 = merge(itemstack, itemstack1, 64);
|
2019-12-10 23:00:00 +01:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- entityitem.setItem(itemstack2);
|
|
|
|
+ if (!itemstack2.isEmpty()) entityitem.setItem(itemstack2); // CraftBukkit - don't set empty stacks
|
2019-04-23 04:00:00 +02:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
private static void merge(EntityItem entityitem, ItemStack itemstack, EntityItem entityitem1, ItemStack itemstack1) {
|
2019-04-23 04:00:00 +02:00
|
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemMergeEvent(entityitem1, entityitem).isCancelled()) return; // CraftBukkit
|
2021-11-21 23:00:00 +01:00
|
|
|
merge(entityitem, itemstack, itemstack1);
|
2019-04-23 04:00:00 +02:00
|
|
|
entityitem.pickupDelay = Math.max(entityitem.pickupDelay, entityitem1.pickupDelay);
|
|
|
|
entityitem.age = Math.min(entityitem.age, entityitem1.age);
|
2021-11-21 23:00:00 +01:00
|
|
|
@@ -263,6 +282,11 @@
|
|
|
|
} else if (!this.getItem().getItem().canBeHurtBy(damagesource)) {
|
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
|
2021-11-21 23:00:00 +01:00
|
|
|
this.markHurt();
|
2021-06-11 07:00:00 +02:00
|
|
|
this.health = (int) ((float) this.health - f);
|
2021-11-21 23:00:00 +01:00
|
|
|
this.gameEvent(GameEvent.ENTITY_DAMAGED, damagesource.getEntity());
|
|
|
|
@@ -326,6 +350,46 @@
|
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
|
2021-06-11 07:00:00 +02:00
|
|
|
+ int canHold = entityhuman.getInventory().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);
|
2021-06-11 07:00:00 +02:00
|
|
|
+ playerEvent.setCancelled(!playerEvent.getPlayer().getCanPickupItems());
|
2021-06-11 13:33:49 +02:00
|
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(playerEvent);
|
2017-07-28 09:47:59 +02:00
|
|
|
+ if (playerEvent.isCancelled()) {
|
2019-09-02 05:17:54 +02:00
|
|
|
+ itemstack.setCount(i); // SPIGOT-5294 - restore count
|
2017-07-28 09:47:59 +02:00
|
|
|
+ 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);
|
2021-06-11 07:00:00 +02:00
|
|
|
+ entityEvent.setCancelled(!entityEvent.getEntity().getCanPickupItems());
|
2021-06-11 13:33:49 +02:00
|
|
|
+ this.level.getCraftServer().getPluginManager().callEvent(entityEvent);
|
2017-07-28 09:47:59 +02:00
|
|
|
+ if (entityEvent.isCancelled()) {
|
2019-09-02 05:17:54 +02:00
|
|
|
+ itemstack.setCount(i); // SPIGOT-5294 - restore count
|
2014-11-25 22:32:16 +01:00
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
2020-08-28 04:26:24 +02:00
|
|
|
+ // Update the ItemStack if it was changed in the event
|
2021-11-21 23:00:00 +01:00
|
|
|
+ ItemStack current = this.getItem();
|
2020-08-28 04:26:24 +02:00
|
|
|
+ if (!itemstack.equals(current)) {
|
|
|
|
+ itemstack = current;
|
|
|
|
+ } else {
|
|
|
|
+ itemstack.setCount(canHold + remaining); // = i
|
|
|
|
+ }
|
2017-07-28 09:47:59 +02:00
|
|
|
+
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // Possibly < 0; fix here so we do not have to modify code below
|
|
|
|
+ this.pickupDelay = 0;
|
2019-06-06 00:32:32 +02:00
|
|
|
+ } else if (this.pickupDelay == 0) {
|
|
|
|
+ // ensure that the code below isn't triggered if canHold says we can't pick the items up
|
|
|
|
+ this.pickupDelay = -1;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2015-02-26 23:41:06 +01:00
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
if (this.pickupDelay == 0 && (this.owner == null || this.owner.equals(entityhuman.getUUID())) && entityhuman.getInventory().add(itemstack)) {
|
|
|
|
entityhuman.take(this, i);
|
2017-05-14 04:00:00 +02:00
|
|
|
if (itemstack.isEmpty()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
@@ -369,7 +433,9 @@
|
2018-07-15 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
public void setItem(ItemStack itemstack) {
|
2018-07-15 02:00:00 +02:00
|
|
|
+ com.google.common.base.Preconditions.checkArgument(!itemstack.isEmpty(), "Cannot drop air"); // CraftBukkit
|
2021-11-21 23:00:00 +01:00
|
|
|
this.getEntityData().set(EntityItem.DATA_ITEM, itemstack);
|
|
|
|
+ this.getEntityData().markDirty(EntityItem.DATA_ITEM); // CraftBukkit - SPIGOT-4591, must mark dirty
|
2018-07-15 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 02:00:00 +02:00
|
|
|
@Override
|