UNPKG

pw-js-world

Version:

An optional package for PW-JS-Api, aims to serve world purposes.

43 lines (42 loc) 2.27 kB
import { type LayerType } from "../Constants.js"; import type { BlockArg, Point, SendableBlockPacket } from "../types"; import Block from "../Block.js"; import { type AnyBlockField, type BlockKeys } from "pw-js-api"; /** * True if objA matches the contents to that of objB * * TODO: proper array support? */ export declare function compareObjs<A extends Record<string, any>, B extends Record<string, any>>(objA: A, objB: B): boolean; export declare function uint8ArrayEquals(a: Uint8Array, b: Uint8Array): boolean; export declare function map<T, U>(arr: Array<T> | Map<any, T>, cb: (value: T, index: number, obj: T[]) => U): U[]; export declare function find<T>(arr: Array<T> | Map<any, T>, pred: (value: T, index: number, obj: T[]) => boolean): T | undefined; export declare function findIndex<T>(arr: Array<T> | Map<any, T>, pred: (value: T, index: number, obj: T[]) => boolean): number; /** * For now this is slightly limited, but this will ONLY create a sendable packet which you must then send it yourself. */ export declare function createBlockPacket(blockId: number | BlockKeys | string, layer: LayerType, pos: Point | Point[], args: Record<string, BlockArg>): SendableBlockPacket; export declare function createBlockPacket(block: Block, layer: LayerType, pos: Point | Point[]): SendableBlockPacket; /** * Creates sendable packets from given blocks. Attempts to minimise packet count, so it's preferable * to use it over creating packets with createBlockPacket multiple times. */ export declare function createBlockPackets(blocks: { block: Block; layer: LayerType; pos: Point; }[]): SendableBlockPacket[]; /** * Since this is literally the only function related to dealing with binary stuff, a file would be redundant. * * Credits: Priddle / NVD https://discord.com/channels/534079923573489667/1230093943941758977/1431632635645530234 */ export declare function read7BitEncodedInt(reader: Buffer, offset: { val: number; }): number; /** * I don't know what else to call this. * * This will convert the type from getListedBlocks#fields to match the one from the game. */ export declare function listedFieldTypeToGameType(type: AnyBlockField["Type"]): "int32Value" | "uint32Value" | "stringValue" | "boolValue" | "byteArrayValue";