实验性实验性要获取其值的方块状态的名称。
Name of the block state who's value is to be returned.
若此组合拥有该状态则返回状态值,否则返回 undefined。
Returns the state if the permutation has it, else
undefined.
实验性若此组合具有该标签则返回 true,否则返回 false。
Returns true if the permutation has the tag, else false.
import { DimensionLocation } from "@minecraft/server";
function checkBlockTags(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
// Fetch the block
const block = targetLocation.dimension.getBlock(targetLocation);
// check that the block is loaded
if (block) {
log(`Block is dirt: ${block.hasTag("dirt")}`);
log(`Block is wood: ${block.hasTag("wood")}`);
log(`Block is stone: ${block.hasTag("stone")}`);
}
}
实验性一个可选的状态集合,用于进行比较。 An optional set of states to compare against.
可选states: BlockStateArg<T>实验性方块属性的标识符。 Identifier of the block property.
方块属性的值。 Value of the block property.
静态resolve实验性要检查的方块的标识符。
Identifier of the block to check.
可选states: BlockStateArg<T>给定一个类型标识符和一个可选的属性集合, 将返回一个可在其他方块 API 中使用的 BlockPermutation(方块参数) 对象(例如,block.setPermutation)。
Given a type identifier and an optional set of properties, will return a BlockPermutation object that is usable in other block APIs (e.g., block.setPermutation)
import { BlockPermutation, DimensionLocation } from "@minecraft/server";
import { Vector3Utils } from "@minecraft/math";
import { MinecraftBlockTypes } from "@minecraft/vanilla-data";
function addBlockColorCube(targetLocation: DimensionLocation) {
const allWoolBlocks: string[] = [
MinecraftBlockTypes.WhiteWool,
MinecraftBlockTypes.OrangeWool,
MinecraftBlockTypes.MagentaWool,
MinecraftBlockTypes.LightBlueWool,
MinecraftBlockTypes.YellowWool,
MinecraftBlockTypes.LimeWool,
MinecraftBlockTypes.PinkWool,
MinecraftBlockTypes.GrayWool,
MinecraftBlockTypes.LightGrayWool,
MinecraftBlockTypes.CyanWool,
MinecraftBlockTypes.PurpleWool,
MinecraftBlockTypes.BlueWool,
MinecraftBlockTypes.BrownWool,
MinecraftBlockTypes.GreenWool,
MinecraftBlockTypes.RedWool,
MinecraftBlockTypes.BlackWool,
];
const cubeDim = 7;
let colorIndex = 0;
for (let x = 0; x <= cubeDim; x++) {
for (let y = 0; y <= cubeDim; y++) {
for (let z = 0; z <= cubeDim; z++) {
colorIndex++;
targetLocation.dimension
.getBlock(Vector3Utils.add(targetLocation, { x, y, z }))
?.setPermutation(BlockPermutation.resolve(allWoolBlocks[colorIndex % allWoolBlocks.length]));
}
}
}
}
表示一个由 BlockType 类型和属性(有时也称为方块状态)组成的组合, 用于描述一个方块(但不属于特定的 Block)。
示例: addTranslatedSign.ts
示例: addTranslatedSign.ts