Add all textures and models from create

This commit is contained in:
2026-10-12 18:47:41 -03:00
parent d4eff11f3e
commit 99bdcaeffc
3775 changed files with 66614 additions and 58 deletions
+27 -3
View File
@@ -117,6 +117,9 @@ export interface BlockVariant {
textures?: BlockTextures;
// turns the model around the vertical axis, clockwise seen from above: 0, 90, 180 or 270
y?: number;
// turns the model around the east-west axis first, like minecraft's: 0, 90, 180 or 270. 90 tips its top to the north,
// so a model pointing up points north, then y turns it to face the rest of the ways
x?: number;
// 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[][];
@@ -133,6 +136,7 @@ export interface BlockPart {
// the block's textures when not set
textures?: BlockTextures;
y?: number;
x?: number;
shape?: number[][];
collision_shape?: number[][];
}
@@ -142,6 +146,7 @@ export interface PlacedModel {
model: string;
textures: BlockTextures;
y: number;
x: number;
shape?: number[][];
collision_shape?: number[][];
}
@@ -244,6 +249,7 @@ export function block_variant(block: BlockRegistry, states?: Record<string, numb
let model: string | undefined;
let textures: BlockTextures | undefined;
let y: number | undefined;
let x: number | undefined;
let shape: number[][] | undefined;
let collision_shape: number[][] | undefined;
if (block.variants && states) {
@@ -252,6 +258,7 @@ export function block_variant(block: BlockRegistry, states?: Record<string, numb
model ??= override.model;
textures ??= override.textures;
y ??= override.y;
x ??= override.x;
shape ??= override.shape;
collision_shape ??= override.collision_shape;
}
@@ -260,6 +267,7 @@ export function block_variant(block: BlockRegistry, states?: Record<string, numb
model: model ?? block.model ?? DEFAULT_MODEL,
textures: textures ?? cube_textures(block),
y: y ?? 0,
x: x ?? 0,
shape: shape ?? block.shape,
collision_shape: collision_shape ?? block.collision_shape,
};
@@ -276,6 +284,7 @@ export function block_parts(block: BlockRegistry, states?: Record<string, number
model: part.model,
textures: part.textures ?? variant.textures,
y: part.y ?? 0,
x: part.x ?? 0,
shape: part.shape,
collision_shape: part.collision_shape,
}));
@@ -306,7 +315,7 @@ export function bake_block(block: BlockRegistry, value: number, models: Record<s
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);
return bake_model(model, part.textures, part.y, part.x);
});
}
@@ -410,6 +419,12 @@ export const FACE_CORNERS = [
export const CORNER_UVS = [[0, 1], [1, 1], [1, 0], [0, 0]] as const;
// the face a face becomes after turning the model 90 degrees clockwise seen from above
const TURN_Y = [0, 1, 4, 5, 3, 2];
// the face a face becomes after a quarter turn around the east-west axis, the top tipping north: top to north, north to
// bottom, bottom to south and south to top
const TURN_X = [3, 2, 0, 1, 4, 5];
// a quarter turn's count for a turn of 0, 90, 180 or 270 degrees
const quarters = (degrees: number) => ((Math.round(degrees / 90) % 4) + 4) % 4;
// minecraft's default uvs: the part of the texture the face would cover if the texture was wrapped around the block
function default_uv(face: ModelFace, from: number[], to: number[]): [number, number, number, number] {
@@ -431,9 +446,16 @@ function default_uv(face: ModelFace, from: number[], to: number[]): [number, num
const EPSILON = 1e-4;
export function bake_model(model: ModelJson, textures: BlockTextures | undefined, y_rotation = 0): BakedQuad[] {
// a model's quads with its textures, turned by x and then y like a block variant's turns
export function bake_model(
model: ModelJson,
textures: BlockTextures | undefined,
y_rotation = 0,
x_rotation = 0,
): BakedQuad[] {
const quads: BakedQuad[] = [];
const turns = ((Math.round(y_rotation / 90) % 4) + 4) % 4;
const turns = quarters(y_rotation);
const x_turns = quarters(x_rotation);
for (const element of model.elements) {
const rotate = element_rotation(element);
@@ -450,6 +472,7 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
FACE_CORNERS[index].forEach((corner, k) => {
let point = corner.map((end, axis) => (end ? element.to[axis] : element.from[axis]) / 16);
point = rotate(point);
for (let t = 0; t < x_turns; t++) point = [point[0], point[2], 1 - point[1]];
for (let t = 0; t < turns; t++) point = [1 - point[2], point[1], point[0]];
positions.push(...point);
const [cu, cv] = CORNER_UVS[(k + uv_turns) % 4];
@@ -457,6 +480,7 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
});
let cull = face_json.cullface ? FACE_INDEX[face_json.cullface] : -1;
for (let t = 0; t < x_turns && cull >= 0; t++) cull = TURN_X[cull];
for (let t = 0; t < turns && cull >= 0; t++) cull = TURN_Y[cull];
const { face: facing, flush, aligned } = classify(positions);
quads.push({
+15 -10
View File
@@ -27,7 +27,7 @@ const FLAT = 1e-4;
// the boxes of a model's elements, turned like the model is. elements turned by their own rotation take the box
// around them. flat planes (plants) aren't boxes, so a model made only of planes gets one box around all of them
export function model_shape(model: ModelJson, y_rotation = 0): Shape {
export function model_shape(model: ModelJson, y_rotation = 0, x_rotation = 0): Shape {
const boxes: Box[] = [];
let bounds: Box | undefined;
for (const element of model.elements) {
@@ -48,13 +48,13 @@ export function model_shape(model: ModelJson, y_rotation = 0): Shape {
if ([0, 1, 2].every((axis) => box[axis + 3] - box[axis] > FLAT)) boxes.push(box);
}
if (boxes.length === 0 && bounds) boxes.push(bounds);
return boxes.map((box) => turn(box, y_rotation));
return boxes.map((box) => turn(box, y_rotation, x_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));
export function pixel_shape(boxes: number[][], y_rotation = 0, top = 1, x_rotation = 0): Shape {
return boxes.map((box) => turn(clamp(box.map((v) => v / 16), top), y_rotation, x_rotation));
}
// how high a collision shape can go, in blocks
@@ -65,9 +65,9 @@ export const COLLISION_TOP = 1.5;
export function block_shape(block: BlockRegistry, states?: Record<string, number>): 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);
if (part.shape) return pixel_shape(part.shape, part.y, 1, part.x);
const model = find_model(part.model, models);
return model ? model_shape(model, part.y) : FULL_SHAPE;
return model ? model_shape(model, part.y, part.x) : FULL_SHAPE;
});
}
@@ -78,10 +78,10 @@ export function block_collision_shape(block: BlockRegistry, states?: Record<stri
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);
if (part.collision_shape) return pixel_shape(part.collision_shape, part.y, COLLISION_TOP, part.x);
if (part.shape) return pixel_shape(part.shape, part.y, 1, part.x);
const model = find_model(part.model, models);
return model ? model_shape(model, part.y) : FULL_SHAPE;
return model ? model_shape(model, part.y, part.x) : FULL_SHAPE;
});
}
@@ -225,9 +225,14 @@ function clamp(box: number[], top = 1): Box {
}
// clockwise seen from above by 0, 90, 180 or 270 degrees, the same as bake_model turns quads
function turn(box: Box, y_rotation: number): Box {
function turn(box: Box, y_rotation: number, x_rotation = 0): Box {
const turns = ((Math.round(y_rotation / 90) % 4) + 4) % 4;
const x_turns = ((Math.round(x_rotation / 90) % 4) + 4) % 4;
let [x1, y1, z1, x2, y2, z2] = box;
for (let t = 0; t < x_turns; t++) {
// a point (y, z) goes to (z, 1 - y), the top tipping north like the model does
[y1, z1, y2, z2] = [z1, 1 - y2, z2, 1 - y1];
}
for (let t = 0; t < turns; t++) {
// a point (x, z) goes to (1 - z, x)
[x1, z1, x2, z2] = [1 - z2, x1, 1 - z1, x2];
+8 -4
View File
@@ -584,8 +584,10 @@ export function validate_block(json: unknown): Problems {
if (variant.textures !== undefined) {
problems.push(...validate_textures(variant.textures, `${where}.textures`));
}
if (variant.y !== undefined && ![0, 90, 180, 270].includes(variant.y as number)) {
problems.push(`${where}.y must be 0, 90, 180 or 270`);
for (const axis of ["x", "y"]) {
if (variant[axis] !== undefined && ![0, 90, 180, 270].includes(variant[axis] as number)) {
problems.push(`${where}.${axis} must be 0, 90, 180 or 270`);
}
}
if (variant.shape !== undefined) problems.push(...validate_shape(variant.shape, `${where}.shape`));
if (variant.collision_shape !== undefined) {
@@ -625,8 +627,10 @@ export function validate_block(json: unknown): Problems {
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`);
for (const axis of ["x", "y"]) {
if (part[axis] !== undefined && ![0, 90, 180, 270].includes(part[axis] as number)) {
problems.push(`${where}.${axis} must be 0, 90, 180 or 270`);
}
}
if (part.shape !== undefined) problems.push(...validate_shape(part.shape, `${where}.shape`));
if (part.collision_shape !== undefined) {