World gen stuff
This commit is contained in:
@@ -17,6 +17,7 @@ import { load_and_check } from "./check_mods.ts";
|
||||
const seed = Deno.args[0] ?? "preview";
|
||||
const out = Deno.args[1] ?? ".";
|
||||
const [center_x, center_z] = [Number(Deno.args[2] ?? 0), Number(Deno.args[3] ?? 0)];
|
||||
Deno.mkdirSync(out, { recursive: true });
|
||||
|
||||
// the base game, from mods/bworld: its data registered like the game does, and its worldgen script for trees and the
|
||||
// rest of its features
|
||||
@@ -89,7 +90,8 @@ const COLORS: Record<number, [number, number, number]> = {
|
||||
12: [100, 70, 40],
|
||||
13: [45, 110, 35],
|
||||
};
|
||||
// every other block after them, so features can place them. other woods look like oak, the rest magenta
|
||||
// every other block after them, so features can place them. other woods look like oak, the rest, like rocks, get a
|
||||
// muted color of their own from their id
|
||||
for (const block of EverythingRegistry.get_registry<BlockRegistry>("blocks").filter((b) => b)) {
|
||||
if (block.id in block_ids) continue;
|
||||
const nid = Object.keys(block_ids).length + 1;
|
||||
@@ -97,6 +99,21 @@ for (const block of EverythingRegistry.get_registry<BlockRegistry>("blocks").fil
|
||||
if (block.id.endsWith("_log")) COLORS[nid] = COLORS[block_ids["bworld:oak_log"]];
|
||||
else if (block.id.endsWith("_leaves")) COLORS[nid] = COLORS[block_ids["bworld:oak_leaves"]];
|
||||
else if (block.id === "bworld:cactus") COLORS[nid] = [70, 140, 50];
|
||||
else COLORS[nid] = color_of(block.id);
|
||||
}
|
||||
const names: string[] = ["air"];
|
||||
for (const [id, nid] of Object.entries(block_ids)) names[nid] = id;
|
||||
|
||||
function color_of(id: string): [number, number, number] {
|
||||
let hash = 2166136261;
|
||||
for (let i = 0; i < id.length; i++) hash = Math.imul(hash ^ id.charCodeAt(i), 16777619);
|
||||
const hue = (hash >>> 0) % 360 / 60;
|
||||
const lightness = 90 + (hash >>> 9) % 90;
|
||||
const channel = (offset: number) => {
|
||||
const k = (offset + hue) % 6;
|
||||
return Math.round(lightness * (1 - 0.45 * Math.max(0, Math.min(k, 4 - k, 1))));
|
||||
};
|
||||
return [channel(5), channel(3), channel(1)];
|
||||
}
|
||||
|
||||
const BIOME_COLORS: Record<string, [number, number, number]> = {
|
||||
@@ -216,10 +233,10 @@ const shade = (color: [number, number, number], factor: number): [number, number
|
||||
const chunks = 48;
|
||||
const size = chunks * CHUNK_SIZE;
|
||||
const top = new Int32Array(size * size);
|
||||
const top_block = new Uint8Array(size * size);
|
||||
const top_block = new Uint32Array(size * size);
|
||||
const water_depth = new Int32Array(size * size);
|
||||
// rows from the top of the world down
|
||||
const section = new Uint8Array(size * shape.height);
|
||||
const section = new Uint32Array(size * shape.height);
|
||||
const section_z = size / 2;
|
||||
const origin = -size / 2;
|
||||
const counts = new Map<number, number>();
|
||||
@@ -292,6 +309,6 @@ const shade = (color: [number, number, number], factor: number): [number, number
|
||||
console.log(`underground air: ${(underground_air / (solid + underground_air) * 100).toFixed(1)}% of the ground`);
|
||||
const total = [...counts.values()].reduce((a, b) => a + b, 0);
|
||||
for (const [nid, count] of [...counts].sort((a, b) => b[1] - a[1])) {
|
||||
console.log(` ${nid === 0 ? "air" : NAMES[nid - 1]}: ${(count / total * 100).toFixed(2)}%`);
|
||||
console.log(` ${names[nid]}: ${(count / total * 100).toFixed(2)}%`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user