Advertisement
sebcraftservers

PlanetWorldGenerator.java MyOwnPlanet Bukkit Plugin

Apr 7th, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. package me.sebagius7110.sebcraft.minigame.MyOwnPlanetWorldGnerator.Generation;
  2.  
  3. import java.util.*;
  4. import java.util.Random;
  5.  
  6. import me.sebagius7110.sebcraft.minigame.MyOwnPlanetWorldGenerator.main.MyOwnPlanetWorldGenerator;
  7.  
  8. import org.bukkit.Location;
  9. import org.bukkit.Material;
  10. import org.bukkit.World;
  11. import org.bukkit.generator.BlockPopulator;
  12. import org.bukkit.generator.ChunkGenerator;
  13.  
  14. public class PlanetWorldGenerator extends ChunkGenerator{
  15.    
  16.     MyOwnPlanetWorldGenerator plugin;
  17.    
  18.     public PlanetWorldGenerator(MyOwnPlanetWorldGenerator instance) {
  19.        
  20.         plugin = instance;
  21.        
  22.     }
  23.    
  24.     public Location getFixedSpawnLocation(World world, Random random) {
  25.        
  26.         return new Location(world, 0, 0, 0);
  27.        
  28.     }
  29.    
  30.     public List<BlockPopulator> getDefaultPopulators(World world) {
  31.        
  32.         return new ArrayList<BlockPopulator>();
  33.        
  34.     }
  35.    
  36.     @SuppressWarnings("deprecation")
  37.     public byte[][] generatorBlockSections(World world, Random random, int chunkX, int chunkY, BiomeGrid biomeGrid) {
  38.        
  39.         byte[][] result = new byte[256 / 16][];
  40.        
  41.         int x, y, z;
  42.        
  43.         for (x = 0; x<16;x++) {
  44.            
  45.             for (z = 0; z<16;z++) {
  46.                
  47.                 setBlock(result, x, 0, z, (byte) Material.AIR.getId());
  48.                
  49.             }
  50.            
  51.         }
  52.        
  53.         for (x = 0; x<16;x++) {
  54.            
  55.             for (z = 0; z<16;z++) {
  56.                
  57.                 for (y = 1; y<=2;y++) {
  58.                    
  59.                     setBlock(result, x, y, z, (byte) Material.AIR.getId());
  60.                    
  61.                 }
  62.             }
  63.            
  64.         }
  65.        
  66.         return result;
  67.     }
  68.    
  69.     @Override
  70.     public short[][] generateExtBlockSections(World world, Random random, int ChunkX,
  71.             int ChunkZ, BiomeGrid biomes) {
  72.        
  73.         short[][] result = new short[256 / 16][];
  74.        
  75.         int x, y, z;
  76.                
  77.         for (x = 0; x<16;x++) {
  78.            
  79.             for (z = 0; z<16;z++) {
  80.                
  81.                 setBlock(result, x, 0, z, (short) Material.AIR.getId());
  82.                
  83.             }
  84.            
  85.         }
  86.        
  87.         for (x = 0; x<16;x++) {
  88.            
  89.             for (z = 0; z<16;z++) {
  90.                
  91.                 for (y = 1; y<=2;y++) {
  92.                    
  93.                     setBlock(result, x, y, z, (short) Material.AIR.getId());
  94.                    
  95.                 }
  96.             }
  97.            
  98.         }
  99.        
  100.         return result;
  101.        
  102.     }
  103.    
  104.     private void setBlock(byte[][] result, int x, int y, int z, byte blockId) {
  105.        
  106.         if(result[y >> 4] == null) {
  107.            
  108.             result[y >> 4] = new byte[4096];
  109.            
  110.         }
  111.        
  112.         result[y >> 4][((y&0xF) << 8) | (z << 4) | x] = blockId;
  113.        
  114.     }
  115.    
  116. private void setBlock(short[][] result, int x, int y, int z, short blockId) {
  117.        
  118.         if(result[y >> 4] == null) {
  119.            
  120.             result[y >> 4] = new short[4096];
  121.            
  122.         }
  123.        
  124.         result[y >> 4][((y&0xF) << 8) | (z << 4) | x] = blockId;
  125.        
  126.     }
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement