Advertisement
HalestormXV

Untitled

Apr 7th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
  2.         switch (world.provider.getDimension()) {
  3.             case -1:
  4.                 break;
  5.  
  6.             case 0:
  7.                 generateStructures(new WorldGenStructure("cultist_hut"), world, random, chunkX, chunkZ, 10, Blocks.GRASS, getBiomeList().toArray(new Class[getBiomeList().size()]));
  8.                 generateRuneAltar(new WorldGenStructure("air_temple"), world, random, chunkX, chunkZ, 120, 98, 176);
  9.                 generateRuneAltar(new WorldGenStructure("earth_temple"), world, random, chunkX, chunkZ, 180, 84, 152);
  10.                 generateTrees(LUPRESIUM_TREE, world, random, chunkX, chunkZ, 10, lupresiumDirt, BiomeLupresiumForest.class);
  11.                 generateTrees(MYSTIC_TREE, world, random, chunkX, chunkZ, 10, mysticDirt, BiomeMysticLands.class);
  12.                 break;
  13.  
  14.             case 1:
  15.                 break;
  16.  
  17.             case 2:
  18.                 break;
  19.  
  20.         }
  21.     }
  22.  
  23. private void generateStructures(WorldGenerator generator, World world, Random random, int chunkX, int chunkZ, int chance, Block topBlock, Class<?>... classes) {
  24.         HighQualityRandom highQualityRandom = new HighQualityRandom();
  25.         ArrayList<Class<?>> classesList = new ArrayList<Class<?>>(Arrays.asList(classes));
  26.         int struc_x = (chunkX * 16) + highQualityRandom.nextInt(15);
  27.         int struc_z = (chunkZ * 16) + highQualityRandom.nextInt(15);
  28.         float y = 0;
  29.         for (int x = 0; x < struc_x; x++)
  30.         {
  31.             for (int z = 0; z < struc_z; z++)
  32.             {
  33.                 int oldY = Math.round(y);
  34.                 y += calculateGenerationHeight(world, x, z, topBlock);
  35.                 y /= 2;
  36.                 if (Math.round(y) != oldY){ return; }
  37.             }
  38.         }
  39.         int struc_y = (int)y;
  40.         BlockPos pos = new BlockPos(struc_x, struc_y, struc_z);
  41.         Class<?> biome = world.provider.getBiomeForCoords(pos).getClass();
  42.         if (world.getWorldType() != WorldType.FLAT) {
  43.             if (classesList.contains(biome) || classesList.isEmpty()) {
  44.                 if (highQualityRandom.nextInt(chance) == 0)
  45.                 {
  46.  
  47.                     generator.generate(world, highQualityRandom, pos);
  48.                 }
  49.             }
  50.         }
  51.     }
  52.  
  53.     private static int calculateGenerationHeight(World world, int x, int z, Block topBlock) {
  54.         int y = world.getHeight();
  55.         boolean foundGround = false;
  56.         while (!foundGround && y-- >= 0) {
  57.             Block block = world.getBlockState(new BlockPos(x, y, z)).getBlock();
  58.             foundGround = block == topBlock;
  59.         }
  60.         return y;
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement