UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

97 lines (96 loc) 4.15 kB
import { IBlockVolume, IBlockTypeData } from "./IBlockVolume"; import Structure from "./Structure"; import Block from "./Block"; /** * Utility functions for working with Structure (MCStructure) objects. */ export default class StructureUtilities { /** * Infers the size of an IBlockVolume from its data. * - size.y = number of layers in blockLayersBottomToTop * - size.z = maximum number of rows across all layers * - size.x = maximum string length across all rows * * @param blockVolume The IBlockVolume to measure * @returns The inferred size as an IVector3 */ static inferBlockVolumeSize(blockVolume: IBlockVolume): { x: number; y: number; z: number; }; /** * Gets the effective size of an IBlockVolume, using the explicit size if provided, * or inferring it from the data if not. * * @param blockVolume The IBlockVolume to get the size of * @returns The effective size as an IVector3 */ static getEffectiveSize(blockVolume: IBlockVolume): { x: number; y: number; z: number; }; /** * Creates a Structure (MCStructure) from an IBlockVolume. * * IBlockVolume uses blockLayersBottomToTop format: * - Outer array: Y layers from bottom (Y=0) to top * - Each layer: rows from north (Z=0) to south (Z=max) * - Each character: X position from west (X=0) to east (X=max) * * Think of it like stacking floors: first layer is ground floor, last is roof. * * If size is not explicitly provided, it is inferred from the data. * Shorter strings and missing rows are treated as air. * * @param blockVolume The IBlockVolume containing layer-based block data * @returns A Structure populated with blocks from the IBlockVolume */ static createStructureFromIBlockVolume(blockVolume: IBlockVolume): Structure; /** * Applies block type data from IBlockTypeData to a Block. * Handles the properties field and also legacy parsing of block states from the typeId if present. * * @param block The Block to apply the type data to * @param blockTypeData The IBlockTypeData containing the type ID and optional properties */ static applyBlockTypeDataToBlock(block: Block, blockTypeData: IBlockTypeData): void; /** * Parses a block states string and applies the states to the block. * * @param block The block to apply states to * @param statesStr The states string (e.g., "facing=north,half=bottom") * @param stateSeparator The character separating multiple states (usually ",") * @param keyValueSeparator The character separating key from value ("=" or ":") */ static parseAndApplyBlockStates(block: Block, statesStr: string, stateSeparator: string, keyValueSeparator: string): void; /** * Creates an IBlockVolume from a Structure. * This is the inverse operation of createStructureFromIBlockVolume. * * Output uses blockLayersBottomToTop format: * - Outer array: Y layers from bottom to top * - Each layer: rows from north to south * - Each character: X position from west to east * * @param structure The Structure to convert * @returns An IBlockVolume representation of the structure */ static createIBlockVolumeFromStructure(structure: Structure): IBlockVolume | undefined; /** * Creates an IBlockTypeData from a Block, with typeId and properties separated. * * @param block The block to get the type data for * @returns An IBlockTypeData with the block's type ID and properties */ static getBlockTypeDataFromBlock(block: Block): IBlockTypeData; /** * Gets the full block type ID with states in square bracket notation. * @deprecated Use getBlockTypeDataFromBlock instead for the new properties-based format. * * @param block The block to get the type ID for * @returns The block type ID, optionally with states (e.g., "minecraft:oak_stairs[facing=north,half=bottom]") */ static getBlockTypeIdWithStates(block: Block): string; }