Skip to content

Blocking main thread on block state query #1

Description

@Bawnorton

Per discussions with TqLxQuanZ, and the following:

not working as expected when c2me is present. The value returned from here will be unreliable as that chunk may be being worked on in another thread, to get around it you need to directly query the chunk building future to see if it has a value or not:

private static boolean isChunkLoaded(Level level, BlockPos pos) {
    if (level instanceof ServerLevel serverLevel) {
        ServerChunkCache chunkSource = serverLevel.getChunkSource();
        int x = SectionPos.blockToSectionCoord(pos.getX());
        int z = SectionPos.blockToSectionCoord(pos.getZ());

        if (chunkSource.mainThread != Thread.currentThread()) return chunkSource.hasChunk(x, z);
        return chunkSource.getChunkFutureMainThread(x, z, ChunkStatus.FULL, false).isDone();
    }
    return level.isLoaded(pos);
}

now of course mainThread and getChunkFutureMainThread are not exposed so you need to use mixin, access transformation or reflection to access these and it does not appear that your build setup allows for mixins or ATs as far as I can tell, I would PR otherwise but I am not overly familiar with your build setup and don't really want to mess with it to allow the necessary access transformation. Reflection is also noticeably slow given the number of times this path is invoked.

I have implemented a fix as a mixin in another mod but it'd be best if this was a part of the main mod: https://github.com/Bawnorton/DCFixes/blob/2163f4bd74157db207617138661b0203a466213a/src/main/java/com/bawnorton/dcfixes/mixin/hazardous/HazardManagerMixin.java

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions