1414import net .minecraft .world .level .chunk .ChunkAccess ;
1515import net .minecraft .world .level .chunk .LevelChunk ;
1616
17- import org .jetbrains .annotations .Nullable ;
1817import org .spongepowered .asm .mixin .Final ;
1918import org .spongepowered .asm .mixin .Mixin ;
2019import org .spongepowered .asm .mixin .Shadow ;
21- import org .spongepowered .asm .mixin .Unique ;
2220import org .spongepowered .asm .mixin .injection .At ;
2321import org .spongepowered .asm .mixin .injection .Inject ;
2422import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
@@ -38,27 +36,31 @@ public abstract class LevelMixin implements LevelAccessor {
3836 @ Final
3937 private Thread thread ;
4038
41- @ Unique
42- private @ Nullable ChunkAccess gtceu$maybeGetChunkAsync (int chunkX , int chunkZ ) {
43- if (this .isClientSide ) return null ;
44- if (Thread .currentThread () == this .thread ) return null ;
45- if (!MultiblockWorldSavedData .isThreadService () && !AsyncThreadData .isThreadService ()) return null ;
46- if (!this .getChunkSource ().hasChunk (chunkX , chunkZ )) return null ;
47-
48- return this .getChunkSource ().getChunkNow (chunkX , chunkZ );
49- }
50-
5139 @ Inject (method = "getBlockEntity" , at = @ At (value = "HEAD" ), cancellable = true )
5240 private void gtceu$getBlockEntityOffThread (BlockPos pos , CallbackInfoReturnable <BlockEntity > cir ) {
53- ChunkAccess chunk = gtceu$maybeGetChunkAsync (pos .getX () >> 4 , pos .getZ () >> 4 );
41+ if (Thread .currentThread () == this .thread ) return ;
42+ if (this .isClientSide ) return ;
43+ if (!MultiblockWorldSavedData .isThreadService () && !AsyncThreadData .isThreadService ()) return ;
44+
45+ int chunkX = pos .getX () >> 4 , chunkZ = pos .getZ () >> 4 ;
46+ if (!this .getChunkSource ().hasChunk (chunkX , chunkZ )) return ;
47+
48+ ChunkAccess chunk = this .getChunkSource ().getChunkNow (chunkX , chunkZ );
5449 if (chunk instanceof LevelChunk levelChunk ) {
5550 cir .setReturnValue (levelChunk .getBlockEntities ().get (pos ));
5651 }
5752 }
5853
5954 @ Inject (method = "getBlockState" , at = @ At (value = "HEAD" ), cancellable = true )
6055 private void gtceu$getBlockStateOffThread (BlockPos pos , CallbackInfoReturnable <BlockState > cir ) {
61- ChunkAccess chunk = gtceu$maybeGetChunkAsync (pos .getX () >> 4 , pos .getZ () >> 4 );
56+ if (Thread .currentThread () == this .thread ) return ;
57+ if (this .isClientSide ) return ;
58+ if (!MultiblockWorldSavedData .isThreadService () && !AsyncThreadData .isThreadService ()) return ;
59+
60+ int chunkX = pos .getX () >> 4 , chunkZ = pos .getZ () >> 4 ;
61+ if (!this .getChunkSource ().hasChunk (chunkX , chunkZ )) return ;
62+
63+ ChunkAccess chunk = this .getChunkSource ().getChunkNow (chunkX , chunkZ );
6264 if (chunk != null ) {
6365 cir .setReturnValue (chunk .getBlockState (pos ));
6466 }
0 commit comments