For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server/classes/WorldBeforeEvents.md.

Class: WorldBeforeEvents

event world

Beta

表示一系列触发于实际动作发生之前的事件。通常来说,即将触发的事件可被修改或取消。 但请注意,在 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)

Properties

chatSend

实验性

readonly chatSend: ChatSendBeforeEventSignal

Beta Early Execution

Remarks

此事件在聊天消息被广播或发送给玩家之后触发。

This event is triggered after a chat message has been broadcast or sent to players.

Example

customCommand.ts

import { 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;
        }
      }
    }
  });
}

effectAdd

readonly effectAdd: EffectAddBeforeEventSignal

Early Execution Beta

Remarks

此事件在某个效果被添加到实体之后触发。

This event is triggered after an event has been added to an entity.


entityHeal

readonly entityHeal: EntityHealBeforeEventSignal

Early Execution Beta

Remarks


entityHurt

readonly entityHurt: EntityHurtBeforeEventSignal

Early Execution Beta

Remarks


entityItemPickup

readonly entityItemPickup: EntityItemPickupBeforeEventSignal

Early Execution Beta

Remarks

此事件在实体被拾取物品之前触发。

This event fires before an entity picks up an item.


entityRemove

readonly entityRemove: EntityRemoveBeforeEventSignal

Early Execution Beta

Remarks

在实体从世界中被移除之前触发(例如,被卸载或在被杀死后被 移除)。

Fires before an entity is removed from the world (for example, unloaded or removed after being killed.)


entityTamed

实验性

readonly entityTamed: EntityTamedBeforeEventSignal

Beta Early Execution

Remarks

在实体被驯服之前触发。

Fires before an entity is tamed.


explosion

readonly explosion: ExplosionBeforeEventSignal

Early Execution Beta

Remarks

此事件在爆炸发生之后触发。

This event is fired after an explosion occurs.


itemUse

readonly itemUse: ItemUseBeforeEventSignal

Early Execution Beta

Remarks

此事件在物品被玩家成功使用时触发。

This event fires when an item is successfully used by a player.


playerBreakBlock

readonly playerBreakBlock: PlayerBreakBlockBeforeEventSignal

Early Execution Beta

Remarks

此事件在方块被玩家破坏之前触发。

This event fires before a block is broken by a player.


playerGameModeChange

readonly playerGameModeChange: PlayerGameModeChangeBeforeEventSignal

Early Execution Beta

Remarks


playerInteractWithBlock

readonly playerInteractWithBlock: PlayerInteractWithBlockBeforeEventSignal

Early Execution Beta

Remarks

在玩家与方块交互之前触发。

Fires before a player interacts with a block.


playerInteractWithEntity

readonly playerInteractWithEntity: PlayerInteractWithEntityBeforeEventSignal

Early Execution Beta

Remarks

在玩家与实体交互之前触发。

Fires before a player interacts with an entity.


playerLeave

readonly playerLeave: PlayerLeaveBeforeEventSignal

Early Execution Beta

Remarks

在玩家离开游戏时触发。

Fires when a player leaves the game.


playerPlaceBlock

实验性

readonly playerPlaceBlock: PlayerPlaceBlockBeforeEventSignal

Beta Early Execution

Remarks

此事件在方块被玩家放置之前触发。

This event fires before a block is placed by a player.


weatherChange

readonly weatherChange: WeatherChangeBeforeEventSignal

Early Execution Beta

Remarks

同领域相关