Advertisement
riking

TemplateGenerator example

Jun 4th, 2013
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package test;
  2.  
  3. import java.util.Random;
  4.  
  5. import org.bukkit.generator.ChunkGenerator;
  6. import org.bukkit.ChunkSnapshot;
  7. import org.bukkit.World;
  8.  
  9. public class TemplateGenerator extends ChunkGenerator {
  10.     protected World world;
  11.  
  12.     public TemplateGenerator(World templateWorld) {
  13.         this.world = templateWorld;
  14.     }
  15.  
  16.     /*
  17.     void setBlock(short[][] result, int x, int y, int z, short blkid) {
  18.         if (result[y >> 4] == null) {
  19.             result[y >> 4] = new short[4096];
  20.         }
  21.         result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
  22.     }
  23.     */
  24.  
  25.     @Override
  26.     public short[][] generateExtBlockSections(World contextWorld, Random worldRandom, int cx, int cz, BiomeGrid biomes) {
  27.         ChunkSnapshot templateChunk = world.getChunkAt(cx, cz).getChunkSnapshot();
  28.  
  29.         // Pure-bukkit impl - can be optimized via NMS
  30.  
  31.         // Load block IDs
  32.         short[][] result = new short[256 / 16][];
  33.         for (int y = 0; y < 256; y += 16) {
  34.             short[] locres = new short[4096];
  35.             for (int py = y; py < y + 16; py++) {
  36.                 for (int px = 0; px < 16; px++) {
  37.                     for (int pz = 0; pz < 16; pz++) {
  38.                         locres[((py & 0xF) << 8) | (pz << 4) | px] = (short) templateChunk.getBlockTypeId(px, py, pz);
  39.                     }
  40.                 }
  41.             }
  42.             result[y >> 4] = locres;
  43.         }
  44.  
  45.         loadBiomesIntoGrid(biomes, templateChunk);
  46.  
  47.         return result;
  48.     }
  49.  
  50.     public void loadBiomesIntoGrid(BiomeGrid biomes, ChunkSnapshot template) {
  51.         for (int px = 0; px < 16; px++) {
  52.             for (int pz = 0; pz < 16; pz++) {
  53.                 biomes.setBiome(px, pz, template.getBiome(px, pz));
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement