@@ -107,14 +107,14 @@ class ItemStackContainer @JvmOverloads constructor(itemStack: ItemStack, useCach
107107 if (display != null ) {
108108 if (display.hasTag(NAME_KEY )) {
109109 if (NAME_JSON ) {
110- children.add(CompoundJsonContainer (display, NAME_KEY , root, true ))
110+ children.add(CompoundJsonContainer (display, NAME_KEY , root))
111111 } else {
112112 children.add(CompoundTextContainer (display, NAME_KEY , root))
113113 }
114114 }
115115 if (display.hasTag(LORE_KEY )) {
116116 if (LORE_JSON ) {
117- if (COMPOUND_JSON )
117+ if (display.getListType( LORE_KEY ) == NBTType . NBTTagCompound )
118118 addJsonList(display.getCompoundList(LORE_KEY ))
119119 else
120120 addJsonList(display.getStringList(LORE_KEY ))
@@ -180,7 +180,7 @@ class ItemStackContainer @JvmOverloads constructor(itemStack: ItemStack, useCach
180180
181181 private fun addJsonTag (compound : ReadWriteNBT , tag : String ) {
182182 if (compound.hasTag(tag)) {
183- children.add(CompoundJsonContainer (compound, tag, root, true ))
183+ children.add(CompoundJsonContainer (compound, tag, root))
184184 }
185185 }
186186
@@ -288,23 +288,48 @@ class ItemStackContainer @JvmOverloads constructor(itemStack: ItemStack, useCach
288288 private val compound : ReadWriteNBT ,
289289 private val key : String ,
290290 root : Container <* >,
291- createComponents : Boolean ,
292- private val jsonCompound : ReadWriteNBT ? = if (COMPOUND_JSON ) compound.getCompound(key) else null ,
293- private val original : String = if (COMPOUND_JSON ) jsonCompound!!.toString() else compound.getString(key)
294- ): ChatJsonContainer(original, root, createComponents) {
291+ ): AbstractContainer<Unit>(Unit , root) {
292+
293+ private val isCompound: Boolean
294+ private val jsonCompound: ReadWriteNBT ?
295+ private val original: String
296+ private val container: Container <String >
297+
298+ init {
299+ if (COMPOUND_JSON ) {
300+ isCompound = compound.getType(key) == NBTType .NBTTagCompound
301+ if (isCompound) {
302+ jsonCompound = compound.getCompound(key)
303+ original = jsonCompound.toString()
304+ container = ChatJsonContainer (original, root)
305+ children.add(container)
306+ } else {
307+ jsonCompound = null
308+ original = compound.getString(key)
309+ container = SimpleTextContainer (original, root)
310+ children.add(container)
311+ }
312+ // TODO string list?
313+ } else {
314+ isCompound = false
315+ jsonCompound = null
316+ original = compound.getString(key)
317+ container = ChatJsonContainer (original, root)
318+ children.add(container)
319+ }
320+ }
295321
296- override fun getResult (): String {
297- val result = super .getResult()
322+ override fun getResult () {
323+ val result = container .getResult()
298324 if (result != original) {
299- if (COMPOUND_JSON ) {
325+ if (isCompound ) {
300326 jsonCompound!!
301327 jsonCompound.clearNBT()
302328 jsonCompound.mergeCompound(NBT .parseNBT(result))
303329 } else {
304330 compound.setString(key, result)
305331 }
306332 }
307- return result
308333 }
309334 }
310335
0 commit comments