Skip to content

Commit 7b617e3

Browse files
authored
Fix builder list (#52)
* Fix builder list * fix types * lint * fix nbt.long type def * fix types * update README
1 parent 2e9cb0e commit 7b617e3

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ Provides a way to build complex nbt structures simply:
9393
const nbt = require('prismarine-nbt')
9494
writePlayerNbt({
9595
Air: nbt.short(300),
96-
Armor: nbt.list(
97-
nbt.comp({ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string("") }),
98-
nbt.comp({ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string("") }),
99-
nbt.comp({ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string("") }),
100-
),
96+
Armor: nbt.list(nbt.comp([
97+
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string("") },
98+
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string("") },
99+
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string("") }
100+
])),
101101
})
102102
```

compiler-tagname.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global ctx */
22
function readPString (buffer, offset) {
33
const { value, size } = ctx.shortString(buffer, offset)
4-
for (var c of value) {
4+
for (const c of value) {
55
if (c === '\0') throw new Error('unexpected tag end')
66
}
77
return { value, size }

nbt.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ const builder = {
159159
short (value) { return { type: 'short', value } },
160160
byte (value) { return { type: 'byte', value } },
161161
string (value) { return { type: 'string', value } },
162-
comp (value) { return { type: 'compound', value } },
162+
comp (value, name = '') { return { type: 'compound', name, value } },
163163
int (value) { return { type: 'int', value } },
164164
double (value) { return { type: 'double', value } },
165165
long (value) { return { type: 'long', value } },
166-
list (...value) {
167-
const type = value[0]?.type ?? 'end'
168-
return { type: 'list', value: { type, value } }
166+
list (value) {
167+
const type = value?.type ?? 'end'
168+
return { type: 'list', value: { type, value: value?.value ?? [] } }
169169
}
170170
}
171171

typings/index.d.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ declare module 'prismarine-nbt'{
6666
/** @deprecated */
6767
export function parse(data: Buffer, callback: (err: Error | null, value: NBT) => any): void;
6868

69-
export function short<T extends number> (val: T): { type: 'short', value: T }
70-
export function byte<T extends number> (val: T): { type: 'byte', value: T }
71-
export function string<T extends string> (val: T): { type: 'string', value: T }
72-
export function comp<T extends object> (val: T): { type: 'compound', value: T }
73-
export function int<T extends number> (val: T): { type: 'int', value: T }
74-
export function list<T extends string, K extends {type: T}>(...value: K[]): { type: 'list'; value: { type: T | 'end', value: K[] } };
75-
export function double<T extends number> (value: T): { type: 'double', value: T}
69+
export function short<T extends number | number[]> (val: T): { type: 'short', value: T }
70+
export function byte<T extends number | number[]> (val: T): { type: 'byte', value: T }
71+
export function string<T extends string | string[]> (val: T): { type: 'string', value: T }
72+
export function comp<T extends object | object[]> (val: T, name?: string): { type: 'compound', name, value: T }
73+
export function int<T extends number | number[]> (val: T): { type: 'int', value: T }
74+
export function list<T extends string, K extends {type: T}>(value: K): { type: 'list'; value: { type: T | 'end', value: K } };
75+
export function double<T extends number | number[]> (value: T): { type: 'double', value: T}
7676
/**
7777
* @param value Takes a BigInt or an array of two 32-bit integers
7878
*/
79-
export function long<T extends number | BigInt> (value: T[] | T): { type: 'long', value: T[] | T}
79+
export function long<T extends number | number[] | number[number[]] | BigInt | BigInt[]> (value: T): { type: 'long', value: T}
8080
}

0 commit comments

Comments
 (0)