Finish verdigris for now
This commit is contained in:
@@ -309,7 +309,7 @@ crushing, fan processing, steam, fluid splashes. Optional for gameplay, so it ca
|
||||
side) and goggles' overlay. A small API for drawing a label or an item at a point in the world, and a HUD element API,
|
||||
which is in bworld's types but throws today. Setting a scroll value is built, the way 0.5.0.j does it: a block with
|
||||
`"scrollable": true` gets the mouse wheel as `on_scroll`, and `send_message(text, { overlay: true })` shows the value
|
||||
above the hotbar until the box can show it (see the pulse repeater in REDSTONE.md).
|
||||
above the hotbar until the box can show it (see [Scrolling](docs/modding/blocks/components.md#scrolling)).
|
||||
|
||||
**R11. 3D in GUIs** (P3). Drawing a model or block in a screen, turned and animated, for the recipe viewer's Create
|
||||
categories (a press pressing over its recipe, like `compat/jei`), goggles and ponder.
|
||||
@@ -584,7 +584,7 @@ Check: a steam engine on a tank boiler, fed by a pump from water and heated by b
|
||||
- S3, in `mods/bworld` first.
|
||||
- Redstone link, nixie tube, display link and display board, threshold switch, smart observer, analog lever, pulse
|
||||
extender and timer, powered latch and toggle latch, contact, desk bell, sequenced gearshift. The pulse repeater is
|
||||
bworld's now, see REDSTONE.md. Clutch and gearshift switch to real signals.
|
||||
bworld's now. Clutch and gearshift switch to real signals.
|
||||
|
||||
Check: a factory that stops when a vault is full and shows its count on a display board.
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ deno task build && deno task server # packs the mods and starts a se
|
||||
show items
|
||||
- [Visuals](docs/modding/blocks/visuals.md): blocks drawn with code, like a shaft that turns
|
||||
- [Crops](docs/modding/blocks/crops.md): farming without writing code
|
||||
- [Verdigris](docs/modding/blocks/verdigris.md): blocks that make and use signals, like levers, torches and doors
|
||||
|
||||
**Items**
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
# Verdigris
|
||||
|
||||
Verdigris is the base game's redstone: power from 0 to 15 that wire carries from the blocks that make it to the blocks
|
||||
that use it. A block joins in by listing the base game's [components](components.md) in its JSON:
|
||||
`bworld:verdigris_source` to give power and `bworld:verdigris_input` to take it. Neither needs code. What a block gives
|
||||
or takes is one of its [states](states.md), so it's saved, sent to players and drawn with variants like any other state,
|
||||
and no script calls another mod's. A block that does something when it's powered, like a door opening, reacts to its
|
||||
input's state in its own component's `on_state_change`.
|
||||
|
||||
## How Power Works
|
||||
|
||||
Every block gives some power out of each of its 6 sides, 0 for most.
|
||||
|
||||
- A **source** gives power out of some of its sides. Some of those are **strong**, and also power a solid block there.
|
||||
- A [solid block](index.md#solid-blocks), like stone, makes no power, but it's powered by the strong sides pointing into
|
||||
it and by wire lying on it, and gives that to the blocks around it. That's how a lever on one side of a wall opens a
|
||||
door on the other. Wire lying on a solid block only takes what strong sides give it, not what other wire does, so a
|
||||
wire can't keep itself on through the block it lies on.
|
||||
- **Wire** carries power. Every wire joined to another is one net with one power, the most anything gives into any of
|
||||
it, however long it is. It joins the sides of blocks that make or take power, and gives its power to the blocks it
|
||||
lies on and the blocks it joins, not to ones it only runs past.
|
||||
- An **input** takes power from each of its sides: what the block there gives out of that side, that block's power if
|
||||
it's solid, or a wire's power when the wire lies on it or joins it. It's powered when any of them gives it more than
|
||||
0.
|
||||
|
||||
## Sides
|
||||
|
||||
Both components name a block's sides by face: `north`, `east`, `south`, `west`, `top` and `bottom`. A block that points
|
||||
somewhere can say `facing`, and then also name `front`, `back` and `sides`, the four around the way it points.
|
||||
|
||||
`facing` is a state's name. With 2 bits it's read as `north`, `east`, `south` and `west`, and with 3 bits as those, then
|
||||
`top` and `bottom`. For a block on a floor, wall or ceiling, like a lever, it's
|
||||
`{ "face": "face", "facing": "facing" }`: `face` 0 is the floor, where it points up, 1 a wall, where it points the way
|
||||
`facing` says, and 2 the ceiling, where it points down. Its `back` is the block it's on.
|
||||
|
||||
## `bworld:verdigris_source`
|
||||
|
||||
| Param | Default | Meaning |
|
||||
| ---------- | ---------- | ------------------------------------------------------------------------- |
|
||||
| `power` | | The power it gives, 0 to 15: a number, or the name of a state that has it |
|
||||
| `when` | | A 1 bit state. It only gives power while that's 1 |
|
||||
| `facing` | | Which way it points, see [Sides](#sides) |
|
||||
| `out` | every side | The sides it gives power out of |
|
||||
| `strong` | none | The sides that also power a solid block there |
|
||||
| `connects` | `out` | The sides wire joins |
|
||||
|
||||
Change the states it reads with `ctx.world.set_state` and the blocks beside it hear of it. The component tells the
|
||||
blocks around the solid blocks its strong sides power, which aren't beside it.
|
||||
|
||||
The verdigris block gives 15 out of every side, always:
|
||||
|
||||
```json
|
||||
"components": { "bworld:verdigris_source": { "power": 15 } }
|
||||
```
|
||||
|
||||
The lever gives 15 while it's `powered`, out of every side, and strongly into the block it's on. Its own component flips
|
||||
`powered` when it's right clicked:
|
||||
|
||||
```json
|
||||
"bworld:verdigris_source": {
|
||||
"power": 15,
|
||||
"when": "powered",
|
||||
"facing": { "face": "face", "facing": "facing" },
|
||||
"strong": ["back"]
|
||||
}
|
||||
```
|
||||
|
||||
The torch gives power out of every side but the block it's on, and strongly into the block above it:
|
||||
|
||||
```json
|
||||
"bworld:verdigris_source": {
|
||||
"power": 15,
|
||||
"when": "lit",
|
||||
"facing": "facing",
|
||||
"out": ["front", "sides"],
|
||||
"strong": ["top"]
|
||||
}
|
||||
```
|
||||
|
||||
## `bworld:verdigris_input`
|
||||
|
||||
| Param | Default | Meaning |
|
||||
| ---------- | ---------- | ------------------------------------------------------------- |
|
||||
| `state` | | A 1 bit state it keeps whether it's powered in: 1 while it is |
|
||||
| `facing` | | Which way it points, see [Sides](#sides) |
|
||||
| `in` | every side | The sides it takes power from |
|
||||
| `connects` | `in` | The sides wire joins |
|
||||
|
||||
The component works out its input when the block is placed and whenever a block beside it changes, and sets the state,
|
||||
which does nothing when it's already right. It's on or off: a state for how much power comes in isn't supported yet.
|
||||
|
||||
A trapdoor lists it with a `powered` state:
|
||||
|
||||
```json
|
||||
"components": {
|
||||
"bworld:trapdoor": {},
|
||||
"bworld:verdigris_input": { "state": "powered" }
|
||||
}
|
||||
```
|
||||
|
||||
and its server component opens it when `powered` changes, so one opened or closed by hand stays that way until the power
|
||||
does:
|
||||
|
||||
```ts
|
||||
ctx.components.register_block("bworld:trapdoor", {
|
||||
on_state_change(block, _params, before) {
|
||||
const powered = ctx.world.get_state(block.x, block.y, block.z, "powered");
|
||||
if (powered !== before.powered) ctx.world.set_state(block.x, block.y, block.z, "open", powered ? 1 : 0);
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## Both
|
||||
|
||||
A block can list both, like the pulse repeater, which takes power from behind it and gives it out of its front. Its
|
||||
component sets `powering` with a [scheduled tick](components.md#scheduled-ticks) once its delay is up:
|
||||
|
||||
```json
|
||||
"bworld:verdigris_source": {
|
||||
"power": 15,
|
||||
"when": "powering",
|
||||
"facing": "facing",
|
||||
"out": ["front"],
|
||||
"strong": ["front"],
|
||||
"connects": ["front", "back"]
|
||||
},
|
||||
"bworld:verdigris_input": { "state": "powered", "facing": "facing", "in": ["back"] }
|
||||
```
|
||||
|
||||
Wire joins a side when either component's `connects` names it. A block whose output leads back to its own input, like an
|
||||
inverter wired to itself, flips back and forth until the [neighbor update limit](components.md#changes) stops it, unless
|
||||
it waits a scheduled tick between flips. The torch waits 2 ticks, and burns out for a while when it flips too often.
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the blocks that make and use signals, see "Blocks" in REDSTONE.md. what they give out is their bworld:verdigris_source
|
||||
// params, this is what makes their states change
|
||||
// the blocks that make and use signals. what they give out is their bworld:verdigris_source params, this is what makes
|
||||
// their states change
|
||||
import type { BlockRef, Face, Position, ServerContext } from "bworld/server";
|
||||
import { power_from } from "./inputs.ts";
|
||||
import type { SignalReader } from "./signals.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the power blocks take in, see "How Power Works" in REDSTONE.md: a source's output, a solid block's power, and the
|
||||
// the power blocks take in, see docs/modding/blocks/verdigris.md: a source's output, a solid block's power, and the
|
||||
// power of wire that lies on them or joins them
|
||||
import type { Face } from "bworld/shared";
|
||||
import { block_power, type InputParams, MAX_POWER, output, sides_of, type SignalReader, WIRE } from "./signals.ts";
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// which faces of its cell a wire covers and what it joins, see "Joining" in REDSTONE.md. a wire cell covers some of its
|
||||
// six faces, each lying on the block on that side, and the wire on two faces that meet joins at that edge. a face's
|
||||
// other directions lead out of the cell, and its arm_ states say which of those it joins. the shared rule sets them the
|
||||
// same on the server and clients, and works out a join between two cells the same from either end
|
||||
// which faces of its cell a wire covers and what it joins. a wire cell covers some of its six faces, each lying on the
|
||||
// block on that side, and the wire on two faces that meet joins at that edge. a face's other directions lead out of the
|
||||
// cell, and its arm_ states say which of those it joins. the shared rule sets them the same on the server and clients,
|
||||
// and works out a join between two cells the same from either end
|
||||
import type { Face } from "bworld/shared";
|
||||
import { AIR, type BlockReader, connects, WIRE } from "./signals.ts";
|
||||
import { DIRECTIONS, FACES, OPPOSITE, step } from "./sides.ts";
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// verdigris's components, see REDSTONE.md: the wire, which keeps its net's power through the net index, sources,
|
||||
// inputs, and the devices
|
||||
// verdigris's components: the wire, which keeps its net's power through the net index, sources, inputs, and the devices
|
||||
import type { BlockRef, Face, Position, ServerContext } from "bworld/server";
|
||||
import { register_lever, register_pulse_repeater, register_torch } from "./devices.ts";
|
||||
import { arms_of, around_edge, can_cover, covers, face_states, faces_of, MAX_ARMS } from "./joins.ts";
|
||||
@@ -87,8 +86,8 @@ function set_input(ctx: ServerContext, world: SignalReader, block: BlockRef, par
|
||||
ctx.world.set_state(block.x, block.y, block.z, params.state, powered);
|
||||
}
|
||||
|
||||
// the wires on the next faces of the blocks a wire lies on, which it joins or could join around their edges. they aren't
|
||||
// among the six blocks beside it the engine tells
|
||||
// the wires on the next faces of the blocks a wire lies on, which it joins or could join around their edges. they
|
||||
// aren't among the six blocks beside it the engine tells
|
||||
function tell_around_edges(world: SignalWorld, block: BlockRef) {
|
||||
const faces = faces_of(world, block.x, block.y, block.z);
|
||||
for (const face of faces) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// verdigris placement and joins, see REDSTONE.md. rules, so a player sees a wire join or a lever turn to the wall the
|
||||
// moment they place it. power, delays and clicks are the server's, see server.ts
|
||||
// verdigris placement and joins. rules, so a player sees a wire join or a lever turn to the wall the moment they place
|
||||
// it. power, delays and clicks are the server's, see server.ts
|
||||
import type { BlockPlacement, Face, SharedContext } from "bworld/shared";
|
||||
import { arms_of, can_cover, face_states, faces_of } from "./joins.ts";
|
||||
import { type BlockReader, type InputParams, params_lookup, type SourceParams } from "./signals.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// faces, and the directions along them a wire lying on one runs, see REDSTONE.md
|
||||
// faces, and the directions along them a wire lying on one runs
|
||||
import type { Face } from "bworld/shared";
|
||||
|
||||
// the six faces in the order of a 3 bit facing state's values: a 2 bit facing's four, then top and bottom
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the power blocks give each other, see "How Power Works" in REDSTONE.md. every signal is a block state, so this only
|
||||
// the power blocks give each other, see docs/modding/blocks/verdigris.md. every signal is a block state, so this only
|
||||
// reads states, through a small world instead of ctx so it runs the same in shared scripts, server scripts and tests
|
||||
import type { Face, Id } from "bworld/shared";
|
||||
import { FACES, type FacingParam, front_of, named_sides, OPPOSITE, type SideName, step } from "./sides.ts";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// wire nets, see "Power" in REDSTONE.md: a wire cell and every wire cell it reaches through its joins are one net, and
|
||||
// they all have the same power, the most any block gives into any of them. a cell's faces always join each other, so
|
||||
// it's one piece of one net. NetIndex keeps the nets between changes, see "The Net Index"
|
||||
// wire nets: a wire cell and every wire cell it reaches through its joins are one net, and they all have the same
|
||||
// power, the most any block gives into any of them. a cell's faces always join each other, so it's one piece of one
|
||||
// net. NetIndex keeps the nets between changes
|
||||
import type { Face } from "bworld/shared";
|
||||
import { cell_through, faces_of, joins_out, ways_out } from "./joins.ts";
|
||||
import { type BlockReader, MAX_POWER, output, type SignalReader, solid_power } from "./signals.ts";
|
||||
@@ -77,9 +77,9 @@ function most(inputs: Map<number, number>) {
|
||||
}
|
||||
|
||||
// the nets of the wire cells anything has touched, kept between changes so most changes cost a few reads instead of a
|
||||
// walk, see "The Net Index" in REDSTONE.md. it's only in memory, and a cell it doesn't have is walked the first time
|
||||
// anything touches it, so it can't hold anything the world doesn't. the wire's server hooks call created, breaking,
|
||||
// reshaped and beside_changed
|
||||
// the nets of the wire cells anything has touched, kept between changes so most changes cost a few reads instead of a
|
||||
// walk. it's only in memory, and a cell it doesn't have is walked the first time anything touches it, so it can't hold
|
||||
// anything the world doesn't. the wire's server hooks call created, breaking, reshaped and beside_changed
|
||||
export class NetIndex {
|
||||
readonly #world: SignalWorld;
|
||||
// each cell's net, by packed position
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the blocks that make and use verdigris signals, see "Blocks" in REDSTONE.md
|
||||
// the blocks that make and use verdigris signals
|
||||
import { assert, assertAlmostEquals, assertEquals } from "@std/assert";
|
||||
import { bake_block, type BakedQuad, type ModelJson } from "$/common/block_models.ts";
|
||||
import { block_shape } from "$/common/block_shapes.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// verdigris wire, see REDSTONE.md: how it's drawn on the faces of its cell, how it joins, and its nets' power
|
||||
// verdigris wire: how it's drawn on the faces of its cell, how it joins, and its nets' power
|
||||
import { assert, assertAlmostEquals, assertEquals } from "@std/assert";
|
||||
import { Alea } from "@paulaboks/rng";
|
||||
import { bake_block, type BakedQuad, FACE_INDEX, type ModelJson } from "$/common/block_models.ts";
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// how long verdigris takes on a stone floor, see "Performance" in REDSTONE.md, and how many set_block messages a
|
||||
// player watching would get: placing a 1000 wire zigzag one wire at a time, a lever switching it, a block placed and
|
||||
// taken away beside it while it's powered, a wire broken out of its middle and put back, a lever switching a 64×64
|
||||
// grid, and a lever switching a tower of 50 torches. with the net index a wire took 0.5 ms to place however big its
|
||||
// net, a block beside the powered zigzag 0.1 ms and no wire messages, and switching took 15 to 20 ms for the zigzag and
|
||||
// 50 to 60 ms for the grid, about 15 µs a wire. walking the net on every change, a wire took 30 ms to place in the
|
||||
// zigzag and 400 ms in the grid, a block beside 20 ms, and switching 35 to 45 ms and 135 ms. the tower's 50 torches
|
||||
// changing over 102 ticks took about 3 ms more than the ticks did with nothing switched. repeater clocks come with
|
||||
// repeaters
|
||||
// how long verdigris takes on a stone floor, and how many set_block messages a player watching would get: placing a
|
||||
// 1000 wire zigzag one wire at a time, a lever switching it, a block placed and taken away beside it while it's
|
||||
// powered, a wire broken out of its middle and put back, a lever switching a 64×64 grid, and a lever switching a tower
|
||||
// of 50 torches. with the net index a wire took 0.5 ms to place however big its net, a block beside the powered zigzag
|
||||
// 0.1 ms and no wire messages, and switching took 15 to 20 ms for the zigzag and 50 to 60 ms for the grid, about 15 µs
|
||||
// a wire. walking the net on every change, a wire took 30 ms to place in the zigzag and 400 ms in the grid, a block
|
||||
// beside 20 ms, and switching 35 to 45 ms and 135 ms. the tower's 50 torches changing over 102 ticks took about 3 ms
|
||||
// more than the ticks did with nothing switched. repeater clocks come with repeaters
|
||||
// deno run -A tools/verdigris_bench.ts
|
||||
import type { Face } from "../common/mod_api/shared.ts";
|
||||
import { AIR_ID } from "../common/protocol.ts";
|
||||
|
||||
Reference in New Issue
Block a user