Allow for textures that aren't 16x16
This commit is contained in:
+11
-2
@@ -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];
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
// the pixels across a block face or an item sprite. block models and item models are made in these units, a texture of
|
||||
// another size is stretched to fit
|
||||
export const TEXTURE_SIZE = 16;
|
||||
// the most a texture can be on either side, entity sprites are bigger than blocks'
|
||||
export const MAX_TEXTURE_SIZE = 256;
|
||||
|
||||
export const TICKS_PER_SECOND = 20;
|
||||
export const TICK_DELTA = 1 / TICKS_PER_SECOND;
|
||||
|
||||
export const SLOT_SIZE = 18 * 3;
|
||||
|
||||
// where a texture is in the atlas, in pixels
|
||||
export interface SpriteRegion {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export const faces = ["west", "east", "bottom", "top", "north", "south"] as const;
|
||||
|
||||
Reference in New Issue
Block a user