diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/LevelMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/LevelMixin.java index d095baa8fa..637226a30e 100644 --- a/src/main/java/com/gregtechceu/gtceu/core/mixins/LevelMixin.java +++ b/src/main/java/com/gregtechceu/gtceu/core/mixins/LevelMixin.java @@ -14,11 +14,9 @@ import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.LevelChunk; -import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -38,19 +36,16 @@ public abstract class LevelMixin implements LevelAccessor { @Final private Thread thread; - @Unique - private @Nullable ChunkAccess gtceu$maybeGetChunkAsync(int chunkX, int chunkZ) { - if (this.isClientSide) return null; - if (Thread.currentThread() == this.thread) return null; - if (!MultiblockWorldSavedData.isThreadService() && !AsyncThreadData.isThreadService()) return null; - if (!this.getChunkSource().hasChunk(chunkX, chunkZ)) return null; - - return this.getChunkSource().getChunkNow(chunkX, chunkZ); - } - @Inject(method = "getBlockEntity", at = @At(value = "HEAD"), cancellable = true) private void gtceu$getBlockEntityOffThread(BlockPos pos, CallbackInfoReturnable cir) { - ChunkAccess chunk = gtceu$maybeGetChunkAsync(pos.getX() >> 4, pos.getZ() >> 4); + if (Thread.currentThread() == this.thread) return; + if (this.isClientSide) return; + if (!MultiblockWorldSavedData.isThreadService() && !AsyncThreadData.isThreadService()) return; + + int chunkX = pos.getX() >> 4, chunkZ = pos.getZ() >> 4; + if (!this.getChunkSource().hasChunk(chunkX, chunkZ)) return; + + ChunkAccess chunk = this.getChunkSource().getChunkNow(chunkX, chunkZ); if (chunk instanceof LevelChunk levelChunk) { cir.setReturnValue(levelChunk.getBlockEntities().get(pos)); } @@ -58,7 +53,14 @@ public abstract class LevelMixin implements LevelAccessor { @Inject(method = "getBlockState", at = @At(value = "HEAD"), cancellable = true) private void gtceu$getBlockStateOffThread(BlockPos pos, CallbackInfoReturnable cir) { - ChunkAccess chunk = gtceu$maybeGetChunkAsync(pos.getX() >> 4, pos.getZ() >> 4); + if (Thread.currentThread() == this.thread) return; + if (this.isClientSide) return; + if (!MultiblockWorldSavedData.isThreadService() && !AsyncThreadData.isThreadService()) return; + + int chunkX = pos.getX() >> 4, chunkZ = pos.getZ() >> 4; + if (!this.getChunkSource().hasChunk(chunkX, chunkZ)) return; + + ChunkAccess chunk = this.getChunkSource().getChunkNow(chunkX, chunkZ); if (chunk != null) { cir.setReturnValue(chunk.getBlockState(pos)); }