Advertisement
Guest User

Untitled

a guest
Nov 26th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1.  
  2.     public CustomTerrainGenerator(ICubicWorld world, final long seed) {
  3.         final int selectorOctaves = 8;
  4.         Random rnd = new Random(seed);
  5.         IBuilder selector = NoiseSource.perlin().
  6.             seed(rnd.nextLong()).
  7.             frequency(8.55515/Math.pow(2, selectorOctaves)/(MAX_ELEV/64.0)).
  8.             octaves(selectorOctaves).
  9.             create();
  10.  
  11.         IBuilder low = NoiseSource.perlin().
  12.             seed(rnd.nextLong()).
  13.             frequency(684.412D/Math.pow(2, OCTAVES)/(MAX_ELEV/64.0)).
  14.             octaves(OCTAVES).
  15.             create();
  16.  
  17.         IBuilder high = NoiseSource.perlin().
  18.             seed(rnd.nextLong()).
  19.             frequency(684.412D/Math.pow(2, OCTAVES)/(MAX_ELEV/64.0)).
  20.             octaves(OCTAVES).
  21.             create();
  22.  
  23.         int heightmapOctaves = 10;
  24.         double heightmapFreq = 200.0/Math.pow(2, heightmapOctaves)/(MAX_ELEV/64);
  25.         IBuilder randomHeight2d = NoiseSource.perlin().
  26.             seed(rnd.nextLong()).
  27.             frequency(heightmapFreq, 0, heightmapFreq).
  28.             octaves(heightmapOctaves).
  29.             create().
  30.             mulIf(NEGATIVE, -0.3).
  31.             mul(3).sub(2).
  32.             clamp(-2, 1).
  33.             divIf(NEGATIVE, 2*2*1.4).
  34.             divIf(NOT_NEGATIVE, 8).
  35.             mul(0.2*17/64.0);
  36.  
  37.         BiomeHeightVolatilitySource biomeSource = new BiomeHeightVolatilitySource(
  38.             world.getBiomeProvider(), 2*(int) (MAX_ELEV/64), X_SECTION_SIZE, Z_SECTION_SIZE);
  39.  
  40.         IBuilder height = biomeSource::getHeight;
  41.         IBuilder volatility = biomeSource::getVolatility;
  42.  
  43.         this.terrainBuilder = selector.
  44.             lerp(low, high).
  45.             mul(volatility.div((x, y, z) -> (y*8/MAX_ELEV < height.get(x, y, z)) ? 4 : 1)).
  46.             add(height).add(randomHeight2d).
  47.             mul(MAX_ELEV).add(64).sub((x, y, z) -> y*8*MAX_ELEV);
  48.     }
  49.  
  50.     public void generate(final ICubePrimer cubePrimer, int cubeX, int cubeY, int cubeZ) {
  51.         CubePos cubePos = new CubePos(cubeX, cubeY, cubeZ);
  52.         BlockPos start = cubePos.getMinBlockPos();
  53.         BlockPos end = cubePos.getMaxBlockPos();
  54.         terrainBuilder.scaledStream(start, end, new Vec3i(4, 8, 4)).
  55.             forEach(e -> cubePrimer.setBlockState(e.getX(), e.getY(), e.getZ(), this.getState(e)));
  56.     }
  57.  
  58.     private IBlockState getState(IBuilder.IEntry e) {
  59.         return e.getValue() > 0 ? Blocks.AIR.getDefaultState() : Blocks.STONE.getDefaultState();
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement