2020-05-06 11:48:49 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2020-04-25 12:52:30 +02:00
From: Aikar <aikar@aikar.co>
Date: Sat, 25 Apr 2020 06:46:35 -0400
Subject: [PATCH] Fix numerous item duplication issues and teleport issues
This notably fixes the newest "Donkey Dupe", but also fixes a lot
of dupe bugs in general around nether portals and entity world transfer
We also fix item duplication generically by anytime we clone an item
to drop it on the ground, destroy the source item.
This avoid an itemstack ever existing twice in the world state pre
clean up stage.
So even if something NEW comes up, it would be impossible to drop the
same item twice because the source was destroyed.
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2021-03-16 17:37:33 +01:00
index 675d0cb32efc99f66c4d2b000bf49cf1c065a5e2..cb5c93dca3b947462b89f79c60c7562085684b87 100644
2021-03-16 08:19:45 +01:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2021-03-16 14:04:28 +01:00
@@ -1969,11 +1969,12 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-04-25 12:52:30 +02:00
} else {
// CraftBukkit start - Capture drops for death event
if (this instanceof EntityLiving && !((EntityLiving) this).forceDrops) {
- ((EntityLiving) this).drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack));
+ ((EntityLiving) this).drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack)); // Paper - mirror so we can destroy it later
return null;
}
// CraftBukkit end
- EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + (double) f, this.locZ(), itemstack);
+ EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + (double) f, this.locZ(), itemstack.cloneItemStack()); // Paper - clone so we can destroy original
+ itemstack.setCount(0); // Paper - destroy this item - if this ever leaks due to game bugs, ensure it doesn't dupe
entityitem.defaultPickupDelay();
// CraftBukkit start
2021-03-16 14:04:28 +01:00
@@ -2621,6 +2622,12 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-04-25 12:52:30 +02:00
@Nullable
2020-06-26 03:53:21 +02:00
public Entity teleportTo(WorldServer worldserver, BlockPosition location) {
2020-04-25 12:52:30 +02:00
// CraftBukkit end
+ // Paper start - fix bad state entities causing dupes
+ if (!isAlive() || !valid) {
2020-06-26 03:53:21 +02:00
+ LOGGER.warn("Illegal Entity Teleport " + this + " to " + worldserver + ":" + location, new Throwable());
2020-04-25 12:52:30 +02:00
+ return null;
+ }
+ // Paper end
2020-06-26 03:53:21 +02:00
if (this.world instanceof WorldServer && !this.dead) {
2020-04-25 12:52:30 +02:00
this.world.getMethodProfiler().enter("changeDimension");
2020-06-26 03:53:21 +02:00
// CraftBukkit start
2021-03-16 14:04:28 +01:00
@@ -2641,6 +2648,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-12-25 07:31:13 +01:00
// CraftBukkit end
this.world.getMethodProfiler().exitEnter("reloading");
+ // Paper start - Change lead drop timing to prevent dupe
+ if (this instanceof EntityInsentient) {
+ ((EntityInsentient) this).unleash(true, true); // Paper drop lead
+ }
+ // Paper end
Entity entity = this.getEntityType().a((World) worldserver);
2020-05-16 10:31:53 +02:00
2020-12-25 07:31:13 +01:00
if (entity != null) {
2021-03-16 14:04:28 +01:00
@@ -2654,10 +2666,6 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-12-25 07:31:13 +01:00
// CraftBukkit start - Forward the CraftEntity to the new entity
this.getBukkitEntity().setHandle(entity);
entity.bukkitEntity = this.getBukkitEntity();
-
- if (this instanceof EntityInsentient) {
2020-08-25 04:22:08 +02:00
- ((EntityInsentient) this).unleash(true, false); // Unleash to prevent duping of leads.
2020-12-25 07:31:13 +01:00
- }
2020-08-25 04:22:08 +02:00
// CraftBukkit end
2020-05-16 10:31:53 +02:00
}
2020-12-25 07:31:13 +01:00
2021-03-16 14:04:28 +01:00
@@ -2782,7 +2790,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2020-04-25 12:52:30 +02:00
}
public boolean canPortal() {
- return true;
+ return isAlive() && valid; // Paper
}
public float a(Explosion explosion, IBlockAccess iblockaccess, BlockPosition blockposition, IBlockData iblockdata, Fluid fluid, float f) {
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/decoration/EntityArmorStand.java b/src/main/java/net/minecraft/world/entity/decoration/EntityArmorStand.java
2021-03-16 14:04:28 +01:00
index 69361caebf0d3caa5195b519a16691705ac5e16a..5eb900619951083b9a777b1645cb5495b99968ec 100644
2021-03-16 08:19:45 +01:00
--- a/src/main/java/net/minecraft/world/entity/decoration/EntityArmorStand.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/EntityArmorStand.java
2021-03-16 14:04:28 +01:00
@@ -602,7 +602,7 @@ public class EntityArmorStand extends EntityLiving {
2020-04-25 12:52:30 +02:00
for (i = 0; i < this.handItems.size(); ++i) {
itemstack = (ItemStack) this.handItems.get(i);
if (!itemstack.isEmpty()) {
- drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops
+ drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack)); // CraftBukkit - add to drops // Paper - mirror so we can destroy it later - though this call site was safe
2020-06-26 03:53:21 +02:00
this.handItems.set(i, ItemStack.b);
2020-04-25 12:52:30 +02:00
}
}
2021-03-16 14:04:28 +01:00
@@ -610,7 +610,7 @@ public class EntityArmorStand extends EntityLiving {
2020-04-25 12:52:30 +02:00
for (i = 0; i < this.armorItems.size(); ++i) {
itemstack = (ItemStack) this.armorItems.get(i);
if (!itemstack.isEmpty()) {
- drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops
+ drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack)); // CraftBukkit - add to drops // Paper - mirror so we can destroy it later - though this call site was safe
2020-06-26 03:53:21 +02:00
this.armorItems.set(i, ItemStack.b);
2020-04-25 12:52:30 +02:00
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2021-04-25 00:47:20 +02:00
index 0b734398905ad4a0e45cb7d17aac8b0c50e4449c..ca60ced988b46c4ef01b1b83a9ce12c5a8170845 100644
2020-04-25 12:52:30 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2021-04-25 00:47:20 +02:00
@@ -820,7 +820,8 @@ public class CraftEventFactory {
2020-04-25 12:52:30 +02:00
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0) continue;
- world.dropItem(entity.getLocation(), stack);
+ world.dropItem(entity.getLocation(), stack); // Paper - note: dropItem already clones due to this being bukkit -> NMS
2020-05-02 03:44:06 +02:00
+ if (stack instanceof CraftItemStack) stack.setAmount(0); // Paper - destroy this item - if this ever leaks due to game bugs, ensure it doesn't dupe, but don't nuke bukkit stacks of manually added items
2020-04-25 12:52:30 +02:00
}
return event;