mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 04:56:50 +01:00
ca708a0944
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: ed7bba95 SPIGOT-6547: Chunk#getEntities() doesn't return all entities immediately after chunk load d99a585c SPIGOT-6719: Add getTileEntities() to LimitedRegion CraftBukkit Changes: 422cec08 Rebuild patch 15f27fc7 SPIGOT-6547: Chunk#getEntities() doesn't return all entities immediately after chunk load cbd747af SPIGOT-6719: Add getTileEntities() to LimitedRegion Spigot Changes: 6c1c1b26 Rebuild patches
117 lines
7 KiB
Diff
117 lines
7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
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.
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 5802b1721a0d8e1c40d87be099d4f1b1c8a921d7..fbcbe0443f843d04738938f10b433bfe1631fe78 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -2159,11 +2159,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
|
} else {
|
|
// CraftBukkit start - Capture drops for death event
|
|
if (this instanceof net.minecraft.world.entity.LivingEntity && !((net.minecraft.world.entity.LivingEntity) this).forceDrops) {
|
|
- ((net.minecraft.world.entity.LivingEntity) this).drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(stack));
|
|
+ ((net.minecraft.world.entity.LivingEntity) this).drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(stack)); // Paper - mirror so we can destroy it later
|
|
return null;
|
|
}
|
|
// CraftBukkit end
|
|
- ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + (double) yOffset, this.getZ(), stack);
|
|
+ ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + (double) yOffset, this.getZ(), stack.copy()); // Paper - clone so we can destroy original
|
|
+ stack.setCount(0); // Paper - destroy this item - if this ever leaks due to game bugs, ensure it doesn't dupe
|
|
|
|
entityitem.setDefaultPickUpDelay();
|
|
// CraftBukkit start
|
|
@@ -2905,6 +2906,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
|
@Nullable
|
|
public Entity teleportTo(ServerLevel worldserver, BlockPos location) {
|
|
// CraftBukkit end
|
|
+ // Paper start - fix bad state entities causing dupes
|
|
+ if (!isAlive() || !valid) {
|
|
+ LOGGER.warn("Illegal Entity Teleport " + this + " to " + worldserver + ":" + location, new Throwable());
|
|
+ return null;
|
|
+ }
|
|
+ // Paper end
|
|
if (this.level instanceof ServerLevel && !this.isRemoved()) {
|
|
this.level.getProfiler().push("changeDimension");
|
|
// CraftBukkit start
|
|
@@ -2925,6 +2932,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
|
// CraftBukkit end
|
|
|
|
this.level.getProfiler().popPush("reloading");
|
|
+ // Paper start - Change lead drop timing to prevent dupe
|
|
+ if (this instanceof Mob) {
|
|
+ ((Mob) this).dropLeash(true, true); // Paper drop lead
|
|
+ }
|
|
+ // Paper end
|
|
Entity entity = this.getType().create((Level) worldserver);
|
|
|
|
if (entity != null) {
|
|
@@ -2938,10 +2950,6 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
|
// CraftBukkit start - Forward the CraftEntity to the new entity
|
|
this.getBukkitEntity().setHandle(entity);
|
|
entity.bukkitEntity = this.getBukkitEntity();
|
|
-
|
|
- if (this instanceof Mob) {
|
|
- ((Mob) this).dropLeash(true, false); // Unleash to prevent duping of leads.
|
|
- }
|
|
// CraftBukkit end
|
|
}
|
|
|
|
@@ -3066,7 +3074,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
|
}
|
|
|
|
public boolean canChangeDimensions() {
|
|
- return true;
|
|
+ return isAlive() && valid; // Paper
|
|
}
|
|
|
|
public float getBlockExplosionResistance(Explosion explosion, BlockGetter world, BlockPos pos, BlockState blockState, FluidState fluidState, float max) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
|
|
index bbde9b758643c087733064a126d90689d71830cf..069cdfce085909991a69ebec3004d407526d469d 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
|
|
@@ -611,7 +611,7 @@ public class ArmorStand extends LivingEntity {
|
|
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
|
|
this.handItems.set(i, ItemStack.EMPTY);
|
|
}
|
|
}
|
|
@@ -619,7 +619,7 @@ public class ArmorStand extends LivingEntity {
|
|
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
|
|
this.armorItems.set(i, ItemStack.EMPTY);
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index 794f8cbcf7072b10fa06c26a122739b37fe0430c..09e0b2fface050699872341215c257d4b8f403c2 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -826,7 +826,8 @@ public class CraftEventFactory {
|
|
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
|
|
+ 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
|
|
}
|
|
|
|
return event;
|