geforkt von Mirrors/Paper
31699ae9a8
* Updated Upstream (Bukkit/CraftBukkit) 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: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
168 Zeilen
11 KiB
Diff
168 Zeilen
11 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 item duplication 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 828ffad0902d28c0dc86995f5f7270c54cd9d32c..7fc411c91b722d1f3494ef8eb37eeed7bbf10475 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -2403,11 +2403,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
} 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 - copy 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
|
|
@@ -3206,6 +3207,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
@Nullable
|
|
public Entity teleportTo(ServerLevel worldserver, Vec3 location) {
|
|
// CraftBukkit end
|
|
+ // Paper start - Fix item duplication and teleport issues
|
|
+ if (!this.isAlive() || !this.valid) {
|
|
+ LOGGER.warn("Illegal Entity Teleport " + this + " to " + worldserver + ":" + location, new Throwable());
|
|
+ return null;
|
|
+ }
|
|
+ // Paper end - Fix item duplication and teleport issues
|
|
if (this.level() instanceof ServerLevel && !this.isRemoved()) {
|
|
this.level().getProfiler().push("changeDimension");
|
|
// CraftBukkit start
|
|
@@ -3232,6 +3239,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
// CraftBukkit end
|
|
|
|
this.level().getProfiler().popPush("reloading");
|
|
+ // Paper start - Fix item duplication and teleport issues
|
|
+ if (this instanceof Mob) {
|
|
+ ((Mob) this).dropLeash(true, true); // Paper drop lead
|
|
+ }
|
|
+ // Paper end - Fix item duplication and teleport issues
|
|
Entity entity = this.getType().create(worldserver);
|
|
|
|
if (entity != null) {
|
|
@@ -3249,10 +3261,6 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
// 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
|
|
}
|
|
|
|
@@ -3371,7 +3379,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
}
|
|
|
|
public boolean canChangeDimensions() {
|
|
- return !this.isPassenger() && !this.isVehicle();
|
|
+ return !this.isPassenger() && !this.isVehicle() && isAlive() && valid; // Paper - Fix item duplication and teleport issues
|
|
}
|
|
|
|
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/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
index 8fff7d4c98e198bba0b4076807adc67476fcaf4b..035faf890c02ebd5bdbb430dc473e7a1bc7b9fd1 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -1706,9 +1706,9 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
// Paper start
|
|
org.bukkit.event.entity.EntityDeathEvent deathEvent = this.dropAllDeathLoot(damageSource);
|
|
if (deathEvent == null || !deathEvent.isCancelled()) {
|
|
- if (this.deathScore >= 0 && entityliving != null) {
|
|
- entityliving.awardKillScore(this, this.deathScore, damageSource);
|
|
- }
|
|
+ // if (this.deathScore >= 0 && entityliving != null) { // Paper - Fix item duplication and teleport issues; moved to be run earlier in #dropAllDeathLoot before destroying the drop items in CraftEventFactory#callEntityDeathEvent
|
|
+ // entityliving.awardKillScore(this, this.deathScore, damageSource);
|
|
+ // }
|
|
// Paper start - clear equipment if event is not cancelled
|
|
if (this instanceof Mob) {
|
|
for (EquipmentSlot slot : this.clearedEquipmentSlots) {
|
|
@@ -1809,8 +1809,13 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
this.dropCustomDeathLoot(source, i, flag);
|
|
this.clearEquipmentSlots = prev; // Paper
|
|
}
|
|
- // CraftBukkit start - Call death event
|
|
- org.bukkit.event.entity.EntityDeathEvent deathEvent = CraftEventFactory.callEntityDeathEvent(this, this.drops); // Paper
|
|
+ // CraftBukkit start - Call death event // Paper start - call advancement triggers with correct entity equipment
|
|
+ org.bukkit.event.entity.EntityDeathEvent deathEvent = CraftEventFactory.callEntityDeathEvent(this, this.drops, () -> {
|
|
+ final LivingEntity entityliving = this.getKillCredit();
|
|
+ if (this.deathScore >= 0 && entityliving != null) {
|
|
+ entityliving.awardKillScore(this, this.deathScore, source);
|
|
+ }
|
|
+ }); // Paper end
|
|
this.postDeathDropItems(deathEvent); // Paper
|
|
this.drops = new ArrayList<>();
|
|
// CraftBukkit end
|
|
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 ddd512e1d7608ec051fb5adf6ec2c6bbb93f5a9d..4e3cf19b83410f3bcacd953a600bf0bed6e45450 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
|
|
@@ -624,7 +624,7 @@ public class ArmorStand extends LivingEntity {
|
|
for (i = 0; i < this.handItems.size(); ++i) {
|
|
itemstack = (ItemStack) this.handItems.get(i);
|
|
if (!itemstack.isEmpty()) {
|
|
- this.drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops
|
|
+ this.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);
|
|
}
|
|
}
|
|
@@ -632,7 +632,7 @@ public class ArmorStand extends LivingEntity {
|
|
for (i = 0; i < this.armorItems.size(); ++i) {
|
|
itemstack = (ItemStack) this.armorItems.get(i);
|
|
if (!itemstack.isEmpty()) {
|
|
- this.drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops
|
|
+ this.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 2b342f81ae8bfefe2a240351f28fcafc40609a75..c9fbc54d7ba10da4f4c376e029b64fb0249171a3 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -893,6 +893,11 @@ public class CraftEventFactory {
|
|
}
|
|
|
|
public static EntityDeathEvent callEntityDeathEvent(net.minecraft.world.entity.LivingEntity victim, List<org.bukkit.inventory.ItemStack> drops) {
|
|
+ // Paper start
|
|
+ return CraftEventFactory.callEntityDeathEvent(victim, drops, com.google.common.util.concurrent.Runnables.doNothing());
|
|
+ }
|
|
+ public static EntityDeathEvent callEntityDeathEvent(net.minecraft.world.entity.LivingEntity victim, List<org.bukkit.inventory.ItemStack> drops, Runnable lootCheck) {
|
|
+ // Paper end
|
|
CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
|
|
EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.getExpReward());
|
|
populateFields(victim, event); // Paper - make cancellable
|
|
@@ -906,11 +911,13 @@ public class CraftEventFactory {
|
|
playDeathSound(victim, event);
|
|
// Paper end
|
|
victim.expToDrop = event.getDroppedExp();
|
|
+ lootCheck.run(); // Paper - advancement triggers before destroying items
|
|
|
|
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;
|