Allow for textures that aren't 16x16

This commit is contained in:
2026-09-28 16:20:37 -03:00
parent 52ef4e5ca6
commit fe149bb9ad
18 changed files with 268 additions and 136 deletions
+11 -2
View File
@@ -2,6 +2,7 @@
// MODS.md. the same code reads them on the server and in the browser, so it only works on bytes
import { unzipSync, zipSync } from "fflate";
import type { ModelJson } from "./block_models.ts";
import { MAX_TEXTURE_SIZE } from "./constants.ts";
import {
type BlockJson,
ID_PATTERN,
@@ -162,8 +163,8 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
problems.push(`${name}: texture names must be a-z, 0-9 and _`);
} else if (!size) {
problems.push(`${name}: isn't a png`);
} else if (size.width !== 16 || size.height !== 16) {
problems.push(`${name}: is ${size.width}×${size.height}, textures must be 16×16`);
} else if (texture_size_problem(size)) {
problems.push(`${name}: ${texture_size_problem(size)}`);
} else {
textures.set(id, content);
}
@@ -193,6 +194,14 @@ function checked(list: unknown, name: string, validate: (json: unknown) => strin
return list;
}
// textures can be any size up to MAX_TEXTURE_SIZE, like 64×32 for an entity. blocks and items stretch theirs to fit
export function texture_size_problem(size: { width: number; height: number }): string | undefined {
const { width, height } = size;
if (width < 1 || height < 1 || width > MAX_TEXTURE_SIZE || height > MAX_TEXTURE_SIZE) {
return `is ${width}×${height}, textures can be at most ${MAX_TEXTURE_SIZE}×${MAX_TEXTURE_SIZE}`;
}
}
// reads the size out of the png header instead of decoding the image
export function png_size(bytes: Uint8Array): { width: number; height: number } | undefined {
const signature = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];