-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor special biome colors to be less special.
- Loading branch information
Showing
4 changed files
with
213 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = false | ||
max_line_length = 120 | ||
tab_width = 2 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,42 +22,86 @@ | |
* @author Jesper Öqvist <[email protected]> | ||
*/ | ||
public class Biome { | ||
public static final int DEFAULT_WATER_COLOR = 0x3f76e4; | ||
public final String resourceLocation; | ||
public final String name; | ||
public final float temperature; | ||
public final float rain; | ||
public final int mapColor; | ||
|
||
/** | ||
* Default grass color before loading from resource pack. | ||
*/ | ||
public int grassColor; | ||
/** | ||
* Default foliage color before loading from resource pack. | ||
*/ | ||
public GrassColorMode grassColorMode; | ||
public int foliageColor; | ||
public FoliageColorMode foliageColorMode; | ||
public int waterColor; | ||
|
||
public float[] grassColorLinear; | ||
public float[] foliageColorLinear; | ||
public float[] waterColorLinear; | ||
|
||
Biome(String resourceLocation, String name, double temperature, double rain, int mapColor, int grassColor, int foliageColor) { | ||
this(resourceLocation, name, temperature, rain, mapColor, grassColor, foliageColor, 0x3f76e4); | ||
this(resourceLocation, name, temperature, rain, mapColor, grassColor, foliageColor, DEFAULT_WATER_COLOR); | ||
} | ||
|
||
Biome(String resourceLocation, String name, double temperature, double rain, int mapColor, int grassColor, int foliageColor, int waterColor) { | ||
this(resourceLocation, name, temperature, rain, mapColor, grassColor, GrassColorMode.DEFAULT, foliageColor, FoliageColorMode.DEFAULT, waterColor); | ||
} | ||
|
||
Biome(String resourceLocation, String name, double temperature, double rain, int mapColor, int grassColor, | ||
GrassColorMode grassColorMode, int foliageColor, FoliageColorMode foliageColorMode, int waterColor) { | ||
this.resourceLocation = resourceLocation; | ||
this.name = name; | ||
this.temperature = (float) temperature; | ||
this.rain = (float) rain; | ||
this.mapColor = 0xFF000000 | mapColor; | ||
this.grassColor = grassColor; | ||
this.grassColorMode = grassColorMode; | ||
this.foliageColor = foliageColor; | ||
this.foliageColorMode = foliageColorMode; | ||
this.waterColor = waterColor; | ||
|
||
this.grassColorLinear = getRGBAComponentsGammaCorrected(grassColor); | ||
this.foliageColorLinear = getRGBAComponentsGammaCorrected(foliageColor); | ||
this.waterColorLinear = getRGBAComponentsGammaCorrected(waterColor); | ||
} | ||
|
||
public static BiomeBuilder create(String resourceLocation, String name, double temperature, double rain) { | ||
return new BiomeBuilder(resourceLocation, name, temperature, rain); | ||
} | ||
|
||
enum GrassColorMode { | ||
/** | ||
* The grass color depends on temperature and humidity. | ||
*/ | ||
DEFAULT, | ||
/** | ||
* The grass color is fixed. | ||
*/ | ||
FIXED_COLOR, | ||
/** | ||
* The grass color depends on temperature and humidity and is also averaged with 0x28340A. | ||
*/ | ||
DARK_FOREST, | ||
/** | ||
* In Java Edition, the grass color would be perlin noise with two colors. | ||
* Since we don't support this, the grass color is 0x6A7039 (as in Bedrock Edition). | ||
*/ | ||
SWAMP | ||
} | ||
|
||
enum FoliageColorMode { | ||
/** | ||
* The foliage color depends on temperature and humidity. | ||
*/ | ||
DEFAULT, | ||
/** | ||
* The foliage color is fixed. | ||
*/ | ||
FIXED_COLOR, | ||
/** | ||
* In Java Edition, the foliage color would be perlin noise with two colors. | ||
* Since we don't support this, the foliage color is 0x6A7039 (as in Bedrock Edition). | ||
*/ | ||
SWAMP | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
chunky/src/java/se/llbit/chunky/world/biome/BiomeBuilder.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package se.llbit.chunky.world.biome; | ||
|
||
public class BiomeBuilder { | ||
private final String resourceLocation; | ||
private final String name; | ||
private final double temperature; | ||
private final double rain; | ||
private int waterColor = Biome.DEFAULT_WATER_COLOR; | ||
private int mapColor = 0x7E7E7E; | ||
private int grassColor; | ||
private Biome.GrassColorMode grassColorMode = Biome.GrassColorMode.DEFAULT; | ||
private int foliageColor; | ||
private Biome.FoliageColorMode foliageColorMode = Biome.FoliageColorMode.DEFAULT; | ||
|
||
public BiomeBuilder(String resourceLocation, String name, double temperature, double rain) { | ||
this.resourceLocation = resourceLocation; | ||
this.name = name; | ||
this.temperature = temperature; | ||
this.rain = rain; | ||
} | ||
|
||
public BiomeBuilder(String resourceLocation, double temperature, double rain) { | ||
this(resourceLocation, resourceLocation, temperature, rain); | ||
} | ||
|
||
public BiomeBuilder mapColor(int mapColor) { | ||
this.mapColor = mapColor; | ||
return this; | ||
} | ||
|
||
public BiomeBuilder defaultColors(int grassColor, int foliageColor) { | ||
this.grassColor = grassColor; | ||
this.foliageColor = foliageColor; | ||
return this; | ||
} | ||
|
||
public BiomeBuilder grassColor(int grassColor) { | ||
this.grassColor = grassColor; | ||
this.grassColorMode = Biome.GrassColorMode.FIXED_COLOR; | ||
return this; | ||
} | ||
|
||
public BiomeBuilder foliageColor(int foliageColor) { | ||
this.foliageColor = foliageColor; | ||
this.foliageColorMode = Biome.FoliageColorMode.FIXED_COLOR; | ||
return this; | ||
} | ||
|
||
public BiomeBuilder waterColor(int waterColor) { | ||
this.waterColor = waterColor; | ||
return this; | ||
} | ||
|
||
public BiomeBuilder swamp() { | ||
this.grassColorMode = Biome.GrassColorMode.SWAMP; | ||
this.foliageColorMode = Biome.FoliageColorMode.SWAMP; | ||
return this; | ||
} | ||
|
||
public BiomeBuilder darkForest() { | ||
this.grassColorMode = Biome.GrassColorMode.DARK_FOREST; | ||
return this; | ||
} | ||
|
||
public BiomeBuilder badlands() { | ||
grassColor(0x90814D); | ||
foliageColor(0x9E814D); | ||
return this; | ||
} | ||
|
||
public Biome build() { | ||
return new Biome( | ||
resourceLocation, name, | ||
temperature, rain, | ||
mapColor, | ||
grassColor, grassColorMode, | ||
foliageColor, foliageColorMode, | ||
waterColor | ||
); | ||
} | ||
} |
Oops, something went wrong.