Used to create a fully customizable pop-up form for a player.
import { Player, world } from "@minecraft/server";import { ModalFormData } from "@minecraft/server-ui";let form = new ModalFormData();let effectList = [ { name: "Regeneration", id: "minecraft:regeneration" }, { name: "Resistance", id: "minecraft:resistance" }, { name: "Fire Resistance", id: "minecraft:fire_resistance" }, { name: "Poison", id: "minecraft:poison" },];form.title("Effect Generator");form.textField("Target", "Target of Effect");form.dropdown( "Effect Type", effectList.map((effect) => effect.name));form.slider("Effect Level", 0, 255, 1);form.toggle("Hide Effect Particle", true);for (const player of world.getAllPlayers()) { form.show(player).then((response) => { if (response.canceled) { player.sendMessage("Canceled due to " + response.cancelationReason); } else { const [targetName, dropdownValue, effectLevel, hideParticles] = response.formValues; if ( typeof dropdownValue !== "string" || typeof dropdownValue !== "number" || typeof effectLevel !== "number" || typeof hideParticles !== "boolean" ) return player.sendMessage("Cannot process form result."); const target = world .getAllPlayers() .find((player) => player.name === targetName); if (!(target instanceof Player)) return player.sendMessage("Target does not exist."); target.addEffect(effectList[dropdownValue].id, 50, { amplifier: effectLevel, showParticles: !hideParticles, }); } });} Copy
import { Player, world } from "@minecraft/server";import { ModalFormData } from "@minecraft/server-ui";let form = new ModalFormData();let effectList = [ { name: "Regeneration", id: "minecraft:regeneration" }, { name: "Resistance", id: "minecraft:resistance" }, { name: "Fire Resistance", id: "minecraft:fire_resistance" }, { name: "Poison", id: "minecraft:poison" },];form.title("Effect Generator");form.textField("Target", "Target of Effect");form.dropdown( "Effect Type", effectList.map((effect) => effect.name));form.slider("Effect Level", 0, 255, 1);form.toggle("Hide Effect Particle", true);for (const player of world.getAllPlayers()) { form.show(player).then((response) => { if (response.canceled) { player.sendMessage("Canceled due to " + response.cancelationReason); } else { const [targetName, dropdownValue, effectLevel, hideParticles] = response.formValues; if ( typeof dropdownValue !== "string" || typeof dropdownValue !== "number" || typeof effectLevel !== "number" || typeof hideParticles !== "boolean" ) return player.sendMessage("Cannot process form result."); const target = world .getAllPlayers() .find((player) => player.name === targetName); if (!(target instanceof Player)) return player.sendMessage("Target does not exist."); target.addEffect(effectList[dropdownValue].id, 50, { amplifier: effectLevel, showParticles: !hideParticles, }); } });}
Optional
Adds a dropdown with choices to the form.
This function can't be called in read-only mode.
Player to show this dialog to.
Creates and shows this modal popup form. Returns asynchronously when the player confirms or cancels the dialog.
This function can throw errors.
Adds a numeric slider to the form.
Adds a textbox to the form.
This builder method sets the title for the modal dialog.
Adds a toggle checkbox button to the form.
Used to create a fully customizable pop-up form for a player.
Example: effectGenerator.js