Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class IslandWorldGenerator implements GenerationPopulator {
- private static final int SIZE = ConfigHelper.getConfig().getNode("islands", "size").getInt();
- private static final int DIST = ConfigHelper.getConfig().getNode("islands", "distance").getInt(); //Must be an odd number > 3
- @Override
- public void populate(World world, MutableBlockVolume buffer, ImmutableBiomeVolume biomes) {
- int height;
- int depth;
- for (int x = buffer.getBlockMin().getX(); x <= buffer.getBlockMax().getX(); x++) {
- for (int z = buffer.getBlockMin().getZ(); z <= buffer.getBlockMax().getZ(); z++) {
- if(draw(x) && draw(z)) {
- height = getDefaultHeight(x, z);
- depth = getDefaultDepth(x, z);
- for(int y = depth; y < height; y++) {
- buffer.setBlockType(x, y, z, BlockTypes.STONE);
- }
- }
- }
- }
- }
- private static boolean draw(int x) {
- return Math.abs(Math.floorMod(x,SIZE+DIST)) < SIZE;
- }
- private int getDefaultHeight(int x, int z) {
- Perlin texture = new Perlin(2345, 4);
- Perlin shape = new Perlin(9863, 30);
- double noise = -10*shape.getNoiseLevelAtPosition(x, z) + texture.getNoiseLevelAtPosition(x,z);
- //Makes the island have a hill in the middle (add to the height a little bit and multiply the noise a little bit)
- double height = Math.pow(((SIZE / 2f) - ((distanceFromCenter(x, z))) * 1.5), 1.2) + (noise * (((SIZE / 2f) - distanceFromCenter(x, z)) / 5));
- return (int) (Math.rint((height/16))+64);
- }
- private int getDefaultDepth(int x, int z) {
- Perlin features = new Perlin(2360, 15);
- Perlin shape = new Perlin(9863, 30);
- double noise = -10*shape.getNoiseLevelAtPosition(x, z) - 8*features.getNoiseLevelAtPosition(x, z);
- double height = (Math.pow(((SIZE / 2f) - ((distanceFromCenter(x, z))) * 1.5), 1.2) + ((noise / 1) * (((SIZE / 2f) - distanceFromCenter(x, z)) / 5))) / 7;
- if ((-height)+64 < 0) {
- return 0;
- } else {
- return (int) (Math.rint(-height+64));
- }
- }
- private double distanceFromCenter(int x, int z) {
- int centerX = Math.floorMod(x, SIZE + DIST);
- int centerZ = Math.floorMod(z, SIZE + DIST);
- double radius = (SIZE / 2f);
- return Math.sqrt(Math.pow((radius - centerX), 2.0) + Math.pow((radius - centerZ), 2.0));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement