Add thin/thick stone walls with diagonal corner autotile.
Neighbor-connect now samples diagonals so L-strips and solid 2×2 fills pick different sprites; thick keeps the existing block id, thin is a new placeable.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -1,39 +1,71 @@
/**
* Generate 16×16 gray cobblestone stone-wall PNGs for neighbor-connect masks 0–15.
* Generate thin + thick stone-wall PNGs for blob neighbor-connect masks
* (cardinals + diagonal corners — 47 valid states).
*
* Truncated-pyramid / frustum look when alone or at free ends. Connected runs use a
* constant cross-section extruded to the tile edge (strip-union like tables/fences)
* so N/S and E/W seams match.
* Shape references (silhouette / shading only, not final texture):
* client/assets/blocks/stone-wall/example-stone-thin.png
* client/assets/blocks/stone-wall/example-stone-thick.png
*
* Corner bits: when both adjacent cardinals join but the diagonal does not,
* paint an L-strip (concave). When the diagonal also joins, fill the quadrant
* so a solid 2×2 reads as one block.
*
* node client/scripts/generate-stone-wall-sprites.mjs
*/
import { mkdirSync, writeFileSync } from "node:fs";
import { mkdirSync, writeFileSync, readdirSync, unlinkSync } from "node:fs";
import { deflateSync } from "node:zlib";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import { NeighborBit } from "../../shared/world/neighborConnect.js";
import {
NeighborBit,
listValidNeighborConnectCornerMasks
} from "../../shared/world/neighborConnect.js";
const SIZE = 16;
const OUT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks/stone-wall");
const TOP = [168, 168, 172, 255];
const TOP_HI = [198, 198, 202, 255];
const TOP_LO = [140, 140, 144, 255];
const FACE = [112, 112, 116, 255];
const FACE_HI = [132, 132, 136, 255];
const FACE_LO = [88, 88, 92, 255];
const EDGE = [70, 70, 74, 255];
const MORTAR = [78, 78, 82, 255];
/** Constant core used for connected runs (must meet neighbour tile edges cleanly). */
const CORE_X0 = 5;
const CORE_X1 = 10;
const TOP_Y0 = 3;
const TOP_Y1 = 6;
const FACE_Y1 = 12;
/** Alone / free-end base is wider than the top (frustum). */
const BASE_X0 = 3;
const BASE_X1 = 12;
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");
const OUT_THICK = join(ROOT, "stone-wall");
const OUT_THIN = join(ROOT, "stone-wall-thin");
const OUTLINE = [0x40, 0x40, 0x40, 255];
const TOP_HI = [0xaf, 0xaf, 0xaf, 255];
const TOP = [0x80, 0x80, 0x80, 255];
const TOP_LO = [0x73, 0x73, 0x73, 255];
const FACE_L = [0x95, 0x95, 0x95, 255];
const FACE = [0x73, 0x73, 0x73, 255];
const FACE_R = [0x6c, 0x6c, 0x6c, 255];
const FACE_FRONT = [0x54, 0x54, 0x54, 255];
const HI_L = [0xb6, 0xb6, 0xb6, 255];
const HI_R = [0x80, 0x80, 0x80, 255];
const MORTAR = [0x58, 0x58, 0x5c, 255];
/**
* Thin: compact top core (table-style strip-union) so L keeps a concave cutout;
* frustum face hangs below on free south edges. Alone matches example-stone-thin.
*/
const THIN = Object.freeze({
topY0: 2,
coreY0: 3,
coreY1: 7,
faceY1: 12,
coreX0: 5,
coreX1: 10,
baseX0: 3,
baseX1: 12,
fullTile: false
});
/** Thick: full-tile footprint; bevels react to free edges / missing diagonals. */
const THICK = Object.freeze({
topY0: 1,
coreY0: 1,
coreY1: 8,
faceY1: 14,
coreX0: 3,
coreX1: 12,
baseX0: 0,
baseX1: 15,
fullTile: true
});
function crcTable ()
{
@@ -109,148 +141,260 @@ function setPx (rgba, x, y, color)
rgba[i + 3] = color[3];
}
/** Frustum half-width in X at row y (alone / free-end silhouette). */
function frustumX0X1 (y)
function hash2 (x, y)
{
if (y <= TOP_Y1)
{ return { x0: CORE_X0, x1: CORE_X1 }; }
if (y >= FACE_Y1)
{ return { x0: BASE_X0, x1: BASE_X1 }; }
const t = (y - TOP_Y1) / (FACE_Y1 - TOP_Y1);
const x0 = Math.round(CORE_X0 + (BASE_X0 - CORE_X0) * t);
const x1 = Math.round(CORE_X1 + (BASE_X1 - CORE_X1) * t);
return { x0, x1 };
let n = (x * 374761393 + y * 668265263) | 0;
n = (n ^ (n >>> 13)) * 1274126177;
return (n ^ (n >>> 16)) >>> 0;
}
/**
* Strip-union with constant core thickness on connected sides.
* Free ends keep the frustum taper so alone / stubs still read as 3D.
*/
function inWall (x, y, connectN, connectE, connectS, connectW)
function cobbleShade (base, x, y)
{
const alone = !connectN && !connectE && !connectS && !connectW;
const wantH = alone || connectE || connectW;
const wantV = alone || connectN || connectS;
if (wantH)
const h = hash2(x, y);
const speck = h & 7;
if (speck === 0)
{ return MORTAR; }
if (speck === 1)
{
const y0 = connectN ? 0 : TOP_Y0;
const y1 = connectS ? SIZE - 1 : FACE_Y1;
if (y >= y0 && y <= y1)
{
const { x0: fx0, x1: fx1 } = frustumX0X1(Math.min(FACE_Y1, Math.max(TOP_Y0, y)));
// Connected cardinals run to the tile edge (constant seam).
// Free ends keep the frustum taper.
const x0 = connectW ? 0 : fx0;
const x1 = connectE ? SIZE - 1 : fx1;
if (x >= x0 && x <= x1)
{ return true; }
}
return [
Math.min(255, base[0] + 18),
Math.min(255, base[1] + 18),
Math.min(255, base[2] + 18),
255
];
}
if (speck === 2)
{
return [
Math.max(0, base[0] - 14),
Math.max(0, base[1] - 14),
Math.max(0, base[2] - 14),
255
];
}
return base;
}
function decodeMask (mask)
{
return {
n: (mask & NeighborBit.n) !== 0,
e: (mask & NeighborBit.e) !== 0,
s: (mask & NeighborBit.s) !== 0,
w: (mask & NeighborBit.w) !== 0,
ne: (mask & NeighborBit.ne) !== 0,
se: (mask & NeighborBit.se) !== 0,
sw: (mask & NeighborBit.sw) !== 0,
nw: (mask & NeighborBit.nw) !== 0
};
}
function frustumX0X1 (y, profile)
{
if (y <= 2)
{ return { x0: 6, x1: 9 }; }
if (y <= 4)
{ return { x0: 5, x1: 10 }; }
if (y <= 6)
{ return { x0: 4, x1: 11 }; }
return { x0: profile.baseX0, x1: profile.baseX1 };
}
if (wantV)
/** Top-plane strip-union + diagonal fills (no front skirt). */
function inTopPlane (x, y, c, profile)
{
const { coreX0, coreX1, coreY0, coreY1 } = profile;
const inCoreX = x >= coreX0 && x <= coreX1;
const inCoreY = y >= coreY0 && y <= coreY1;
const wantH = c.e || c.w;
const wantV = c.n || c.s;
if (inCoreX && inCoreY)
{ return true; }
if (wantH && inCoreY)
{
const x0 = CORE_X0;
const x1 = CORE_X1;
const x0 = c.w ? 0 : coreX0;
const x1 = c.e ? SIZE - 1 : coreX1;
if (x >= x0 && x <= x1)
{
const y0 = connectN ? 0 : TOP_Y0;
const y1 = connectS ? SIZE - 1 : FACE_Y1;
if (y >= y0 && y <= y1)
{ return true; }
}
{ return true; }
}
if (wantV && inCoreX)
{
const y0 = c.n ? 0 : coreY0;
const y1 = c.s ? SIZE - 1 : coreY1;
if (y >= y0 && y <= y1)
{ return true; }
}
// Close concave L/T cutouts when the diagonal neighbour is present.
if (c.se && c.s && c.e && x > coreX1 && y > coreY1)
{ return true; }
if (c.sw && c.s && c.w && x < coreX0 && y > coreY1)
{ return true; }
if (c.ne && c.n && c.e && x > coreX1 && y < coreY0)
{ return true; }
if (c.nw && c.n && c.w && x < coreX0 && y < coreY0)
{ return true; }
return false;
}
function hash2 (x, y)
function inWall (x, y, c, profile)
{
let n = (x * 374761393 + y * 668265263) | 0;
n = (n ^ (n >>> 13)) * 1274126177;
return (n ^ (n >>> 16)) >>> 0;
}
if (profile.fullTile)
{ return true; }
function cobbleShade (base, x, y)
{
const h = hash2(x, y);
const speck = (h & 7);
if (speck === 0)
{ return MORTAR; }
if (speck === 1 || speck === 2)
{ return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_HI : FACE_HI; }
if (speck === 3)
{ return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_LO : FACE_LO; }
return base;
const alone = !c.n && !c.e && !c.s && !c.w;
if (alone)
{
if (y < profile.topY0 || y > profile.faceY1)
{ return false; }
const { x0, x1 } = frustumX0X1(y, profile);
return x >= x0 && x <= x1;
}
if (inTopPlane(x, y, c, profile))
{ return true; }
// Front-face skirt under top-plane pixels that do not continue south.
if (y > profile.coreY1 && y <= profile.faceY1)
{
if (!inTopPlane(x, profile.coreY1, c, profile))
{ return false; }
// Vertical run into a southern neighbour: no skirt in the core column.
if (c.s && x >= profile.coreX0 && x <= profile.coreX1)
{ return false; }
// Diagonal-filled SE mass continues as solid top — skirt only at very bottom
// of columns that are the south perimeter (no further south neighbour top).
if (c.s && ((c.se && c.e && x > profile.coreX1) || (c.sw && c.w && x < profile.coreX0)))
{ return false; }
const { x0, x1 } = frustumX0X1(y, profile);
const skirtX0 = c.w ? 0 : x0;
const skirtX1 = c.e ? SIZE - 1 : x1;
if (x < skirtX0 || x > skirtX1)
{ return false; }
return inTopPlane(x, profile.coreY1, c, profile);
}
return false;
}
function isTopRow (y, connectN)
function shadeAt (x, y, c, profile, occ)
{
if (connectN)
{ return y <= TOP_Y1; }
return y >= TOP_Y0 && y <= TOP_Y1;
const n = occ(x, y - 1);
const e = occ(x + 1, y);
const s = occ(x, y + 1);
const w = occ(x - 1, y);
const openCount = (!n ? 1 : 0) + (!s ? 1 : 0) + (!e ? 1 : 0) + (!w ? 1 : 0);
if (openCount > 0)
{
const edgeHeavy = (!n && y <= (profile.fullTile ? 0 : profile.topY0))
|| (!s && y >= (profile.fullTile ? SIZE - 1 : profile.faceY1))
|| (!w && x <= (profile.fullTile ? 0 : profile.baseX0))
|| (!e && x >= (profile.fullTile ? SIZE - 1 : profile.baseX1));
if (edgeHeavy || openCount >= 2)
{ return OUTLINE; }
}
if (profile.fullTile)
{
const freeN = !c.n;
const freeS = !c.s;
const freeW = !c.w;
const freeE = !c.e;
const openNe = c.n && c.e && !c.ne;
const openSe = c.s && c.e && !c.se;
const openSw = c.s && c.w && !c.sw;
const openNw = c.n && c.w && !c.nw;
if (y === 0 || x === 0 || x === SIZE - 1 || y === SIZE - 1)
{ return OUTLINE; }
if ((freeW && x <= 2) || (openNw && x <= 2 && y <= 2) || (openSw && x <= 2 && y >= SIZE - 3))
{ return FACE_L; }
if ((freeE && x >= SIZE - 3) || (openNe && x >= SIZE - 3 && y <= 2) || (openSe && x >= SIZE - 3 && y >= SIZE - 3))
{ return FACE_R; }
if (freeN && y === 1)
{ return TOP_HI; }
if (y <= 8 && x >= 3 && x <= 12)
{ return TOP; }
if (freeS || y >= 10)
{ return FACE_FRONT; }
return TOP_LO;
}
if (y <= profile.coreY1)
{
if (!n)
{ return OUTLINE; }
if (!w)
{ return HI_L; }
if (!e)
{ return HI_R; }
return TOP;
}
if (!s)
{ return OUTLINE; }
if (!w)
{ return HI_L; }
if (!e)
{ return HI_R; }
return FACE;
}
function paintWall (mask)
function paintWall (mask, profile)
{
const rgba = new Uint8Array(SIZE * SIZE * 4);
const connectN = (mask & NeighborBit.n) !== 0;
const connectE = (mask & NeighborBit.e) !== 0;
const connectS = (mask & NeighborBit.s) !== 0;
const connectW = (mask & NeighborBit.w) !== 0;
const c = decodeMask(mask);
const occ = (x, y) =>
{
if (x < 0)
{ return c.w; }
if (x >= SIZE)
{ return c.e; }
if (y < 0)
{ return c.n; }
if (y >= SIZE)
{ return c.s; }
return inWall(x, y, c, profile);
};
for (let y = 0; y < SIZE; y++)
{
for (let x = 0; x < SIZE; x++)
{
if (!inWall(x, y, connectN, connectE, connectS, connectW))
if (!occ(x, y))
{ continue; }
const n = inWall(x, y - 1, connectN, connectE, connectS, connectW);
const e = inWall(x + 1, y, connectN, connectE, connectS, connectW);
const s = inWall(x, y + 1, connectN, connectE, connectS, connectW);
const w = inWall(x - 1, y, connectN, connectE, connectS, connectW);
let base;
if (isTopRow(y, connectN))
{
if (!n)
{ base = TOP_HI; }
else if (!s && y === TOP_Y1)
{ base = TOP_LO; }
else
{ base = TOP; }
}
else
{
if (!s)
{ base = FACE_LO; }
else if (!n)
{ base = FACE_HI; }
else
{ base = FACE; }
}
// Free side bevels (not on edges that continue into a neighbour).
const freeW = !w && !(connectW && x === 0);
const freeE = !e && !(connectE && x === SIZE - 1);
if (freeW || freeE)
{
if (base === TOP || base === TOP_HI)
{ base = TOP_LO; }
else if (base === FACE || base === FACE_HI)
{ base = EDGE; }
}
setPx(rgba, x, y, cobbleShade(base, x, y));
setPx(rgba, x, y, cobbleShade(shadeAt(x, y, c, profile, occ), x, y));
}
}
return rgba;
}
mkdirSync(OUT, { recursive: true });
for (let mask = 0; mask < 16; mask++)
function clearGenerated (dir)
{
mkdirSync(dir, { recursive: true });
for (const name of readdirSync(dir))
{
if (!/^\d+\.png$/i.test(name))
{ continue; }
unlinkSync(join(dir, name));
}
}
function writeSet (dir, profile, label)
{
writeFileSync(join(OUT, `${mask}.png`), encodePng(paintWall(mask)));
clearGenerated(dir);
const masks = listValidNeighborConnectCornerMasks();
for (const mask of masks)
{
writeFileSync(join(dir, `${mask}.png`), encodePng(paintWall(mask, profile)));
}
console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);
}
console.log(`Wrote cobblestone frustum stone-wall sprites 0–15 to ${OUT}`);
writeSet(OUT_THICK, THICK, "thick");
writeSet(OUT_THIN, THIN, "thin");
@@ -1,39 +1,71 @@/**/** * Generate 16×16 gray cobblestone stone-wall PNGs for neighbor-connect masks 0–15. * Generate thin + thick stone-wall PNGs for blob neighbor-connect masks * (cardinals + diagonal corners — 47 valid states). * * * Truncated-pyramid / frustum look when alone or at free ends. Connected runs use a * Shape references (silhouette / shading only, not final texture): * constant cross-section extruded to the tile edge (strip-union like tables/fences) * client/assets/blocks/stone-wall/example-stone-thin.png * so N/S and E/W seams match. * client/assets/blocks/stone-wall/example-stone-thick.png * * Corner bits: when both adjacent cardinals join but the diagonal does not, * paint an L-strip (concave). When the diagonal also joins, fill the quadrant * so a solid 2×2 reads as one block. * * * node client/scripts/generate-stone-wall-sprites.mjs * node client/scripts/generate-stone-wall-sprites.mjs */ */import { mkdirSync, writeFileSync } from "node:fs";import { mkdirSync, writeFileSync, readdirSync, unlinkSync } from "node:fs";import { deflateSync } from "node:zlib";import { deflateSync } from "node:zlib";import { fileURLToPath } from "node:url";import { fileURLToPath } from "node:url";import { dirname, join } from "node:path";import { dirname, join } from "node:path";import { NeighborBit } from "../../shared/world/neighborConnect.js";import { NeighborBit, listValidNeighborConnectCornerMasks} from "../../shared/world/neighborConnect.js";const SIZE = 16;const SIZE = 16;const OUT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks/stone-wall");const ROOT = join(dirname(fileURLToPath(import.meta.url)), "../assets/blocks");const OUT_THICK = join(ROOT, "stone-wall");const TOP = [168, 168, 172, 255];const OUT_THIN = join(ROOT, "stone-wall-thin");const TOP_HI = [198, 198, 202, 255];const TOP_LO = [140, 140, 144, 255];const OUTLINE = [0x40, 0x40, 0x40, 255];const FACE = [112, 112, 116, 255];const TOP_HI = [0xaf, 0xaf, 0xaf, 255];const FACE_HI = [132, 132, 136, 255];const TOP = [0x80, 0x80, 0x80, 255];const FACE_LO = [88, 88, 92, 255];const TOP_LO = [0x73, 0x73, 0x73, 255];const EDGE = [70, 70, 74, 255];const FACE_L = [0x95, 0x95, 0x95, 255];const MORTAR = [78, 78, 82, 255];const FACE = [0x73, 0x73, 0x73, 255];const FACE_R = [0x6c, 0x6c, 0x6c, 255];/** Constant core used for connected runs (must meet neighbour tile edges cleanly). */const FACE_FRONT = [0x54, 0x54, 0x54, 255];const CORE_X0 = 5;const HI_L = [0xb6, 0xb6, 0xb6, 255];const CORE_X1 = 10;const HI_R = [0x80, 0x80, 0x80, 255];const TOP_Y0 = 3;const MORTAR = [0x58, 0x58, 0x5c, 255];const TOP_Y1 = 6;const FACE_Y1 = 12;/**/** Alone / free-end base is wider than the top (frustum). */ * Thin: compact top core (table-style strip-union) so L keeps a concave cutout;const BASE_X0 = 3; * frustum face hangs below on free south edges. Alone matches example-stone-thin.const BASE_X1 = 12; */const THIN = Object.freeze({ topY0: 2, coreY0: 3, coreY1: 7, faceY1: 12, coreX0: 5, coreX1: 10, baseX0: 3, baseX1: 12, fullTile: false});/** Thick: full-tile footprint; bevels react to free edges / missing diagonals. */const THICK = Object.freeze({ topY0: 1, coreY0: 1, coreY1: 8, faceY1: 14, coreX0: 3, coreX1: 12, baseX0: 0, baseX1: 15, fullTile: true});function crcTable ()function crcTable (){{@@ -109,148 +141,260 @@ function setPx (rgba, x, y, color) rgba[i + 3] = color[3]; rgba[i + 3] = color[3];}}/** Frustum half-width in X at row y (alone / free-end silhouette). */function hash2 (x, y)function frustumX0X1 (y){{ if (y <= TOP_Y1) let n = (x * 374761393 + y * 668265263) | 0; { return { x0: CORE_X0, x1: CORE_X1 }; } n = (n ^ (n >>> 13)) * 1274126177; if (y >= FACE_Y1) return (n ^ (n >>> 16)) >>> 0; { return { x0: BASE_X0, x1: BASE_X1 }; } const t = (y - TOP_Y1) / (FACE_Y1 - TOP_Y1); const x0 = Math.round(CORE_X0 + (BASE_X0 - CORE_X0) * t); const x1 = Math.round(CORE_X1 + (BASE_X1 - CORE_X1) * t); return { x0, x1 };}}/**function cobbleShade (base, x, y) * Strip-union with constant core thickness on connected sides. * Free ends keep the frustum taper so alone / stubs still read as 3D. */function inWall (x, y, connectN, connectE, connectS, connectW){{ const alone = !connectN && !connectE && !connectS && !connectW; const h = hash2(x, y); const wantH = alone || connectE || connectW; const speck = h & 7; const wantV = alone || connectN || connectS; if (speck === 0) { return MORTAR; } if (wantH) if (speck === 1) { { const y0 = connectN ? 0 : TOP_Y0; return [ const y1 = connectS ? SIZE - 1 : FACE_Y1; Math.min(255, base[0] + 18), if (y >= y0 && y <= y1) Math.min(255, base[1] + 18), { Math.min(255, base[2] + 18), const { x0: fx0, x1: fx1 } = frustumX0X1(Math.min(FACE_Y1, Math.max(TOP_Y0, y))); 255 // Connected cardinals run to the tile edge (constant seam). ]; // Free ends keep the frustum taper. const x0 = connectW ? 0 : fx0; const x1 = connectE ? SIZE - 1 : fx1; if (x >= x0 && x <= x1) { return true; } } } } if (speck === 2) { return [ Math.max(0, base[0] - 14), Math.max(0, base[1] - 14), Math.max(0, base[2] - 14), 255 ]; } return base;}function decodeMask (mask){ return { n: (mask & NeighborBit.n) !== 0, e: (mask & NeighborBit.e) !== 0, s: (mask & NeighborBit.s) !== 0, w: (mask & NeighborBit.w) !== 0, ne: (mask & NeighborBit.ne) !== 0, se: (mask & NeighborBit.se) !== 0, sw: (mask & NeighborBit.sw) !== 0, nw: (mask & NeighborBit.nw) !== 0 };}function frustumX0X1 (y, profile){ if (y <= 2) { return { x0: 6, x1: 9 }; } if (y <= 4) { return { x0: 5, x1: 10 }; } if (y <= 6) { return { x0: 4, x1: 11 }; } return { x0: profile.baseX0, x1: profile.baseX1 };} if (wantV)/** Top-plane strip-union + diagonal fills (no front skirt). */function inTopPlane (x, y, c, profile){ const { coreX0, coreX1, coreY0, coreY1 } = profile; const inCoreX = x >= coreX0 && x <= coreX1; const inCoreY = y >= coreY0 && y <= coreY1; const wantH = c.e || c.w; const wantV = c.n || c.s; if (inCoreX && inCoreY) { return true; } if (wantH && inCoreY) { { const x0 = CORE_X0; const x0 = c.w ? 0 : coreX0; const x1 = CORE_X1; const x1 = c.e ? SIZE - 1 : coreX1; if (x >= x0 && x <= x1) if (x >= x0 && x <= x1) { { return true; } const y0 = connectN ? 0 : TOP_Y0; const y1 = connectS ? SIZE - 1 : FACE_Y1; if (y >= y0 && y <= y1) { return true; } } } } if (wantV && inCoreX) { const y0 = c.n ? 0 : coreY0; const y1 = c.s ? SIZE - 1 : coreY1; if (y >= y0 && y <= y1) { return true; } } // Close concave L/T cutouts when the diagonal neighbour is present. if (c.se && c.s && c.e && x > coreX1 && y > coreY1) { return true; } if (c.sw && c.s && c.w && x < coreX0 && y > coreY1) { return true; } if (c.ne && c.n && c.e && x > coreX1 && y < coreY0) { return true; } if (c.nw && c.n && c.w && x < coreX0 && y < coreY0) { return true; } return false; return false;}}function hash2 (x, y)function inWall (x, y, c, profile){{ let n = (x * 374761393 + y * 668265263) | 0; if (profile.fullTile) n = (n ^ (n >>> 13)) * 1274126177; { return true; } return (n ^ (n >>> 16)) >>> 0;}function cobbleShade (base, x, y) const alone = !c.n && !c.e && !c.s && !c.w;{ if (alone) const h = hash2(x, y); { const speck = (h & 7); if (y < profile.topY0 || y > profile.faceY1) if (speck === 0) { return false; } { return MORTAR; } const { x0, x1 } = frustumX0X1(y, profile); if (speck === 1 || speck === 2) return x >= x0 && x <= x1; { return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_HI : FACE_HI; } } if (speck === 3) { return base === TOP || base === TOP_HI || base === TOP_LO ? TOP_LO : FACE_LO; } if (inTopPlane(x, y, c, profile)) return base; { return true; } // Front-face skirt under top-plane pixels that do not continue south. if (y > profile.coreY1 && y <= profile.faceY1) { if (!inTopPlane(x, profile.coreY1, c, profile)) { return false; } // Vertical run into a southern neighbour: no skirt in the core column. if (c.s && x >= profile.coreX0 && x <= profile.coreX1) { return false; } // Diagonal-filled SE mass continues as solid top — skirt only at very bottom // of columns that are the south perimeter (no further south neighbour top). if (c.s && ((c.se && c.e && x > profile.coreX1) || (c.sw && c.w && x < profile.coreX0))) { return false; } const { x0, x1 } = frustumX0X1(y, profile); const skirtX0 = c.w ? 0 : x0; const skirtX1 = c.e ? SIZE - 1 : x1; if (x < skirtX0 || x > skirtX1) { return false; } return inTopPlane(x, profile.coreY1, c, profile); } return false;}}function isTopRow (y, connectN)function shadeAt (x, y, c, profile, occ){{ if (connectN) const n = occ(x, y - 1); { return y <= TOP_Y1; } const e = occ(x + 1, y); return y >= TOP_Y0 && y <= TOP_Y1; const s = occ(x, y + 1); const w = occ(x - 1, y); const openCount = (!n ? 1 : 0) + (!s ? 1 : 0) + (!e ? 1 : 0) + (!w ? 1 : 0); if (openCount > 0) { const edgeHeavy = (!n && y <= (profile.fullTile ? 0 : profile.topY0)) || (!s && y >= (profile.fullTile ? SIZE - 1 : profile.faceY1)) || (!w && x <= (profile.fullTile ? 0 : profile.baseX0)) || (!e && x >= (profile.fullTile ? SIZE - 1 : profile.baseX1)); if (edgeHeavy || openCount >= 2) { return OUTLINE; } } if (profile.fullTile) { const freeN = !c.n; const freeS = !c.s; const freeW = !c.w; const freeE = !c.e; const openNe = c.n && c.e && !c.ne; const openSe = c.s && c.e && !c.se; const openSw = c.s && c.w && !c.sw; const openNw = c.n && c.w && !c.nw; if (y === 0 || x === 0 || x === SIZE - 1 || y === SIZE - 1) { return OUTLINE; } if ((freeW && x <= 2) || (openNw && x <= 2 && y <= 2) || (openSw && x <= 2 && y >= SIZE - 3)) { return FACE_L; } if ((freeE && x >= SIZE - 3) || (openNe && x >= SIZE - 3 && y <= 2) || (openSe && x >= SIZE - 3 && y >= SIZE - 3)) { return FACE_R; } if (freeN && y === 1) { return TOP_HI; } if (y <= 8 && x >= 3 && x <= 12) { return TOP; } if (freeS || y >= 10) { return FACE_FRONT; } return TOP_LO; } if (y <= profile.coreY1) { if (!n) { return OUTLINE; } if (!w) { return HI_L; } if (!e) { return HI_R; } return TOP; } if (!s) { return OUTLINE; } if (!w) { return HI_L; } if (!e) { return HI_R; } return FACE;}}function paintWall (mask)function paintWall (mask, profile){{ const rgba = new Uint8Array(SIZE * SIZE * 4); const rgba = new Uint8Array(SIZE * SIZE * 4); const connectN = (mask & NeighborBit.n) !== 0; const c = decodeMask(mask); const connectE = (mask & NeighborBit.e) !== 0; const occ = (x, y) => const connectS = (mask & NeighborBit.s) !== 0; { const connectW = (mask & NeighborBit.w) !== 0; if (x < 0) { return c.w; } if (x >= SIZE) { return c.e; } if (y < 0) { return c.n; } if (y >= SIZE) { return c.s; } return inWall(x, y, c, profile); }; for (let y = 0; y < SIZE; y++) for (let y = 0; y < SIZE; y++) { { for (let x = 0; x < SIZE; x++) for (let x = 0; x < SIZE; x++) { { if (!inWall(x, y, connectN, connectE, connectS, connectW)) if (!occ(x, y)) { continue; } { continue; } setPx(rgba, x, y, cobbleShade(shadeAt(x, y, c, profile, occ), x, y)); const n = inWall(x, y - 1, connectN, connectE, connectS, connectW); const e = inWall(x + 1, y, connectN, connectE, connectS, connectW); const s = inWall(x, y + 1, connectN, connectE, connectS, connectW); const w = inWall(x - 1, y, connectN, connectE, connectS, connectW); let base; if (isTopRow(y, connectN)) { if (!n) { base = TOP_HI; } else if (!s && y === TOP_Y1) { base = TOP_LO; } else { base = TOP; } } else { if (!s) { base = FACE_LO; } else if (!n) { base = FACE_HI; } else { base = FACE; } } // Free side bevels (not on edges that continue into a neighbour). const freeW = !w && !(connectW && x === 0); const freeE = !e && !(connectE && x === SIZE - 1); if (freeW || freeE) { if (base === TOP || base === TOP_HI) { base = TOP_LO; } else if (base === FACE || base === FACE_HI) { base = EDGE; } } setPx(rgba, x, y, cobbleShade(base, x, y)); } } } } return rgba; return rgba;}}mkdirSync(OUT, { recursive: true });function clearGenerated (dir)for (let mask = 0; mask < 16; mask++){ mkdirSync(dir, { recursive: true }); for (const name of readdirSync(dir)) { if (!/^\d+\.png$/i.test(name)) { continue; } unlinkSync(join(dir, name)); }}function writeSet (dir, profile, label){{ writeFileSync(join(OUT, `${mask}.png`), encodePng(paintWall(mask))); clearGenerated(dir); const masks = listValidNeighborConnectCornerMasks(); for (const mask of masks) { writeFileSync(join(dir, `${mask}.png`), encodePng(paintWall(mask, profile))); } console.log(`Wrote ${masks.length} ${label} stone-wall sprites to ${dir}`);}}console.log(`Wrote cobblestone frustum stone-wall sprites 0–15 to ${OUT}`);writeSet(OUT_THICK, THICK, "thick");writeSet(OUT_THIN, THIN, "thin");@@ -26,6 +26,7 @@ import
computeNeighborConnectMask,
composeNeighborConnectState,
definitionUsesNeighborConnect,
definitionUsesNeighborConnectCorners,
neighborConnectBlocksMatch,
neighborConnectRefreshTiles,
worldTileToChunkLocal
@@ -667,9 +668,10 @@ function refreshNeighborConnect (localX, localY, typeId)
const def = BLOCK_DEFINITIONS[typeId];
if (!draft || !definitionUsesNeighborConnect(def))
{ return; }
const corners = definitionUsesNeighborConnectCorners(def);
const originTileX = chunkX * CHUNK_SIZE + localX;
const originTileY = chunkY * CHUNK_SIZE + localY;
for (const [tileX, tileY] of neighborConnectRefreshTiles(originTileX, originTileY))
for (const [tileX, tileY] of neighborConnectRefreshTiles(originTileX, originTileY, { corners }))
{
const block = blockAtWorld(tileX, tileY);
if (!block || block.typeId !== typeId)
@@ -678,7 +680,7 @@ function refreshNeighborConnect (localX, localY, typeId)
{
const neighbor = blockAtWorld(tileX + dx, tileY + dy);
return neighborConnectBlocksMatch(block, neighbor, def);
});
}, { corners });
const nextState = composeNeighborConnectState(def, block.state, mask);
if (block.state === nextState)
{ continue; }
@@ -26,6 +26,7 @@ import computeNeighborConnectMask, computeNeighborConnectMask, composeNeighborConnectState, composeNeighborConnectState, definitionUsesNeighborConnect, definitionUsesNeighborConnect, definitionUsesNeighborConnectCorners, neighborConnectBlocksMatch, neighborConnectBlocksMatch, neighborConnectRefreshTiles, neighborConnectRefreshTiles, worldTileToChunkLocal worldTileToChunkLocal@@ -667,9 +668,10 @@ function refreshNeighborConnect (localX, localY, typeId) const def = BLOCK_DEFINITIONS[typeId]; const def = BLOCK_DEFINITIONS[typeId]; if (!draft || !definitionUsesNeighborConnect(def)) if (!draft || !definitionUsesNeighborConnect(def)) { return; } { return; } const corners = definitionUsesNeighborConnectCorners(def); const originTileX = chunkX * CHUNK_SIZE + localX; const originTileX = chunkX * CHUNK_SIZE + localX; const originTileY = chunkY * CHUNK_SIZE + localY; const originTileY = chunkY * CHUNK_SIZE + localY; for (const [tileX, tileY] of neighborConnectRefreshTiles(originTileX, originTileY)) for (const [tileX, tileY] of neighborConnectRefreshTiles(originTileX, originTileY, { corners })) { { const block = blockAtWorld(tileX, tileY); const block = blockAtWorld(tileX, tileY); if (!block || block.typeId !== typeId) if (!block || block.typeId !== typeId)@@ -678,7 +680,7 @@ function refreshNeighborConnect (localX, localY, typeId) { { const neighbor = blockAtWorld(tileX + dx, tileY + dy); const neighbor = blockAtWorld(tileX + dx, tileY + dy); return neighborConnectBlocksMatch(block, neighbor, def); return neighborConnectBlocksMatch(block, neighbor, def); }); }, { corners }); const nextState = composeNeighborConnectState(def, block.state, mask); const nextState = composeNeighborConnectState(def, block.state, mask); if (block.state === nextState) if (block.state === nextState) { continue; } { continue; }@@ -504,5 +504,6 @@ function listPngStems (folder)
return entries
.filter((entry) => entry.isFile() && extname(entry.name).toLowerCase() === ".png")
.map((entry) => entry.name.slice(0, -extname(entry.name).length))
.filter((stem) => !stem.startsWith("example") && !stem.startsWith("_"))
.sort((a, b) => a.localeCompare(b, "en", { numeric: true, sensitivity: "base" }));
}
@@ -504,5 +504,6 @@ function listPngStems (folder) return entries return entries .filter((entry) => entry.isFile() && extname(entry.name).toLowerCase() === ".png") .filter((entry) => entry.isFile() && extname(entry.name).toLowerCase() === ".png") .map((entry) => entry.name.slice(0, -extname(entry.name).length)) .map((entry) => entry.name.slice(0, -extname(entry.name).length)) .filter((stem) => !stem.startsWith("example") && !stem.startsWith("_")) .sort((a, b) => a.localeCompare(b, "en", { numeric: true, sensitivity: "base" })); .sort((a, b) => a.localeCompare(b, "en", { numeric: true, sensitivity: "base" }));}}@@ -9,7 +9,8 @@ import {
neighborConnectBlocksMatch,
parseMaterialNeighborConnectState,
worldTileToChunkLocal,
neighborConnectRefreshTiles
neighborConnectRefreshTiles,
listValidNeighborConnectCornerMasks
} from "../../shared/world/neighborConnect.js";
import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";
import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";
@@ -30,6 +31,28 @@ test("neighbor connect masks cover all NESW combinations", () =>
assert.equal(mask, NeighborBit.n | NeighborBit.e);
});
test("corner-aware neighbor connect sets diagonals only with both cardinals", () =>
{
const isL = (dx, dy) => (dx === 1 && dy === 0) || (dx === 0 && dy === 1);
assert.equal(
computeNeighborConnectMask(isL, { corners: true }),
NeighborBit.e | NeighborBit.s
);
const isSolid2x2 = (dx, dy) =>
(dx === 1 && dy === 0)
|| (dx === 0 && dy === 1)
|| (dx === 1 && dy === 1);
assert.equal(
computeNeighborConnectMask(isSolid2x2, { corners: true }),
NeighborBit.e | NeighborBit.s | NeighborBit.se
);
assert.equal(listValidNeighborConnectCornerMasks().length, 47);
assert.deepEqual(
neighborConnectRefreshTiles(5, 5, { corners: true }).length,
9
);
});
test("material neighbor-connect states keep wood id and only match same material", () =>
{
const def = BLOCK_DEFINITIONS[BlockType.table];
@@ -9,7 +9,8 @@ import { neighborConnectBlocksMatch, neighborConnectBlocksMatch, parseMaterialNeighborConnectState, parseMaterialNeighborConnectState, worldTileToChunkLocal, worldTileToChunkLocal, neighborConnectRefreshTiles neighborConnectRefreshTiles, listValidNeighborConnectCornerMasks} from "../../shared/world/neighborConnect.js";} from "../../shared/world/neighborConnect.js";import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";import { CENTRAL_EXCHANGE_STAFF, pickExchangeClerk } from "../../shared/market/exchange.js";import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";import { MobId, normalizeSpawnerConfig, isCentralExchangeSpawner } from "../../shared/definitions/mobs.js";@@ -30,6 +31,28 @@ test("neighbor connect masks cover all NESW combinations", () => assert.equal(mask, NeighborBit.n | NeighborBit.e); assert.equal(mask, NeighborBit.n | NeighborBit.e);});});test("corner-aware neighbor connect sets diagonals only with both cardinals", () =>{ const isL = (dx, dy) => (dx === 1 && dy === 0) || (dx === 0 && dy === 1); assert.equal( computeNeighborConnectMask(isL, { corners: true }), NeighborBit.e | NeighborBit.s ); const isSolid2x2 = (dx, dy) => (dx === 1 && dy === 0) || (dx === 0 && dy === 1) || (dx === 1 && dy === 1); assert.equal( computeNeighborConnectMask(isSolid2x2, { corners: true }), NeighborBit.e | NeighborBit.s | NeighborBit.se ); assert.equal(listValidNeighborConnectCornerMasks().length, 47); assert.deepEqual( neighborConnectRefreshTiles(5, 5, { corners: true }).length, 9 );});test("material neighbor-connect states keep wood id and only match same material", () =>test("material neighbor-connect states keep wood id and only match same material", () =>{{ const def = BLOCK_DEFINITIONS[BlockType.table]; const def = BLOCK_DEFINITIONS[BlockType.table];@@ -13,11 +13,15 @@ const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.meta
test("sprite folders expose alphabetical states; first is default", () =>
{
const catalog = buildSpriteCatalog(ASSET_ROOT);
assert.deepEqual(catalog.blocks["stone-wall"].states, [
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"
]);
assert.equal(catalog.blocks["stone-wall"].states.length, 47);
assert.equal(catalog.blocks["stone-wall"].defaultState, "0");
assert.ok(catalog.images.some((image) => image.name === "block:stone-wall:15"));
assert.ok(catalog.blocks["stone-wall"].states.includes("15"));
assert.ok(catalog.blocks["stone-wall"].states.includes("38"));
assert.ok(catalog.blocks["stone-wall"].states.includes("255"));
assert.ok(catalog.images.some((image) => image.name === "block:stone-wall:255"));
assert.equal(catalog.blocks["stone-wall-thin"].states.length, 47);
assert.equal(catalog.blocks["stone-wall-thin"].defaultState, "0");
assert.ok(catalog.images.some((image) => image.name === "block:stone-wall-thin:38"));
assert.equal(catalog.images[0].subImgTotal, 1);
assert.equal(catalog.images[0].perRow, 1);
});
@@ -13,11 +13,15 @@ const ASSET_ROOT = join(fileURLToPath(new URL("../../client/assets", import.metatest("sprite folders expose alphabetical states; first is default", () =>test("sprite folders expose alphabetical states; first is default", () =>{{ const catalog = buildSpriteCatalog(ASSET_ROOT); const catalog = buildSpriteCatalog(ASSET_ROOT); assert.deepEqual(catalog.blocks["stone-wall"].states, [ assert.equal(catalog.blocks["stone-wall"].states.length, 47); "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" ]); assert.equal(catalog.blocks["stone-wall"].defaultState, "0"); assert.equal(catalog.blocks["stone-wall"].defaultState, "0"); assert.ok(catalog.images.some((image) => image.name === "block:stone-wall:15")); assert.ok(catalog.blocks["stone-wall"].states.includes("15")); assert.ok(catalog.blocks["stone-wall"].states.includes("38")); assert.ok(catalog.blocks["stone-wall"].states.includes("255")); assert.ok(catalog.images.some((image) => image.name === "block:stone-wall:255")); assert.equal(catalog.blocks["stone-wall-thin"].states.length, 47); assert.equal(catalog.blocks["stone-wall-thin"].defaultState, "0"); assert.ok(catalog.images.some((image) => image.name === "block:stone-wall-thin:38")); assert.equal(catalog.images[0].subImgTotal, 1); assert.equal(catalog.images[0].subImgTotal, 1); assert.equal(catalog.images[0].perRow, 1); assert.equal(catalog.images[0].perRow, 1);});});