This commit is contained in:
2026-09-24 23:28:01 -03:00
parent 79faa556de
commit bb42dd662e
73 changed files with 2349 additions and 34 deletions
+14
View File
@@ -0,0 +1,14 @@
import type { ClientContext } from "bworld/client";
// called on every player's client after the mod is downloaded, before the world shows up.
// everything here is visible to players, so keep secrets and game rules in server.ts
export function setup(ctx: ClientContext) {
ctx.log("loaded");
// a HUD element, drawn every frame
// ctx.hud.register("example_mod:hint", {
// on_render(g) {
// g.text("example mod is here", 8, 8);
// },
// });
}
+26
View File
@@ -0,0 +1,26 @@
import type { ServerContext } from "bworld/server";
// called once when the server starts
export function setup(ctx: ServerContext) {
// used by blocks/example_block.json, which passes { message } as params
ctx.components.register_block<{ message: string }>("example_mod:announce", {
on_interact(_block, params, player) {
player.send_message(params.message);
// handled, so right clicking it doesn't place a block
return true;
},
});
// /example_mod:hello, or /hello when no other mod uses that name
ctx.commands.register("hello", {
description: "Say hello",
usage: "/hello",
run(_args, player) {
player.send_message(`Hello ${player.name}!`);
},
});
ctx.events.after.player_join.subscribe(({ player }) => {
ctx.log(`${player.name} joined`);
});
}
+15
View File
@@ -0,0 +1,15 @@
import type { WorldgenContext } from "bworld/worldgen";
// runs in chunk workers on the server and every client, which must all generate the same world.
// only use chunk.rng and the noise helpers, never Math.random or the time
export function setup(gen: WorldgenContext) {
// a boulder on one chunk in ten
gen.register_feature("example_mod:boulders", (chunk) => {
if (chunk.rng.next() > 0.1) {
return;
}
const x = chunk.x * 16 + Math.floor(chunk.rng.next() * 16);
const z = chunk.z * 16 + Math.floor(chunk.rng.next() * 16);
chunk.set_block(x, chunk.height_at(x, z) + 1, z, "bworld:stone");
});
}