实验性
Contains information related to changes to a lever activating or deactivating.
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); } });} 复制
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); } });}
只读
此事件影响的方块。
Block impacted by this event.
包含此事件相关方块的所在维度。
Dimension that contains the block that is the subject of this event.
True if the lever is activated (that is, transmitting power).
Optional player that triggered the lever activation.
Contains information related to changes to a lever activating or deactivating.
示例: leverActionEvent.ts