From 3d9ecc4e085d9cfb6c97fd7efe877b3468c6b4fb Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Sat, 11 Jan 2025 04:52:21 -0800 Subject: [PATCH] Log thread check parameters when the thread check fails This provides additional debug information that may be useful. --- .../moonrise/common/util/TickThread.java | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/paper-server/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java b/paper-server/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java index 217d1f908..157e5edb5 100644 --- a/paper-server/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java +++ b/paper-server/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java @@ -28,43 +28,64 @@ public class TickThread extends Thread { public static void ensureTickThread(final Level world, final BlockPos pos, final String reason) { if (!isTickThreadFor(world, pos)) { - LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable()); - throw new IllegalStateException(reason); + final String ex = "Thread " + Thread.currentThread().getName() + " failed main thread check: " + + reason + ", world=" + WorldUtil.getWorldName(world) + ", block_pos=" + pos; + LOGGER.error(ex, new Throwable()); + throw new IllegalStateException(ex); + } + } + + public static void ensureTickThread(final Level world, final BlockPos pos, final int blockRadius, final String reason) { + if (!isTickThreadFor(world, pos, blockRadius)) { + final String ex = "Thread " + Thread.currentThread().getName() + " failed main thread check: " + + reason + ", world=" + WorldUtil.getWorldName(world) + ", block_pos=" + pos + ", block_radius=" + blockRadius; + LOGGER.error(ex, new Throwable()); + throw new IllegalStateException(ex); } } public static void ensureTickThread(final Level world, final ChunkPos pos, final String reason) { if (!isTickThreadFor(world, pos)) { - LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable()); - throw new IllegalStateException(reason); + final String ex = "Thread " + Thread.currentThread().getName() + " failed main thread check: " + + reason + ", world=" + WorldUtil.getWorldName(world) + ", chunk_pos=" + pos; + LOGGER.error(ex, new Throwable()); + throw new IllegalStateException(ex); } } public static void ensureTickThread(final Level world, final int chunkX, final int chunkZ, final String reason) { if (!isTickThreadFor(world, chunkX, chunkZ)) { - LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable()); - throw new IllegalStateException(reason); + final String ex = "Thread " + Thread.currentThread().getName() + " failed main thread check: " + + reason + ", world=" + WorldUtil.getWorldName(world) + ", chunk_pos=" + new ChunkPos(chunkX, chunkZ); + LOGGER.error(ex, new Throwable()); + throw new IllegalStateException(ex); } } public static void ensureTickThread(final Entity entity, final String reason) { if (!isTickThreadFor(entity)) { - LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable()); - throw new IllegalStateException(reason); + final String ex = "Thread " + Thread.currentThread().getName() + " failed main thread check: " + + reason + ", entity=" + entity; + LOGGER.error(ex, new Throwable()); + throw new IllegalStateException(ex); } } public static void ensureTickThread(final Level world, final AABB aabb, final String reason) { if (!isTickThreadFor(world, aabb)) { - LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable()); - throw new IllegalStateException(reason); + final String ex = "Thread " + Thread.currentThread().getName() + " failed main thread check: " + + reason + ", world=" + WorldUtil.getWorldName(world) + ", aabb=" + aabb; + LOGGER.error(ex, new Throwable()); + throw new IllegalStateException(ex); } } public static void ensureTickThread(final Level world, final double blockX, final double blockZ, final String reason) { if (!isTickThreadFor(world, blockX, blockZ)) { - LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable()); - throw new IllegalStateException(reason); + final String ex = "Thread " + Thread.currentThread().getName() + " failed main thread check: " + + reason + ", world=" + WorldUtil.getWorldName(world) + ", block_pos=" + new Vec3(blockX, 0.0, blockZ); + LOGGER.error(ex, new Throwable()); + throw new IllegalStateException(ex); } } @@ -105,6 +126,10 @@ public class TickThread extends Thread { return isTickThread(); } + public static boolean isTickThreadFor(final Level world, final BlockPos pos, final int blockRadius) { + return isTickThread(); + } + public static boolean isTickThreadFor(final Level world, final ChunkPos pos) { return isTickThread(); }