modalForm.textField('Input w/o default', 'type text here'); modalForm.textField('Input w/ default', 'type text here', 'this is default');
modalForm .show(player) .then(formData=> { player.sendMessage(`Modal form results: ${JSON.stringify(formData.formValues, undefined, 2)}`); }) .catch((error: Error) => { player.sendMessage('Failed to show form: ' + error); return -1; }); }
Example: effectGenerator.js
import { Player, world } from"@minecraft/server"; import { ModalFormData } from"@minecraft/server-ui"; letform = newModalFormData(); leteffectList = [ { 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 (constplayerofworld.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 ( typeofdropdownValue !== "string" || typeofdropdownValue !== "number" || typeofeffectLevel !== "number" || typeofhideParticles !== "boolean" ) returnplayer.sendMessage("Cannot process form result."); consttarget = world .getAllPlayers() .find((player) =>player.name === targetName); if (!(targetinstanceofPlayer)) returnplayer.sendMessage("Target does not exist."); target.addEffect(effectList[dropdownValue].id, 50, { amplifier:effectLevel, showParticles: !hideParticles, }); } }); }
Effect Generator Form Preview
Modal Form v2.0.0-beta features
@minecraft/server-ui v2.0.0-beta module currently adds headers, dividers, labels and more. The following images demostrates those features (subject to change).
Used to create a fully customizable pop-up form for a player.
Example: modalFormSimple.ts
Example: effectGenerator.js
Effect Generator Form Preview
Modal Form v2.0.0-beta features
@minecraft/server-ui v2.0.0-beta module currently adds headers, dividers, labels and more. The following images demostrates those features (subject to change).