Missing blocks

This commit is contained in:
2026-11-22 13:55:30 -03:00
parent 784bac7dd2
commit b9deda1a55
30 changed files with 1320 additions and 11 deletions
+20 -11
View File
@@ -1,4 +1,4 @@
import type { SharedContext } from "cubi/shared";
import type { Face, SharedContext } from "cubi/shared";
export const FACILITY_DOOR = "dangerous_business:facility_door";
export const DOOR = "dangerous_business:door";
@@ -41,26 +41,35 @@ function register_pipe(ctx: SharedContext) {
}
// sets its north, east, south and west states (and top, with "up") to 1 where the same block is beside it, so it can
// hide its edges there, like floor grates joining into one floor
// hide its edges there, like floor grates joining into one floor. with "solid" it joins the full sides of other blocks
// beside it too, like iron bars, fences and walls set into a wall
interface ConnectsParams {
up?: boolean;
solid?: boolean;
}
function register_connects(ctx: SharedContext) {
const sides = (id: string | undefined, x: number, y: number, z: number, up: boolean) => {
const sides = (id: string | undefined, x: number, y: number, z: number, params: ConnectsParams) => {
const same = (dx: number, dy: number, dz: number) => ctx.world.get_block(x + dx, y + dy, z + dz) === id ? 1 : 0;
// the side of the block there that faces this one
const joins = (dx: number, dz: number, face: Face) =>
same(dx, 0, dz) || (params.solid && ctx.world.is_face_sturdy(x + dx, y, z + dz, face)) ? 1 : 0;
const states: Record<string, number> = {
north: same(0, 0, -1),
east: same(1, 0, 0),
south: same(0, 0, 1),
west: same(-1, 0, 0),
north: joins(0, -1, "south"),
east: joins(1, 0, "west"),
south: joins(0, 1, "north"),
west: joins(-1, 0, "east"),
};
if (up) states.top = same(0, 1, 0);
if (params.up) states.top = same(0, 1, 0);
return states;
};
ctx.components.register_block<{ up?: boolean }>("dangerous_business:connects", {
ctx.components.register_block<ConnectsParams>("dangerous_business:connects", {
// the block being placed is the item's
state_for_placement: (placement, params) =>
sides(placement.item, placement.x, placement.y, placement.z, params.up ?? false),
sides(placement.item, placement.x, placement.y, placement.z, params),
on_neighbor_change(block, params) {
const id = ctx.world.get_block(block.x, block.y, block.z);
for (const [state, value] of Object.entries(sides(id, block.x, block.y, block.z, params.up ?? false))) {
for (const [state, value] of Object.entries(sides(id, block.x, block.y, block.z, params))) {
ctx.world.set_state(block.x, block.y, block.z, state, value);
}
},