Skip to content

Instantly share code, notes, and snippets.

@tenowg
Last active December 14, 2015 07:59
Show Gist options
  • Save tenowg/5054888 to your computer and use it in GitHub Desktop.
Save tenowg/5054888 to your computer and use it in GitHub Desktop.
Spout server heightmap world generator, would love some help optimizing this for use with Spout.
public class WHHieghtMapGenerator implements WorldGenerator {
private BufferedImage worldImage;
public WHHieghtMapGenerator(String imagefile) {
try {
URL url = getClass().getResource("/" + imagefile);
worldImage = ImageIO.read(url);
} catch (IOException ex) {
Spout.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
}
}
@Override
public void generate(CuboidBlockMaterialBuffer blockData, int x, int y, int z, World world) {
x <<= 4;
y <<= 4;
z <<= 4;
final Vector3 size = blockData.getSize();
final int sizeX = size.getFloorX();
final int sizeY = size.getFloorY();
final int sizeZ = size.getFloorZ();
for (int xx = 0; xx < sizeX; xx++) {
for (int zz = 0; zz < sizeZ; zz++) {
int clr;
try {
clr = worldImage.getRGB(x + xx, z + zz);
} catch (Exception e) {
continue;
}
for (int yy = 0; yy < sizeY; yy++) {
int red;
red = (clr >> 16) & 0xff;
if (y + yy <= red) {
blockData.set(x + xx, y + yy, z + zz, BlockMaterial.SOLID_GREEN);
} else {
blockData.set(x + xx, y + yy, z + zz, BlockMaterial.AIR);
}
}
}
}
}
@Override
public int[][] getSurfaceHeight(World world, int i, int i1) {
int[][] heights = new int[Chunk.BLOCKS.SIZE][Chunk.BLOCKS.SIZE];
return heights;
}
@Override
public Populator[] getPopulators() {
return new Populator[0];
}
@Override
public String getName() {
return "WHHeightMap";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment