Finish mixed biome/block coloring

This commit is contained in:
Jesse Boyd 2017-04-29 23:32:08 +10:00
parent 96f9452608
commit cc3a3f159f
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
5 changed files with 46 additions and 11 deletions

View File

@ -275,18 +275,18 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
BaseBlock block = textureUtil.getNearestBlock(color);
TextureUtil.BiomeColor biome = textureUtil.getNearestBiome(color);
int blockColor = textureUtil.getColor(block);
if (textureUtil.colorDistance(biome.grass, color) < textureUtil.colorDistance(blockColor, color)) {
if (textureUtil.colorDistance(biome.grass, color) <= textureUtil.colorDistance(blockColor, color)) {
byte biomeByte = (byte) biome.id;
biomes[index] = biomeByte;
if (yBiome && x > 0 && x < widthIndex) {
setBiomeIfZero(index+ 1, biomeByte);
setBiomeIfZero(index- 1, biomeByte);
setBiomeIfZero(index+ getWidth(), biomeByte);
setBiomeIfZero(index+ getWidth() + 1, biomeByte);
setBiomeIfZero(index+ getWidth() - 1, biomeByte);
setBiomeIfZero(index- getWidth(), biomeByte);
setBiomeIfZero(index- getWidth() + 1, biomeByte);
setBiomeIfZero(index- getWidth() - 1, biomeByte);
setBiomeIfZero(index + 1, biomeByte);
setBiomeIfZero(index - 1, biomeByte);
setBiomeIfZero(index + getWidth(), biomeByte);
setBiomeIfZero(index + getWidth() + 1, biomeByte);
setBiomeIfZero(index + getWidth() - 1, biomeByte);
setBiomeIfZero(index - getWidth(), biomeByte);
setBiomeIfZero(index - getWidth() + 1, biomeByte);
setBiomeIfZero(index - getWidth() - 1, biomeByte);
}
} else {
char combined = (char) block.getCombined();

View File

@ -11,6 +11,7 @@ public class CleanTextureUtil extends TextureUtil {
long max = parent.distances[maxIndex];
int num = maxIndex - minIndex + 1;
this.validBiomes = parent.validBiomes;
this.blockColors = parent.blockColors;
this.blockDistance = parent.blockDistance;
this.distances = Arrays.copyOfRange(parent.blockDistance, minIndex, maxIndex + 1);

View File

@ -9,6 +9,10 @@ import org.json.simple.parser.ParseException;
public class DelegateTextureUtil extends TextureUtil {
private final TextureUtil parent;
public static void main(String[] args) throws Throwable {
TextureUtil.main(args);
}
public DelegateTextureUtil(TextureUtil parent) {
super(parent.getFolder());
this.parent = parent;
@ -39,6 +43,16 @@ public class DelegateTextureUtil extends TextureUtil {
return parent.getColor(block);
}
@Override
public BiomeColor getBiome(int biome) {
return parent.getBiome(biome);
}
@Override
public BiomeColor getNearestBiome(int color) {
return parent.getNearestBiome(color);
}
@Override
public File getFolder() {
return parent.getFolder();
@ -49,11 +63,21 @@ public class DelegateTextureUtil extends TextureUtil {
return parent.combineTransparency(top, bottom);
}
@Override
public void calculateLayerArrays() {
parent.calculateLayerArrays();
}
@Override
public void loadModTextures() throws IOException, ParseException {
parent.loadModTextures();
}
@Override
public int multiply(int c1, int c2) {
return parent.multiply(c1, c2);
}
@Override
public BaseBlock getNearestBlock(BaseBlock block, boolean darker) {
return parent.getNearestBlock(block, darker);
@ -79,8 +103,17 @@ public class DelegateTextureUtil extends TextureUtil {
return parent.colorDistance(red1, green1, blue1, c2);
}
public static int hueDistance(int red1, int green1, int blue1, int red2, int green2, int blue2) {
return TextureUtil.hueDistance(red1, green1, blue1, red2, green2, blue2);
}
@Override
public int getColor(BufferedImage image) {
return parent.getColor(image);
}
@Override
public long getDistance(BufferedImage image, int c1) {
return parent.getDistance(image, c1);
}
}

View File

@ -7,6 +7,7 @@ import java.util.Set;
public class FilteredTextureUtil extends TextureUtil {
public FilteredTextureUtil(TextureUtil parent, Set<BaseBlock> blocks) {
super(parent.getFolder());
this.validBiomes = parent.validBiomes;
this.blockColors = parent.blockColors;
this.blockDistance = parent.blockDistance;
this.distances = parent.distances;

View File

@ -52,7 +52,7 @@ public class TextureUtil {
/**
* https://github.com/erich666/Mineways/blob/master/Win/biomes.cpp
*/
private BiomeColor[] validBiomes;
protected BiomeColor[] validBiomes;
private BiomeColor[] biomes = new BiomeColor[] {
// ID Name Temperature, rainfall, grass, foliage colors
// - note: the colors here are just placeholders, they are computed in the program
@ -823,7 +823,7 @@ public class TextureUtil {
int g = green1 - green2;
int b = blue1 - blue2;
int hd = hueDistance(red1, green1, blue1, red2, green2, blue2);
return (((512 + rmean) * r * r) >> 8) + 4 * g * g + (((767 - rmean) * b * b) >> 8) + (hd);
return (((512 + rmean) * r * r) >> 8) + 4 * g * g + (((767 - rmean) * b * b) >> 8) + (hd * hd);
}
protected static int hueDistance(int red1, int green1, int blue1, int red2, int green2, int blue2) {