Lesson learned: structural typing and obfuscation don't play nice. Fixes #1492.

This commit is contained in:
Florian Nücke 2015-10-17 12:29:41 +02:00
parent e47cc37d38
commit ffecc8347f
3 changed files with 10 additions and 9 deletions

View File

@ -238,7 +238,7 @@ object NetworkControl {
nbt.setInteger("y", controller.yCoord)
nbt.setInteger("z", controller.zCoord)
}
nbt.setNewTagList("links", links)
nbt.setNewTagList("links", links.map(_.writeToNBT _))
}
}

View File

@ -421,7 +421,7 @@ object DebugCard {
checkEnabled()
val (x, y, z) = (args.checkInteger(0), args.checkInteger(1), args.checkInteger(2))
world.getTileEntity(x, y, z) match {
case tileEntity: TileEntity => result(toNbt(tileEntity).toTypedMap)
case tileEntity: TileEntity => result(toNbt(tileEntity.writeToNBT _).toTypedMap)
case _ => null
}
}

View File

@ -3,6 +3,7 @@ package li.cil.oc.util
import com.google.common.base.Charsets
import net.minecraft.item.ItemStack
import net.minecraft.nbt._
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.Constants.NBT
import net.minecraftforge.common.util.ForgeDirection
@ -36,12 +37,6 @@ object ExtendedNBT {
implicit def toNbt(value: String): NBTTagString = new NBTTagString(value)
implicit def toNbt(value: {def writeToNBT(nbt: NBTTagCompound): Unit}): NBTTagCompound = {
val nbt = new NBTTagCompound()
value.writeToNBT(nbt)
nbt
}
implicit def toNbt(value: ItemStack): NBTTagCompound = {
val nbt = new NBTTagCompound()
if (value != null) {
@ -50,6 +45,12 @@ object ExtendedNBT {
nbt
}
implicit def toNbt(value: NBTTagCompound => Unit): NBTTagCompound = {
val nbt = new NBTTagCompound()
value(nbt)
nbt
}
implicit def toNbt(value: Map[String, _]): NBTTagCompound = {
val nbt = new NBTTagCompound()
for ((key, value) <- value) value match {
@ -182,7 +183,7 @@ object ExtendedNBT {
implicit def stringIterableToNbt(value: Iterable[String]): Iterable[NBTTagString] = value.map(toNbt)
implicit def writableIterableToNbt(value: Iterable[ {def writeToNBT(nbt: NBTTagCompound): Unit}]): Iterable[NBTTagCompound] = value.map(toNbt)
implicit def writableIterableToNbt(value: Iterable[NBTTagCompound => Unit]): Iterable[NBTTagCompound] = value.map(toNbt)
implicit def itemStackIterableToNbt(value: Iterable[ItemStack]): Iterable[NBTTagCompound] = value.map(toNbt)