pw-js-world
Version:
An optional package for PW-JS-Api, aims to serve world purposes.
89 lines (88 loc) • 3.55 kB
TypeScript
import type { BlockArg, Point, SendableBlockPacket } from "./types/index.js";
import { LayerType } from "./Constants.js";
import { AnyBlockField, OmitRecursively, ProtoGen, type BlockKeys } from "pw-js-api";
export default class Block {
bId: number;
/**
* NOTE as of October 2025, this is an object NOT an array.
*
* Stores the arguments
*/
args: Record<string, BlockArg>;
constructor(bId: number | BlockKeys | string, args?: BlockArg[] | OmitRecursively<Record<string, ProtoGen.BlockFieldValue>, "$typeName" | "$unknown">);
/**
* True if there is at least one argument, otherwise false.
*/
hasArgs(): boolean;
/**
* This is for the fields parameter in sending world block placement.
*/
static getArgsAsFields(block: Block): OmitRecursively<ProtoGen.WorldBlockPlacedPacket["fields"], "$typeName">;
static getArgsAsFields(bId: number, args?: Record<string, BlockArg>): OmitRecursively<ProtoGen.WorldBlockPlacedPacket["fields"], "$typeName">;
/**
*
*/
static getArgsAsArray(block: Block): BlockArg[];
static getArgsAsArray(bId: number, args?: Record<string, BlockArg>): BlockArg[];
/**
* Returns an object suitable for sending worldBlockPlacedPacket to connection.
* @param pos List of possible positions (a max of 250 positions) - this does not automatically truncate if it overfills.
*/
toPacket(pos: Point[], layer: LayerType): SendableBlockPacket;
toPacket(x: number, y: number, layer: LayerType): SendableBlockPacket;
/**
* This will return the block name in UPPER_CASE form.
*
* For eg EFFECTS_INVULNERABILITY.
*
* @throws {MissingBlockError}
* If the ID of this block is not known.
*/
get name(): string;
/**
* Returns a copy of the block.
*/
clone(obj?: false): Block;
clone(obj: true): {
bId: number;
args: Record<string, BlockArg>;
name: string;
};
compareTo(b: Block): boolean;
/**
* This can be convenient as it will always return the ID if it exists, and it will throw an error if it doesn't.
*
* This expects the name sent to be in full upper capital form though.
*
* @throws {MissingBlockError}
* If the connection is unknown, this can be because you're trying to use this function when Api#getListBlocks has never been invoked, or the object is missing.
*/
static getIdByName(paletteId: string): number;
/**
* This will return the corresponding palette id by the ID of that block.
*
* The name sent will be in full upper capital if it exists.
*
* @throws {MissingBlockError}
* If the connection is unknown, this can be because you're trying to use this function when Api#getListBlocks has never been invoked, or the object is missing.
*/
static getPaletteIdById(blockId: number): string;
/**
* Returns the block fields for that block by given block ID.
*
* If a block don't have args, it will return an empty array.
*
* If the block don't exist, it may throw an exception.
*/
static getFieldsByBlockId(blockId: number): AnyBlockField[];
/**
* Returns the block fields for that block by given palette ID (full upper case).
*
* For eg "EMPTY" or "SIGN_GOLD"
*
* If a block don't have args, it will return an empty array.
*
* If the block don't exist, it may throw an exception.
*/
static getFieldsByPaletteId(paletteId: string): AnyBlockField[];
}