3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-24 07:10:10 +01:00
Paper/nms-patches/EntityItem.patch

139 Zeilen
5.9 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityItem.java
+++ b/net/minecraft/server/EntityItem.java
2019-12-10 23:00:00 +01:00
@@ -5,6 +5,10 @@
import java.util.Objects;
2018-07-15 02:00:00 +02:00
import java.util.UUID;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityPickupItemEvent;
+import org.bukkit.event.player.PlayerPickupItemEvent;
+// CraftBukkit end
public class EntityItem extends Entity {
2019-12-10 23:00:00 +01:00
@@ -15,6 +19,7 @@
2019-04-23 04:00:00 +02:00
private UUID thrower;
private UUID owner;
public final float b;
2016-11-25 00:31:53 +01:00
+ private int lastTick = MinecraftServer.currentTick - 1; // CraftBukkit
2019-04-23 04:00:00 +02:00
public EntityItem(EntityTypes<? extends EntityItem> entitytypes, World world) {
super(entitytypes, world);
2019-12-10 23:00:00 +01:00
@@ -50,9 +55,12 @@
this.die();
} else {
2018-07-15 02:00:00 +02:00
super.tick();
- 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;
+ this.lastTick = MinecraftServer.currentTick;
+ // CraftBukkit end
2019-12-10 23:00:00 +01:00
this.lastX = this.locX();
this.lastY = this.locY();
2020-06-25 02:00:00 +02:00
@@ -103,9 +111,11 @@
2019-05-14 02:00:00 +02:00
}
}
2020-02-02 01:18:17 +01:00
+ /* CraftBukkit start - moved up
if (this.age != -32768) {
++this.age;
}
2020-02-02 01:18:17 +01:00
+ // CraftBukkit end */
2020-06-25 02:00:00 +02:00
this.impulse |= this.aG();
2016-11-17 02:41:03 +01:00
if (!this.world.isClientSide) {
2020-06-25 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) {
+ // CraftBukkit start - fire ItemDespawnEvent
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
+ this.age = 0;
+ return;
+ }
+ // CraftBukkit end
this.die();
}
2020-06-25 02:00:00 +02:00
@@ -192,10 +208,11 @@
2019-12-10 23:00:00 +01:00
private static void a(EntityItem entityitem, ItemStack itemstack, ItemStack itemstack1) {
ItemStack itemstack2 = a(itemstack, itemstack1, 64);
- entityitem.setItemStack(itemstack2);
+ if (!itemstack2.isEmpty()) entityitem.setItemStack(itemstack2); // CraftBukkit - don't set empty stacks
2019-04-23 04:00:00 +02:00
}
private static void a(EntityItem entityitem, ItemStack itemstack, EntityItem entityitem1, ItemStack itemstack1) {
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemMergeEvent(entityitem1, entityitem).isCancelled()) return; // CraftBukkit
2019-12-10 23:00:00 +01:00
a(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);
2020-06-25 02:00:00 +02:00
@@ -219,6 +236,11 @@
} else if (!this.getItemStack().getItem().a(damagesource)) {
return false;
} else {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f)) {
+ return false;
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
this.velocityChanged();
this.f = (int) ((float) this.f - f);
if (this.f <= 0) {
2020-06-25 02:00:00 +02:00
@@ -280,6 +302,40 @@
2016-11-17 02:41:03 +01:00
Item item = itemstack.getItem();
int i = itemstack.getCount();
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - fire PlayerPickupItemEvent
+ int canHold = entityhuman.inventory.canHold(itemstack);
2016-11-17 02:41:03 +01:00
+ int remaining = i - canHold;
+
+ if (this.pickupDelay <= 0 && canHold > 0) {
2016-11-17 02:41:03 +01:00
+ itemstack.setCount(canHold);
+ // 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()) {
+ itemstack.setCount(i); // SPIGOT-5294 - restore count
+ return;
+ }
+
+ // 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()) {
+ itemstack.setCount(i); // SPIGOT-5294 - restore count
+ return;
+ }
+
+ itemstack.setCount(canHold + remaining); // = i
+
+ // Possibly < 0; fix here so we do not have to modify code below
+ this.pickupDelay = 0;
+ } 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;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2019-12-10 23:00:00 +01:00
if (this.pickupDelay == 0 && (this.owner == null || this.owner.equals(entityhuman.getUniqueID())) && entityhuman.inventory.pickup(itemstack)) {
2017-05-14 04:00:00 +02:00
entityhuman.receive(this, i);
if (itemstack.isEmpty()) {
2020-06-25 02:00:00 +02:00
@@ -323,7 +379,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
2019-04-23 04:00:00 +02:00
this.getDataWatcher().set(EntityItem.ITEM, itemstack);
+ this.getDataWatcher().markDirty(EntityItem.ITEM); // CraftBukkit - SPIGOT-4591, must mark dirty
2018-07-15 02:00:00 +02:00
}
2020-06-25 02:00:00 +02:00
@Override