实验性
表示按钮按下后相关的更改信息。
Contains information related to changes to a button push.
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); } });} 复制
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); } });}
只读
此事件影响的方块。
Block impacted by this event.
包含此事件相关方块的所在维度。
Dimension that contains the block that is the subject of this event.
可选的触发按钮按下的来源。
Optional source that triggered the button push.
表示按钮按下后相关的更改信息。
Contains information related to changes to a button push.
示例: buttonPushEvent.ts