This commit is contained in:
2026-10-22 19:55:59 -03:00
parent 1b30d71a47
commit 4cd29a17b3
37 changed files with 427 additions and 155 deletions
+5 -3
View File
@@ -307,7 +307,9 @@ crushing, fan processing, steam, fluid splashes. Optional for gameplay, so it ca
**R10. In-world text and boxes** (P3). Create's value boxes (the number on a scroll value, filter slots on a block's
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.
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).
**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.
@@ -581,8 +583,8 @@ 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
repeater, extender and timer, powered latch and toggle latch, contact, desk bell, sequenced gearshift. Clutch and
gearshift switch to real signals.
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.
Check: a factory that stops when a vault is full and shows its count on a display board.
+7 -2
View File
@@ -25,7 +25,7 @@ import { back_to_title } from "./gui/title_screen.ts";
import { TICK_DELTA } from "$/common/constants.ts";
import { Container } from "$/common/inventory.ts";
import { PLAYER_MENU } from "$/common/protocol.ts";
import { EverythingRegistry } from "$/common/everything_registry.ts";
import { type BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
import type { EntityJson } from "$/common/mod_data.ts";
import { tick_texture_animations } from "./texture_animations.ts";
@@ -365,7 +365,12 @@ export class Client {
const previous = inventories.hotbar_selected;
const scroll = InputManager.get_wheel_delta();
if (scroll > 0) {
// at a block that takes the mouse wheel, like a pulse repeater's delay, it goes to the block instead
const hit = this.hit_result;
if (scroll !== 0 && hit && EverythingRegistry.get_by_id<BlockRegistry>("blocks", hit.block)?.scrollable) {
const { x, y, z, face } = hit;
this.connection.send({ type: "scroll_block", x, y, z, face, hit: hit.hit, amount: scroll < 0 ? 1 : -1 });
} else if (scroll > 0) {
inventories.hotbar_selected = Math.min(8, inventories.hotbar_selected + 1);
} else if (scroll < 0) {
inventories.hotbar_selected = Math.max(0, inventories.hotbar_selected - 1);
+30 -6
View File
@@ -33,6 +33,10 @@ const AIR_ROW_SPACING = 10;
const HELD_NAME_MS = 2000;
const HELD_NAME_FADE_MS = 500;
const HELD_NAME_GAP = 12;
// a server's overlay message, see MessageOptions.overlay: above the held item's name, for as long as minecraft's
const OVERLAY_MS = 3000;
const OVERLAY_FADE_MS = 500;
const OVERLAY_GAP = 4;
const CROSSHAIR_SIZE = 15;
// under the crosshair so it shows on bright sky and snow, minecraft inverts the colors behind it instead
const CROSSHAIR_SHADOW: [number, number, number, number] = [0, 0, 0, 0.4];
@@ -53,12 +57,21 @@ export class Hud {
// what was held last frame, as slot and item id, and when the held item last changed
#held = "";
#held_since = -Infinity;
#overlay = "";
#overlay_since = -Infinity;
// shows text above the hotbar for a moment, see MessageOptions.overlay
show_overlay(text: string) {
this.#overlay = text;
this.#overlay_since = performance.now();
}
render(client: Client) {
this.#render_hotbar(client.player.inventories);
this.#render_vitals(client);
const top = Math.min(icons_y() - heart_rows_height(client.player.max_health), air_y(client.player));
this.#render_held_name(client.player.inventories, top);
this.#render_overlay(top);
this.#render_crosshair(client);
this.#render_info(client);
client.chat.render(false, top - HELD_NAME_GAP);
@@ -97,12 +110,16 @@ export class Hud {
return;
}
const alpha = Math.min(1, (HELD_NAME_MS - shown_for) / HELD_NAME_FADE_MS);
const name = display_name(item.type_id);
const x = (canvas.width - measure_text(name, TEXT_SCALE)) / 2;
const y = top - HELD_NAME_GAP - TEXT_HEIGHT * TEXT_SCALE;
// a shadow so it reads over bright sky and snow
draw_text(name, x + TEXT_SCALE, y + TEXT_SCALE, TEXT_SCALE, [0.15, 0.15, 0.15, alpha]);
draw_text(name, x, y, TEXT_SCALE, [1, 1, 1, alpha]);
draw_centered(display_name(item.type_id), top - HELD_NAME_GAP - TEXT_HEIGHT * TEXT_SCALE, alpha);
}
// top is the top of the hearts, like for the held item's name, which it goes above
#render_overlay(top: number) {
const shown_for = performance.now() - this.#overlay_since;
if (shown_for > OVERLAY_MS) return;
const alpha = Math.min(1, (OVERLAY_MS - shown_for) / OVERLAY_FADE_MS);
const y = top - HELD_NAME_GAP - OVERLAY_GAP * GUI_SCALE - TEXT_HEIGHT * TEXT_SCALE * 2;
draw_centered(this.#overlay, y, alpha);
}
// hearts on the left and hunger on the right like minecraft, each icon 2 points. saturation is appleskin's outline
@@ -193,6 +210,13 @@ export class Hud {
}
}
// text across the middle of the screen at y, with a shadow so it reads over bright sky and snow
function draw_centered(text: string, y: number, alpha: number) {
const x = (canvas.width - measure_text(text, TEXT_SCALE)) / 2;
draw_text(text, x + TEXT_SCALE, y + TEXT_SCALE, TEXT_SCALE, [0.15, 0.15, 0.15, alpha]);
draw_text(text, x, y, TEXT_SCALE, [1, 1, 1, alpha]);
}
function hotbar_position() {
return {
x: Math.round((canvas.width - HOTBAR_WIDTH * GUI_SCALE) / 2),
+2 -1
View File
@@ -223,7 +223,8 @@ export class ClientPacketListener {
level.set_center(message.x, message.z);
break;
case "chat":
client.chat.add(message.from ? `<${message.from}> ${message.text}` : message.text);
if (message.overlay) client.game_renderer.hud.show_overlay(message.text);
else client.chat.add(message.from ? `<${message.from}> ${message.text}` : message.text);
break;
case "suggestions":
if (client.screen instanceof GuiChat) {
+2
View File
@@ -145,6 +145,8 @@ export interface BlockRegistry {
// right clicking it does something instead of placing a block, clients don't predict placing against it.
// behavior runs on the server, see server/game/blocks.ts
interactive?: boolean;
// the mouse wheel turned while looking at it goes to its components' on_scroll instead of the hotbar
scrollable?: boolean;
// placing a block into it replaces it, like water
replaceable?: boolean;
// the blocks (ids or #tags) it can stand on, like crops on farmland. it can't be placed elsewhere, and breaks when
+19 -1
View File
@@ -67,6 +67,9 @@ export interface BlockComponent<P = any> {
on_click?(block: BlockRef, params: P, player: Player): void;
// return true if it did something, so no block gets placed
on_interact?(block: BlockRef, params: P, player: Player): boolean;
// the player turned the mouse wheel while looking at it, for a block whose json has "scrollable": true, like a
// setting turned up and down. the wheel doesn't change their hotbar slot then
on_scroll?(block: BlockRef, params: P, player: Player, scroll: BlockScroll): void;
on_tick?(block: BlockRef, params: P, dt: number): void;
on_second?(block: BlockRef, params: P, dt: number): void;
// every morning at 06:00, for every block with data in the world, near a player or not. day is ServerWorld.day
@@ -318,6 +321,21 @@ export interface ServerWorld {
set_time(time: number): void;
}
// the mouse wheel turned at a block, see BlockComponent.on_scroll
export interface BlockScroll {
// how many notches, more than 0 turned up and less than 0 down
readonly amount: number;
readonly face: Face;
// where on the block they look, 0 to 1 on each axis, like BlockInteraction's
readonly hit: readonly [number, number, number];
}
export interface MessageOptions {
// shows it above their hotbar for a moment instead of in chat, like neoforge's overlay messages. for something
// that changes as they do it, like a setting they're scrolling through
overlay?: boolean;
}
export interface SetStateOptions {
// true when not given
update_neighbors?: boolean;
@@ -389,7 +407,7 @@ export interface Player {
readonly held_item: ItemStack | undefined;
// what doesn't fit in the inventory drops at their feet
give_item(id: Id, count?: number, data?: unknown): void;
send_message(text: string): void;
send_message(text: string, options?: MessageOptions): void;
// items drawn on them, under a key so each mod keeps its own list, like "bworld:curios". replaces what that key
// had, [] clears it. only items whose json has worn show. not saved: set it again when they join
set_worn(key: string, items: ItemStack[]): void;
+4 -1
View File
@@ -81,6 +81,7 @@ export interface BlockJson {
drops?: string;
item?: boolean;
interactive?: boolean;
scrollable?: boolean;
replaceable?: boolean;
place_on?: string[];
place_in?: string[];
@@ -320,6 +321,7 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
if (block.loot_table !== undefined) json.loot_table = block.loot_table;
if (!has_item) json.item = false;
if (block.interactive) json.interactive = true;
if (block.scrollable) json.scrollable = true;
if (!!block.replaceable !== !!block.liquid) json.replaceable = !!block.replaceable;
if (block.place_on) json.place_on = block.place_on;
if (block.place_in) json.place_in = block.place_in;
@@ -370,6 +372,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
if (json.drops !== undefined) block.drop_table = json.drops;
if (json.loot_table !== undefined) block.loot_table = json.loot_table;
if (json.interactive) block.interactive = true;
if (json.scrollable) block.scrollable = true;
if (json.replaceable ?? json.liquid) block.replaceable = true;
if (json.place_on) block.place_on = json.place_on;
if (json.place_in) block.place_in = json.place_in;
@@ -666,7 +669,7 @@ export function validate_block(json: unknown): Problems {
}
}
problems.push(...validate_text(json.name, "name"));
for (const key of ["cull_same", "transparent", "collision", "item", "interactive", "replaceable"]) {
for (const key of ["cull_same", "transparent", "collision", "item", "interactive", "scrollable", "replaceable"]) {
if (json[key] !== undefined && typeof json[key] !== "boolean") problems.push(`${key} must be true or false`);
}
if (json.tint !== undefined) {
+14 -2
View File
@@ -10,7 +10,7 @@ export const AIR_ID = "bworld:air";
// bump when a client and server of different versions can't play together.
// the server rejects a different version before the client downloads anything
export const PROTOCOL_VERSION = 23;
export const PROTOCOL_VERSION = 24;
export interface PlayerInfo {
id: string;
@@ -123,6 +123,17 @@ export type ClientMessage =
// right click on a block: interact with it, or place the held block against `face`. hit is where on the block it
// clicked, 0 to 1 on each axis, like minecraft's click location. seq is like break_block's
| { type: "use_block"; x: number; y: number; z: number; face: Faces; hit?: [number, number, number]; seq?: number }
// the mouse wheel turned while looking at a scrollable block, see BlockRegistry.scrollable. amount is how many
// notches, up above 0. face and hit are like use_block's
| {
type: "scroll_block";
x: number;
y: number;
z: number;
face: Faces;
hit: [number, number, number];
amount: number;
}
| { type: "select_slot"; slot: number }
// a slot of the open menu, or of menu 0 when none is. shift moves the stack to the other part of the menu instead,
// like minecraft's quick move. clicks for a menu that isn't open any more are ignored
@@ -224,7 +235,8 @@ export type ServerMessage =
// fields of a block's client data, see BlockRef.set_client_data. to the players who have the chunk: every field
// right after it, then each field when it changes. null when a field is gone, and every field when the block is
| { type: "block_data"; x: number; y: number; z: number; data: Record<string, unknown> }
| { type: "chat"; from?: string; text: string }
// overlay shows it above the hotbar for a moment instead of in chat, like how long a pulse repeater waits
| { type: "chat"; from?: string; text: string; overlay?: boolean }
// the player is here now. with motion, they're moving that fast (blocks per second) too: the server is moving them,
// like when knocked back, and the client keeps going that way until the next one. id counts up, see move
| { type: "teleport"; id: number; x: number; y: number; z: number; motion?: [number, number, number] }
+19
View File
@@ -65,6 +65,7 @@ component.
| `on_break(block, params, player?)` | The block is broken or replaced. `player` when a player broke it. | |
| `on_click(block, params, player)` | A player starts hitting it. | |
| `on_interact(block, params, player)` | A player right clicks it. | `true` if it did something |
| `on_scroll(block, params, player, scroll)` | A player turns the mouse wheel looking at it. See [Scrolling](#scrolling). | |
| `on_tick(block, params, dt)` | Every tick, 20 times a second, near a player. | |
| `on_second(block, params, dt)` | Every second, near a player. | |
| `on_new_day(block, params, day)` | Every morning at 06:00. See [Ticking](#ticking) for where. | |
@@ -214,6 +215,24 @@ on_interact(block) {
Give a block `"interactive": true` when right clicking it always does something, like opening a screen. Otherwise
clients guess that the click places the held block and show it for a moment before the server corrects them.
### Scrolling
A block whose JSON has `"scrollable": true` takes the mouse wheel: a player turning it while looking at the block, in
reach, runs its components' `on_scroll` on the server, and their hotbar slot stays where it is. It's for a setting that
goes up and down, like how long the pulse repeater waits. `scroll` is `{ amount, face, hit }`: how many notches, more
than 0 for up, and the face and point they look at, like `on_interact`'s. Clients don't guess what it does, so keep what
it changes in states or [client data](tiledata.md#client-data) for them to see, and show the new value with
`player.send_message(text, { overlay: true })`, which puts it above their hotbar for a moment. The pulse repeater's is
in `mods/bworld/scripts/verdigris/devices.ts`:
```ts
on_scroll(block, _params, player, scroll) {
const delay = Math.max(0, Math.min(PULSE_DELAYS.length - 1, state(block, "delay") + scroll.amount));
set(block, "delay", delay);
player.send_message(`Delay: ${delay_text(PULSE_DELAYS[delay])}`, { overlay: true });
},
```
### Ticking
`on_tick` and `on_second` only run for blocks that **have tile data**, within 6 chunks of a player. So a component that
+1
View File
@@ -64,6 +64,7 @@ there will be holes in the world behind them.
| `loot_table` | none | A [loot table](../resources/loot_tables.md) it drops from when broken instead, with its states and the tool. Not with `drops`. |
| `item` | `true` | Also register an item that places it, with the same id. To give that item more, see [Block Items](../items/index.md#block-items). |
| `interactive` | `false` | Right clicking it does something, like opening a screen, so clients don't guess that it places a block. |
| `scrollable` | `false` | The mouse wheel turned while looking at it goes to its components' `on_scroll` instead of the hotbar, see [Scrolling](components.md#scrolling). |
| `replaceable` | `false` | Placing a block into it replaces it, like water. Liquids default to `true`. |
| `place_in` | see meaning | Block ids or [tags](../resources/tags.md) it can be placed into, replacing them, like `["bworld:water"]` for rice. Air and `replaceable` blocks when not set. |
| `place_on` | anywhere | Block ids or [tags](../resources/tags.md) it can stand on, like `["bworld:hoed_dirt"]` for crops or `["#bworld:logs"]`. See [below](#placement). |
+1 -1
View File
@@ -29,7 +29,7 @@ interface Player {
readonly held_item: ItemStack | undefined;
give_item(id: string, count?: number, data?: unknown): void; // what doesn't fit drops at their feet
send_message(text: string): void;
send_message(text: string, options?: { overlay?: boolean }): void; // in chat, or above the hotbar with overlay
set_worn(key: string, items: ItemStack[]): void; // what's drawn on them, see Worn Items
teleport(x: number, y: number, z: number): void;
+32
View File
@@ -2237,3 +2237,35 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
# Create
https://github.com/Creators-of-Create/Create by simibubi and the Create team. The pulse repeater's textures
(`pulse_repeater_*.png`) and model (`models/pulse_repeater.json`) come from its version 0.5.0.j for Minecraft 1.19.3,
whose only license was this one:
license:
```
MIT License
Copyright (c) 2019 simibubi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
+64
View File
@@ -0,0 +1,64 @@
{
"format_version": 1,
"block": {
"id": "bworld:pulse_repeater",
"textures": {
"base": "bworld:pulse_repeater_base",
"top": "bworld:pulse_repeater_idle",
"torch": "bworld:verdigris_torch_off"
},
"model": "bworld:pulse_repeater",
"item_model": "bworld:pulse_repeater_item",
"render_layer": "cutout",
"shape": [[0, 0, 0, 16, 2, 16]],
"mining": { "toughness": 0 },
"drops": "bworld:pulse_repeater",
"interactive": true,
"scrollable": true,
"states": [
{ "name": "facing", "bits": 2, "default": 0 },
{ "name": "powered", "bits": 1, "default": 0 },
{ "name": "powering", "bits": 1, "default": 0 },
{ "name": "inverted", "bits": 1, "default": 0 },
{ "name": "delay", "bits": 8, "default": 0 }
],
"variants": {
"powered=1,powering=1": {
"textures": {
"base": "bworld:pulse_repeater_base",
"top": "bworld:pulse_repeater_powered_powering",
"torch": "bworld:verdigris_torch"
}
},
"powered=1": {
"textures": {
"base": "bworld:pulse_repeater_base",
"top": "bworld:pulse_repeater_powered",
"torch": "bworld:verdigris_torch_off"
}
},
"powering=1": {
"textures": {
"base": "bworld:pulse_repeater_base",
"top": "bworld:pulse_repeater_powering",
"torch": "bworld:verdigris_torch"
}
},
"facing=1": { "y": 90 },
"facing=2": { "y": 180 },
"facing=3": { "y": 270 }
},
"components": {
"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"] },
"bworld:pulse_repeater": {}
}
}
}
@@ -1,13 +1,7 @@
{
"format_version": 1,
"model": {
"id": "create:block_diodes_pulse_repeater",
"textures": {
"4": "create:block_diodes_brass_diode_base",
"particle": "create:block_diodes_brass_diode_base",
"top": "create:block_diodes_pulse_repeater_idle",
"torch": "bworld:verdigris_torch_off"
},
"id": "bworld:pulse_repeater",
"elements": [
{
"from": [5, 2.1, 5],
@@ -24,12 +18,12 @@
"from": [0, 0, 0],
"to": [16, 2, 16],
"faces": {
"north": { "texture": "#4", "uv": [0, 14, 16, 16] },
"east": { "texture": "#4", "uv": [0, 0, 2, 16], "rotation": 270 },
"south": { "texture": "#4", "uv": [0, 0, 16, 2], "rotation": 180 },
"west": { "texture": "#4", "uv": [14, 0, 16, 16], "rotation": 90 },
"north": { "texture": "#base", "uv": [0, 14, 16, 16] },
"east": { "texture": "#base", "uv": [0, 0, 2, 16], "rotation": 270 },
"south": { "texture": "#base", "uv": [0, 0, 16, 2], "rotation": 180 },
"west": { "texture": "#base", "uv": [14, 0, 16, 16], "rotation": 90 },
"top": { "texture": "#top", "uv": [0, 0, 16, 16] },
"bottom": { "texture": "#4", "uv": [0, 0, 16, 16] }
"bottom": { "texture": "#base", "uv": [0, 0, 16, 16] }
}
},
{
@@ -48,13 +42,7 @@
"west": { "texture": "#torch", "uv": [6, 5, 10, 11] }
}
},
{
"from": [7, 6, 1],
"to": [9, 7, 3],
"faces": {
"top": { "texture": "#torch", "uv": [7, 6, 9, 8] }
}
}
{ "from": [7, 6, 1], "to": [9, 7, 3], "faces": { "top": { "texture": "#torch", "uv": [7, 6, 9, 8] } } }
],
"display": {
"gui": { "rotation": [30, 45, 0], "translation": [0, 2.5, 0], "scale": [0.625, 0.625, 0.625] },
@@ -0,0 +1,8 @@
{
"format_version": 1,
"model": {
"id": "bworld:pulse_repeater_item",
"parent": "bworld:pulse_repeater",
"textures": { "top": "bworld:pulse_repeater_item" }
}
}
+55
View File
@@ -19,6 +19,16 @@ const TORCH_BURNOUT = 8;
const TORCH_BURNOUT_WINDOW = 60;
const TORCH_BURNOUT_TICKS = 160;
// how long a pulse repeater's pulse lasts, in ticks
const PULSE_TICKS = 2;
// the delays a pulse repeater's delay state picks from, in ticks: scrolled through a tick at a time below a second, a
// second at a time below a minute, then a minute at a time up to an hour
export const PULSE_DELAYS: readonly number[] = [
...Array.from({ length: 18 }, (_, i) => 2 + i),
...Array.from({ length: 59 }, (_, i) => 20 + i * 20),
...Array.from({ length: 60 }, (_, i) => 1200 + i * 1200),
];
// switched on and off by right clicking it, and it breaks when what it's on goes
export function register_lever(ctx: ServerContext) {
ctx.components.register_block("bworld:lever", {
@@ -94,6 +104,51 @@ export function register_torch(ctx: ServerContext, world: SignalReader) {
});
}
// once the block behind it is powered, it waits its delay and then gives a PULSE_TICKS pulse out of its front. it
// pulses once each time that block is powered, and while it's counting down or pulsing it doesn't start again. powering
// is its output, so inverted it's on, and the pulse turns it off. right clicking it inverts it, and scrolling the mouse
// wheel at it changes its delay
export function register_pulse_repeater(ctx: ServerContext) {
const state = (block: Position, name: string) => ctx.world.get_state(block.x, block.y, block.z, name) ?? 0;
const set = (block: Position, name: string, value: number) =>
ctx.world.set_state(block.x, block.y, block.z, name, value);
ctx.components.register_block("bworld:pulse_repeater", {
on_interact(block) {
set(block, "inverted", 1 - state(block, "inverted"));
set(block, "powering", 1 - state(block, "powering"));
return true;
},
on_scroll(block, _params, player, scroll) {
const delay = Math.max(0, Math.min(PULSE_DELAYS.length - 1, state(block, "delay") + scroll.amount));
set(block, "delay", delay);
player.send_message(`Delay: ${delay_text(PULSE_DELAYS[delay])}`, { overlay: true });
},
on_neighbor_change(block, _params, neighbor) {
breaks_without(ctx, block, "bottom", neighbor);
},
on_state_change(block, _params, before) {
const started = state(block, "powered") === 1 && before.powered === 0;
if (started && !ctx.world.has_scheduled_tick(block.x, block.y, block.z)) {
ctx.world.schedule_tick(block.x, block.y, block.z, PULSE_DELAYS[state(block, "delay")]);
}
},
// its delay is up and the pulse starts, or the pulse is over
on_scheduled_tick(block) {
const inverted = state(block, "inverted");
const pulsing = state(block, "powering") !== inverted;
set(block, "powering", pulsing ? inverted : 1 - inverted);
if (!pulsing) ctx.world.schedule_tick(block.x, block.y, block.z, PULSE_TICKS);
},
});
}
// a delay in ticks the way a player reads it: ticks below a second, then seconds, then minutes
function delay_text(ticks: number) {
if (ticks < 20) return `${ticks} ticks`;
const [count, unit] = ticks < 1200 ? [ticks / 20, "second"] : [ticks / 1200, "minute"];
return `${count} ${unit}${count === 1 ? "" : "s"}`;
}
// breaks a block that hangs from the block toward face when the neighbor that changed is that block and its face isn't
// something to attach to anymore. whether it broke
function breaks_without(ctx: ServerContext, block: BlockRef, face: Face, neighbor: Position) {
+2 -1
View File
@@ -4,7 +4,7 @@
// verdigris's components, see REDSTONE.md: 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_torch } from "./devices.ts";
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";
import { input_power } from "./inputs.ts";
import {
@@ -79,6 +79,7 @@ export function register_verdigris(ctx: ServerContext) {
register_lever(ctx);
register_torch(ctx, world);
register_pulse_repeater(ctx);
}
function set_input(ctx: ServerContext, world: SignalReader, block: BlockRef, params: InputParams) {
+8
View File
@@ -43,6 +43,14 @@ export function register_verdigris_rules(ctx: SharedContext) {
},
});
// on a floor, its front the way the player placing it looks, so it gives power away from them
ctx.components.register_block("bworld:pulse_repeater", {
state_for_placement(placement) {
const { x, y, z } = placement;
return ctx.world.is_face_sturdy(x, y - 1, z, "top") ? { facing: FACES.indexOf(placement.facing) } : false;
},
});
// on a floor pointing up, or on a wall pointing out of it. not under a ceiling
ctx.components.register_block("bworld:verdigris_torch", {
state_for_placement(placement) {
Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Before

Width:  |  Height:  |  Size: 313 B

After

Width:  |  Height:  |  Size: 313 B

Before

Width:  |  Height:  |  Size: 310 B

After

Width:  |  Height:  |  Size: 310 B

Before

Width:  |  Height:  |  Size: 320 B

After

Width:  |  Height:  |  Size: 320 B

Before

Width:  |  Height:  |  Size: 314 B

After

Width:  |  Height:  |  Size: 314 B

Before

Width:  |  Height:  |  Size: 319 B

After

Width:  |  Height:  |  Size: 319 B

-70
View File
@@ -1,70 +0,0 @@
{
"format_version": 1,
"block": {
"id": "create:pulse_repeater",
"textures": {},
"model": "create:block_diodes_pulse_repeater",
"variants": {
"facing=1,inverted=0,powered=0,powering=0": { "model": "create:block_diodes_pulse_repeater", "y": 270 },
"facing=1,inverted=0,powered=0,powering=1": { "model": "create:block_pulse_repeater_powering", "y": 270 },
"facing=1,inverted=0,powered=1,powering=0": { "model": "create:block_pulse_repeater_powered", "y": 270 },
"facing=1,inverted=0,powered=1,powering=1": {
"model": "create:block_pulse_repeater_powered_powering",
"y": 270
},
"facing=1,inverted=1,powered=0,powering=0": { "model": "create:block_pulse_repeater_powering", "y": 270 },
"facing=1,inverted=1,powered=0,powering=1": { "model": "create:block_diodes_pulse_repeater", "y": 270 },
"facing=1,inverted=1,powered=1,powering=0": {
"model": "create:block_pulse_repeater_powered_powering",
"y": 270
},
"facing=1,inverted=1,powered=1,powering=1": { "model": "create:block_pulse_repeater_powered", "y": 270 },
"facing=0,inverted=0,powered=0,powering=0": { "model": "create:block_diodes_pulse_repeater", "y": 180 },
"facing=0,inverted=0,powered=0,powering=1": { "model": "create:block_pulse_repeater_powering", "y": 180 },
"facing=0,inverted=0,powered=1,powering=0": { "model": "create:block_pulse_repeater_powered", "y": 180 },
"facing=0,inverted=0,powered=1,powering=1": {
"model": "create:block_pulse_repeater_powered_powering",
"y": 180
},
"facing=0,inverted=1,powered=0,powering=0": { "model": "create:block_pulse_repeater_powering", "y": 180 },
"facing=0,inverted=1,powered=0,powering=1": { "model": "create:block_diodes_pulse_repeater", "y": 180 },
"facing=0,inverted=1,powered=1,powering=0": {
"model": "create:block_pulse_repeater_powered_powering",
"y": 180
},
"facing=0,inverted=1,powered=1,powering=1": { "model": "create:block_pulse_repeater_powered", "y": 180 },
"facing=2,inverted=0,powered=0,powering=0": { "model": "create:block_diodes_pulse_repeater" },
"facing=2,inverted=0,powered=0,powering=1": { "model": "create:block_pulse_repeater_powering" },
"facing=2,inverted=0,powered=1,powering=0": { "model": "create:block_pulse_repeater_powered" },
"facing=2,inverted=0,powered=1,powering=1": { "model": "create:block_pulse_repeater_powered_powering" },
"facing=2,inverted=1,powered=0,powering=0": { "model": "create:block_pulse_repeater_powering" },
"facing=2,inverted=1,powered=0,powering=1": { "model": "create:block_diodes_pulse_repeater" },
"facing=2,inverted=1,powered=1,powering=0": { "model": "create:block_pulse_repeater_powered_powering" },
"facing=2,inverted=1,powered=1,powering=1": { "model": "create:block_pulse_repeater_powered" },
"facing=3,inverted=0,powered=0,powering=0": { "model": "create:block_diodes_pulse_repeater", "y": 90 },
"facing=3,inverted=0,powered=0,powering=1": { "model": "create:block_pulse_repeater_powering", "y": 90 },
"facing=3,inverted=0,powered=1,powering=0": { "model": "create:block_pulse_repeater_powered", "y": 90 },
"facing=3,inverted=0,powered=1,powering=1": {
"model": "create:block_pulse_repeater_powered_powering",
"y": 90
},
"facing=3,inverted=1,powered=0,powering=0": { "model": "create:block_pulse_repeater_powering", "y": 90 },
"facing=3,inverted=1,powered=0,powering=1": { "model": "create:block_diodes_pulse_repeater", "y": 90 },
"facing=3,inverted=1,powered=1,powering=0": {
"model": "create:block_pulse_repeater_powered_powering",
"y": 90
},
"facing=3,inverted=1,powered=1,powering=1": { "model": "create:block_pulse_repeater_powered", "y": 90 }
},
"states": [
{ "name": "facing", "bits": 2, "default": 0 },
{ "name": "inverted", "bits": 1, "default": 0 },
{ "name": "powered", "bits": 1, "default": 0 },
{ "name": "powering", "bits": 1, "default": 0 }
],
"render_layer": "cutout",
"mining": { "toughness": 1 },
"drops": "create:pulse_repeater",
"item_model": "create:item_pulse_repeater"
}
}
+4 -1
View File
@@ -29,4 +29,7 @@ turn it. Each block's fields there replace the ones the importer would write.
`block/radial_chassis_side_x` would both be `create:block_radial_chassis_side_x`.
Its `skip` leaves out the crimson and warped windows and window panes, and their models and textures, since bworld won't
have those woods.
have those woods. It leaves out the pulse repeater too, which is bworld's now
(`mods/bworld/blocks/pulse_repeater.json`): its id becomes bworld's, and so does the texture of the `indicator` model,
which uses the pulse repeater's. Its `textures` and `ids` also turn Minecraft's redstone torch into bworld's verdigris
torch.
+10 -1
View File
@@ -2,8 +2,17 @@
"models": {
"create:block/radial_chassis/": "create:block/radial_chassis/template_"
},
"textures": {
"minecraft:block/redstone_torch": "bworld:verdigris_torch",
"minecraft:block/redstone_torch_off": "bworld:verdigris_torch_off",
"create:block/diodes/pulse_repeater/idle": "bworld:pulse_repeater_idle"
},
"ids": {
"minecraft:redstone_torch": "bworld:verdigris_torch"
},
"skip": [
"crimson",
"warped"
"warped",
"pulse_repeater"
]
}
@@ -2,7 +2,7 @@
"format_version": 1,
"model": {
"id": "create:block_diodes_indicator",
"textures": { "flexpeater_off": "create:block_diodes_pulse_repeater_idle" },
"textures": { "flexpeater_off": "bworld:pulse_repeater_idle" },
"elements": [
{
"from": [3.96875, 1.96875, 3.96875],
@@ -1,8 +0,0 @@
{
"format_version": 1,
"model": {
"id": "create:block_pulse_repeater_powered",
"parent": "create:block_diodes_pulse_repeater",
"textures": { "top": "create:block_diodes_pulse_repeater_powered" }
}
}
@@ -1,8 +0,0 @@
{
"format_version": 1,
"model": {
"id": "create:block_pulse_repeater_powered_powering",
"parent": "create:block_diodes_pulse_repeater",
"textures": { "top": "create:block_diodes_pulse_repeater_powered_powering", "torch": "bworld:verdigris_torch" }
}
}
@@ -1,8 +0,0 @@
{
"format_version": 1,
"model": {
"id": "create:block_pulse_repeater_powering",
"parent": "create:block_diodes_pulse_repeater",
"textures": { "top": "create:block_diodes_pulse_repeater_powering", "torch": "bworld:verdigris_torch" }
}
}
@@ -1,8 +0,0 @@
{
"format_version": 1,
"model": {
"id": "create:item_pulse_repeater",
"parent": "create:block_diodes_pulse_repeater",
"textures": { "top": "create:block_diodes_pulse_repeater_item" }
}
}
@@ -24,7 +24,6 @@
"create:redstone_link",
"create:analog_lever",
"create:placard",
"create:pulse_repeater",
"create:pulse_extender",
{ "id": "#bworld:banners", "required": false },
{ "id": "#bworld:signs", "required": false }
@@ -3,9 +3,9 @@
"tag": {
"values": [
{ "id": "bworld:redstone_wire", "required": false },
{ "id": "bworld:verdigris_torch", "required": false },
"bworld:verdigris_torch",
{ "id": "bworld:repeater", "required": false },
{ "id": "bworld:lever", "required": false },
"bworld:lever",
{ "id": "bworld:comparator", "required": false },
{ "id": "bworld:observer", "required": false },
{ "id": "bworld:redstone_wall_torch", "required": false },
+48 -8
View File
@@ -562,8 +562,9 @@ export class GameServer {
return this.entities.all().filter((entity) => entity instanceof ItemEntity);
}
send_chat(player: ServerPlayer, text: string) {
this.#send(player, { type: "chat", text });
// in chat, or above their hotbar for a moment with overlay, see MessageOptions
send_chat(player: ServerPlayer, text: string, overlay = false) {
this.#send(player, overlay ? { type: "chat", text, overlay } : { type: "chat", text });
}
// a mod's server script to its client script, see ctx.net
@@ -1092,16 +1093,27 @@ export class GameServer {
// a client that hadn't heard it's using an item yet: what it guessed the click did, it didn't
this.#correct_use(player, message.x, message.y, message.z, message.face);
} else {
// the middle of the block when a client doesn't say, or says something that isn't on it
const hit = Array.isArray(message.hit) && message.hit.length === 3 &&
message.hit.every((v) => typeof v === "number" && v >= 0 && v <= 1)
? message.hit
: [0.5, 0.5, 0.5];
this.#use_block(player, message.x, message.y, message.z, message.face, hit);
this.#use_block(
player,
message.x,
message.y,
message.z,
message.face,
hit_on_block(message.hit),
);
}
}
this.#ack(player, message.seq);
break;
case "scroll_block":
if (
is_block_position(message.x, message.y, message.z) && faces.includes(message.face) &&
is_int(message.amount) && message.amount !== 0
) {
const { x, y, z, face, amount } = message;
this.#scroll_block(player, x, y, z, face, hit_on_block(message.hit), amount);
}
break;
case "select_slot":
if (is_int(message.slot) && message.slot >= 0 && message.slot < 9) {
if (message.slot !== player.selected_slot) player.attack_strength_ticker = 0;
@@ -1277,6 +1289,26 @@ export class GameServer {
this.#correct(player, target.x, target.y, target.z);
}
// the mouse wheel turned at a scrollable block in reach: its components' on_scroll
#scroll_block(
player: ServerPlayer,
x: number,
y: number,
z: number,
face: Faces,
hit: [number, number, number],
amount: number,
) {
const info = this.world.get_block_info(x, y, z);
if (!info?.scrollable || !this.#in_reach(player, x, y, z)) return;
const block = this.mods.block_ref(x, y, z, info.id);
const player_api = this.mods.player(player);
const scroll = { amount, face, hit };
for (const { mod, id, component, params } of this.mods.components_with(info.id, "on_scroll")) {
run_guarded(mod, `${id} on_scroll`, () => component.on_scroll!(block, params, player_api, scroll));
}
}
#use_block(player: ServerPlayer, x: number, y: number, z: number, face: Faces, hit: number[]) {
const info = this.world.get_block_info(x, y, z);
const target = placement_target(x, y, z, FACE_OFFSETS[face], info);
@@ -2391,6 +2423,14 @@ function view_distance(requested: unknown, server: number): number {
return Math.min(server, Math.max(MIN_VIEW_DISTANCE, Math.min(MAX_VIEW_DISTANCE, requested)));
}
// where on a block a client says it clicked or looks, 0 to 1 on each axis. the middle when it doesn't say, or says
// something that isn't on it
function hit_on_block(hit: unknown): [number, number, number] {
return Array.isArray(hit) && hit.length === 3 && hit.every((v) => typeof v === "number" && v >= 0 && v <= 1)
? [hit[0], hit[1], hit[2]]
: [0.5, 0.5, 0.5];
}
// messages are parsed json, so the types in ClientMessage are only what a well behaved client sends
function is_block_position(x: unknown, y: unknown, z: unknown): boolean {
return is_int(x) && is_int(y) && is_int(z) && y >= 0 && y < CHUNK_HEIGHT &&
+2 -2
View File
@@ -1383,8 +1383,8 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
if (!EverythingRegistry.get("items", id)) throw new Error(`unknown item ${id}`);
game.give(player, id, count, data);
},
send_message(text) {
game.send_chat(player, String(text));
send_message(text, options) {
game.send_chat(player, String(text), options?.overlay === true);
},
set_worn(key, items) {
if (typeof key !== "string" || key.length === 0) throw new Error('set_worn needs a key, like "mymod:hats"');
+80
View File
@@ -258,3 +258,83 @@ Deno.test("a trapdoor opens while it's powered, and opens straight away when it'
b.use(TRAPDOOR, 3, 99, 0, "top", [3, 100, 2]);
assertEquals(open(b, [3, 100, 0]), true);
});
const PULSE_REPEATER = "bworld:pulse_repeater";
// a pulse repeater at 0 100 0 placed by alice looking north, so it gives power north, with a lever behind it and wire on
// the floor in front of it. the wire's power after each of ticks ticks
async function pulse_repeater() {
const b = await builder();
b.use(PULSE_REPEATER, 0, 99, 0, "top", [0, 100, 2]);
assertEquals(b.states(0, 100, 0).facing, FACES.indexOf("north"));
b.use("bworld:lever", 0, 99, 1, "top", [0, 100, 3]);
b.use("bworld:verdigris", 0, 99, -1, "top", [0, 100, 2]);
const switch_lever = () => b.use(undefined, 0, 100, 1, "top", [0, 100, 3]);
const wire = (ticks: number) =>
Array.from({ length: ticks }, () => {
b.t.game.tick();
return b.power(0, 100, -1);
});
const scroll = (amount: number, at: Pos = [0, 100, 0]) =>
b.t.send(1, { type: "scroll_block", x: at[0], y: at[1], z: at[2], face: "top", hit: [0.5, 1, 0.5], amount });
const overlays = () => b.t.take(1).filter((m) => m.type === "chat" && m.overlay).map((m) => m.text);
return { ...b, switch_lever, wire, scroll, overlays };
}
Deno.test("a pulse repeater pulses out of its front its delay after what's behind it is powered, once each time", async () => {
const b = await pulse_repeater();
b.switch_lever();
// 2 ticks by default, then 2 ticks of power, and no more while the lever stays on
assertEquals(b.wire(10), [0, 15, 15, 0, 0, 0, 0, 0, 0, 0]);
b.switch_lever();
assertEquals(b.wire(4), [0, 0, 0, 0]);
b.switch_lever();
assertEquals(b.wire(4), [0, 15, 15, 0]);
});
Deno.test("scrolling the mouse wheel at a pulse repeater changes its delay, and shows it above the hotbar", async () => {
const b = await pulse_repeater();
b.overlays();
b.scroll(1);
assertEquals(b.overlays(), ["Delay: 3 ticks"]);
// a tick at a time up to a second, then seconds
b.scroll(17);
b.scroll(1);
assertEquals(b.overlays(), ["Delay: 1 second", "Delay: 2 seconds"]);
b.switch_lever();
const wire = b.wire(42);
assertEquals([wire.indexOf(15), wire.lastIndexOf(15)], [39, 40]);
// it goes no further than an hour, and no lower than 2 ticks
b.scroll(1000);
b.scroll(-1);
b.scroll(-1000);
assertEquals(b.overlays(), ["Delay: 60 minutes", "Delay: 59 minutes", "Delay: 2 ticks"]);
// blocks that aren't scrollable and ones out of reach don't hear it
b.scroll(1, [0, 99, 0]);
b.t.game.teleport(b.t.game.players()[0], 0.5, 100, 20.5);
b.scroll(1);
assertEquals(b.overlays(), []);
assertEquals(b.states(0, 100, 0).delay, 0);
});
Deno.test("right clicking a pulse repeater inverts it, so it's on and its pulse turns it off", async () => {
const b = await pulse_repeater();
b.use(undefined, 0, 100, 0, "top", [0, 100, 2]);
assertEquals(b.power(0, 100, -1), 15);
b.switch_lever();
assertEquals(b.wire(4), [15, 0, 0, 15]);
b.use(undefined, 0, 100, 0, "top", [0, 100, 2]);
assertEquals(b.power(0, 100, -1), 0);
});
Deno.test("a pulse repeater only goes on a floor, and breaks when the floor goes", async () => {
const b = await builder();
b.t.game.set_block(3, 101, 3, "bworld:stone");
b.use(PULSE_REPEATER, 3, 101, 3, "south", [3, 101, 6]);
assertEquals(b.id(3, 101, 4), AIR_ID);
b.use(PULSE_REPEATER, 3, 101, 3, "top", [3, 102, 6]);
assertEquals(b.id(3, 102, 3), PULSE_REPEATER);
b.t.game.set_block(3, 101, 3, AIR_ID);
assertEquals(b.id(3, 102, 3), AIR_ID);
});