diff --git a/src/commands/implementations/world/data.ts b/src/commands/implementations/world/data.ts index df3dfa3..9c37e5c 100644 --- a/src/commands/implementations/world/data.ts +++ b/src/commands/implementations/world/data.ts @@ -127,7 +127,7 @@ export class DataModifyValuesCommand extends CommandArgum * @param end Optional. Index of the first character to exclude at the end of the string */ block: (sourcePosition: Macroable, MACRO>, sourcePath: Macroable, start?: Macroable, end?: Macroable) => { - const command: (string | VectorClass<[string, string, string]> | number | MacroArgument)[] = ['from', 'block', coordinatesParser(sourcePosition), sourcePath] + const command: (string | VectorClass<[string, string, string]> | number | MacroArgument)[] = ['string', 'block', coordinatesParser(sourcePosition), sourcePath] if (start) { command.push(start) if (end) command.push(end) @@ -144,7 +144,7 @@ export class DataModifyValuesCommand extends CommandArgum * @param end Optional. Index of the first character to exclude at the end of the string */ entity: (source: Macroable, MACRO>, sourcePath: Macroable, start?: Macroable, end?: Macroable) => { - const command: (Macroable | number, MACRO>)[] = ['from', 'entity', targetParser(source), sourcePath] + const command: (Macroable | number, MACRO>)[] = ['string', 'entity', targetParser(source), sourcePath] if (start) { command.push(start) if (end) command.push(end) @@ -161,7 +161,7 @@ export class DataModifyValuesCommand extends CommandArgum * @param end Optional. Index of the first character to exclude at the end of the string */ storage: (source: Macroable, sourcePath: Macroable, start?: Macroable, end?: Macroable) => { - const command: (string | number | MacroArgument)[] = ['from', 'storage', source, sourcePath] + const command: (string | number | MacroArgument)[] = ['string', 'storage', source, sourcePath] if (start) { command.push(start) if (end) command.push(end) diff --git a/src/core/sandstoneCore.ts b/src/core/sandstoneCore.ts index 6f41e8f..b078903 100644 --- a/src/core/sandstoneCore.ts +++ b/src/core/sandstoneCore.ts @@ -35,7 +35,15 @@ export class SandstoneCore { this.mcfunctionStack = [] this.awaitNodes = new Set() - this.depend = this.depend.bind(this) + // ESM is funny + + for (const method of Object.getOwnPropertyNames(Object.getPrototypeOf(this))) { + /* @ts-ignore */ + if (method !== 'constructor' && typeof this[method] === 'function' && typeof this[method].bind === 'function') { + /* @ts-ignore */ + this[method] = this[method].bind(this) + } + } } /** diff --git a/src/pack/pack.ts b/src/pack/pack.ts index 0edbaaf..0a33c54 100644 --- a/src/pack/pack.ts +++ b/src/pack/pack.ts @@ -188,7 +188,15 @@ export class SandstonePack { this.setupLantern() this.dependencies = new Map() - this.MCFunction = this.MCFunction.bind(this) + // ESM is funny + + for (const method of Object.getOwnPropertyNames(Object.getPrototypeOf(this))) { + /* @ts-ignore */ + if (method !== 'constructor' && typeof this[method] === 'function' && typeof this[method].bind === 'function') { + /* @ts-ignore */ + this[method] = this[method].bind(this) + } + } } setupLantern = () => { diff --git a/src/variables/Data.ts b/src/variables/Data.ts index 0df8d1c..dedb09d 100644 --- a/src/variables/Data.ts +++ b/src/variables/Data.ts @@ -146,6 +146,7 @@ export class DataPointClass extends MacroArgument if (value instanceof StringDataPointClass) { if (value.sliceBounds[1]) this.string((data) => data.set, value, value.sliceBounds[0], value.sliceBounds[1]) else this.string((data) => data.set, value, value.sliceBounds[0]) + return this } if (value instanceof Score) { this.executeStore(storeType || 'int', scale).run.scoreboard.players.get(value.target, value.objective) diff --git a/src/variables/ResolveNBT.ts b/src/variables/ResolveNBT.ts index 024a297..62015c9 100644 --- a/src/variables/ResolveNBT.ts +++ b/src/variables/ResolveNBT.ts @@ -3,14 +3,16 @@ import * as util from 'util' import { capitalize } from '../utils.js' import { DataPointPickClass } from './abstractClasses.js' +import { StringDataPointClass } from './Data.js' import { + NBTAnyValue, NBTClass, NBTInt, NBTIntArray, NBTPrimitive, } from './nbt/index.js' import { Score } from './Score.js' import type { NBTObject } from '../arguments/nbt.js' import type { SandstonePack } from '../pack/index.js' -import type { DataPointClass, StringDataPointClass } from './Data.js' +import type { DataPointClass } from './Data.js' import type { NBTAllArrays, NBTAllNumbers, NBTAllValues, NBTString, @@ -46,6 +48,8 @@ export class ResolveNBTClass extends DataPointPickClass { if (Array.isArray(nbt)) { resolvedNBT = [] + this.dataPoint.set([]) + if (resolvedNBT.length !== 0) { for (const [i, value] of nbt.entries()) { const resolved = this._resolveNBT(value, `${path === undefined ? '' : path}`, i) @@ -65,6 +69,8 @@ export class ResolveNBTClass extends DataPointPickClass { if (nbt instanceof NBTPrimitive) { return resolvedNBT } + this.dataPoint.set({}) + for (const [key, value] of Object.entries(nbt)) { const resolved = this._resolveNBT(value, `${path === undefined ? '' : `${path}.`}${key}`) if (resolved !== undefined) { @@ -77,14 +83,23 @@ export class ResolveNBTClass extends DataPointPickClass { /** * @internal */ - _resolveData(value: ResolveNBTPartClass<'data', NBTAllValues>, path: string, index?: number) { + _resolveData(part: ResolveNBTPartClass<'data', NBTAllValues>, path: string, index?: number) { + const { value } = part const dataPoint = this.dataPoint.select(path) if (index) { - dataPoint.insert(value, index) + let _value = value + if (value instanceof StringDataPointClass) { + _value = this.pack.DataVariable(value) + } + dataPoint.insert(_value as DataPointClass, index) + return undefined + } + if (value instanceof StringDataPointClass) { + dataPoint.set(value) return undefined } - dataPoint.set(value) + dataPoint.set(value as DataPointClass) return undefined } @@ -192,5 +207,5 @@ export function ResolveNBTPart(value, 'score' as ValueType, (option2 || NBTInt) as Primitive, (option1 || 1) as number) } - return new ResolveNBTPartClass(value, 'data' as ValueType, option1 as Primitive) + return new ResolveNBTPartClass(value, 'data' as ValueType, (option1 || NBTAnyValue) as Primitive) } diff --git a/src/variables/parsers.ts b/src/variables/parsers.ts index 4c1c20c..d0aac2c 100644 --- a/src/variables/parsers.ts +++ b/src/variables/parsers.ts @@ -142,7 +142,10 @@ export function targetParser(target: any): string { return target } if (target._toSelector) { - return target._toSelector().toString() + return target._toSelector() + } + if (target.toMacro) { + return target } return target.toString() }