pw-js-world
Version:
An optional package for PW-JS-Api, aims to serve world purposes.
120 lines (119 loc) • 4.21 kB
TypeScript
import type { BlockArg, Point, SendableBlockPacket } from "./types/index.js";
import BufferReader, { ComponentTypeHeader } from "./BufferReader.js";
import { LayerType } from "./Constants.js";
import { type BlockKeys } from "pw-js-api";
export default class Block {
bId: number;
args: BlockArg[];
constructor(bId: number | BlockKeys | string, args?: BlockArg[]);
/**
* I mean... Just use .args.length !== 0 to see if it has args.
*
* But anyway, this will return true if there is at least one args, otherwise false.
*/
hasArgs(): boolean;
/**
* For helper.
*
* This is in Block class for organisation.
*
* This will deserialise by using the reader to get the block ID then retrieve the args, if applicable.
*/
static deserialize(reader: BufferReader): Block;
protected deserializeArgs(reader: BufferReader, flag?: boolean): this;
/**
* For helper.
*
* This is in Block class for organisation.
*/
static deserializeArgs(reader: BufferReader): BlockArg[];
/**
* Serializes the block into a buffer. This is used to convert
* the block into a binary format that can be sent over the game
* server. As this is static, block id and args are required.
*
* - Little Endian
* - With Id
* - Type Byte omitted
*/
static serializeArgs(bId: number, args: BlockArg[]): Buffer;
/**
* Serializes the block into a buffer. This is used to convert
* the block into a binary format that can be sent over the game
* server. As this is static, block id and args are required.
*
* - Big Endian
* - No Id
* - Type Byte included
*/
static serializeArgs(bId: number, args: BlockArg[], options: {
endian: "big";
writeId: false;
readTypeByte: true;
}): Buffer;
static serializeArgs(bId: number, args: BlockArg[], options: {
endian: "little";
writeId: false;
readTypeByte: true;
}): Buffer;
/**
*
* @param pos List of points (X and Y)
*/
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: BlockArg[];
name: string;
};
/**
* 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 arg types 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 getArgTypesByBlockId(blockId: number): ComponentTypeHeader[];
/**
* Returns the arg types 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 getArgTypesByPaletteId(paletteId: string): ComponentTypeHeader[];
}