ctx.blocks.solid(id) api

This commit is contained in:
2026-10-20 14:22:11 -03:00
parent 987e7a0f9a
commit 0bc66c21b9
11 changed files with 115 additions and 5 deletions
+23 -1
View File
@@ -9,11 +9,12 @@ import {
collision_shape_at,
EMPTY_SHAPE,
FULL_SHAPE,
is_solid,
model_shape,
raycast_blocks,
type Shape,
} from "$/common/block_shapes.ts";
import { block_from_json, validate_block } from "$/common/mod_data.ts";
import { block_from_json, type BlockJson, validate_block } from "$/common/mod_data.ts";
import { move_body } from "$/common/physics.ts";
import { box_overlaps_block } from "$/common/utils.ts";
@@ -173,3 +174,24 @@ Deno.test("an x turn turns a model's shape with it", () => {
// then y turns the south half to the west
assertEquals(model_shape(slab, 90, 90), [[0, 0, 0, 0.5, 1, 1]]);
});
Deno.test("a solid block is drawn in the solid layer and is a whole block to bump into, whatever its states", () => {
const block = (json: Partial<BlockJson>) =>
block_from_json({ id: "test:block", textures: "test:stone", ...json }).block;
const states = [{ name: "age", bits: 1, default: 0 }];
assert(is_solid(block({})));
assert(
is_solid(block({ states, variants: { "age=1": { y: 90, textures: "test:mossy" } } })),
"turned, other textures",
);
assert(!is_solid(block({ render_layer: "cutout" })), "like leaves");
assert(!is_solid(block({ render_layer: "translucent" })), "like glass");
assert(!is_solid(block({ collision: false })));
assert(!is_solid(block({ shape: [[0, 0, 0, 16, 8, 16]] })), "like a slab");
assert(!is_solid(block({ states, variants: { "age=1": { model: "engine:cross" } } })), "not in one of its states");
assert(!is_solid(block({ states, variants: { "age=1": { collision_shape: [[0, 0, 0, 16, 8, 16]] } } })));
assert(
is_solid(block({ shape: [[0, 0, 0, 16, 8, 16]], collision_shape: [[0, 0, 0, 16, 16, 16]] })),
"what it bumps into counts",
);
});