From 8230fe297df53b8b7f45649933a387a6fcc1655c Mon Sep 17 00:00:00 2001 From: Paula Date: Tue, 17 Nov 2026 08:20:29 -0300 Subject: [PATCH] Double steel pipes model --- .../blocks/double_steel_pipes.json | 23 +++++++++++++++++++ mods/dangerous_business/scripts/shared.ts | 12 ++++++++++ tests/dangerous_business_test.ts | 21 +++++++++++++++-- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/mods/dangerous_business/blocks/double_steel_pipes.json b/mods/dangerous_business/blocks/double_steel_pipes.json index 3a42959..281877a 100644 --- a/mods/dangerous_business/blocks/double_steel_pipes.json +++ b/mods/dangerous_business/blocks/double_steel_pipes.json @@ -9,14 +9,37 @@ "model": "dangerous_business:double_steel_pipes", "item_model": "dangerous_business:double_steel_pipes", "shape": [[0, 0, 4.5, 16, 16, 11.5]], + "components": { + "dangerous_business:pipe": {} + }, "states": [ { "name": "facing", "bits": 2, "default": 0 + }, + { + "name": "horizontal", + "bits": 1, + "default": 0 } ], "variants": { + "horizontal=1,facing=0": { + "x": 90 + }, + "horizontal=1,facing=1": { + "x": 90, + "y": 90 + }, + "horizontal=1,facing=2": { + "x": 90, + "y": 180 + }, + "horizontal=1,facing=3": { + "x": 90, + "y": 270 + }, "facing=0": { "y": 180 }, diff --git a/mods/dangerous_business/scripts/shared.ts b/mods/dangerous_business/scripts/shared.ts index 04ed616..0957309 100644 --- a/mods/dangerous_business/scripts/shared.ts +++ b/mods/dangerous_business/scripts/shared.ts @@ -11,6 +11,7 @@ export function shared(ctx: SharedContext) { register_door(ctx); register_facility_door(ctx); register_half(ctx); + register_pipe(ctx); register_connects(ctx); register_random_look(ctx); } @@ -28,6 +29,17 @@ function register_half(ctx: SharedContext) { }); } +// stands up when placed against the top or bottom of a block, and lies along the way it was placed (horizontal 1, facing +// that way) against a side, so a run of them can go up walls and along them +function register_pipe(ctx: SharedContext) { + ctx.components.register_block("dangerous_business:pipe", { + state_for_placement(placement): Record { + if (placement.face === "top" || placement.face === "bottom") return { horizontal: 0 }; + return { horizontal: 1, facing: FACINGS.indexOf(placement.face) }; + }, + }); +} + // 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 function register_connects(ctx: SharedContext) { diff --git a/tests/dangerous_business_test.ts b/tests/dangerous_business_test.ts index 4134a34..a2f6b61 100644 --- a/tests/dangerous_business_test.ts +++ b/tests/dangerous_business_test.ts @@ -2,7 +2,8 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // dangerous business's placement components: slabs and other blocks that go in the top or bottom half, blocks that -// join the same block beside them, and blocks that pick some of their looks when placed. and the death block +// join the same block beside them, blocks that pick some of their looks when placed, and pipes that stand up or lie +// down. and the death block import { assert, assertEquals, assertNotEquals } from "@std/assert"; import { ItemStack } from "@/common/inventory.ts"; import { get_state_value } from "@/common/utils.ts"; @@ -13,6 +14,7 @@ const CONNECTS = "dangerous_business:floor_grate"; const RANDOM_LOOK = "dangerous_business:water_puddle"; const FLOOR = "dangerous_business:concrete_floor"; const DEATH = "dangerous_business:death"; +const PIPE = "dangerous_business:double_steel_pipes"; // alice on a concrete floor at y 100, south of 0 100 0 and looking north, holding each of the blocks. it's a game of // its own, which tests playing mods/ leave out @@ -28,7 +30,7 @@ async function setup() { } } t.send(1, { type: "move", x: 0.5, y: 100, z: 3.5, yaw: 0, pitch: 0 }); - for (const id of [HALF, CONNECTS, RANDOM_LOOK]) t.send(1, { type: "chat", text: `/give ${id} 64` }); + for (const id of [HALF, CONNECTS, RANDOM_LOOK, PIPE]) t.send(1, { type: "chat", text: `/give ${id} 64` }); const hold = (slot: number) => t.send(1, { type: "select_slot", slot }); const state = (x: number, y: number, z: number, name: string) => get_state_value(t.game.world.get_block_value(x, y, z), t.game.world.get_block_info(x, y, z)!, name); @@ -51,6 +53,21 @@ Deno.test("a half block goes in the top half against the underside of a block or assertEquals(state(-1, 102, -1, "half"), 0); }); +Deno.test("a pipe stands up on top of a block and lies along the way it was placed against a side", async () => { + const { t, hold, state } = await setup(); + hold(3); + t.send(1, { type: "use_block", x: 0, y: 99, z: 0, face: "top", hit: [0.5, 1, 0.5] }); + assertEquals(state(0, 100, 0, "horizontal"), 0); + + t.game.set_block(0, 101, -2, FLOOR); + t.send(1, { type: "use_block", x: 0, y: 101, z: -2, face: "east", hit: [1, 0.5, 0.5] }); + assertEquals(state(1, 101, -2, "horizontal"), 1); + assertEquals(state(1, 101, -2, "facing"), 1); + t.send(1, { type: "use_block", x: 0, y: 101, z: -2, face: "south", hit: [0.5, 0.5, 1] }); + assertEquals(state(0, 101, -1, "horizontal"), 1); + assertEquals(state(0, 101, -1, "facing"), 2); +}); + Deno.test("a connecting block joins the same block beside it, and parts when it's gone", async () => { const { t, hold, state } = await setup(); hold(1);