Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions definitions/readme_biomes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ the new tag "data18" is used to define Biomes:

Some special values can be derived from the Minecraft source code:

"watermodifier" - special color of water (in swamps)
"temperature" - default 0.5
"humidity" - default 0.5
"watermodifier" - special color of water (in swamps)
"grassmodifier" - special color of grass (otherwise derived by temperature and humidity)
"foliagemodifier" - special color of leaves (otherwise derived by temperature and humidity)
"temperature" - default 0.5
"humidity" - default 0.5


Some stuff is hard coded inside Minecraft source code. To handle these edge cases,
Expand All @@ -40,9 +42,7 @@ some additional boolean flags can be used:

"ocean" - used for Drawned spawn detection (guess trigger is "ocean")
"river" - used for Drawned spawn detection (guess trigger is "river")
"swamp" - used for hard coded foliage colors (guess trigger is "swamp")
"darkforest" - used for hard coded foliage colors (guess trigger is "dark forest")
"badlands" - used for hard coded foliage colors (guess trigger is "badlands" and "mesa")
"darkforest" - used for special blended foliage colors (guess trigger is "dark forest")


For Minecraft up to 1.17 Biomes were stored as numerical ID for that we have
Expand Down
32 changes: 29 additions & 3 deletions definitions/vanilla_biomes.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Vanilla",
"type": "biome",
"version": "26.3.1",
"version": "26.3.1a",
"data18": [
{
"id": "minecraft:ocean",
Expand Down Expand Up @@ -41,6 +41,8 @@
"id": "minecraft:swamp",
"color": "#07f9b2",
"watermodifier": "#617b64",
"grassmodifier": "#6a7039",
"foliagemodifier": "#6a7039",
"temperature": 0.8,
"humidity": 0.9
},
Expand Down Expand Up @@ -163,12 +165,16 @@
{
"id": "minecraft:badlands",
"color": "#d94515",
"grassmodifier": "#90814d",
"foliagemodifier": "#9e814d",
"temperature": 2.0,
"humidity": 0.0
},
{
"id": "minecraft:wooded_badlands",
"color": "#b09765",
"grassmodifier": "#90814d",
"foliagemodifier": "#9e814d",
"temperature": 2.0,
"humidity": 0.0
},
Expand Down Expand Up @@ -272,6 +278,8 @@
{
"id": "minecraft:eroded_badlands",
"color": "#ff6d3d",
"grassmodifier": "#90814d",
"foliagemodifier": "#9e814d",
"temperature": 2.0,
"humidity": 0.0
},
Expand Down Expand Up @@ -397,8 +405,10 @@
},
{
"id": "minecraft:dappled_forest",
"color": "#c8c828",
"watermodifier": "#9a3f35",
"color": "#9a3f35",
"watermodifier": "#375154",
"grassmodifier": "#df6827",
"foliagemodifier": "#e68e30",
"temperature": 0.6,
"humidity": 0.6
}
Expand Down Expand Up @@ -455,6 +465,8 @@
"name": "Swamp",
"color": "#07f9b2",
"watermodifier": "#617b64",
"grassmodifier": "#6a7039",
"foliagemodifier": "#6a7039",
"temperature": 0.8,
"humidity": 0.9
},
Expand Down Expand Up @@ -696,6 +708,8 @@
"name": "Badlands",
"color": "#d94515",
"watermodifier": "#3f76e4",
"grassmodifier": "#90814d",
"foliagemodifier": "#9e814d",
"temperature": 2.0,
"humidity": 0.0
},
Expand All @@ -704,6 +718,8 @@
"name": "Wooded Badlands Plateau",
"color": "#b09765",
"watermodifier": "#3f76e4",
"grassmodifier": "#90814d",
"foliagemodifier": "#9e814d",
"temperature": 2.0,
"humidity": 0.0
},
Expand All @@ -712,6 +728,8 @@
"name": "Badlands Plateau",
"color": "#ca8c65",
"watermodifier": "#3f76e4",
"grassmodifier": "#90814d",
"foliagemodifier": "#9e814d",
"temperature": 2.0,
"humidity": 0.0
},
Expand Down Expand Up @@ -832,6 +850,8 @@
"name": "Swamp Hills",
"color": "#2fffda",
"watermodifier": "#617b64",
"grassmodifier": "#6a7039",
"foliagemodifier": "#6a7039",
"temperature": 0.8,
"humidity": 0.9
},
Expand Down Expand Up @@ -936,6 +956,8 @@
"name": "Eroded Badlands",
"color": "#ff6d3d",
"watermodifier": "#3f76e4",
"grassmodifier": "#90814d",
"foliagemodifier": "#9e814d",
"temperature": 2.0,
"humidity": 0.0
},
Expand All @@ -944,6 +966,8 @@
"name": "Modified Wooded Badlands Plateau",
"color": "#d8bf8d",
"watermodifier": "#3f76e4",
"grassmodifier": "#90814d",
"foliagemodifier": "#9e814d",
"temperature": 2.0,
"humidity": 0.0
},
Expand All @@ -952,6 +976,8 @@
"name": "Modified Badlands Plateau",
"color": "#f2b48d",
"watermodifier": "#3f76e4",
"grassmodifier": "#90814d",
"foliagemodifier": "#9e814d",
"temperature": 2.0,
"humidity": 0.0
},
Expand Down
86 changes: 50 additions & 36 deletions identifier/biomeidentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ BiomeInfo::BiomeInfo()
, enabled(false)
, ocean(false)
, river(false)
, swamp(false)
, darkforest(false)
, badlands(false)
, temperature(0.5)
, humidity(0.5)
, enabledwatermodifier(false)
, watermodifier(255,255,255)
{}
, enabledgrassmodifier(false)
, grassmodifier(255,255,255)
, enabledfoliagemodifier(false)
, foliagemodifier(255,255,255)
{
// default water color for most Biomes
this->watermodifier.setRgb(0x3f, 0x76, 0xe4);
}


