From 990be1691b8b89295de56ed7ebda5d77aa43aac2 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 26 Jun 2023 18:41:08 +0200 Subject: [PATCH] Iterate over entity array copy for entity scheduler --- .../server/0019-Rewrite-chunk-system.patch | 9 ++++++-- ...Folia-scheduler-and-owned-region-API.patch | 22 ++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/patches/server/0019-Rewrite-chunk-system.patch b/patches/server/0019-Rewrite-chunk-system.patch index 2382b951d..e91f31b09 100644 --- a/patches/server/0019-Rewrite-chunk-system.patch +++ b/patches/server/0019-Rewrite-chunk-system.patch @@ -3742,10 +3742,10 @@ index 0000000000000000000000000000000000000000..924539d4ac50c70178ba220424ffacd6 +} diff --git a/src/main/java/io/papermc/paper/chunk/system/entity/EntityLookup.java b/src/main/java/io/papermc/paper/chunk/system/entity/EntityLookup.java new file mode 100644 -index 0000000000000000000000000000000000000000..82ccaf612548a7dbab7e5aeffb6eb8db84367477 +index 0000000000000000000000000000000000000000..41791c7331c80d496cde4e3d1846a178bef0bbe3 --- /dev/null +++ b/src/main/java/io/papermc/paper/chunk/system/entity/EntityLookup.java -@@ -0,0 +1,840 @@ +@@ -0,0 +1,845 @@ +package io.papermc.paper.chunk.system.entity; + +import com.destroystokyo.paper.util.maplist.EntityList; @@ -3776,6 +3776,7 @@ index 0000000000000000000000000000000000000000..82ccaf612548a7dbab7e5aeffb6eb8db +import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import java.util.ArrayList; ++import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; @@ -3939,6 +3940,10 @@ index 0000000000000000000000000000000000000000..82ccaf612548a7dbab7e5aeffb6eb8db + return new ArrayIterable<>(this.accessibleEntities.getRawData(), 0, this.accessibleEntities.size()); + } + ++ public Entity[] getAllCopy() { ++ return Arrays.copyOf(this.accessibleEntities.getRawData(), this.accessibleEntities.size(), Entity[].class); ++ } ++ + @Override + public void get(final EntityTypeTest filter, final AbortableIterationConsumer action) { + for (final Entity entity : this.entityById.values()) { diff --git a/patches/server/0977-Folia-scheduler-and-owned-region-API.patch b/patches/server/0977-Folia-scheduler-and-owned-region-API.patch index dd099b06e..dd7e0f3ee 100644 --- a/patches/server/0977-Folia-scheduler-and-owned-region-API.patch +++ b/patches/server/0977-Folia-scheduler-and-owned-region-API.patch @@ -1121,24 +1121,26 @@ index 0000000000000000000000000000000000000000..d306f911757a4d556c82c0070d4837db + } +} diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 80cf4852e4010eeeadaf920ab927a40df0179b40..912affb0ab1c4c40f7a655194e95ec6f0ebf1fcd 100644 +index 80cf4852e4010eeeadaf920ab927a40df0179b40..3238cbcba567b1242c77e41f6b6f19a8d157fb4e 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -1479,6 +1479,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop level.getAllEntities().forEach(entity -> { -+ if (entity.isRemoved()) { -+ return; ++ getAllLevels().forEach(level -> { ++ for (final Entity entity : level.getEntityLookup().getAllCopy()) { ++ if (entity.isRemoved()) { ++ continue; ++ } ++ final org.bukkit.craftbukkit.entity.CraftEntity bukkit = entity.getBukkitEntityRaw(); ++ if (bukkit != null) { ++ bukkit.taskScheduler.executeTick(); ++ } + } -+ org.bukkit.craftbukkit.entity.CraftEntity bukkit = entity.getBukkitEntityRaw(); -+ if (bukkit != null) { -+ bukkit.taskScheduler.executeTick(); -+ } -+ })); ++ }); + // Paper end - Folia scheduler API io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper this.profiler.push("commandFunctions");