CppEdition is a C++ library that mimics the biome and feature generation of Minecraft Java Edition.
This project is a clone of the following C library made by Cubitect : https://github.com/Cubitect/cubiomes. My goal was to convert it to a C++ lib in order to enhance my C++ skills and use it for future applications.
It's intended as a powerful tool to create custom seed-finding apps and large-scale map viewers with minimal memory usage.
#include "generator.h"
#include <cstdio>
int main()
{
// Set up a biome generator that reflects the biome generation of
// Minecraft 1.18.
Generator g;
setupGenerator(&g, MC_1_18, 0);
// Seeds are internally represented as unsigned 64-bit integers.
uint64_t seed;
for (seed = 0; ; seed++)
{
// Apply the seed to the generator for the Overworld dimension.
applySeed(&g, DIM_OVERWORLD, seed);
// To get the biome at a single block position, we can use getBiomeAt().
int scale = 1; // scale=1: block coordinates, scale=4: biome coordinates
int x = 0, y = 63, z = 0;
int biomeID = getBiomeAt(&g, scale, x, y, z);
if (biomeID == mushroom_fields)
{
printf("Seed %" PRId64 " has a Mushroom Fields biome at block position (%d, %d).\n", (int64_t) seed, x, z);
break;
}
}
return 0;
}#include "generator.h"
#include "util.h"
int main()
{
Generator g;
setupGenerator(&g, MC_1_18, LARGE_BIOMES);
uint64_t seed = 123LL;
applySeed(&g, DIM_OVERWORLD, seed);
Range r;
// 1:16, a.k.a. horizontal chunk scaling
r.scale = 16;
// Define the position and size for a horizontal area:
r.x = -60, r.z = -60; // position (x,z)
r.sx = 120, r.sz = 120; // size (width,height)
// Set the vertical range as a plane near sea level at scale 1:4.
r.y = 15, r.sy = 1;
// Allocate the necessary cache for this range.
int *biomeIds = allocCache(&g, r);
// Generate the area inside biomeIds, indexed as:
// biomeIds[i_y*r.sx*r.sz + i_z*r.sx + i_x]
// where (i_x, i_y, i_z) is a position relative to the range cuboid.
genBiomes(&g, biomeIds, r);
// Map the biomes to an image buffer, with 4 pixels per biome cell.
int pix4cell = 4;
int imgWidth = pix4cell*r.sx, imgHeight = pix4cell*r.sz;
unsigned char biomeColors[256][3];
initBiomeColors(biomeColors);
unsigned char *rgb = (unsigned char *) std::malloc(3*imgWidth*imgHeight);
biomesToImage(rgb, biomeColors, biomeIds, r.sx, r.sz, pix4cell, 2);
// Save the RGB buffer to a PPM image file.
savePPM("map.ppm", rgb, imgWidth, imgHeight);
// Clean up.
std::free(biomeIds);
std::free(rgb);
return 0;
}#include "finders.h"
#include <cstdio>
int main()
{
int structType = Outpost;
int mc = MC_1_18;
Generator g;
setupGenerator(&g, mc, 0);
uint64_t lower48;
for (lower48 = 0; ; lower48++)
{
// The structure position depends only on the region coordinates and
// the lower 48-bits of the world seed.
Pos p;
if (!getStructurePos(structType, mc, lower48, 0, 0, &p))
continue;
// Look for a seed with the structure at the origin chunk.
if (p.x >= 16 || p.z >= 16)
continue;
// Look for a full 64-bit seed with viable biomes.
uint64_t upper16;
for (upper16 = 0; upper16 < 0x10000; upper16++)
{
uint64_t seed = lower48 | (upper16 << 48);
applySeed(&g, DIM_OVERWORLD, seed);
if (isViableStructurePos(structType, &g, p.x, p.z, 0))
{
printf("Seed %" PRId64 " has a Pillager Outpost at (%d, %d).\n",
(int64_t) seed, p.x, p.z);
return 0;
}
}
}
}