Created
February 12, 2012 16:58
-
-
Save jmurth1234/1809635 to your computer and use it in GitHub Desktop.
Main ChunkGenerator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.rymate.WorldGen; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Random; | |
import org.bukkit.Material; | |
import org.bukkit.World; | |
import org.bukkit.block.Biome; | |
import org.bukkit.generator.BlockPopulator; | |
import org.bukkit.generator.ChunkGenerator; | |
import org.bukkit.util.noise.PerlinOctaveGenerator; | |
import org.bukkit.util.noise.SimplexOctaveGenerator; | |
class WorldGenerator extends ChunkGenerator { | |
public WorldGen plugin; | |
public List<BlockPopulator> getDefaultPopulators(World world) { | |
return Arrays.asList(new BlockPopulator[]{new MetaPopulator(this.plugin)}); | |
} | |
public boolean canSpawn(World world, int x, int z) { | |
double xX = Math.random() * x; | |
double zZ = Math.random() * z; | |
return xX > zZ; | |
} | |
public int xyzToByte(int x, int y, int z) { | |
return (x * 16 + z) * 128 + y; | |
} | |
public byte[] generate(World world, Random random, int chunkx, int chunkz) { | |
byte[] block = new byte[32768]; | |
byte bedrock = (byte) Material.BEDROCK.getId(); | |
byte stone = (byte) Material.STONE.getId(); | |
byte dirt = (byte) Material.DIRT.getId(); | |
byte grass = (byte) Material.GRASS.getId(); | |
byte water = (byte) Material.STATIONARY_WATER.getId(); | |
byte sand = (byte) Material.SAND.getId(); | |
Random seed = new Random(world.getSeed()); | |
SimplexOctaveGenerator g = new SimplexOctaveGenerator(seed, 8); | |
PerlinOctaveGenerator gg = new PerlinOctaveGenerator(seed, 8); | |
g.setScale(0.0025D); | |
gg.setScale(0.015625D); | |
for (int x = 0; x < 16; x++) { | |
for (int z = 0; z < 16; z++) { | |
int trueX = chunkx * 16 + x; | |
int trueZ = chunkz * 16 + z; | |
Biome b = world.getBiome(chunkx * 16 + x, chunkz * 16 + z); | |
for (int y = 0; y < 1; y++) { | |
block[xyzToByte(x, y, z)] = bedrock; | |
} | |
for (int y = 4; y < 48; y++) { | |
if (block[xyzToByte(x, y, z)] == 0) { | |
block[xyzToByte(x, y, z)] = water; | |
} | |
} | |
double n1 = g.noise(x + chunkx * 16, z + chunkz * 16, 0.45D, 0.7D) * 16.0D; | |
double n2 = gg.noise(x + chunkx * 16, z + chunkz * 16, 0.75D, 0.6D) * 16.0D; | |
double h = Function.get(trueX, trueZ) * 5.0D; //see http://forums.bukkit.org/threads/fun-wgen-create-a-world-from-trigonometric-functions.40213/ | |
double noise = n1 - n2 * h; | |
if (b == Biome.DESERT) { | |
//lazy deserts :P | |
for (int y = 8; y < 48.0D + noise; y++) { | |
block[xyzToByte(x, y, z)] = sand; | |
} | |
for (int y = 47; y < 48.0D + noise; y++) { | |
block[xyzToByte(x, y, z)] = sand; | |
} | |
for (int y = 1; y < 40.0D + noise; y++) { | |
block[xyzToByte(x, y, z)] = stone; | |
} | |
} else { | |
//all other land | |
for (int y = 8; y < 48.0D + noise; y++) { | |
block[xyzToByte(x, y, z)] = dirt; | |
} | |
for (int y = 47; y < 48.0D + noise; y++) { | |
block[xyzToByte(x, y, z)] = grass; | |
} | |
for (int y = 1; y < 40.0D + noise; y++) { | |
block[xyzToByte(x, y, z)] = stone; | |
} | |
} | |
} | |
} | |
return block; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment