This package provides the TypeScript bindings for building Pumpkin plugins using WebAssembly (Wasm) components.
- Type-safe API: Full TypeScript definitions for all Pumpkin plugin interfaces.
- Easy Build Process: Includes a build script to bundle your TypeScript code and componentize it into a
.wasmfile. - Wasm Components: Built on the WebAssembly Component Model for high performance and portability.
npm install @pumpkinmc/pumpkin-api-ts- Create a new TypeScript file (e.g.,
my-plugin.ts). - Extend the
Pluginclass and implement themetadata()method. - Register your plugin using
registerPlugin(). - Add
export * from "@pumpkinmc/pumpkin-api-ts";at the end.
Example:
import { Plugin, registerPlugin } from "@pumpkinmc/pumpkin-api-ts";
import { PluginMetadata } from "pumpkin:plugin/[email protected]";
import { Context } from "pumpkin:plugin/[email protected]";
import { TextComponent } from "pumpkin:plugin/[email protected]";
import * as logging from "pumpkin:plugin/[email protected]";
import { Event } from "pumpkin:plugin/[email protected]";
class MyPlugin extends Plugin {
metadata(): PluginMetadata {
return {
name: "My TypeScript Plugin",
version: "0.1.0",
authors: ["alex"],
description: "A sample plugin written in TypeScript",
dependencies: [],
permissions: [],
};
}
onLoad(ctx: Context): void {
super.onLoad(ctx);
logging.log("info", "Hello from TypeScript plugin!");
this.registerEvent(ctx, "player-join", (_srv, evt: Event) => {
const data = evt.getPlayerJoin();
logging.log("info", `Player ${data.player.getName()} joined!`);
data.player
.getWorld()
.broadcastSystemMessage(
TextComponent.text(`Welcome ${data.player.getName()} to the server!`),
false,
);
});
}
}
registerPlugin(new MyPlugin());
export * from "@pumpkinmc/pumpkin-api-ts";To build your plugin into a .wasm component, use the provided build script:
./node_modules/.bin/pumpkin-plugin-build <entry-file.ts> <output-file.wasm>Example:
./node_modules/.bin/pumpkin-plugin-build my-plugin.ts build/my-plugin.wasmFor convience, it's recommended to add a scripts section to your package.json
{
"scripts": {
"build": "pumpkin-plugin-build my-plugin.ts build/my-plugin.wasm"
},
"dependencies": {
...
}
}Execute with npm run build