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
+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];