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

Class: PistonActivateAfterEvent

event

Beta

包含与活塞伸出或缩回相关的信息。

Contains information related to changes to a piston expanding or retracting.

Example

pistonAfterEvent.ts

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

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

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

  piston.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.Piston).withState('facing_direction', 3));
  button.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.AcaciaButton).withState('facing_direction', 1));

  world.afterEvents.pistonActivate.subscribe((pistonEvent: PistonActivateAfterEvent) => {
    const eventLoc = pistonEvent.piston.block.location;

    if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y && eventLoc.z === targetLocation.z) {
      log(
        'Piston event at ' +
          system.currentTick +
          (pistonEvent.piston.isMoving ? ' Moving' : '') +
          (pistonEvent.piston.state === BlockPistonState.Expanding ? ' Expanding' : '') +
          (pistonEvent.piston.state === BlockPistonState.Expanded ? ' Expanded' : '') +
          (pistonEvent.piston.state === BlockPistonState.Retracting ? ' Retracting' : '') +
          (pistonEvent.piston.state === BlockPistonState.Retracted ? ' Retracted' : '')
      );
    }
  });
}

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


isExpanding

readonly isExpanding: boolean

Beta

如果活塞正在伸出过程中,则为 true

Remarks

True if the piston is the process of expanding.


piston

readonly piston: BlockPistonComponent

Beta

包含活塞的附加属性和详细信息。

Remarks

Contains additional properties and details of the piston.

同领域相关