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

Class: TripWireTripAfterEvent

event

Beta

Contains information related to changes to a trip wire trip.

包含与绊线被触发相关的信息。

Example

tripWireTripEvent.ts

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

function tripWireTripEvent(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
  // set up a tripwire
  const redstone = targetLocation.dimension.getBlock({
    x: targetLocation.x,
    y: targetLocation.y - 1,
    z: targetLocation.z,
  });
  const tripwire = targetLocation.dimension.getBlock(targetLocation);

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

  redstone.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.RedstoneBlock));
  tripwire.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.TripWire));

  world.afterEvents.tripWireTrip.subscribe((tripWireTripEvent: TripWireTripAfterEvent) => {
    const eventLoc = tripWireTripEvent.block.location;

    if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y && eventLoc.z === targetLocation.z) {
      log(
        'Tripwire trip event at tick ' +
          system.currentTick +
          (tripWireTripEvent.sources.length > 0 ? ' by entity ' + tripWireTripEvent.sources[0].id : '')
      );
    }
  });
}

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

Whether or not the block has redstone power.

该方块是否具有红石信号。


sources

readonly sources: Entity[]

Beta

Remarks

The sources that triggered the trip wire to trip.

触发绊线的来源。

同领域相关