Verdigris torch

This commit is contained in:
2026-10-22 16:31:09 -03:00
parent db0589d965
commit 20e6ac6fbb
12 changed files with 500 additions and 73 deletions
+5 -55
View File
@@ -9,13 +9,13 @@ import { block_shape, is_solid } from "$/common/block_shapes.ts";
import { type BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
import type { Face } from "$/common/mod_api/shared.ts";
import { AIR_ID } from "$/common/protocol.ts";
import { block_states, default_block_value, set_state_value } from "$/common/utils.ts";
import { default_block_value, set_state_value } from "$/common/utils.ts";
import type { SavedChunk, WorldSave } from "$/server/game/saves.ts";
import { can_cover, joined_cell, ways_out } from "$/mods/bworld/scripts/verdigris/joins.ts";
import type { BlockReader } from "$/mods/bworld/scripts/verdigris/signals.ts";
import { can_cover, ways_out } from "$/mods/bworld/scripts/verdigris/joins.ts";
import { DIRECTIONS, FACE_OFFSETS, FACES, OPPOSITE, step } from "$/mods/bworld/scripts/verdigris/sides.ts";
import { NetIndex, wire_at } from "$/mods/bworld/scripts/verdigris/wires.ts";
import { type Area, client_of, server_blocks, test_game } from "./helpers.ts";
import { NetIndex } from "$/mods/bworld/scripts/verdigris/wires.ts";
import { client_of, server_blocks, test_game } from "./helpers.ts";
import { AREA, type Builder, builder, type Pos } from "./verdigris.ts";
// how far it stands off the face it lies on, in blocks
const HEIGHT = 0.25 / 16;
@@ -172,56 +172,6 @@ Deno.test("a wire shows its powered texture while it has power, and can be point
}
});
type Pos = [number, number, number];
const AREA: Area = { x: [-6, 6], y: [99, 104], z: [-6, 6] };
// alice on a stone floor at y 99, with air above it to build in
async function builder(save?: WorldSave) {
const t = await test_game("mods", save);
t.join(1, "alice");
if (!save) {
for (let x = AREA.x[0]; x <= AREA.x[1]; x++) {
for (let z = AREA.z[0]; z <= AREA.z[1]; z++) {
t.game.set_block(x, 99, z, "bworld:stone");
for (let y = 100; y <= AREA.y[1]; y++) t.game.set_block(x, y, z, AIR_ID);
}
}
}
t.send(1, { type: "move", x: 0.5, y: 100, z: 0.5, yaw: 0, pitch: 0 });
const player = t.game.players()[0];
// alice uses id, or whatever she's holding, on face of the block at x y z, from right by it
const use = (id: string | undefined, x: number, y: number, z: number, face: Face) => {
if (id) {
t.send(1, { type: "chat", text: `/give ${id}` });
const slot = player.inventory.to_synced_data().findIndex((item) => item?.id === id);
t.send(1, { type: "select_slot", slot });
}
t.game.teleport(player, x + 0.5, y + 1, z + 0.5);
t.send(1, { type: "use_block", x, y, z, face, hit: [0.5, 0.5, 0.5] });
};
const states = (x: number, y: number, z: number) =>
block_states(t.game.world.get_block_value(x, y, z), t.game.world.get_block_info(x, y, z)!);
const id = (x: number, y: number, z: number) => t.game.world.get_block_id(x, y, z);
const power = (...at: Pos) => states(...at).power;
// the world the way the wire's own code reads it
const reader: BlockReader = {
get_block: id,
get_state: (x, y, z, name) => states(x, y, z)[name],
source: (block) =>
EverythingRegistry.get<BlockRegistry>("blocks", block)?.components?.["bworld:verdigris_source"] as never,
};
const covers = (...at: Pos) => FACES.filter((face) => states(...at)[face] === 1);
// the wire cells the wire at x y z joins
const joins = (...at: Pos) =>
(wire_at(reader, ...at)?.out ?? []).flatMap(([face, direction]) => {
const cell = joined_cell(reader, ...at, face, direction);
return cell ? [cell.join(" ")] : [];
});
return { t, use, states, id, power, covers, joins, reader };
}
type Builder = Awaited<ReturnType<typeof builder>>;
// every wire cell these join joins them back
function joined_both_ways(b: Builder, wires: Pos[]) {
for (const at of wires) {