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/LeverActionAfterEvent.md.

Class: LeverActionAfterEvent

event

Beta

包含与拉杆激活或停用相关的信息。

Contains information related to changes to a lever activating or deactivating.

Example

leverActionEvent.ts

import { world, system, BlockPermutation, LeverActionAfterEvent, DimensionLocation } from '@minecraft/server';
import { MinecraftBlockTypes } from '@minecraft/vanilla-data';

function leverActionEvent(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
  // set up a lever
  const cobblestone = targetLocation.dimension.getBlock(targetLocation);
  const lever = targetLocation.dimension.getBlock({
    x: targetLocation.x,
    y: targetLocation.y + 1,
    z: targetLocation.z,
  });

  if (cobblestone === undefined || lever === undefined) {
    log('Could not find block at location.');
    return -1;
  }

  cobblestone.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.Cobblestone));
  lever.setPermutation(
    BlockPermutation.resolve(MinecraftBlockTypes.Lever).withState('lever_direction', 'up_north_south')
  );

  world.afterEvents.leverAction.subscribe((leverActionEvent: LeverActionAfterEvent) => {
    const eventLoc = leverActionEvent.block.location;

    if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y + 1 && eventLoc.z === targetLocation.z) {
      log('Lever activate event at tick ' + system.currentTick);
    }
  });
}

Extends

Properties

block

readonly block: Block

Beta

Remarks

当前世界中此事件所在位置的方块。

Block currently in the world at the location of this event.

Inherited from

BlockEvent.block


dimension

readonly dimension: Dimension

Beta

Remarks

包含此事件主体方块的维度。

Dimension that contains the block that is the subject of this event.

Inherited from

BlockEvent.dimension


isPowered

readonly isPowered: boolean

Beta

Remarks

如果拉杆已激活(即正在传输电力),则为 true

True if the lever is activated (that is, transmitting power).


player

readonly player: Player

Beta

Remarks

触发拉杆激活的可选玩家。

Optional player that triggered the lever activation.

同领域相关