From 658c0a284a175ce9dae12a2118de5f4a16c8aed5 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Tue, 17 Nov 2020 13:41:47 +1100 Subject: [PATCH] =?UTF-8?q?SPIGOT-6186:=20Canceling=20a=20CreatureSpawnEve?= =?UTF-8?q?nt=E2=80=8B=20results=20in=20a=20"Unable=20to=20summon=20entity?= =?UTF-8?q?=20due=20to=20duplicate=20UUIDs"=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By: md_5 --- paper-server/nms-patches/EntityTypes.patch | 11 +++--- .../nms-patches/SpawnerCreature.patch | 9 ++--- paper-server/nms-patches/WorldAccess.patch | 5 ++- paper-server/nms-patches/WorldServer.patch | 35 +++++++++---------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/paper-server/nms-patches/EntityTypes.patch b/paper-server/nms-patches/EntityTypes.patch index 409187aa2e..d949b80252 100644 --- a/paper-server/nms-patches/EntityTypes.patch +++ b/paper-server/nms-patches/EntityTypes.patch @@ -18,7 +18,7 @@ return (EntityTypes) IRegistry.a((IRegistry) IRegistry.ENTITY_TYPE, s, (Object) entitytypes_builder.a(s)); } -@@ -169,10 +169,17 @@ +@@ -169,10 +169,18 @@ @Nullable public T spawnCreature(WorldServer worldserver, @Nullable NBTTagCompound nbttagcompound, @Nullable IChatBaseComponent ichatbasecomponent, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) { @@ -32,12 +32,13 @@ if (t0 != null) { - worldserver.addAllEntities(t0); -+ return worldserver.addAllEntities(t0, spawnReason) ? t0 : null; // Don't return an entity when CreatureSpawnEvent is canceled ++ worldserver.addAllEntities(t0, spawnReason); ++ return !t0.dead ? t0 : null; // Don't return an entity when CreatureSpawnEvent is canceled + // CraftBukkit end } return t0; -@@ -208,7 +215,7 @@ +@@ -208,7 +216,7 @@ t0.setCustomName(ichatbasecomponent); } @@ -46,7 +47,7 @@ return t0; } } -@@ -351,7 +358,7 @@ +@@ -351,7 +359,7 @@ } return entity; @@ -55,7 +56,7 @@ } private static Optional b(NBTTagCompound nbttagcompound, World world) { -@@ -403,7 +410,7 @@ +@@ -403,7 +411,7 @@ this.g = enumcreaturetype == EnumCreatureType.CREATURE || enumcreaturetype == EnumCreatureType.MISC; } diff --git a/paper-server/nms-patches/SpawnerCreature.patch b/paper-server/nms-patches/SpawnerCreature.patch index 9d413d4f95..6d9d50e0f4 100644 --- a/paper-server/nms-patches/SpawnerCreature.patch +++ b/paper-server/nms-patches/SpawnerCreature.patch @@ -72,7 +72,7 @@ a(enumcreaturetype, worldserver, chunk, (entitytypes, blockposition, ichunkaccess) -> { return spawnercreature_d.a(entitytypes, blockposition, ichunkaccess); }, (entityinsentient, ichunkaccess) -> { -@@ -147,10 +191,13 @@ +@@ -147,10 +191,14 @@ entityinsentient.setPositionRotation(d0, (double) i, d1, worldserver.random.nextFloat() * 360.0F, 0.0F); if (a(worldserver, entityinsentient, d2)) { groupdataentity = entityinsentient.prepare(worldserver, worldserver.getDamageScaler(entityinsentient.getChunkCoordinates()), EnumMobSpawn.NATURAL, groupdataentity, (NBTTagCompound) null); @@ -81,7 +81,8 @@ - worldserver.addAllEntities(entityinsentient); - spawnercreature_a.run(entityinsentient, ichunkaccess); + // CraftBukkit start -+ if (worldserver.addAllEntities(entityinsentient, SpawnReason.NATURAL)) { ++ worldserver.addAllEntities(entityinsentient, SpawnReason.NATURAL); ++ if (!entityinsentient.dead) { + ++j; + ++k1; + spawnercreature_a.run(entityinsentient, ichunkaccess); @@ -90,7 +91,7 @@ if (j >= entityinsentient.getMaxSpawnGroup()) { return; } -@@ -333,7 +380,7 @@ +@@ -333,7 +381,7 @@ if (entityinsentient.a((GeneratorAccess) worldaccess, EnumMobSpawn.CHUNK_GENERATION) && entityinsentient.a((IWorldReader) worldaccess)) { groupdataentity = entityinsentient.prepare(worldaccess, worldaccess.getDamageScaler(entityinsentient.getChunkCoordinates()), EnumMobSpawn.CHUNK_GENERATION, groupdataentity, (NBTTagCompound) null); @@ -99,7 +100,7 @@ flag = true; } } -@@ -456,8 +503,10 @@ +@@ -456,8 +504,10 @@ return this.d; } diff --git a/paper-server/nms-patches/WorldAccess.patch b/paper-server/nms-patches/WorldAccess.patch index 25cfac4ec2..01ee8eae20 100644 --- a/paper-server/nms-patches/WorldAccess.patch +++ b/paper-server/nms-patches/WorldAccess.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/WorldAccess.java +++ b/net/minecraft/server/WorldAccess.java -@@ -5,6 +5,13 @@ +@@ -5,6 +5,12 @@ WorldServer getMinecraftWorld(); default void addAllEntities(Entity entity) { @@ -9,9 +9,8 @@ + this.addAllEntities(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); } + -+ default boolean addAllEntities(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) { ++ default void addAllEntities(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) { + entity.cp().forEach((e) -> this.addEntity(e, reason)); -+ return !entity.dead; + } + // CraftBukkit end } diff --git a/paper-server/nms-patches/WorldServer.patch b/paper-server/nms-patches/WorldServer.patch index 0a06b52169..bba6fabbe4 100644 --- a/paper-server/nms-patches/WorldServer.patch +++ b/paper-server/nms-patches/WorldServer.patch @@ -395,7 +395,7 @@ return true; } } -@@ -813,11 +954,16 @@ +@@ -813,10 +954,16 @@ } public boolean addAllEntitiesSafely(Entity entity) { @@ -409,12 +409,11 @@ return false; } else { - this.addAllEntities(entity); -- return true; -+ return this.addAllEntities(entity, reason); // CraftBukkit ++ this.addAllEntities(entity, reason); // CraftBukkit + return true; } } - -@@ -867,10 +1013,17 @@ +@@ -867,10 +1014,17 @@ } this.getScoreboard().a(entity); @@ -432,7 +431,7 @@ } private void registerEntity(Entity entity) { -@@ -891,9 +1044,16 @@ +@@ -891,9 +1045,16 @@ this.entitiesByUUID.put(entity.getUniqueID(), entity); this.getChunkProvider().addEntity(entity); @@ -449,7 +448,7 @@ } } -@@ -923,10 +1083,33 @@ +@@ -923,10 +1084,33 @@ this.everyoneSleeping(); } @@ -483,7 +482,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -@@ -935,6 +1118,12 @@ +@@ -935,6 +1119,12 @@ double d1 = (double) blockposition.getY() - entityplayer.locY(); double d2 = (double) blockposition.getZ() - entityplayer.locZ(); @@ -496,7 +495,7 @@ if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) { entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockBreakAnimation(i, blockposition, j)); } -@@ -995,10 +1184,20 @@ +@@ -995,10 +1185,20 @@ @Override public Explosion createExplosion(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) { @@ -517,7 +516,7 @@ if (explosion_effect == Explosion.Effect.NONE) { explosion.clearBlocks(); } -@@ -1063,13 +1262,20 @@ +@@ -1063,13 +1263,20 @@ } public int a(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) { @@ -540,7 +539,7 @@ ++j; } } -@@ -1111,7 +1317,7 @@ +@@ -1111,7 +1318,7 @@ @Nullable public BlockPosition a(StructureGenerator structuregenerator, BlockPosition blockposition, int i, boolean flag) { @@ -549,7 +548,7 @@ } @Nullable -@@ -1149,7 +1355,13 @@ +@@ -1149,7 +1356,13 @@ @Override public WorldMap a(String s) { return (WorldMap) this.getMinecraftServer().E().getWorldPersistentData().b(() -> { @@ -564,7 +563,7 @@ }, s); } -@@ -1460,6 +1672,11 @@ +@@ -1460,6 +1673,11 @@ @Override public void update(BlockPosition blockposition, Block block) { if (!this.isDebugWorld()) { @@ -576,7 +575,7 @@ this.applyPhysics(blockposition, block); } -@@ -1474,12 +1691,12 @@ +@@ -1474,12 +1692,12 @@ } public boolean isFlatWorld() { @@ -591,7 +590,7 @@ } @Nullable -@@ -1499,9 +1716,9 @@ +@@ -1499,9 +1717,9 @@ @VisibleForTesting public String F() { @@ -603,7 +602,7 @@ return IRegistry.BLOCK_ENTITY_TYPE.getKey(tileentity.getTileType()); }), this.getBlockTickList().a(), this.getFluidTickList().a(), this.P()); } -@@ -1509,7 +1726,7 @@ +@@ -1509,7 +1727,7 @@ private static String a(Collection collection, Function function) { try { Object2IntOpenHashMap object2intopenhashmap = new Object2IntOpenHashMap(); @@ -612,7 +611,7 @@ while (iterator.hasNext()) { T t0 = iterator.next(); -@@ -1518,7 +1735,8 @@ +@@ -1518,7 +1736,8 @@ object2intopenhashmap.addTo(minecraftkey, 1); } @@ -622,7 +621,7 @@ return it_unimi_dsi_fastutil_objects_object2intmap_entry.getKey() + ":" + it_unimi_dsi_fastutil_objects_object2intmap_entry.getIntValue(); }).collect(Collectors.joining(",")); } catch (Exception exception) { -@@ -1527,16 +1745,32 @@ +@@ -1527,16 +1746,32 @@ } public static void a(WorldServer worldserver) {