4jcraft/targets/minecraft/world/level/newbiome/layer/BiomeOverrideLayer.cpp
Tropical e4883d87fc
Some checks are pending
Build (Linux, x86-64) / build-linux-amalgamate (push) Waiting to run
Build (Linux, x86-64) / build-linux-full (push) Waiting to run
Format Check / clang-format (push) Waiting to run
Release Nightly (Linux, x86-64) / release-linux (push) Waiting to run
replace __debugbreak with assert, fix full build
2026-04-07 18:58:49 -05:00

57 lines
1.9 KiB
C++

#include "minecraft/util/Log.h"
#include "BiomeOverrideLayer.h"
#include <string.h>
#include "minecraft/IGameServices.h"
#include "platform/fs/fs.h"
#include "minecraft/world/level/newbiome/layer/Layer.h"
#if defined(__linux__)
#include "app/linux/Stubs/winapi_stubs.h"
#endif
#include "minecraft/world/level/biome/Biome.h"
BiomeOverrideLayer::BiomeOverrideLayer(int seedMixup) : Layer(seedMixup) {
m_biomeOverride = std::vector<uint8_t>(width * height);
{
const char* path = "GameRules/biomemap.bin";
auto result = PlatformFilesystem.readFile(
path, m_biomeOverride.data(), m_biomeOverride.size());
if (result.status == IPlatformFilesystem::ReadStatus::NotFound) {
Log::info("Biome override not found, using plains as default\n");
memset(m_biomeOverride.data(), Biome::plains->id,
m_biomeOverride.size());
} else if (result.status == IPlatformFilesystem::ReadStatus::TooLarge) {
Log::info("Biomemap binary is too large!!\n");
assert(0);
} else if (result.status != IPlatformFilesystem::ReadStatus::Ok) {
gameServices().fatalLoadError();
}
}
}
std::vector<int> BiomeOverrideLayer::getArea(int xo, int yo, int w, int h) {
std::vector<int> result(w * h);
int xOrigin = xo + width / 2;
int yOrigin = yo + height / 2;
if (xOrigin < 0) xOrigin = 0;
if (xOrigin >= width) xOrigin = width - 1;
if (yOrigin < 0) yOrigin = 0;
if (yOrigin >= height) yOrigin = height - 1;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int curX = xOrigin + x;
int curY = yOrigin + y;
if (curX >= width) curX = width - 1;
if (curY >= height) curY = height - 1;
int index = curX + curY * width;
unsigned char headerValue = m_biomeOverride[index];
result[x + y * w] = headerValue;
}
}
return result;
}