Advertisement
PaleoCrafter

Regenerate chunk

Aug 28th, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. Chunk oldChunk = world.getChunkFromBlockCoords(position);
  2. if (world instanceof WorldServer)
  3. {
  4.     WorldServer worldServer = (WorldServer) world;
  5.     ChunkProviderServer chunkProviderServer = worldServer.theChunkProviderServer;
  6.     IChunkProvider chunkProviderGenerate = chunkProviderServer.serverChunkGenerator;
  7.  
  8.     Chunk newChunk = chunkProviderGenerate.provideChunk(oldChunk.xPosition, oldChunk.zPosition);
  9.     BlockPos chunkPos = new BlockPos(oldChunk.xPosition * 16, 0, oldChunk.zPosition * 16);
  10.     for (int x = 0; x < 16; x++)
  11.     {
  12.         for (int z = 0; z < 16; z++)
  13.         {
  14.             for (int y = 0; y < world.getHeight(); y++)
  15.             {
  16.                 BlockPos posInChunk = new BlockPos(x, y, z);
  17.                 BlockPos pos = chunkPos.add(posInChunk);
  18.                 IBlockState state = newChunk.getBlockState(posInChunk);
  19.  
  20.                 worldServer.setBlockState(pos, state, 2);
  21.  
  22.                 TileEntity tileEntity = newChunk.getTileEntity(posInChunk, Chunk.EnumCreateEntityType.IMMEDIATE);
  23.                 if (tileEntity != null)
  24.                 {
  25.                     worldServer.setTileEntity(pos, tileEntity);
  26.                 }
  27.             }
  28.         }
  29.     }
  30.     ObfuscationReflectionHelper.setPrivateValue(Chunk.class, oldChunk, false, "field_76646_k", "isTerrainPopulated");
  31.     chunkProviderGenerate.populate(chunkProviderGenerate, oldChunk.xPosition, oldChunk.zPosition);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement