diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/IslandSurvivalCraft.java b/src/main/java/ca/recrown/islandsurvivalcraft/IslandSurvivalCraft.java index 0fec8eb..7962075 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/IslandSurvivalCraft.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/IslandSurvivalCraft.java @@ -1,5 +1,8 @@ package ca.recrown.islandsurvivalcraft; +import java.util.Random; + +import org.bukkit.World; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.java.JavaPlugin; @@ -8,6 +11,7 @@ import nl.rutgerkok.worldgeneratorapi.WorldGeneratorApi; import nl.rutgerkok.worldgeneratorapi.WorldRef; public class IslandSurvivalCraft extends JavaPlugin { + @Override public void onEnable() { // TODO Auto-generated method stub @@ -19,14 +23,13 @@ public class IslandSurvivalCraft extends JavaPlugin { // TODO Auto-generated method stub super.onDisable(); } - @Override public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { WorldGeneratorApi worldGenAPI = WorldGeneratorApi.getInstance(this, 0, 1); - return worldGenAPI.createCustomGenerator(WorldRef.ofName(worldName), gen -> { - gen.setBaseTerrainGenerator(new IslandBaseTerrainGenerator(getServer().getWorld(worldName).getSeed(), 63, 20, 73)); + World world = getServer().getWorld(worldName); + gen.setBaseTerrainGenerator(new IslandBaseTerrainGenerator(world)); }); } } diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandBaseTerrainGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandBaseTerrainGenerator.java index f0d42de..9d78878 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandBaseTerrainGenerator.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandBaseTerrainGenerator.java @@ -3,44 +3,54 @@ package ca.recrown.islandsurvivalcraft.worldgen; import java.util.Random; import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Biome; import org.bukkit.generator.ChunkGenerator.ChunkData; -import org.bukkit.util.noise.PerlinOctaveGenerator; +import org.bukkit.util.noise.SimplexOctaveGenerator; import nl.rutgerkok.worldgeneratorapi.BaseTerrainGenerator; +import nl.rutgerkok.worldgeneratorapi.BaseNoiseGenerator.TerrainSettings; public class IslandBaseTerrainGenerator implements BaseTerrainGenerator { - private int seaLevel; - private int minimumHeight; - private int maximumHeight; + private TerrainSettings settings; + private SimplexOctaveGenerator baseNoiseGenerator; + private SimplexOctaveGenerator islandShapeGenerator; + private final int scale = 100; + private final int maximumHeight = 65; + private final int minimumHeight = 3; + private Random random; + private World world; - private PerlinOctaveGenerator noiseGenerator; - - public IslandBaseTerrainGenerator(long seed, int seaLevel, int seaFloor, int maximumHeight) { - Random random = new Random(seed); - this.seaLevel = seaLevel; - this.minimumHeight = seaFloor; - this.maximumHeight = maximumHeight; - - this.noiseGenerator = new PerlinOctaveGenerator(random, 8); - noiseGenerator.setScale(0.025D); + public IslandBaseTerrainGenerator(World world) { + this.random = new Random(world.getSeed()); + this.baseNoiseGenerator = new SimplexOctaveGenerator(random, 8); + this.baseNoiseGenerator.setScale(0.015D); + this.islandShapeGenerator = new SimplexOctaveGenerator(random, 8); + this.islandShapeGenerator.setScale(0.02D); + this.settings = new TerrainSettings(); + this.settings.seaLevel = world.getSeaLevel(); + + this.world = world; } @Override public void setBlocksInChunk(GeneratingChunk chunk) { - for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { int worldX = 16 * chunk.getChunkX() + x; int worldZ = 16 * chunk.getChunkZ() + z; int height = baseHeight(worldX, worldZ); + Biome biome = chunk.getBiomesForChunk().getBiome(x, height, z); + height += additionalHeight(worldX, worldZ, biome); fillChunkColumn(x, z, height, chunk.getBlocksForChunk()); } } + private void fillChunkColumn(int x, int z, int height, ChunkData chunkData) { - if (height <= seaLevel) { - chunkData.setRegion(x, height, z, x+1, seaLevel, z+1, Material.WATER); + if (height <= settings.seaLevel) { + chunkData.setRegion(x, height, z, x+1, settings.seaLevel, z+1, Material.WATER); chunkData.setRegion(x, 0, z, x+1, height, z+1, Material.STONE); } else { chunkData.setRegion(x, 0, z, x+1, height, z+1, Material.STONE); @@ -48,16 +58,44 @@ public class IslandBaseTerrainGenerator implements BaseTerrainGenerator { } private int baseHeight(int x, int z) { - return (int) ((noiseGenerator.noise(x, z, 0.5D, 0.5D, true) + 1D) * maximumHeight/2D) + minimumHeight; + return Math.min((int) ((baseNoiseGenerator.noise(x, z, 0.3D, 0.6D, true) + 1D) * scale/2D) + minimumHeight, maximumHeight); + } + + private int additionalHeight(int worldX, int worldZ, Biome biome) { + int height = 0; + String biomeName = biome.name(); + if (biomeName.contains("hills")) { + height += islandHeight(worldX, worldZ, 0.5D, 0.5D, 15); + } else if (biomeName.contains("mountains")) { + height += islandHeight(worldX, worldZ, 0.5D, 0.5D, 60); + } else if (biomeName.contains("plateau")) { + height *= 1.2f; + height += Math.min(55, islandHeight(worldX, worldZ, 0.3D, 0.3D, 5)); + } else if (biomeName.contains("modified")) { + height += islandHeight(worldX, worldZ, 0.5D, 0.5D, 20); + } else if (biomeName.contains("shattered")) { + height += islandHeight(worldX, worldZ, 0.5D, 0.5D, 20); + } else if (biomeName.contains("tall")) { + height += islandHeight(worldX, worldZ, 0.5D, 0.5D, 30); + } else { + height += islandHeight(worldX, worldZ, 0.5D, 0.5D, 8); + } + return height; + } + + private int islandHeight(int x, int z, double freq, double amp, int maximumHeight) { + return (int) ((islandShapeGenerator.noise(x, z, 0.5D, 0.5D, true) + 1D) * maximumHeight/2D); } @Override public int getHeight(int x, int z, HeightType type) { - int baseHeight = baseHeight(x, z); - if (baseHeight <= seaLevel && type == HeightType.WORLD_SURFACE) { - return seaLevel; + // TODO FIX THIS. Innacurate readings. Due to innacurate biomes. + Biome biome = world.getBiome(x, settings.seaLevel, z); + int totalHeight = additionalHeight(x, z, biome) + baseHeight(x, z); + if (totalHeight <= settings.seaLevel && type == HeightType.OCEAN_FLOOR) { + return totalHeight; } - return baseHeight; + return totalHeight; } } \ No newline at end of file diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandNoiseGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandNoiseGenerator.java new file mode 100644 index 0000000..a01be56 --- /dev/null +++ b/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandNoiseGenerator.java @@ -0,0 +1,48 @@ +package ca.recrown.islandsurvivalcraft.worldgen; + +import java.util.Random; + +import org.bukkit.Material; +import org.bukkit.generator.ChunkGenerator.ChunkData; +import org.bukkit.util.noise.SimplexOctaveGenerator; + +import nl.rutgerkok.worldgeneratorapi.BaseNoiseGenerator; +import nl.rutgerkok.worldgeneratorapi.BiomeGenerator; + +public class IslandNoiseGenerator implements BaseNoiseGenerator { + private TerrainSettings settings; + private SimplexOctaveGenerator baseNoiseGenerator; + private final int maximumHeight = 78; + private final int minimumHeight = 3; + + public IslandNoiseGenerator(TerrainSettings settings, Random random) { + this.baseNoiseGenerator = new SimplexOctaveGenerator(random, 4); + } + + @Override + public void getNoise(BiomeGenerator biomeGenerator, double[] buffer, int x4, int z4) { + for (int multiple = 0; multiple < buffer.length; multiple++) { + for (int x = 0; x < 4; x++) + for (int z = 0; z < 4; z++) { + int xBlock = x4 + x; + int zBlock = z4 + z; + + } + } + } + + private void fillChunkColumn(int x, int z, int height, ChunkData chunkData) { + if (height <= settings.seaLevel) { + chunkData.setRegion(x, height, z, x+1, settings.seaLevel, z+1, Material.WATER); + chunkData.setRegion(x, 0, z, x+1, height, z+1, Material.STONE); + } else { + chunkData.setRegion(x, 0, z, x+1, height, z+1, Material.STONE); + } + } + + private int baseHeight(int x, int z) { + return (int) ((baseNoiseGenerator.noise(x, z, 0.5D, 0.5D, true) + 1D) * maximumHeight/2D) + minimumHeight; + } + + +} \ No newline at end of file diff --git a/test-server/server.properties b/test-server/server.properties index e537f4a..2c57687 100644 --- a/test-server/server.properties +++ b/test-server/server.properties @@ -1,5 +1,5 @@ #Minecraft server properties -#Sun Apr 19 00:42:51 CDT 2020 +#Sun Apr 19 03:02:41 CDT 2020 spawn-protection=16 max-tick-time=60000 query.port=25565 @@ -38,10 +38,10 @@ spawn-animals=true white-list=false rcon.password= generate-structures=true -online-mode=true max-build-height=256 +online-mode=true level-seed= -prevent-proxy-connections=false use-native-transport=true -motd=A Minecraft Server +prevent-proxy-connections=false enable-rcon=false +motd=A Minecraft Server