you shoudve post this in script api not in json ui, btw
1 make sure to change the version in the manifest to theese
{
"module_name": "@minecraft/server",
"version": "1.11.0-beta"
},
{
"module_name": "@minecraft/server-gametest",
"version": "1.0.0-beta"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.2.0-beta"
}
2 create script folder then create main.js
3 import in main.js this:
import { world, system, EquipmentSlot } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui"
4 when player clicks on item (copy that after imports)
world.afterEvents.itemUse.subscribe((eventData) => {
let player = eventData.source
let itemUse = eventData.itemStack.typeId
if (itemUse == "YOUR_NAMESPACE:YOUR_ITEM example: minecraft:compass") {
book(player); // book means open the book ui
}
});
5 book ui
function book(player) {// book is the name of the function make sure it mathes the opening
let mainForm = new ActionFormData()
.title("title")
.body("your text")
.button("button", "textures/ui/texture you want")
mainForm.show(player).then(result => {
if (result.selection === 0) { //if player select first button take him to tha page second
second(player);
}
})
}
then do the same and create another function changing the id the code is the same
function second(player) {// book is the name of the function make sure it mathes the opening
let mainForm = new ActionFormData()
.title("title")
.body("your text")
.button("button", "textures/ui/texture you want")
mainForm.show(player).then(result => {
if (result.selection === 0) { //if player select first button take him to tha page secondform
book(player);
}
})
}