Plex-FAWE/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ArrayHeightMap.java
Jesse Boyd a629d15c74
Copy paste/merge FAWE classes to this WorldEdit fork
- so certain people can look at the diff and complain about my sloppy code :(

Signed-off-by: Jesse Boyd <jessepaleg@gmail.com>
2018-08-13 00:03:07 +10:00

34 lines
919 B
Java

package com.boydti.fawe.object.brush.heightmap;
public class ArrayHeightMap extends ScalableHeightMap {
// The heights
private final byte[][] height;
// The height map width/length
private final int width, length;
// The size to width/length ratio
private double rx, rz;
public ArrayHeightMap(byte[][] height) {
setSize(5);
this.height = height;
this.width = height.length;
this.length = height[0].length;
}
@Override
public void setSize(int size) {
super.setSize(size);
this.rx = (double) width / (size << 1);
this.rz = (double) length / (size << 1);
}
@Override
public double getHeight(int x, int z) {
x = (int) Math.max(0, Math.min(width - 1, (x + size) * rx));
z = (int) Math.max(0, Math.min(length - 1, (z + size) * rz));
return ((height[x][z] & 0xFF) * size) / 256d;
}
}