From ffecc8347f87fd873a1630233f4c941f18893e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 17 Oct 2015 12:29:41 +0200 Subject: [PATCH] Lesson learned: structural typing and obfuscation don't play nice. Fixes #1492. --- .../oc/integration/appeng/NetworkControl.scala | 2 +- .../li/cil/oc/server/component/DebugCard.scala | 2 +- src/main/scala/li/cil/oc/util/ExtendedNBT.scala | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala b/src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala index 059a56bac..20fa762f6 100644 --- a/src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala +++ b/src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala @@ -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 _)) } } diff --git a/src/main/scala/li/cil/oc/server/component/DebugCard.scala b/src/main/scala/li/cil/oc/server/component/DebugCard.scala index 5e5cd39c1..cd3e0d83b 100644 --- a/src/main/scala/li/cil/oc/server/component/DebugCard.scala +++ b/src/main/scala/li/cil/oc/server/component/DebugCard.scala @@ -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 } } diff --git a/src/main/scala/li/cil/oc/util/ExtendedNBT.scala b/src/main/scala/li/cil/oc/util/ExtendedNBT.scala index 0df8ac050..863222bc0 100644 --- a/src/main/scala/li/cil/oc/util/ExtendedNBT.scala +++ b/src/main/scala/li/cil/oc/util/ExtendedNBT.scala @@ -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)