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

Class: TripWireTripAfterEventSignal

event

Beta

Manages callbacks that are connected to when a trip wire is tripped.

管理与绊线被触发时相关的回调。

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

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 trip wire is tripped.

添加一个回调,当绊线被触发时调用。


unsubscribe()

unsubscribe(callback): void

World Mutation Early Execution Beta

Parameters

callback

(arg0) => void

Returns

void

Remarks

Removes a callback from being called when a trip wire is tripped.

移除一个在绊线被触发时调用的回调。

同领域相关