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

Class: LeverActionAfterEventSignal

event

Beta

管理与拉杆移动(激活或停用)相关的回调。

Manages callbacks that are connected to lever moves (activates or deactivates).

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

Methods

subscribe()

subscribe(callback): (arg0) => void

World Mutation Early Execution Beta

Parameters

callback

(arg0) => void

Returns

(arg0) => void

Remarks

添加一个回调,当拉杆被移动(激活或停用)时将被调用。

Adds a callback that will be called when a lever is moved (activates or deactivates).


unsubscribe()

unsubscribe(callback): void

World Mutation Early Execution Beta

Parameters

callback

(arg0) => void

Returns

void

Remarks

移除一个回调,使其在拉杆被移动(激活或停用)时不再被调用。

Removes a callback from being called when a lever is moved (activates or deactivates).

同领域相关