import { NbtCompound } from '../utils/nbt/nbt' ; import { getNbtCompound , completeNamespace } from './utils' ; export class ItemStack { public name : string ; public nbt : NbtCompound ; constructor ( input ) { let index = 0 ; index = this . parseName ( input , index ) + 1 ; this . parseNbt ( input , index ) ; } public toString ( ) { let result = this . name ; if ( this . nbt !== undefined ) { result += this . nbt . toString ( ) ; } return result ; } returns private parseName ( input , index ) { let name = '' ; while ( input . charAt ( index ) !== '' && input . charAt ( index ) !== '[' && input . charAt ( index ) !== '{' ) { name += input . charAt ( index ) ; index += 1 ; } name = completeNamespace ( name ) ; this . name = name ; return index - 1 ; } returns private parseNbt ( input , index ) { if ( input . charAt ( index ) === '{' ) { this . nbt = getNbtCompound ( input . slice ( index ) ) ; } return index ; } }