This commit is contained in:
2026-10-03 16:28:09 -03:00
parent 24fe7cdede
commit 91655c28c5
53 changed files with 1752 additions and 114 deletions
+95 -8
View File
@@ -3,6 +3,7 @@
// into quads in block space (0 to 1) that the chunk mesher and the item renderers draw
import type { BlockRegistry, BlockTextures } from "./everything_registry.ts";
import { tint_without_biome } from "./worldgen/biome_colors.ts";
import { get_state_value } from "./utils.ts";
export type ModelFace = "top" | "bottom" | "north" | "south" | "west" | "east";
export const MODEL_FACES: ModelFace[] = ["top", "bottom", "north", "south", "west", "east"];
@@ -51,6 +52,30 @@ export interface BlockVariant {
// what the player points at and bumps into, as boxes in pixels: [x1, y1, z1, x2, y2, z2]. the model's boxes when
// not set, see common/block_shapes.ts
shape?: number[][];
// what entities bump into, when it isn't the shape. can go up to 24 pixels high, like a fence's
collision_shape?: number[][];
}
// one piece of a block made of pieces, like minecraft's multipart blockstates: a fence is a post, and a bar for each
// side it connects on. every part whose "when" matches is drawn, and adds its shape
export interface BlockPart {
// a condition on the block's states like a variant's key, "north=1". always when not set
when?: string;
model: string;
// the block's textures when not set
textures?: BlockTextures;
y?: number;
shape?: number[][];
collision_shape?: number[][];
}
// a model with everything it's drawn with, a variant or a part
export interface PlacedModel {
model: string;
textures: BlockTextures;
y: number;
shape?: number[][];
collision_shape?: number[][];
}
export const DEFAULT_MODEL = "engine:cube";
@@ -147,14 +172,12 @@ export function texture_variables(reference: string, textures: BlockTextures | u
// the block's model, textures, turn and shape for a value with state bits. each comes from the first variant whose conditions
// match that sets it, so "lit=1" can change the textures and "facing=1" the turn of the same block
export function block_variant(
block: BlockRegistry,
states?: Record<string, number>,
): Required<Omit<BlockVariant, "shape">> & Pick<BlockVariant, "shape"> {
export function block_variant(block: BlockRegistry, states?: Record<string, number>): PlacedModel {
let model: string | undefined;
let textures: BlockTextures | undefined;
let y: number | undefined;
let shape: number[][] | undefined;
let collision_shape: number[][] | undefined;
if (block.variants && states) {
for (const [condition, override] of Object.entries(block.variants)) {
if (!variant_matches(condition, states)) continue;
@@ -162,6 +185,7 @@ export function block_variant(
textures ??= override.textures;
y ??= override.y;
shape ??= override.shape;
collision_shape ??= override.collision_shape;
}
}
return {
@@ -169,9 +193,55 @@ export function block_variant(
textures: textures ?? block.textures,
y: y ?? 0,
shape: shape ?? block.shape,
collision_shape: collision_shape ?? block.collision_shape,
};
}
// what a block is drawn with at a value with state bits: every matching part for a block made of parts, or its variant.
// parts take the variant's textures when they don't set their own
export function block_parts(block: BlockRegistry, states?: Record<string, number>): PlacedModel[] {
const variant = block_variant(block, states);
if (!block.parts) return [variant];
return block.parts
.filter((part) => variant_matches(part.when ?? "", states ?? {}))
.map((part) => ({
model: part.model,
textures: part.textures ?? variant.textures,
y: part.y ?? 0,
shape: part.shape,
collision_shape: part.collision_shape,
}));
}
// whether it's a full cube in every state, so it hides what's behind it from light like minecraft's solid render
// shape. slabs, fences and pots aren't, even with collision
export function is_full_cube(block: BlockRegistry) {
const cube = (model: string | undefined) => (model ?? DEFAULT_MODEL) === DEFAULT_MODEL;
return !block.parts && !block.shape && cube(block.model) &&
Object.values(block.variants ?? {}).every((variant) => !variant.shape && cube(variant.model ?? block.model));
}
// whether how the block looks depends on its states, so it has to be worked out per value and not per block
export function looks_by_state(block: BlockRegistry) {
return block.variants !== undefined || block.parts !== undefined;
}
// the states of a value with state bits, by name
export function states_of(block: BlockRegistry, value: number): Record<string, number> {
const states: Record<string, number> = {};
for (const state of block.states ?? []) states[state.name] = get_state_value(value, block, state.name)!;
return states;
}
// every quad of the block at a value with state bits, its parts' quads together
export function bake_block(block: BlockRegistry, value: number, models: Record<string, ModelJson>): BakedQuad[] {
const states = looks_by_state(block) ? states_of(block, value) : undefined;
return block_parts(block, states).flatMap((part) => {
const model = find_model(part.model, models) ?? BUILTIN_MODELS[DEFAULT_MODEL];
return bake_model(model, part.textures, part.y);
});
}
// "age=7" or "age=7,facing=2", "" matches everything
export function variant_matches(condition: string, states: Record<string, number>) {
if (condition === "") return true;
@@ -181,10 +251,12 @@ export function variant_matches(condition: string, states: Record<string, number
});
}
// for inventories and dropped items: blocks with a full cube draw as a cube, anything else as a flat sprite
// of its first texture, like minecraft's items for plants
// for inventories and dropped items: blocks with a full cube or an item_model draw as that model, anything else as a
// flat sprite of its first texture, like minecraft's items for plants
export function block_item_texture(block: BlockRegistry): string | undefined {
if ((block.model ?? DEFAULT_MODEL) === DEFAULT_MODEL) return undefined;
if (block.item_model !== undefined || (!block.parts && (block.model ?? DEFAULT_MODEL) === DEFAULT_MODEL)) {
return undefined;
}
const textures = block.textures;
if (typeof textures === "string") return textures;
return Object.values(textures)[0] ?? "engine:missing";
@@ -197,12 +269,27 @@ export function cube_face_texture(block: BlockRegistry, face: "top" | "bottom" |
// the color to draw a face of a block's item in, as r g b from 0 to 1. items aren't in a biome, so a biome "tint"
// gets the default grass or foliage color, like minecraft's grass block item
export function cube_face_tint(block: BlockRegistry, face: "top" | "bottom" | "front" | "side"): number[] {
const variables = texture_variables(`#${face}`, block.textures, BUILTIN_MODELS[DEFAULT_MODEL]);
return item_tint(block, texture_variables(`#${face}`, block.textures, BUILTIN_MODELS[DEFAULT_MODEL]));
}
// the color to draw a part of a block's item in that got its texture through these variables, see cube_face_tint
export function item_tint(block: BlockRegistry, variables: string[]): number[] {
if (!is_tinted(block, variables)) return [1, 1, 1];
const color = tint_without_biome(block.tint!.color);
return [color >> 16, (color >> 8) & 0xff, color & 0xff].map((c) => c / 255);
}
// the quads of a block's item_model with the block's textures, for its item in inventories, hands and on the ground.
// undefined for blocks without one
export function block_item_quads(block: BlockRegistry, models: Record<string, ModelJson>): BakedQuad[] | undefined {
if (block.item_model === undefined) return undefined;
const model = find_model(block.item_model, models);
return model ? bake_model(model, block.textures) : undefined;
}
// how much darker each side of an item's model is drawn, like the mesher's: top, bottom, south, north, west, east
export const ITEM_FACE_SHADE = [1.0, 0.5, 0.8, 0.8, 0.6, 0.6];
// whether a face that got its texture through these variables is drawn in the block's tint
export function is_tinted(block: BlockRegistry, variables: string[]) {
if (!block.tint) return false;
+74 -24
View File
@@ -1,9 +1,16 @@
// a block's shape, like minecraft's VoxelShape: the boxes it's made of. it's what the player points at and what the
// cracks are drawn on when it breaks (minecraft's getShape), and what entities bump into when it has collision
// (getCollisionShape). blocks get theirs from the boxes of their model, or set "shape" like minecraft's Block.box
import { block_variant, element_rotation, find_model, type ModelJson } from "./block_models.ts";
import {
block_parts,
element_rotation,
find_model,
looks_by_state,
type ModelJson,
states_of,
} from "./block_models.ts";
import { type BlockRegistry, EverythingRegistry } from "./everything_registry.ts";
import { get_state_value } from "./utils.ts";
import { STATE_SHIFT } from "./constants.ts";
// min x y z then max x y z, in block space (0 to 1)
export type Box = readonly [number, number, number, number, number, number];
@@ -41,43 +48,70 @@ export function model_shape(model: ModelJson, y_rotation = 0): Shape {
return boxes.map((box) => turn(box, y_rotation));
}
// boxes in pixels, like a block's "shape" ([x1, y1, z1, x2, y2, z2], 0 to 16), turned like the model is
export function pixel_shape(boxes: number[][], y_rotation = 0): Shape {
return boxes.map((box) => turn(clamp(box.map((v) => v / 16)), y_rotation));
// boxes in pixels, like a block's "shape" ([x1, y1, z1, x2, y2, z2], 0 to 16), turned like the model is. a collision
// shape can go up to 24 pixels high, like minecraft's fences, so nothing jumps over them
export function pixel_shape(boxes: number[][], y_rotation = 0, top = 1): Shape {
return boxes.map((box) => turn(clamp(box.map((v) => v / 16), top), y_rotation));
}
// what the block is at a value with state bits: its "shape" when it (or a variant) sets one, otherwise its model's
// how high a collision shape can go, in blocks
export const COLLISION_TOP = 1.5;
// what the block is at a value with state bits: each part's (or the variant's) "shape" when it sets one, otherwise
// its model's boxes
export function block_shape(block: BlockRegistry, states?: Record<string, number>): Shape {
const variant = block_variant(block, states);
if (variant.shape) return pixel_shape(variant.shape, variant.y);
const model = find_model(variant.model, Object.fromEntries(EverythingRegistry.entries<ModelJson>("models")));
return model ? model_shape(model, variant.y) : FULL_SHAPE;
const models = Object.fromEntries(EverythingRegistry.entries<ModelJson>("models"));
return block_parts(block, states).flatMap((part) => {
if (part.shape) return pixel_shape(part.shape, part.y);
const model = find_model(part.model, models);
return model ? model_shape(model, part.y) : FULL_SHAPE;
});
}
// what entities bump into, like getCollisionShape: each part's "collision_shape" when it sets one, otherwise its shape
export function block_collision_shape(block: BlockRegistry, states?: Record<string, number>): Shape {
if (!block.has_collision) return EMPTY_SHAPE;
const parts = block_parts(block, states);
if (parts.every((part) => !part.collision_shape)) return block_shape(block, states);
const models = Object.fromEntries(EverythingRegistry.entries<ModelJson>("models"));
return parts.flatMap((part) => {
if (part.collision_shape) return pixel_shape(part.collision_shape, part.y, COLLISION_TOP);
if (part.shape) return pixel_shape(part.shape, part.y);
const model = find_model(part.model, models);
return model ? model_shape(model, part.y) : FULL_SHAPE;
});
}
// shapes by block, then by value with state bits, worked out the first time they're asked for
const cache = new WeakMap<BlockRegistry, Map<number, Shape>>();
const shapes_cache = new WeakMap<BlockRegistry, Map<number, Shape>>();
const collision_cache = new WeakMap<BlockRegistry, Map<number, Shape>>();
// the block's shape at a value from the world, see block_shape
export function shape_at(block: BlockRegistry, value: number): Shape {
function cached(
cache: WeakMap<BlockRegistry, Map<number, Shape>>,
block: BlockRegistry,
value: number,
make: (block: BlockRegistry, states?: Record<string, number>) => Shape,
): Shape {
let shapes = cache.get(block);
if (!shapes) cache.set(block, shapes = new Map());
const key = block.variants ? value : 0;
const by_state = looks_by_state(block);
const key = by_state ? value >>> STATE_SHIFT : 0;
let shape = shapes.get(key);
if (!shape) {
let states: Record<string, number> | undefined;
if (block.variants && block.states) {
states = {};
for (const state of block.states) states[state.name] = get_state_value(value, block, state.name)!;
}
shape = block_shape(block, states);
shape = make(block, by_state ? states_of(block, value) : undefined);
shapes.set(key, shape);
}
return shape;
}
// what entities bump into, like getCollisionShape: the shape, or nothing for blocks with "collision": false
// the block's shape at a value from the world, see block_shape
export function shape_at(block: BlockRegistry, value: number): Shape {
return cached(shapes_cache, block, value, block_shape);
}
// what entities bump into at a value from the world, see block_collision_shape. nothing for "collision": false
export function collision_shape_at(block: BlockRegistry, value: number): Shape {
return block.has_collision ? shape_at(block, value) : EMPTY_SHAPE;
return cached(collision_cache, block, value, block_collision_shape);
}
// how far along the ray (origin plus direction times distance) it first goes into one of the boxes of a block at
@@ -119,8 +153,24 @@ export function clip_shape(
return closest;
}
function clamp(box: number[]): Box {
const c = box.map((v) => Math.min(Math.max(v, 0), 1));
// whether the shape's boxes cover the whole of one of the block's sides, like minecraft's Block.isFaceFull. checked
// pixel by pixel, which is as fine as shapes in pixels get
export function covers_face(shape: Shape, face: "west" | "east" | "bottom" | "top" | "north" | "south"): boolean {
const axis = face === "west" || face === "east" ? 0 : face === "bottom" || face === "top" ? 1 : 2;
const high = face === "east" || face === "top" || face === "south";
const [a, b] = [(axis + 1) % 3, (axis + 2) % 3];
const touching = shape.filter((box) => high ? box[axis + 3] >= 1 - FLAT && box[axis] < 1 : box[axis] <= FLAT);
for (let i = 0; i < 16; i++) {
for (let j = 0; j < 16; j++) {
const [u, v] = [(i + 0.5) / 16, (j + 0.5) / 16];
if (!touching.some((box) => box[a] <= u && u <= box[a + 3] && box[b] <= v && v <= box[b + 3])) return false;
}
}
return true;
}
function clamp(box: number[], top = 1): Box {
const c = box.map((v, i) => Math.min(Math.max(v, 0), i % 3 === 1 ? top : 1));
return [c[0], c[1], c[2], c[3], c[4], c[5]];
}
+7 -2
View File
@@ -1,6 +1,6 @@
import type { TintColor } from "./worldgen/biome_colors.ts";
import type { ItemStack } from "./inventory.ts";
import type { BlockVariant } from "./block_models.ts";
import type { BlockPart, BlockVariant } from "./block_models.ts";
export class EverythingRegistry {
static #key_to_id = new Map<string, Map<string, number>>();
@@ -119,8 +119,13 @@ export interface BlockRegistry {
alpha?: number;
has_collision: boolean;
// boxes in pixels, see BlockVariant.shape
// boxes in pixels, see BlockVariant.shape and collision_shape
shape?: number[][];
collision_shape?: number[][];
// made of pieces instead of one model, see BlockPart
parts?: BlockPart[];
// the model its item is drawn with, with the block's textures, like minecraft's fence_inventory
item_model?: string;
toughness?: number;
requires_tool?: boolean;
tool_to_break?: string;
+6
View File
@@ -49,6 +49,9 @@ export interface BlockComponent<P = any> {
on_second?(block: BlockRef, params: P, dt: number): void;
// every morning at 06:00, for every block with data in the world, near a player or not. day is ServerWorld.day
on_new_day?(block: BlockRef, params: P, day: number): void;
// a block next to it (on any of the 6 sides) was placed, broken or changed its states, like minecraft's
// updateShape. neighbor is where, and what's there now
on_neighbor_change?(block: BlockRef, params: P, neighbor: Position & { readonly id: Id }): void;
}
// deno-lint-ignore no-explicit-any
@@ -199,6 +202,9 @@ export interface ServerWorld {
break_block(x: number, y: number, z: number): boolean;
get_state(x: number, y: number, z: number, name: string): number | undefined;
set_state(x: number, y: number, z: number, name: string, value: number): boolean;
// whether the block's side is a full square things can attach to, like minecraft's isFaceSturdy: its collision
// shape covers the whole face. false for air, plants, water and the sides of a slab
is_face_sturdy(x: number, y: number, z: number, face: Face): boolean;
get_block_data<T>(x: number, y: number, z: number): T | undefined;
// the item a block with item_display shows on top of it, like a block entity renderer: saved with the block's data
// and synced to players. undefined shows nothing. it goes away with the block, without dropping
+59 -6
View File
@@ -11,7 +11,7 @@ import {
type ToolProperties,
type WornProperties,
} from "./everything_registry.ts";
import { type BlockVariant, MODEL_FACES, type ModelFace } from "./block_models.ts";
import { type BlockPart, type BlockVariant, MODEL_FACES, type ModelFace } from "./block_models.ts";
import { expand_items, list_matches } from "./tags.ts";
export const FORMAT_VERSION = 1;
@@ -56,6 +56,9 @@ export interface BlockJson {
alpha?: number;
collision?: boolean;
shape?: number[][];
collision_shape?: number[][];
parts?: BlockPart[];
item_model?: string;
mining?: { toughness: number; tool?: string; requires_tool?: boolean; tier?: number };
drops?: string;
item?: boolean;
@@ -269,6 +272,9 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
if (block.alpha !== undefined) json.alpha = block.alpha;
if (!block.has_collision) json.collision = false;
if (block.shape !== undefined) json.shape = block.shape;
if (block.collision_shape !== undefined) json.collision_shape = block.collision_shape;
if (block.parts !== undefined) json.parts = block.parts;
if (block.item_model !== undefined) json.item_model = block.item_model;
if (block.toughness !== undefined) {
json.mining = { toughness: block.toughness };
if (block.tool_to_break !== undefined) json.mining.tool = block.tool_to_break;
@@ -297,6 +303,9 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
if (json.model !== undefined) block.model = json.model;
if (json.variants !== undefined) block.variants = json.variants;
if (json.shape !== undefined) block.shape = json.shape;
if (json.collision_shape !== undefined) block.collision_shape = json.collision_shape;
if (json.parts !== undefined) block.parts = json.parts;
if (json.item_model !== undefined) block.item_model = json.item_model;
const render_layer = json.render_layer ?? (json.transparent ? "translucent" : undefined);
if (render_layer && render_layer !== "solid") block.render_layer = render_layer;
if (json.cull_same !== undefined) block.cull_same = json.cull_same;
@@ -452,7 +461,7 @@ export function validate_block(json: unknown): Problems {
if (!is_object(json)) return ["block must be an object"];
const problems = validate_id(json.id, "id");
if (json.model !== undefined) problems.push(...validate_id(json.model, "model"));
const is_cube = json.model === undefined || json.model === "engine:cube";
const is_cube = json.parts === undefined && (json.model === undefined || json.model === "engine:cube");
const textures = json.textures;
if (is_cube) {
const texture_ok = typeof textures === "string" ||
@@ -488,10 +497,53 @@ export function validate_block(json: unknown): Problems {
problems.push(`${where}.y must be 0, 90, 180 or 270`);
}
if (variant.shape !== undefined) problems.push(...validate_shape(variant.shape, `${where}.shape`));
if (variant.collision_shape !== undefined) {
problems.push(...validate_shape(variant.collision_shape, `${where}.collision_shape`, 24));
}
}
}
}
if (json.shape !== undefined) problems.push(...validate_shape(json.shape, "shape"));
if (json.collision_shape !== undefined) {
problems.push(...validate_shape(json.collision_shape, "collision_shape", 24));
}
if (json.item_model !== undefined) problems.push(...validate_id(json.item_model, "item_model"));
if (json.parts !== undefined) {
if (!Array.isArray(json.parts) || json.parts.length === 0) {
problems.push("parts must be a list of { when, model, y }");
} else {
const names = new Set(Array.isArray(json.states) ? json.states.map((s) => is_object(s) ? s.name : "") : []);
json.parts.forEach((part, i) => {
const where = `parts[${i}]`;
if (!is_object(part)) {
problems.push(`${where} must be { when, model, y }`);
return;
}
problems.push(...validate_id(part.model, `${where}.model`));
if (part.when !== undefined) {
const parts = typeof part.when === "string" ? part.when.split(",") : [undefined];
for (const condition of part.when === "" ? [] : parts) {
const [name, value] = (condition ?? "").split("=").map((p) => p.trim());
if (!names.has(name) || !/^\d+$/.test(value ?? "")) {
problems.push(
`${where}.when: "${condition}" must be a state of this block and a number, like north=1`,
);
}
}
}
if (part.textures !== undefined) {
problems.push(...validate_textures(part.textures, `${where}.textures`));
}
if (part.y !== undefined && ![0, 90, 180, 270].includes(part.y as number)) {
problems.push(`${where}.y must be 0, 90, 180 or 270`);
}
if (part.shape !== undefined) problems.push(...validate_shape(part.shape, `${where}.shape`));
if (part.collision_shape !== undefined) {
problems.push(...validate_shape(part.collision_shape, `${where}.collision_shape`, 24));
}
});
}
}
if (json.render_layer !== undefined && !RENDER_LAYERS.includes(json.render_layer as RenderLayer)) {
problems.push(`render_layer must be one of ${RENDER_LAYERS.join(", ")}`);
}
@@ -554,14 +606,15 @@ export function validate_block(json: unknown): Problems {
return problems;
}
// boxes in pixels: [[x1, y1, z1, x2, y2, z2], ...], each corner from 0 to 16 and the second past the first
function validate_shape(shape: unknown, where: string): Problems {
// boxes in pixels: [[x1, y1, z1, x2, y2, z2], ...], each corner from 0 to 16 (y to top) and the second past the first
function validate_shape(shape: unknown, where: string, top = 16): Problems {
const is_box = (box: unknown) =>
Array.isArray(box) && box.length === 6 &&
box.every((v) => typeof v === "number" && v >= 0 && v <= 16) &&
box.every((v, i) => typeof v === "number" && v >= 0 && v <= (i % 3 === 1 ? top : 16)) &&
box[0] <= box[3] && box[1] <= box[4] && box[2] <= box[5];
if (!Array.isArray(shape) || shape.length === 0 || !shape.every(is_box)) {
return [`${where} must be a list of boxes in pixels, like [[0, 0, 0, 16, 8, 16]]`];
const most = top === 16 ? "" : `, up to ${top} high`;
return [`${where} must be a list of boxes in pixels${most}, like [[0, 0, 0, 16, 8, 16]]`];
}
return [];
}
+13 -7
View File
@@ -1,6 +1,6 @@
// collision against blocks, shared by the client's entities and the server's, so both move things the same way
import { TICK_DELTA } from "./constants.ts";
import { EMPTY_SHAPE, FULL_SHAPE, type Shape } from "./block_shapes.ts";
import { COLLISION_TOP, EMPTY_SHAPE, FULL_SHAPE, type Shape } from "./block_shapes.ts";
// how far inside a block face still counts as touching it, so boxes resting exactly on a face don't snag
const EPSILON = 1e-7;
@@ -15,6 +15,12 @@ function shape_of(collision: boolean | Shape): Shape {
return collision === true ? FULL_SHAPE : collision === false ? EMPTY_SHAPE : collision;
}
// the lowest block whose shape can reach up to a box starting at min along an axis: on y that's one more below,
// since a collision shape can be taller than its block, like a fence's
function lowest(axis: number, min: number) {
return Math.floor(min + EPSILON) - (axis === 1 ? Math.ceil(COLLISION_TOP) - 1 : 0);
}
// something with a box that moves. position is the middle of its feet, velocity is in blocks per second
export interface Body {
x: number;
@@ -131,13 +137,13 @@ function clip(
}
const [a, b] = OTHER_AXES[axis];
const from = Math.floor(Math.min(min[axis], min[axis] + distance));
const from = lowest(axis, Math.min(min[axis], min[axis] + distance) - EPSILON);
const to = Math.floor(Math.max(max[axis], max[axis] + distance));
const position = [0, 0, 0];
for (let i = from; i <= to; i++) {
for (let j = Math.floor(min[a] + EPSILON); j <= Math.floor(max[a] - EPSILON); j++) {
for (let k = Math.floor(min[b] + EPSILON); k <= Math.floor(max[b] - EPSILON); k++) {
for (let j = lowest(a, min[a]); j <= Math.floor(max[a] - EPSILON); j++) {
for (let k = lowest(b, min[b]); k <= Math.floor(max[b] - EPSILON); k++) {
position[axis] = i;
position[a] = j;
position[b] = k;
@@ -204,9 +210,9 @@ export function box_is_free(
}
function overlaps_solid(min: number[], max: number[], is_solid: BlockCollision) {
for (let x = Math.floor(min[0] + EPSILON); x <= Math.floor(max[0] - EPSILON); x++) {
for (let y = Math.floor(min[1] + EPSILON); y <= Math.floor(max[1] - EPSILON); y++) {
for (let z = Math.floor(min[2] + EPSILON); z <= Math.floor(max[2] - EPSILON); z++) {
for (let x = lowest(0, min[0]); x <= Math.floor(max[0] - EPSILON); x++) {
for (let y = lowest(1, min[1]); y <= Math.floor(max[1] - EPSILON); y++) {
for (let z = lowest(2, min[2]); z <= Math.floor(max[2] - EPSILON); z++) {
for (const box of shape_of(is_solid(x, y, z))) {
if (
x + box[0] < max[0] - EPSILON && x + box[3] > min[0] + EPSILON &&