只读
实验性
早期执行
chatimport { world, DimensionLocation } from "@minecraft/server";
function customCommand(targetLocation: DimensionLocation) {
const chatCallback = world.beforeEvents.chatSend.subscribe((eventData) => {
if (eventData.message.includes("cancel")) {
// Cancel event if the message contains "cancel"
eventData.cancel = true;
} else {
const args = eventData.message.split(" ");
if (args.length > 0) {
switch (args[0].toLowerCase()) {
case "echo":
// Send a modified version of chat message
world.sendMessage(`Echo '${eventData.message.substring(4).trim()}'`);
break;
case "help":
world.sendMessage(`Available commands: echo <message>`);
break;
}
}
}
});
}
只读
早期执行
effect只读
早期执行
entity只读
早期执行
explosion只读
早期执行
item只读
早期执行
player只读
早期执行
player只读
早期执行
player只读
早期执行
player只读
早期执行
player只读
实验性
早期执行
player只读
早期执行
weather
表示一系列触发于实际动作发生之前的事件。通常来说,即将触发的事件可被修改或取消。 但请注意,在 before 类事件过程中,能够改变游戏状态的 API 将失效,试图调用将会抛出错误。 (例如:dimension.spawnEntity)
A set of events that fire before an actual action occurs. In most cases, you can potentially cancel or modify the impending event. Note that in before events any APIs that modify gameplay state will not function and will throw an error. (e.g., dimension.spawnEntity)