35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
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", {
|
|
// block data is saved with the world. on_tick and on_second only run for blocks that have some
|
|
on_create(block) {
|
|
block.data = { age: 0 };
|
|
},
|
|
// on_tick runs 20 times a second, on_second once, while a player is nearby
|
|
on_second(block) {
|
|
block.data.age += 1;
|
|
},
|
|
on_interact(block, params, player) {
|
|
player.send_message(`${params.message} It's been here for ${block.data?.age ?? 0} seconds.`);
|
|
// 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`);
|
|
});
|
|
}
|