# Pastebin VDHGL0BG // Requires getKType<*> from this gist: // https://gist.github.com/udalov/bb6f398c2e643ee69586356fdd67e9b1 inline operator fun NBTTagCompound.getValue(thisRef: Any?, prop: KProperty<*>): T { when (getKType()) { getKType() -> { if (!hasKey(prop.name)) return 0 as T return getInteger(prop.name) as T } getKType() -> { if (!hasKey(prop.name)) return "" as T return getString(prop.name) as T } getKType>() -> { if (!hasKey(prop.name)) return mutableListOf() as T val list = getTag(prop.name) as NBTTagList return (MutableList(list.tagCount()) { it: Int -> list.getStringTagAt(it) }) as T } } throw IllegalArgumentException("Can not handle value: ${getKType()}") } inline operator fun NBTTagCompound.setValue(thisRef: Any?, prop: KProperty<*>, value: T) { when (getKType()) { getKType() -> { setInteger(prop.name, value as Int) ButtsMod.log.info("Wrote ${prop.name} to $this") return } getKType() -> { setString(prop.name, value as String) ButtsMod.log.info("Wrote ${prop.name} to $this") return } getKType>() -> { val list = NBTTagList() (value as MutableList).forEach { list.appendTag(NBTTagString(it)) } setTag(prop.name, list) ButtsMod.log.info("Wrote ${prop.name} to $this") return } } throw IllegalArgumentException("Can not handle value: ${getKType()}") }