#How to make custom ui for new item
1 messages · Page 1 of 1 (latest)
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;
}
});
Tysm
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
Im not good at coding can you sent download pls ill just re-code it
what
Edit it to do what?
Idk how to open ui
Just asking but what fires the event
Is it looking for paper?
(New to form stuff and async functions)
Nvm I found out
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
Yeah I found that out
I removed async and broke it 😂