// Biome based Grass and Foliage color is based on an interpolation in special
Expand Down Expand Up @@ -128,16 +132,13 @@ QColor BiomeInfo::mixColor( QColor colorizer, QColor blockcolor )
QColor BiomeInfo::getBiomeGrassColor( QColor blockcolor, int elevation ) const
{
QColor colorizer;
// swampland
if (this->swamp) {
// perlin noise generator omitted due to performance reasons
// otherwise the random temperature distribution selects
// (below -0.1°C) 4C.76.3C or 6A.70.39 (above -0.1°C)
colorizer = QColor::fromRgb(0x6a,0x70,0x39); // hard wired
}
// mesa / badlands
else if (this->badlands) {
colorizer = QColor::fromRgb(0x90,0x81,0x4d); // hard wired
// swampland:
// perlin noise generator omitted due to performance reasons
// otherwise the random temperature distribution selects
// (below -0.1°C) 4C.76.3C or 6A.70.39 (above -0.1°C)
if (this->enabledgrassmodifier) {
// modifier color given via Biome JSON file
colorizer = grassmodifier;
} else {
// standard way
colorizer = getBiomeColor( this->temperature, this->humidity, elevation, grassCorners );
Expand All @@ -156,16 +157,13 @@ QColor BiomeInfo::getBiomeGrassColor( QColor blockcolor, int elevation ) const
QColor BiomeInfo::getBiomeFoliageColor( QColor blockcolor, int elevation ) const
{
QColor colorizer;
// swampland
if (this->swamp) {
colorizer = QColor::fromRgb(0x6a,0x70,0x39); // hard wired
}
// mesa / badlands
else if (this->badlands) {
colorizer = QColor::fromRgb(0x9e,0x81,0x4d); // hard wired
} else
if (this->enabledfoliagemodifier) {
// modifier color given via Biome JSON file
colorizer = foliagemodifier;
} else {
// standard way
colorizer = getBiomeColor( this->temperature, this->humidity, elevation, foliageCorners );
}

return mixColor( colorizer, blockcolor );
}
Expand All @@ -189,7 +187,6 @@ QColor BiomeInfo::getBiomeWaterColor( QColor watercolor ) const
// --------- --------- --------- ---------

BiomeIdentifier::BiomeIdentifier() {
unknownBiome.watermodifier.setNamedColor("#3f76e4");
unknownBiome.enabledwatermodifier = true;
for (int c = 0; c < 16; c++)
unknownBiome.colors[c] = QColor(0,0,0);
Expand Down Expand Up @@ -278,22 +275,11 @@ void BiomeIdentifier::guessSpecialBiomes(QJsonObject b, BiomeInfo *biome)
} else if (biome->name.contains("river", Qt::CaseInsensitive)) {
biome->river = true;
}
if (b.contains("swamp")) {
biome->swamp = b.value("swamp").toBool();
} else if (biome->name.contains("swamp", Qt::CaseInsensitive)) {
biome->swamp = true;
}
if (b.contains("darkforest")) {
biome->darkforest = b.value("darkforest").toBool();
} else if (biome->name.contains("dark forest", Qt::CaseInsensitive)) {
biome->darkforest = true;
}
if (b.contains("badlands")) {
biome->badlands = b.value("badlands").toBool();
} else if ((biome->name.contains("mesa", Qt::CaseInsensitive)) ||
(biome->name.contains("badlands", Qt::CaseInsensitive))) {
biome->badlands = true;
}
}

// legacy Biome definitions before Cliffs & Caves (up to 1.17)
Expand Down Expand Up @@ -328,6 +314,20 @@ void BiomeIdentifier::parseBiomeDefinitions0000(QJsonArray data, int pack) {
assert(biome->watermodifier.isValid());
}

// get grassmodifier definition
if (b.contains("grassmodifier")) {
biome->enabledgrassmodifier = true;
biome->grassmodifier.setNamedColor(b.value("grassmodifier").toString());
assert(biome->grassmodifier.isValid());
}

// get foliagemodifier definition
if (b.contains("foliagemodifier")) {
biome->enabledfoliagemodifier = true;
biome->foliagemodifier.setNamedColor(b.value("foliagemodifier").toString());
assert(biome->foliagemodifier.isValid());
}

// get color definition
QColor biomecolor;
if (b.contains("color")) {
Expand Down Expand Up @@ -395,11 +395,25 @@ void BiomeIdentifier::parseBiomeDefinitions2800(QJsonArray data18, int pack) {
biome->humidity = b.value("humidity").toDouble();

// get watermodifier definition
biome->enabledwatermodifier = true;
biome->enabledwatermodifier = true; // now always used
if (b.contains("watermodifier")) {
biome->watermodifier.setNamedColor(b.value("watermodifier").toString());
assert(biome->watermodifier.isValid());
} else biome->watermodifier.setNamedColor("#3f76e4");
}

// get grassmodifier definition
if (b.contains("grassmodifier")) {
biome->enabledgrassmodifier = true;
biome->grassmodifier.setNamedColor(b.value("grassmodifier").toString());
assert(biome->grassmodifier.isValid());
}

// get foliagemodifier definition
if (b.contains("foliagemodifier")) {
biome->enabledfoliagemodifier = true;
biome->foliagemodifier.setNamedColor(b.value("foliagemodifier").toString());
assert(biome->foliagemodifier.isValid());
}

// get color definition
QColor biomecolor;
Expand Down
6 changes: 4 additions & 2 deletions identifier/biomeidentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class BiomeInfo {
bool enabled;
bool ocean;
bool river;
bool swamp;
bool darkforest;
bool badlands;
double temperature;
double humidity;
bool enabledwatermodifier;
QColor watermodifier;
bool enabledgrassmodifier;
QColor grassmodifier;
bool enabledfoliagemodifier;
QColor foliagemodifier;
QColor colors[16];

// private methods and members
Expand Down
8 changes: 4 additions & 4 deletions nbt/nbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void NBT::unpack_lz4(const unsigned char * data, unsigned long length) {

const unsigned char * input = data;

while ((input - data) < length) {
while (static_cast<unsigned long>(input - data) < length) {
// decode LZ4-Java block header
for (int m=0; m<LZ4_MAGIC_LENGTH; m++) {
if (input[m] != LZ4_MAGIC[m]) return;
Expand All @@ -109,8 +109,8 @@ void NBT::unpack_lz4(const unsigned char * data, unsigned long length) {
const unsigned char compression_method = token & 0xF0;
// unsigned char compression_level = LZ4_COMPRESSION_LEVEL_BASE + (token & 0x0F);
if ((compression_method != LZ4_COMPRESSION_METHOD_RAW) && (compression_method != LZ4_COMPRESSION_METHOD_LZ4)) return;
const long length_compressed = readIntLE(input + LZ4_MAGIC_LENGTH + 1);
const long length_original = readIntLE(input + LZ4_MAGIC_LENGTH + 5);
const unsigned long length_compressed = readIntLE(input + LZ4_MAGIC_LENGTH + 1);
const unsigned long length_original = readIntLE(input + LZ4_MAGIC_LENGTH + 5);
const XXH32_hash_t checksum = readIntLE(input + LZ4_MAGIC_LENGTH + 9);
input += LZ4_MAGIC_LENGTH + 13;

Expand All @@ -124,7 +124,7 @@ void NBT::unpack_lz4(const unsigned char * data, unsigned long length) {
if ((compression_method == LZ4_COMPRESSION_METHOD_RAW) && (length_original != length_compressed)) return;

// input buffer overflow check
if (((input - data) + length_compressed) > length) return;
if ((static_cast<unsigned long>(input - data) + length_compressed) > length) return;

XXH32_hash_t checksum1;

Expand Down
Loading