Advertisement
Guest User

Minecraft Forge: force chunk loading

a guest
Apr 16th, 2017
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. RenderGlobal render = Minecraft.getMinecraft().renderGlobal;
  2.  
  3. /* Getting private fields from RenderGlobal using reflection, safest way,
  4.  * I guess */
  5. Field frustumField = null;
  6. Field chunkyField = null;
  7.  
  8. for (Field field : render.getClass().getDeclaredFields())
  9. {
  10.     if (chunkyField == null && field.getType().equals(ChunkRenderDispatcher.class))
  11.     {
  12.         chunkyField = field;
  13.         chunkyField.setAccessible(true);
  14.     }
  15.  
  16.     if (frustumField == null && field.getType().equals(ViewFrustum.class))
  17.     {
  18.         frustumField = field;
  19.         frustumField.setAccessible(true);
  20.     }
  21.  
  22.     if (chunkyField != null && frustumField != null)
  23.     {
  24.         break;
  25.     }
  26. }
  27.  
  28. /* Forcing all possible chunks to be loaded */
  29. if (chunkyField != null && frustumField != null)
  30. {
  31.     try
  32.     {
  33.         ChunkRenderDispatcher chunks = (ChunkRenderDispatcher) chunkyField.get(render);
  34.         ViewFrustum frustum = (ViewFrustum) frustumField.get(render);
  35.  
  36.         for (RenderChunk chunk : frustum.renderChunks)
  37.         {
  38.             /* Unloaded chunks seem to have compiled chunk field default to
  39.              * CompiledChunk.DUMMY */
  40.             boolean isDummy = chunk.getCompiledChunk() == CompiledChunk.DUMMY;
  41.  
  42.             if (isDummy)
  43.             {
  44.                 chunks.updateChunkNow(chunk);
  45.             }
  46.         }
  47.     }
  48.     catch (Exception e)
  49.     {
  50.         e.printStackTrace();
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement