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

Class: ButtonPushAfterEvent

event

Beta

包含与按钮按压变化相关的信息。

Example

buttonPushEvent.ts

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

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

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

  cobblestone.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.Cobblestone));
  button.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.AcaciaButton).withState('facing_direction', 1));

  world.afterEvents.buttonPush.subscribe((buttonPushEvent: ButtonPushAfterEvent) => {
    const eventLoc = buttonPushEvent.block.location;

    if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y + 1 && eventLoc.z === targetLocation.z) {
      log('Button push 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


source

readonly source: Entity

Beta

Remarks

触发按钮按压的可选来源。

Optional source that triggered the button push.

同领域相关