diff --git a/paper-server/patches/sources/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java.patch b/paper-server/patches/sources/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java.patch index 7061a75f4..9f0303442 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java.patch @@ -18,7 +18,7 @@ ChunkStatusTasks.postLoadProtoChunk(worldserver, protochunk.getEntities()); }); generationchunkholder.replaceProtoChunk(new ImposterProtoChunk(chunk1, false)); -@@ -168,9 +168,19 @@ +@@ -168,10 +168,61 @@ }, context.mainThreadExecutor()); } @@ -34,9 +34,51 @@ + entity.discard(null); // CraftBukkit - add Bukkit remove cause + needsRemoval = true; + } ++ checkDupeUUID(world, entity); // Paper - duplicate uuid resolving + return !needsRemoval; + })); + // CraftBukkit end } } ++ ++ // Paper start - duplicate uuid resolving ++ // rets true if to prevent the entity from being added ++ public static boolean checkDupeUUID(ServerLevel level, net.minecraft.world.entity.Entity entity) { ++ io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DuplicateUUID.DuplicateUUIDMode mode = level.paperConfig().entities.spawning.duplicateUuid.mode; ++ if (mode != io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DuplicateUUID.DuplicateUUIDMode.WARN ++ && mode != io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DuplicateUUID.DuplicateUUIDMode.DELETE ++ && mode != io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DuplicateUUID.DuplicateUUIDMode.SAFE_REGEN) { ++ return false; ++ } ++ net.minecraft.world.entity.Entity other = level.getEntity(entity.getUUID()); ++ ++ if (other == null || other == entity) { ++ return false; ++ } ++ ++ if (mode == io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DuplicateUUID.DuplicateUUIDMode.SAFE_REGEN && other != null && !other.isRemoved() ++ && Objects.equals(other.getEncodeId(), entity.getEncodeId()) ++ && entity.getBukkitEntity().getLocation().distance(other.getBukkitEntity().getLocation()) < level.paperConfig().entities.spawning.duplicateUuid.safeRegenDeleteRange ++ ) { ++ entity.discard(null); ++ return true; ++ } ++ if (!other.isRemoved()) { ++ switch (mode) { ++ case SAFE_REGEN: { ++ entity.setUUID(java.util.UUID.randomUUID()); ++ break; ++ } ++ case DELETE: { ++ entity.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD); ++ return true; ++ } ++ default: ++ break; ++ } ++ } ++ return false; ++ } ++ // Paper end - duplicate uuid resolving + }