Skip to content

Commit

Permalink
Held item colors are computed properly
Browse files Browse the repository at this point in the history
  • Loading branch information
kvverti committed Jul 8, 2019
1 parent 005d6d9 commit 3dd6336
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package io.github.kvverti.colormatic.colormap;

import io.github.kvverti.colormatic.properties.ColormapProperties;
import io.github.kvverti.colormatic.properties.HexColor;

import java.util.Random;

Expand All @@ -27,17 +28,39 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.ExtendedBlockView;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;

public class BiomeColormap {

private static final Random GRID_RANDOM = new Random(47L);

private final ColormapProperties properties;
private final NativeImage colormap;
private transient final int defaultColor;

public BiomeColormap(ColormapProperties props, NativeImage image) {
properties = props;
colormap = image;
HexColor col = props.getColor();
if(col != null) {
defaultColor = col.get();
} else {
defaultColor = computeDefaultColor(props);
}
}

private final int computeDefaultColor(ColormapProperties props) {
switch(props.getFormat()) {
case VANILLA:
return colormap.getPixelRGBA(128, 128);
case GRID:
int x = props.getColumn(Biomes.PLAINS);
int y = MathHelper.clamp(63 - props.getOffset(), 0, colormap.getHeight() - 1);
return x != -1 ? colormap.getPixelRGBA(x, y) : 0xffffffff;
case FIXED:
return 0xffffffff;
}
throw new AssertionError();
}

public ColormapProperties getProperties() {
Expand Down Expand Up @@ -97,7 +120,7 @@ public int getColor(Biome biome, BlockPos pos) {
* Returns the default color given by the custom colormap.
*/
public int getDefaultColor() {
return properties.getColor();
return defaultColor;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public class ColormapProperties {

/**
* For format = fixed only, the single color that is applied to all relevant
* block states.
* block states. Null if not specified.
*/
private final int color;
private final HexColor color;

/**
* For format = grid only, the amount of noise to add to the y coordinate
Expand All @@ -97,7 +97,7 @@ private ColormapProperties(Settings settings) {
this.format = settings.format;
this.blocks = settings.blocks;
this.source = new Identifier(settings.source);
this.color = settings.color.get();
this.color = settings.color;
this.yVariance = settings.yVariance;
this.yOffset = settings.yOffset;
if(settings.biomes != null) {
Expand All @@ -117,7 +117,7 @@ public Format getFormat() {
return format;
}

public int getColor() {
public HexColor getColor() {
return color;
}

Expand Down Expand Up @@ -261,7 +261,7 @@ private static class Settings {
Format format = Format.VANILLA;
Collection<ApplicableBlockStates> blocks;
String source;
HexColor color = HexColor.WHITE;
HexColor color = null;
int yVariance = 0;
int yOffset = 0;
Map<Identifier, Integer> biomes = null;
Expand Down

0 comments on commit 3dd6336

Please sign in to comment.