HaniiPuppy

World generation

Aug 25th, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. public final class RoadWorldGenerator implements IWorldGenerator
  2. {
  3.     private static final Material[] allowedMaterials = new Material[]
  4.     { Material.CLAY, Material.GRASS, Material.GROUND, Material.ICE, Material.PACKED_ICE, Material.SAND, Material.SNOW };
  5.    
  6.     private static boolean materialIsAllowed(Material material)
  7.     {
  8.         for(Material i : allowedMaterials)
  9.             if(material == i)
  10.                 return true;
  11.        
  12.         return false;
  13.     }
  14.    
  15.     @Override
  16.     public void generate(Random          random,
  17.                          int             chunkX,
  18.                          int             chunkZ,
  19.                          World           world,
  20.                          IChunkGenerator chunkGenerator,
  21.                          IChunkProvider  chunkProvider)
  22.     {
  23.         RoadMap roadmap = RoadMapRegistry.get(world.provider.getDimension());
  24.        
  25.         if(roadmap == null)
  26.             return;
  27.        
  28.         int blockX = chunkX * 16;
  29.         int blockZ = chunkZ * 16;
  30.         Set<BlockPos> blockPositions = new HashSet<BlockPos>();
  31.        
  32.         for(int x = blockX; x < (blockX + 16); x++)
  33.             for(int z = blockZ; z < (blockZ + 16); z++)
  34.             {
  35.                 if(!roadmap.getAt(x, z))
  36.                     continue;
  37.                
  38.                 blockPositions.addAll(RoadStyle.grassy.getRoadBlocks(new BlockPos(x, 255, z)));
  39.             }
  40.        
  41.         for(BlockPos i : blockPositions)
  42.         {
  43.             BlockPos topBlock = world.getTopSolidOrLiquidBlock(i).down();
  44.            
  45.             if(!materialIsAllowed(world.getBlockState(topBlock).getMaterial()))
  46.                 continue;
  47.            
  48.             RoadStyle.grassy.drawRoadBlockAt(world, topBlock);
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment