Description
Plinth is designed to communicate between addons using scriptevent. This script can accept config for your addons that require configuration, and custom menus that you create yourself, suitable for novice dev.
Features
- custom menu & config
- permission system
- global & personal settings
- dev friendly
Installation & configuration
- download this pack
- extract the archive
- open file entry.js, do according to the existing instructions.
- Copy the class entry and all its contents then insert it into the file that you have provided in your addon
- change this
class Entry {
constructor(id, name, icon, kind) {
this.id = id; (e.g example)
this.name = name; // (e.g §bexample)
this.icon = icon; // (e.g textures/..)
this.kind = kind; // (e.g "menu"/"config")
if (kind !== "menu") {
this.desc = ""; // only if kind is config (e.g example description)
this.meta = {enabled: true, access: "hidden", intended: "hidden"};
this.defs = {}; // (content)
}
}
example for menu
import { Entry } from "./entry.js"; // < if not using import delete this but rewrite send
const example = Entry.menu(
"example", // id
"example", // name
"textures/.." // icon
);
example.send(); // < this, if you use import then it is enough like this, but if you don't use import then send must be rewritten like this.
Note : you MUST use scriptevent click:menuid custom menu and only for custom menu, and use scriptevent plinth:present if you need a fallback to standalone system and automatically merge to plinth if plinth is detected.
example for config
class Example {
constructor() {
this.id = "example";
this.name = "§bExample";
this.icon = "textures/items/compass_item";
this.kind = "config";
this.desc = "§7Example config with every field type.";
this.defs = {
header: {
type: "header",
label: "§eExample Header",
},
divider: {
type: "divider",
},
toggle: {
type: "toggle",
label: "Example Toggle",
default: true,
tooltip: "Example toggle tooltip",
},
slider: {
type: "slider",
label: "Example Slider",
default: 50,
min: 0,
max: 100,
step: 5,
tooltip: "Example slider tooltip",
},
textField: {
type: "textField",
label: "Example Text Field",
default: "",
placeholder: "Example placeholder...",
tooltip: "Example text field tooltip",
},
dropdown: {
type: "dropdown",
label: "Example Dropdown",
default: 0,
options: ["Example Option 1", "Example Option 2"],
tooltip: "Example dropdown tooltip",
},
};
this.meta = { enabled: true, access: "hidden", intended: "hidden" };
this._receive();
}
send() {
try {
const payload = {
id: this.id,
name: this.name,
icon: this.icon,
kind: this.kind,
desc: this.desc,
meta: this.meta,
defs: this.defs,
};
system.runTimeout(() => {
try {
const dim = world.getDimension("minecraft:overworld");
const json = JSON.stringify(payload);
const chunks = json.match(/.{1,2048}/g) ?? [json];
for (const chunk of chunks) {
dim.runCommand(`scriptevent load:${this.id} ${chunk}`);
}
} catch {}
});
} catch {}
}
}
How to use
- Open menu via command /p:mainmenu or uncomment /* */ in main.js to enable item function, and change item "minecraft:release" to the item you want (e.g minecraft:stick).
2. Click button to open the menu, if it has a subtext "enabled/disabled" it means it is a config, but if there isn't one it means it is a menu (unless you create a custom subtext).
How does it work
Simple, just two scriptevent, that is load: and sync:, one additional for the menu only namely click:menuid, and one for the plinth, namely plinth:present itself which is used for other addons as a detection that the plinth is there
1.Flow for menu
- ur addon send scriptevent load: > plinth accept it > parse > map
- u click the button > plinth send scriptevent click:menuid > ur addon receive scriptevent click:menuid > menu open
2. Flow for config
- ur addon send scriptevent load: > plinth accept it > parse > map > dynamic properties > plinth send scriptevent sync: > ur addon receive that > values applied
- u change value > save > scriptevent sync: > values applied
You are allowed to :
- uses or modify the entire entry.js file including the class entry and class manager for personal use
- using class entry and all its contents in class entry are for public use
You are not allowed to :
- modify the class manager and use it for public use