#How to make custom ui for new item

1 messages · Page 1 of 1 (latest)

torpid wasp
#

How to make a ui menu but it will not affect the npc ui

charred rover
# torpid wasp How to make a ui menu but it will not affect the npc ui
import { ItemStack, world } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";

world.afterEvents.itemUse.subscribe(async function (event) {
    if (event.itemStack.typeId !== "minecraft:paper") return;
    const form = new ActionFormData();
    form.title("Title Text");
    form.body("Diamond or Dirt?");
    form.button("Diamond");
    form.button("Dirt");
    const result = await form.show(event.source);
    if (result.canceled) return;
    const inventory = event.source.getComponent("inventory");
    if (inventory === undefined) return;
    const container = inventory.container;
    if (container === undefined) return;
    switch (result.selection) {
        case 0: {
            container.addItem(new ItemStack("minecraft:diamond"))
        }; break;
        case 1: {
            container.addItem(new ItemStack("minecraft:dirt"));
        }; break;
    }
});
torpid wasp
#

Tysm

torpid wasp
#

But how can i edit this

import { ItemStack, world } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";

world.afterEvents.itemUse.subscribe(async function (event) {
if (event.itemStack.typeId !== "minecraft:paper") return;
const form = new ActionFormData();
form.title("Title Text");
form.body("Diamond or Dirt?");
form.button("Diamond");
form.button("Dirt");
const result = await form.show(event.source);
if (result.canceled) return;
const inventory = event.source.getComponent("inventory");
if (inventory === undefined) return;
const container = inventory.container;
if (container === undefined) return;
switch (result.selection) {
case 0: {
container.addItem(new ItemStack("minecraft:diamond"))
}; break;
case 1: {
container.addItem(new ItemStack("minecraft:dirt"));
}; break;
}
});

#

What should i do i don't know it

torpid wasp
charred rover
#

what

torpid wasp
#

To a file

#

Behavior?

torpid wasp
fierce aurora
#

Is it looking for paper?

#

(New to form stuff and async functions)

#

Nvm I found out

charred rover
#

ik you said you found out but async/await is just to wait for something

#

in this example, it awaits for the user to do something in the form

#

if forms wernt async it would freeze the entire gametest script until the user made a decision which wouldnt be ideal

#

async at the start of the function just tells the interpreter that you are going to be using await within it

#

@fierce aurora

fierce aurora
#

I removed async and broke it 😂