SAPI1.mcpack(2.11 KB, 下载次数: 5)
- import { world, system } from "@minecraft/server"
- import { ActionFormData, MessageFormData, ModalFormData } from "@minecraft/server-ui"
- world.beforeEvents.itemUseOn.subscribe((event) => {
- const huchu = event.itemStack
- const player = event.source
- if (item.typeId == `minecraft:snowball`) system.run(() => Action(player))
-
- function Action(player) {
- const Action = new ActionFormData()
- .title(`SAPI测试1|作者KLPBBS星空晶体`)
- .body(`下方测试`)
- .button(`时间设置`)
- .button(`效果设置`)
- .button(`清除设置`)
- .button(`矿物给予`)
- .button(`当前位置设置重生点`)
- .button(`游戏模式`)
- .show(player)
- .then((Action) => {
- if (Action.selection == 0) {
- timeshzh(player)
- }
- if (Action.selection == 1) {
- effectshzh(player)
- }
- if (Action.selection == 2) {
- killshzh(player)
- }
- if (Action.selection == 3) {
- oregiving(player)
- }
- if (Action.selection == 4) {
- player.runCommand(`setworldspawn`)
- }
- if (Action.selection == 5) {
- mode(player)
- }
- })
- }
- function timeshzh(player) {
- const timeshzh = new ActionFormData()
- .title(`时间设置`)
- .body(`下方设置`)
- .button(`日出`)
- .button(`白天`)
- .button(`正午`)
- .button(`傍晚`)
- .button(`夜晚`)
- .button(`午夜`)
- .show(player)
- .then((timeshzh) => {
- if (timeshzh.selection == 0) {
- player.runCommand(`time set sunrise`)
- player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间: 日出`}]})
- }
- if (timeshzh.selection == 1) {
- player.runCommand(`time set day`)
- player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间:白日`}]})
- }
- if (timeshzh.selection == 2) {
- player.runCommand(`time set noon`)
- player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间:中午`}]})
- }
- if (timeshzh.selection == 3) {
- player.runCommand(`time set sunset`)
- player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间: 傍晚`}]})
- }
- if (timeshzh.selection == 4) {
- player.runCommand(`time set night`)
- player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间: 夜晚`}]})
- }
- if (timeshzh.selection == 5) {
- player.runCommand(`time set midnight`)
- player.onScreenDisplay.setActionBar({"rawtext":[{"text":`时间: 正夜`}]})
- }
- })
- }
- function effectshzh(player) {
- const effectshzh = new ModalFormData()
- .title(`药水效果`)
- .toggle(`瞬间治疗`,false)
- .toggle(`夜视`,false)
- .toggle(`饱和`,false)
- .toggle(`抗性`,false)
- .toggle(`生命恢复`,false)
- .toggle(`速度`,false)
- .toggle(`水下呼吸`,false)
- .toggle(`力量`,false)
- .toggle(`隐身`,false)
- .toggle(`跳跃增强`,false)
- .toggle(`急迫`,false)
- .toggle(`抗火`,false)
- .show(player)
- .then((effectshzh) {
- if (effectshzh.formValues[0] == true) {
- player.runCommand(`effect ${player.nameTag} instant_health 99999 255 true`)
- }
- if (effectshzh.formValues[1] == true) {
- player.runCommand(`effect ${player.nameTag} night_vision 99999 255 true`)
- }
- if (effectshzh.formValues[2] == true) {
- player.runCommand(`effect ${player.nameTag} saturation 99999 255 true`)
- }
- if (effectshzh.formValues[3] == true) {
- player.runCommand(`effect ${player.nameTag} resistance 99999 255 true`)
- }
- if (effectshzh.formValues[4] == true) {
- player.runCommand(`effect ${player.nameTag} regeneration 99999 255 true`)
- }
- if (effectshzh.formValues[5] == true) {
- player.runCommand(`effect ${player.nameTag} speed 99999 10 true`)
- }
- if (effectshzh.formValues[6] == true) {
- player.runCommand(`effect ${player.nameTag} water_breathing 99999 255 true`)
- }
- if (effectshzh.formValues[7] == true) {
- player.runCommand(`effect ${player.nameTag} strength 99999 255 true`)
- }
- if (effectshzh.formValues[8] == true) {
- player.runCommand(`effect ${player.nameTag} invisibility 99999 255 true`)
- }
- if (effectshzh.formValues[9] == true) {
- player.runCommand(`effect ${player.nameTag} fire_resistance 99999 255 true`)
- }
- if (effectshzh.formValues[10] == true) {
- player.runCommand(`effect ${player.nameTag} jump_boost 99999 10 true`)
- }
- if (effectshzh.formValues[11] == true) {
- player.runCommand(`effect ${player.nameTag} haste 99999 10 true`)
- }
- })
- }
- function killshzh(player) {
- const killshzh = new ActionFormData()
- .title(`清除目标选择`)
- .button(`清除随机玩家(需多人)`)
- .button(`清除所有玩家`)
- .button(`清除所有实体`)
- .button(`清除命令执行者`)
- .show(player)
- .then((killshzh) {
- if (killshzh.selection == 0) {
- player.runCommand(`kill @r`)
- }
- if (killshzh.selection == 1) {
- player.runCommand(`kill @a`)
- }
- if (killshzh.selection == 2) {
- player.runCommand(`kill @e`)
- }
- if (killshzh.selection == 3) {
- player.runCommand(`kill @s`)
- }
- })
- }
- function oregiving(player) {
- const oregiving = new ActionFormData()
- .title(`矿物给予`)
- .button(`没写,累[悲]`)
- .show(player)
- .then((oregiving) {
- if (oregiving.selection == 0) {
- player.runCommand(`say 偷懒一下,下个版本再写[滑稽]`)
- }
- }
- }
- function mode(player) {
- const mode = new ModalFormData()
- .title(`游戏模式`)
- .dropdown(`模式选择`,[`生存`,`创造`,`冒险`,`旁观`],0)
- .show(player)
- .then((mode) {
- if (mode.formValues[0] == `生存`) {
- player.runCommand(`gamemode survival`)
- } else if (mode.formValues[1] == `创造`){
- player.runCommand(`gamemode creative`)
- } else if (mode.formValues[2] == `冒险`) {
- player.runCommand(`gamemode adventure`)
- } else {
- player.runCommand(`gamemode spectator`)
- }
- })
- }
复制代码
|