From fa188fca423a562b71dac5ef4a5b928eed586a7e Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 08:34:04 +0200 Subject: [PATCH] mob_ai oracle: wait for the scene's light updates before ticking (#290) The oracle started a scenario once hasLightWork() had been false for six ticks, but light updates reach the light thread through the chunk task dispatcher, where hasLightWork() can't see them. A drowned's first sun-burn roll (Mob.isSunBurnTick draws only when the brightness at its eyes is above 0.5) then read the dirt's light under a freshly filled pool or the water's, depending on thread timing: one random draw more or less, and drowned_pool / drowned_pool_swimmer failed at random. Queue ThreadedLevelLightEngine.waitForPendingTasks on every forced chunk after building the scene and tick only once they have all completed. Fixes #290 Co-Authored-By: Claude Opus 5.5 --- .../dev/horizonlab/parity/VanillaMobAiOracle.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java index 80559155a..8bdb0df18 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java @@ -315,6 +315,8 @@ public final class VanillaMobAiOracle { int scenario = 0; int phase = 0; int wait = 0; + /** The light engine's post-update tasks queued after the scene was built. */ + final List> lit = new ArrayList<>(); ServerPlayer player; int failures = 0; @@ -428,13 +430,23 @@ public final class VanillaMobAiOracle { ready = level.isPositionEntityTicking(new BlockPos((cx + dx) * 16, -60, (cz + dz) * 16)); if (ready) { build(s, level); + // The scene's light updates reach the light thread through the chunk task + // dispatcher, where hasLightWork() can't see them: a mob's first sun-burn + // roll then reads stale light. A post-update task queued behind them on + // every chunk completes once they have all run. + var light = (net.minecraft.server.level.ThreadedLevelLightEngine) level.getChunkSource().getLightEngine(); + lit.clear(); + for (int dx = -4; dx <= 4; dx++) + for (int dz = -4; dz <= 4; dz++) + lit.add(light.waitForPendingTasks(cx + dx, cz + dz)); phase = 2; wait = 0; } } case 2 -> { super.tickServer(haveTime); - if (!level.getChunkSource().getLightEngine().hasLightWork() && ++wait > 5) { + if (lit.stream().allMatch(java.util.concurrent.CompletableFuture::isDone) + && !level.getChunkSource().getLightEngine().hasLightWork() && ++wait > 5) { run(s, level); for (int dx = -4; dx <= 4; dx++) for (int dz = -4; dz <= 4; dz++)