Advertisement
Guest User

IslandGenerator

a guest
Dec 11th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 KB | None | 0 0
  1.  
  2. public class IslandWorldGenerator implements GenerationPopulator {
  3.  
  4.     private static final int SIZE = ConfigHelper.getConfig().getNode("islands", "size").getInt();
  5.     private static final int DIST = ConfigHelper.getConfig().getNode("islands", "distance").getInt(); //Must be an odd number > 3
  6.  
  7.     @Override
  8.     public void populate(World world, MutableBlockVolume buffer, ImmutableBiomeVolume biomes) {
  9.  
  10.         int height;
  11.         int depth;
  12.  
  13.         for (int x = buffer.getBlockMin().getX(); x <= buffer.getBlockMax().getX(); x++) {
  14.             for (int z = buffer.getBlockMin().getZ(); z <= buffer.getBlockMax().getZ(); z++) {
  15.                 if(draw(x) && draw(z)) {
  16.                     height = getDefaultHeight(x, z);
  17.                     depth = getDefaultDepth(x, z);
  18.                     for(int y = depth; y < height; y++) {
  19.                         buffer.setBlockType(x, y, z, BlockTypes.STONE);
  20.                     }
  21.                 }
  22.             }
  23.         }
  24.     }
  25.  
  26.     private static boolean draw(int x) {
  27.         return Math.abs(Math.floorMod(x,SIZE+DIST)) < SIZE;
  28.     }
  29.  
  30.     private int getDefaultHeight(int x, int z) {
  31.         Perlin texture = new Perlin(2345, 4);
  32.         Perlin shape = new Perlin(9863, 30);
  33.         double noise = -10*shape.getNoiseLevelAtPosition(x, z) + texture.getNoiseLevelAtPosition(x,z);
  34.         //Makes the island have a hill in the middle (add to the height a little bit and multiply the noise a little bit)
  35.         double height = Math.pow(((SIZE / 2f) - ((distanceFromCenter(x, z))) * 1.5), 1.2) + (noise * (((SIZE / 2f) - distanceFromCenter(x, z)) / 5));
  36.         return (int) (Math.rint((height/16))+64);
  37.     }
  38.  
  39.     private int getDefaultDepth(int x, int z) {
  40.         Perlin features = new Perlin(2360, 15);
  41.         Perlin shape = new Perlin(9863, 30);
  42.         double noise = -10*shape.getNoiseLevelAtPosition(x, z) - 8*features.getNoiseLevelAtPosition(x, z);
  43.         double height = (Math.pow(((SIZE / 2f) - ((distanceFromCenter(x, z))) * 1.5), 1.2) + ((noise / 1) * (((SIZE / 2f) - distanceFromCenter(x, z)) / 5))) / 7;
  44.         if ((-height)+64 < 0) {
  45.             return 0;
  46.         } else {
  47.             return (int) (Math.rint(-height+64));
  48.         }
  49.  
  50.     }
  51.  
  52.     private double distanceFromCenter(int x, int z) {
  53.         int centerX = Math.floorMod(x, SIZE + DIST);
  54.         int centerZ = Math.floorMod(z, SIZE + DIST);
  55.         double radius = (SIZE / 2f);
  56.         return Math.sqrt(Math.pow((radius - centerX), 2.0) + Math.pow((radius - centerZ), 2.0));
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement