Skip to content

Commit

Permalink
Log thread check parameters when the thread check fails
Browse files Browse the repository at this point in the history
This provides additional debug information that may be useful.
  • Loading branch information
Spottedleaf committed Jan 11, 2025
1 parent 0973595 commit d270cf0
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,64 @@ public static void ensureTickThread(final String reason) {

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);
}
}

Expand Down Expand Up @@ -105,6 +126,10 @@ public static boolean isTickThreadFor(final Level world, final BlockPos pos) {
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();
}
Expand Down

0 comments on commit d270cf0

Please sign in to comment.