diff --git a/src/main/java/li/cil/oc/api/prefab/DriverItem.java b/src/main/java/li/cil/oc/api/prefab/DriverItem.java index 57f5a59c8..58a5adb21 100644 --- a/src/main/java/li/cil/oc/api/prefab/DriverItem.java +++ b/src/main/java/li/cil/oc/api/prefab/DriverItem.java @@ -45,13 +45,13 @@ public abstract class DriverItem implements li.cil.oc.api.driver.Item { @Override public NBTTagCompound dataTag(final ItemStack stack) { if (!stack.hasTagCompound()) { - stack.setTagCompound(new NBTTagCompound("tag")); + stack.setTagCompound(new NBTTagCompound()); } final NBTTagCompound nbt = stack.getTagCompound(); // This is the suggested key under which to store item component data. // You are free to change this as you please. if (!nbt.hasKey("oc:data")) { - nbt.setCompoundTag("oc:data", new NBTTagCompound()); + nbt.setTag("oc:data", new NBTTagCompound()); } return nbt.getCompoundTag("oc:data"); } diff --git a/src/main/java/li/cil/oc/api/prefab/ManagedEnvironment.java b/src/main/java/li/cil/oc/api/prefab/ManagedEnvironment.java index 844696807..f0fc7b12f 100644 --- a/src/main/java/li/cil/oc/api/prefab/ManagedEnvironment.java +++ b/src/main/java/li/cil/oc/api/prefab/ManagedEnvironment.java @@ -48,7 +48,7 @@ public abstract class ManagedEnvironment implements li.cil.oc.api.network.Manage if (node != null) { final NBTTagCompound nodeTag = new NBTTagCompound(); node.save(nodeTag); - nbt.setCompoundTag("node", nodeTag); + nbt.setTag("node", nodeTag); } } } diff --git a/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java b/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java index 309cc33e7..a1b638396 100644 --- a/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java +++ b/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java @@ -150,7 +150,7 @@ public abstract class TileEntityEnvironment extends TileEntity implements Enviro if (node != null && node.host() == this) { final NBTTagCompound nodeNbt = new NBTTagCompound(); node.save(nodeNbt); - nbt.setCompoundTag("oc:node", nodeNbt); + nbt.setTag("oc:node", nodeNbt); } } } diff --git a/src/main/java/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala b/src/main/java/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala index 2fb53061b..9d5585d99 100644 --- a/src/main/java/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala +++ b/src/main/java/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala @@ -244,7 +244,7 @@ object ScreenRenderer extends TileEntitySpecialRenderer with Callable[Int] with def onRemoval(e: RemovalNotification[TileEntity, Int]) { GLAllocation.deleteDisplayLists(e.getValue) - } q + } // TODO this doesn't seem to work @SubscribeEvent diff --git a/src/main/java/li/cil/oc/common/inventory/Inventory.scala b/src/main/java/li/cil/oc/common/inventory/Inventory.scala index fc976daed..124d97cd9 100644 --- a/src/main/java/li/cil/oc/common/inventory/Inventory.scala +++ b/src/main/java/li/cil/oc/common/inventory/Inventory.scala @@ -5,6 +5,7 @@ import li.cil.oc.util.ExtendedNBT._ import net.minecraft.inventory.IInventory import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound +import net.minecraftforge.common.util.Constants.NBT trait Inventory extends IInventory { def items: Array[Option[ItemStack]] @@ -19,7 +20,7 @@ trait Inventory extends IInventory { stack case Some(stack) => val result = stack.splitStack(amount) - onInventoryChanged() + markDirty() result case _ => null } @@ -43,23 +44,24 @@ trait Inventory extends IInventory { onItemAdded(slot, items(slot).get) } - onInventoryChanged() + markDirty() } def getInventoryStackRequired = 1 override def getStackInSlotOnClosing(slot: Int) = null - override def openChest() {} + override def openInventory() {} - override def closeChest() {} + override def closeInventory() {} - override def isInvNameLocalized = false + override def hasCustomInventoryName = false // ----------------------------------------------------------------------- // def load(nbt: NBTTagCompound) { - nbt.getTagList(Settings.namespace + "items").foreach[NBTTagCompound](slotNbt => { + nbt.getTagList(Settings.namespace + "items", NBT.TAG_COMPOUND).foreach((list, index) => { + val slotNbt = list.getCompoundTagAt(index) val slot = slotNbt.getByte("slot") if (slot >= 0 && slot < items.length) { items(slot) = Option(ItemStack.loadItemStackFromNBT(slotNbt.getCompoundTag("item"))) diff --git a/src/main/java/li/cil/oc/common/inventory/ItemStackInventory.scala b/src/main/java/li/cil/oc/common/inventory/ItemStackInventory.scala index f2f0be277..d4d20e477 100644 --- a/src/main/java/li/cil/oc/common/inventory/ItemStackInventory.scala +++ b/src/main/java/li/cil/oc/common/inventory/ItemStackInventory.scala @@ -3,6 +3,7 @@ package li.cil.oc.common.inventory import li.cil.oc.Settings import net.minecraft.item.ItemStack import net.minecraft.nbt.{NBTTagList, NBTTagCompound} +import net.minecraftforge.common.util.Constants.NBT trait ItemStackInventory extends Inventory { // The item stack that provides the inventory. @@ -18,15 +19,15 @@ trait ItemStackInventory extends Inventory { // Load items from tag. def reinitialize() { if (!container.hasTagCompound) { - container.setTagCompound(new NBTTagCompound("tag")) + container.setTagCompound(new NBTTagCompound()) } for (i <- 0 until items.length) { items(i) = None } if (container.getTagCompound.hasKey(Settings.namespace + "items")) { - val list = container.getTagCompound.getTagList(Settings.namespace + "items") + val list = container.getTagCompound.getTagList(Settings.namespace + "items", NBT.TAG_COMPOUND) for (i <- 0 until (list.tagCount min items.length)) { - val tag = list.tagAt(i).asInstanceOf[NBTTagCompound] + val tag = list.getCompoundTagAt(i) if (!tag.hasNoTags) { items(i) = Option(ItemStack.loadItemStackFromNBT(tag)) } @@ -35,7 +36,7 @@ trait ItemStackInventory extends Inventory { } // Write items back to tag. - override def onInventoryChanged() { + override def markDirty() { val list = new NBTTagList() for (i <- 0 until items.length) { val tag = new NBTTagCompound() diff --git a/src/main/java/li/cil/oc/common/tileentity/Adapter.scala b/src/main/java/li/cil/oc/common/tileentity/Adapter.scala index ee5a1c598..c513137a5 100644 --- a/src/main/java/li/cil/oc/common/tileentity/Adapter.scala +++ b/src/main/java/li/cil/oc/common/tileentity/Adapter.scala @@ -5,7 +5,8 @@ import li.cil.oc.server.driver import li.cil.oc.{Settings, api} import net.minecraft.entity.player.EntityPlayer import net.minecraft.nbt.{NBTTagList, NBTTagCompound} -import net.minecraftforge.common.ForgeDirection +import net.minecraftforge.common.util.Constants.NBT +import net.minecraftforge.common.util.ForgeDirection import scala.{Array, Some} class Adapter extends Environment with Analyzable { @@ -17,7 +18,7 @@ class Adapter extends Environment with Analyzable { // ----------------------------------------------------------------------- // - def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = blocks collect { + override def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = blocks collect { case Some(((environment, _))) => environment.node } @@ -83,10 +84,9 @@ class Adapter extends Environment with Analyzable { override def readFromNBT(nbt: NBTTagCompound) { super.readFromNBT(nbt) - val blocksNbt = nbt.getTagList(Settings.namespace + "adapter.blocks") + val blocksNbt = nbt.getTagList(Settings.namespace + "adapter.blocks", NBT.TAG_COMPOUND) (0 until (blocksNbt.tagCount min blocksData.length)). - map(blocksNbt.tagAt). - map(_.asInstanceOf[NBTTagCompound]). + map(blocksNbt.getCompoundTagAt). zipWithIndex. foreach { case (blockNbt, i) => @@ -109,7 +109,7 @@ class Adapter extends Environment with Analyzable { case _ => } blockNbt.setString("name", data.name) - blockNbt.setCompoundTag("data", data.data) + blockNbt.setTag("data", data.data) case _ => } blocksNbt.appendTag(blockNbt) diff --git a/src/main/java/li/cil/oc/common/tileentity/BundledRedstoneAware.scala b/src/main/java/li/cil/oc/common/tileentity/BundledRedstoneAware.scala index 52e5de0ad..0d18c253b 100644 --- a/src/main/java/li/cil/oc/common/tileentity/BundledRedstoneAware.scala +++ b/src/main/java/li/cil/oc/common/tileentity/BundledRedstoneAware.scala @@ -6,9 +6,9 @@ import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.mods.ProjectRed import mods.immibis.redlogic.api.wiring.{IInsulatedRedstoneWire, IBundledUpdatable, IBundledEmitter} import mrtjp.projectred.api.{ProjectRedAPI, IBundledTile} -import net.minecraft.block.Block -import net.minecraft.nbt.{NBTTagIntArray, NBTTagCompound} -import net.minecraftforge.common.ForgeDirection +import net.minecraft.nbt.NBTTagCompound +import net.minecraftforge.common.util.Constants.NBT +import net.minecraftforge.common.util.ForgeDirection import powercrystals.minefactoryreloaded.api.rednet.IRedNetNetworkContainer import scala.Array @@ -87,21 +87,24 @@ trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBund override def readFromNBT(nbt: NBTTagCompound) { super.readFromNBT(nbt) - nbt.getTagList(Settings.namespace + "rs.bundledInput").iterator[NBTTagIntArray].zipWithIndex.foreach { - case (input, side) if side < _bundledInput.length => - val safeLength = input.intArray.length min _bundledInput(side).length - input.intArray.copyToArray(_bundledInput(side), 0, safeLength) + nbt.getTagList(Settings.namespace + "rs.bundledInput", NBT.TAG_INT_ARRAY).foreach { + case (list, index) if index < _bundledInput.length => + val input = list.func_150306_c(index) + val safeLength = input.length min _bundledInput(index).length + input.copyToArray(_bundledInput(index), 0, safeLength) } - nbt.getTagList(Settings.namespace + "rs.bundledOutput").iterator[NBTTagIntArray].zipWithIndex.foreach { - case (input, side) if side < _bundledOutput.length => - val safeLength = input.intArray.length min _bundledOutput(side).length - input.intArray.copyToArray(_bundledOutput(side), 0, safeLength) + nbt.getTagList(Settings.namespace + "rs.bundledOutput", NBT.TAG_INT_ARRAY).foreach { + case (list, index) if index < _bundledOutput.length => + val input = list.func_150306_c(index) + val safeLength = input.length min _bundledOutput(index).length + input.copyToArray(_bundledOutput(index), 0, safeLength) } - nbt.getTagList(Settings.namespace + "rs.rednetInput").iterator[NBTTagIntArray].zipWithIndex.foreach { - case (input, side) if side < _rednetInput.length => - val safeLength = input.intArray.length min _rednetInput(side).length - input.intArray.copyToArray(_rednetInput(side), 0, safeLength) + nbt.getTagList(Settings.namespace + "rs.rednetInput", NBT.TAG_INT_ARRAY).foreach { + case (list, index) if index < _rednetInput.length => + val input = list.func_150306_c(index) + val safeLength = input.length min _rednetInput(index).length + input.copyToArray(_rednetInput(index), 0, safeLength) } } @@ -118,7 +121,7 @@ trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBund protected def computeBundledInput(side: ForgeDirection): Array[Int] = { val redLogic = if (Loader.isModLoaded("RedLogic")) { - world.getBlockTileEntity( + world.getTileEntity( x + side.offsetX, y + side.offsetY, z + side.offsetZ) match { @@ -156,7 +159,7 @@ trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBund val nx = x + side.offsetX val ny = y + side.offsetY val nz = z + side.offsetZ - Block.blocksList(world.getBlockId(nx, ny, nz)) match { + world.getBlock(nx, ny, nz) match { case block: IRedNetNetworkContainer => block.updateNetwork(world, x, y, z) case _ => } @@ -168,7 +171,7 @@ trait BundledRedstoneAware extends RedstoneAware with IBundledEmitter with IBund val ny = y + side.offsetY val nz = z + side.offsetZ if (Loader.isModLoaded("MineFactoryReloaded")) { - Block.blocksList(world.getBlockId(nx, ny, nz)) match { + world.getBlock(nx, ny, nz) match { case block: IRedNetNetworkContainer => block.updateNetwork(world, x, y, z) case _ => } diff --git a/src/main/java/li/cil/oc/common/tileentity/Computer.scala b/src/main/java/li/cil/oc/common/tileentity/Computer.scala index c188ed934..52a75518d 100644 --- a/src/main/java/li/cil/oc/common/tileentity/Computer.scala +++ b/src/main/java/li/cil/oc/common/tileentity/Computer.scala @@ -9,8 +9,9 @@ import li.cil.oc.server.{PacketSender => ServerPacketSender, driver} import li.cil.oc.util.ExtendedNBT._ import net.minecraft.entity.player.EntityPlayer import net.minecraft.nbt.{NBTTagString, NBTTagCompound} -import net.minecraft.util.ChatMessageComponent -import net.minecraftforge.common.ForgeDirection +import net.minecraft.util.ChatComponentTranslation +import net.minecraftforge.common.util.Constants.NBT +import net.minecraftforge.common.util.ForgeDirection import scala.Some import scala.collection.mutable import stargatetech2.api.bus.IBusDevice @@ -49,7 +50,7 @@ abstract class Computer(isRemote: Boolean) extends Environment with ComponentInv @SideOnly(Side.CLIENT) def setRunning(value: Boolean) = { _isRunning = value - world.markBlockForRenderUpdate(x, y, z) + world.markBlockForUpdate(x, y, z) this } @@ -142,19 +143,19 @@ abstract class Computer(isRemote: Boolean) extends Environment with ComponentInv super.readFromNBTForClient(nbt) setRunning(nbt.getBoolean("isRunning")) _users.clear() - _users ++= nbt.getTagList("users").iterator[NBTTagString].map(_.data) + _users ++= nbt.getTagList("users", NBT.TAG_STRING).map((list, index) => list.getStringTagAt(index)) } override def writeToNBTForClient(nbt: NBTTagCompound) { super.writeToNBTForClient(nbt) nbt.setBoolean("isRunning", isRunning) - nbt.setNewTagList("users", computer.users.map(user => new NBTTagString(null, user))) + nbt.setNewTagList("users", computer.users.map(user => new NBTTagString(user))) } // ----------------------------------------------------------------------- // - override def onInventoryChanged() { - super.onInventoryChanged() + override def markDirty() { + super.markDirty() if (isServer) { computer.recomputeMemory() isOutputEnabled = hasRedstoneCard @@ -177,15 +178,15 @@ abstract class Computer(isRemote: Boolean) extends Environment with ComponentInv override def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = { computer.lastError match { case Some(value) => - player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions( - Settings.namespace + "gui.Analyzer.LastError", ChatMessageComponent.createFromTranslationKey(value))) + player.addChatMessage(new ChatComponentTranslation( + Settings.namespace + "gui.Analyzer.LastError", new ChatComponentTranslation(value))) case _ => } - player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions( + player.addChatMessage(new ChatComponentTranslation( Settings.namespace + "gui.Analyzer.Components", computer.componentCount + "/" + maxComponents)) val list = users if (list.size > 0) { - player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions( + player.addChatMessage(new ChatComponentTranslation( Settings.namespace + "gui.Analyzer.Users", list.mkString(", "))) } Array(computer.node) diff --git a/src/main/java/li/cil/oc/common/tileentity/Hub.scala b/src/main/java/li/cil/oc/common/tileentity/Hub.scala index 69ede28ce..43939dcf2 100644 --- a/src/main/java/li/cil/oc/common/tileentity/Hub.scala +++ b/src/main/java/li/cil/oc/common/tileentity/Hub.scala @@ -5,7 +5,8 @@ import li.cil.oc.api.network.{Node, Message, Visibility, SidedEnvironment} import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.{api, Settings} import net.minecraft.nbt.NBTTagCompound -import net.minecraftforge.common.ForgeDirection +import net.minecraftforge.common.util.Constants.NBT +import net.minecraftforge.common.util.ForgeDirection trait Hub extends Environment with SidedEnvironment { protected val plugs = ForgeDirection.VALID_DIRECTIONS.map(side => new Plug(side)) @@ -23,8 +24,8 @@ trait Hub extends Environment with SidedEnvironment { override def readFromNBT(nbt: NBTTagCompound) { super.readFromNBT(nbt) - nbt.getTagList(Settings.namespace + "plugs").iterator[NBTTagCompound].zip(plugs).foreach { - case (plugNbt, plug) => plug.node.load(plugNbt) + nbt.getTagList(Settings.namespace + "plugs", NBT.TAG_COMPOUND).foreach { + case (list, index) => plugs(index).node.load(list.getCompoundTagAt(index)) } } diff --git a/src/main/java/li/cil/oc/common/tileentity/PowerDistributor.scala b/src/main/java/li/cil/oc/common/tileentity/PowerDistributor.scala index eda2ae94f..8999f64e2 100644 --- a/src/main/java/li/cil/oc/common/tileentity/PowerDistributor.scala +++ b/src/main/java/li/cil/oc/common/tileentity/PowerDistributor.scala @@ -7,7 +7,8 @@ import li.cil.oc.api.network._ import li.cil.oc.util.ExtendedNBT._ import net.minecraft.entity.player.EntityPlayer import net.minecraft.nbt.NBTTagCompound -import net.minecraftforge.common.ForgeDirection +import net.minecraftforge.common.util.Constants.NBT +import net.minecraftforge.common.util.ForgeDirection class PowerDistributor extends Environment with PowerBalancer with Analyzable { val node = null @@ -29,8 +30,8 @@ class PowerDistributor extends Environment with PowerBalancer with Analyzable { override def readFromNBT(nbt: NBTTagCompound) { super.readFromNBT(nbt) - nbt.getTagList(Settings.namespace + "connector").iterator[NBTTagCompound].zip(nodes).foreach { - case (connectorNbt, connector) => connector.load(connectorNbt) + nbt.getTagList(Settings.namespace + "connector", NBT.TAG_COMPOUND).foreach { + case (list, index) => nodes(index).load(list.getCompoundTagAt(index)) } } diff --git a/src/main/java/li/cil/oc/common/tileentity/Rack.scala b/src/main/java/li/cil/oc/common/tileentity/Rack.scala index 384f9d1e8..7bc738ec5 100644 --- a/src/main/java/li/cil/oc/common/tileentity/Rack.scala +++ b/src/main/java/li/cil/oc/common/tileentity/Rack.scala @@ -1,5 +1,6 @@ package li.cil.oc.common.tileentity +import com.google.common.base.Strings import cpw.mods.fml.common.Optional import cpw.mods.fml.relauncher.{Side, SideOnly} import li.cil.oc.api.Network @@ -11,8 +12,9 @@ import li.cil.oc.{api, Items, Settings} import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack import net.minecraft.nbt.{NBTTagString, NBTTagCompound} -import net.minecraft.util.ChatMessageComponent -import net.minecraftforge.common.ForgeDirection +import net.minecraft.util.ChatComponentTranslation +import net.minecraftforge.common.util.Constants.NBT +import net.minecraftforge.common.util.ForgeDirection import stargatetech2.api.bus.IBusDevice // See AbstractBusAware as to why we have to define the IBusDevice here. @@ -48,7 +50,7 @@ class Rack extends Hub with PowerBalancer with Inventory with Rotatable with Bun @SideOnly(Side.CLIENT) def setRunning(number: Int, value: Boolean) = { _isRunning(number) = value - world.markBlockForRenderUpdate(x, y, z) + world.markBlockForUpdate(x, y, z) this } @@ -94,7 +96,7 @@ class Rack extends Hub with PowerBalancer with Inventory with Rotatable with Bun override def getSizeInventory = 4 - override def getInvName = Settings.namespace + "container.Rack" + override def getInventoryName = Settings.namespace + "container.Rack" override def getInventoryStackLimit = 1 @@ -111,15 +113,15 @@ class Rack extends Hub with PowerBalancer with Inventory with Rotatable with Bun val computer = servers(slot).get.machine computer.lastError match { case Some(value) => - player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions( - Settings.namespace + "gui.Analyzer.LastError", ChatMessageComponent.createFromTranslationKey(value))) + player.addChatMessage(new ChatComponentTranslation( + Settings.namespace + "gui.Analyzer.LastError", new ChatComponentTranslation(value))) case _ => } - player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions( + player.addChatMessage(new ChatComponentTranslation( Settings.namespace + "gui.Analyzer.Components", computer.componentCount + "/" + servers(slot).get.maxComponents)) val list = computer.users if (list.size > 0) { - player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions( + player.addChatMessage(new ChatComponentTranslation( Settings.namespace + "gui.Analyzer.Users", list.mkString(", "))) } Array(computer.node) @@ -194,18 +196,15 @@ class Rack extends Hub with PowerBalancer with Inventory with Rotatable with Bun servers(slot) = Some(server) } } - for ((serverNbt, slot) <- nbt.getTagList(Settings.namespace + "servers").iterator[NBTTagCompound].zipWithIndex if slot < servers.length) { - servers(slot) match { - case Some(server) => server.load(serverNbt) + nbt.getTagList(Settings.namespace + "servers", NBT.TAG_COMPOUND).foreach((list, index) => + if (index < servers.length) servers(index) match { + case Some(server) => server.load(list.getCompoundTagAt(index)) case _ => - } - } - val sidesNbt = nbt.getByteArray(Settings.namespace + "sides").byteArray.map(ForgeDirection.getOrientation(_)) + }) + val sidesNbt = nbt.getByteArray(Settings.namespace + "sides").map(ForgeDirection.getOrientation(_)) Array.copy(sidesNbt, 0, sides, 0, math.min(sidesNbt.length, sides.length)) - val terminalsNbt = nbt.getTagList(Settings.namespace + "terminals").iterator[NBTTagCompound].toArray - for (i <- 0 until math.min(terminals.length, terminalsNbt.length)) { - terminals(i).load(terminalsNbt(i)) - } + nbt.getTagList(Settings.namespace + "terminals", NBT.TAG_COMPOUND). + foreach((list, index) => if (index < terminals.length) terminals(index).load(list.getCompoundTagAt(index))) range = nbt.getInteger(Settings.namespace + "range") } @@ -232,23 +231,24 @@ class Rack extends Hub with PowerBalancer with Inventory with Rotatable with Bun @SideOnly(Side.CLIENT) override def readFromNBTForClient(nbt: NBTTagCompound) { super.readFromNBTForClient(nbt) - val isRunningNbt = nbt.getByteArray("isServerRunning").byteArray.map(_ == 1) + val isRunningNbt = nbt.getByteArray("isServerRunning").map(_ == 1) Array.copy(isRunningNbt, 0, _isRunning, 0, math.min(isRunningNbt.length, _isRunning.length)) - val isPresentNbt = nbt.getTagList("isPresent").iterator[NBTTagString].map(value => if (value.data == "") None else Some(value.data)).toArray + val isPresentNbt = nbt.getTagList("isPresent", NBT.TAG_STRING).map((list, index) => { + val value = list.getStringTagAt(index) + if (Strings.isNullOrEmpty(value)) None else Some(value) + }).toArray Array.copy(isPresentNbt, 0, isPresent, 0, math.min(isPresentNbt.length, isPresent.length)) - val sidesNbt = nbt.getByteArray("sides").byteArray.map(ForgeDirection.getOrientation(_)) + val sidesNbt = nbt.getByteArray("sides").map(ForgeDirection.getOrientation(_)) Array.copy(sidesNbt, 0, sides, 0, math.min(sidesNbt.length, sides.length)) - val terminalsNbt = nbt.getTagList("terminals").iterator[NBTTagCompound].toArray - for (i <- 0 until math.min(terminals.length, terminalsNbt.length)) { - terminals(i).readFromNBTForClient(terminalsNbt(i)) - } + nbt.getTagList("terminals", NBT.TAG_COMPOUND). + foreach((list, index) => if (index < terminals.length) terminals(index).readFromNBTForClient(list.getCompoundTagAt(index))) range = nbt.getInteger("range") } override def writeToNBTForClient(nbt: NBTTagCompound) { super.writeToNBTForClient(nbt) nbt.setByteArray("isServerRunning", _isRunning.map(value => (if (value) 1 else 0).toByte)) - nbt.setNewTagList("isPresent", servers.map(value => new NBTTagString(null, value.fold("")(_.machine.address)))) + nbt.setNewTagList("isPresent", servers.map(value => new NBTTagString(value.fold("")(_.machine.address)))) nbt.setByteArray("sides", sides.map(_.ordinal.toByte)) nbt.setNewTagList("terminals", terminals.map(t => { val terminalNbt = new NBTTagCompound() @@ -297,22 +297,22 @@ class Rack extends Hub with PowerBalancer with Inventory with Rotatable with Bun server.machine.node.remove() server.inventory.containerOverride = stack server.inventory.save(new NBTTagCompound()) // Only flush components. - server.inventory.onInventoryChanged() + server.inventory.markDirty() case _ => } servers(slot) = None } } - override def onInventoryChanged() { - super.onInventoryChanged() + override def markDirty() { + super.markDirty() if (isServer) { isOutputEnabled = hasRedstoneCard isAbstractBusAvailable = hasAbstractBusCard ServerPacketSender.sendServerPresence(this) } else { - world.markBlockForRenderUpdate(x, y, z) + world.markBlockForUpdate(x, y, z) } } diff --git a/src/main/java/li/cil/oc/common/tileentity/Robot.scala b/src/main/java/li/cil/oc/common/tileentity/Robot.scala index cbf5a48cf..c1fa90d7e 100644 --- a/src/main/java/li/cil/oc/common/tileentity/Robot.scala +++ b/src/main/java/li/cil/oc/common/tileentity/Robot.scala @@ -10,13 +10,14 @@ import li.cil.oc.server.driver.Registry import li.cil.oc.server.{PacketSender => ServerPacketSender, driver, component} import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.{Blocks, Settings, api, common} +import net.minecraft.block.Block import net.minecraft.client.Minecraft import net.minecraft.entity.player.EntityPlayer import net.minecraft.inventory.ISidedInventory import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound -import net.minecraft.util.ChatMessageComponent -import net.minecraftforge.common.ForgeDirection +import net.minecraft.util.ChatComponentTranslation +import net.minecraftforge.common.util.ForgeDirection // Implementation note: this tile entity is never directly added to the world. // It is always wrapped by a `RobotProxy` tile entity, which forwards any @@ -63,7 +64,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w } val keyboard = new component.Keyboard { override def isUseableByPlayer(p: EntityPlayer) = - world.getBlockTileEntity(x, y, z) == proxy && + world.getTileEntity(x, y, z) == proxy && p.getDistanceSq(x + 0.5, y + 0.5, z + 0.5) <= 64 } (gpu, keyboard) @@ -124,11 +125,11 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w // ----------------------------------------------------------------------- // override def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = { - player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions( + player.addChatMessage(new ChatComponentTranslation( Settings.namespace + "gui.Analyzer.RobotOwner", owner)) - player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions( + player.addChatMessage(new ChatComponentTranslation( Settings.namespace + "gui.Analyzer.RobotName", player_.getCommandSenderName)) - player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions( + player.addChatMessage(new ChatComponentTranslation( Settings.namespace + "gui.Analyzer.RobotXp", xp.formatted("%.2f"), level: Integer)) super.onAnalyze(player, side, hitX, hitY, hitZ) } @@ -146,7 +147,8 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w if (!world.blockExists(nx, ny, nz)) { return false // Don't fall off the earth. } - val blockId = world.getBlockId(nx, ny, nz) + val wasAir = world.isAirBlock(nx, ny, nz) + val block = world.getBlock(nx, ny, nz) val metadata = world.getBlockMetadata(nx, ny, nz) try { // Setting this will make the tile entity created via the following call @@ -161,10 +163,10 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w // In some cases (though I couldn't quite figure out which one) setBlock // will return true, even though the block was not created / adjusted. val created = Blocks.robotProxy.setBlock(world, nx, ny, nz, 1) && - world.getBlockTileEntity(nx, ny, nz) == proxy + world.getTileEntity(nx, ny, nz) == proxy if (created) { assert(x == nx && y == ny && z == nz) - world.setBlock(ox, oy, oz, 0, 0, 1) + world.setBlock(ox, oy, oz, net.minecraft.init.Blocks.air, 0, 1) Blocks.robotAfterimage.setBlock(world, ox, oy, oz, 1) assert(Delegator.subBlock(world, ox, oy, oz).exists(_ == Blocks.robotAfterimage)) // Here instead of Lua callback so that it gets called on client, too. @@ -176,11 +178,11 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w } else { // If we broke some replaceable block (like grass) play its break sound. - if (blockId > 0) { - world.playAuxSFX(2001, nx, ny, nz, blockId + (metadata << 12)) + if (!wasAir) { + world.playAuxSFX(2001, nx, ny, nz, Block.getIdFromBlock(block) + (metadata << 12)) } - world.markBlockForRenderUpdate(ox, oy, oz) - world.markBlockForRenderUpdate(nx, ny, nz) + world.markBlockForUpdate(ox, oy, oz) + world.markBlockForUpdate(nx, ny, nz) } assert(!isInvalid) } @@ -194,7 +196,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w def createItemStack() = { val stack = Blocks.robotProxy.createItemStack() if (globalBuffer > 1 || xp > 0) { - stack.setTagCompound(new NBTTagCompound("tag")) + stack.setTagCompound(new NBTTagCompound()) } if (xp > 0) { stack.getTagCompound.setDouble(Settings.namespace + "xp", xp) @@ -503,7 +505,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w // ----------------------------------------------------------------------- // - override def getInvName = Settings.namespace + "container.Robot" + override def getInventoryName = Settings.namespace + "container.Robot" override def getSizeInventory = 20 @@ -522,7 +524,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w } override def isUseableByPlayer(player: EntityPlayer) = - world.getBlockTileEntity(x, y, z) match { + world.getTileEntity(x, y, z) match { case t: RobotProxy if t == proxy && computer.canInteract(player.getCommandSenderName) => player.getDistanceSq(x + 0.5, y + 0.5, z + 0.5) <= 64 case _ => false diff --git a/src/main/java/li/cil/oc/server/component/Filesystem.scala b/src/main/java/li/cil/oc/server/component/Filesystem.scala index 3958e788c..9ed3c391a 100644 --- a/src/main/java/li/cil/oc/server/component/Filesystem.scala +++ b/src/main/java/li/cil/oc/server/component/Filesystem.scala @@ -6,7 +6,8 @@ import li.cil.oc.api.Network import li.cil.oc.api.fs.{Label, Mode, FileSystem => IFileSystem} import li.cil.oc.api.network._ import li.cil.oc.util.ExtendedNBT._ -import net.minecraft.nbt.{NBTTagInt, NBTTagList, NBTTagCompound} +import net.minecraft.nbt.{NBTTagIntArray, NBTTagList, NBTTagCompound} +import net.minecraftforge.common.util.Constants.NBT import scala.collection.mutable class FileSystem(val fileSystem: IFileSystem, var label: Label) extends ManagedComponent { @@ -228,15 +229,11 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label) extends ManagedC override def load(nbt: NBTTagCompound) { super.load(nbt) - val ownersNbt = nbt.getTagList("owners") - (0 until ownersNbt.tagCount).map(ownersNbt.tagAt).map(_.asInstanceOf[NBTTagCompound]).foreach(ownerNbt => { + nbt.getTagList("owners", NBT.TAG_COMPOUND).foreach((list, index) => { + val ownerNbt = list.getCompoundTagAt(index) val address = ownerNbt.getString("address") if (address != "") { - val handlesNbt = ownerNbt.getTagList("handles") - owners += address -> (0 until handlesNbt.tagCount). - map(handlesNbt.tagAt). - map(_.asInstanceOf[NBTTagInt].data). - to[mutable.Set] + owners += address -> ownerNbt.getIntArray("handles").to[mutable.Set] } }) @@ -250,11 +247,7 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label) extends ManagedC for ((address, handles) <- owners) { val ownerNbt = new NBTTagCompound() ownerNbt.setString("address", address) - val handlesNbt = new NBTTagList() - for (handle <- handles) { - handlesNbt.appendTag(new NBTTagInt(null, handle)) - } - ownerNbt.setTag("handles", handlesNbt) + ownerNbt.setTag("handles", new NBTTagIntArray(handles.toArray)) ownersNbt.appendTag(ownerNbt) } nbt.setTag("owners", ownersNbt) diff --git a/src/main/java/li/cil/oc/server/component/Keyboard.scala b/src/main/java/li/cil/oc/server/component/Keyboard.scala index 0cfae7679..742d13f05 100644 --- a/src/main/java/li/cil/oc/server/component/Keyboard.scala +++ b/src/main/java/li/cil/oc/server/component/Keyboard.scala @@ -98,6 +98,7 @@ abstract class Keyboard extends ManagedComponent { node.sendToReachable("computer.checked_signal", args: _*) } +// TODO verify these work (they don't seem to) object Keyboard { @SubscribeEvent diff --git a/src/main/java/li/cil/oc/server/component/NetworkCard.scala b/src/main/java/li/cil/oc/server/component/NetworkCard.scala index 04c3a4dc2..54f0aec30 100644 --- a/src/main/java/li/cil/oc/server/component/NetworkCard.scala +++ b/src/main/java/li/cil/oc/server/component/NetworkCard.scala @@ -3,8 +3,7 @@ package li.cil.oc.server.component import li.cil.oc.Settings import li.cil.oc.api.Network import li.cil.oc.api.network._ -import li.cil.oc.util.ExtendedNBT._ -import net.minecraft.nbt.{NBTTagInt, NBTTagCompound} +import net.minecraft.nbt.NBTTagCompound import scala.collection.convert.WrapAsScala._ import scala.collection.mutable @@ -90,13 +89,13 @@ class NetworkCard extends ManagedComponent { super.load(nbt) assert(openPorts.isEmpty) - openPorts ++= nbt.getTagList("openPorts").iterator[NBTTagInt].map(_.data) + openPorts ++= nbt.getIntArray("openPorts") } override def save(nbt: NBTTagCompound) { super.save(nbt) - nbt.setNewTagList("openPorts", openPorts) + nbt.setIntArray("openPorts", openPorts.toArray) } // ----------------------------------------------------------------------- // diff --git a/src/main/java/li/cil/oc/server/component/machine/Machine.scala b/src/main/java/li/cil/oc/server/component/machine/Machine.scala index 8cbd9b27b..c33a2efbe 100644 --- a/src/main/java/li/cil/oc/server/component/machine/Machine.scala +++ b/src/main/java/li/cil/oc/server/component/machine/Machine.scala @@ -10,11 +10,13 @@ import li.cil.oc.server.component.ManagedComponent import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.{LuaStateFactory, ThreadPoolFactory} import li.cil.oc.{OpenComputers, Settings} +import net.minecraft.client.Minecraft import net.minecraft.entity.player.EntityPlayer import net.minecraft.nbt._ import net.minecraft.server.MinecraftServer import net.minecraft.server.integrated.IntegratedServer import net.minecraft.world.World +import net.minecraftforge.common.util.Constants.NBT import scala.Array.canBuildFrom import scala.collection.mutable @@ -504,14 +506,20 @@ class Machine(val owner: Machine.Owner) extends ManagedComponent with Context wi super.load(nbt) - state.pushAll(nbt.getTagList("state").iterator[NBTTagInt].reverse.map(s => Machine.State(s.data))) - nbt.getTagList("users").foreach[NBTTagString](u => _users += u.data) + // For upgrading from 1.6 - was tag list of int before. + if (nbt.hasKey("state", NBT.TAG_INT_ARRAY)) { + state.pushAll(nbt.getIntArray("state").reverse.map(Machine.State(_))) + } + else state.push(Machine.State.Stopped) + nbt.getTagList("users", NBT.TAG_STRING).foreach((list, index) => _users += list.getStringTagAt(index)) if (nbt.hasKey("message")) { message = Some(nbt.getString("message")) } - components ++= nbt.getTagList("components").iterator[NBTTagCompound].map(c => - c.getString("address") -> c.getString("name")) + components ++= nbt.getTagList("components", NBT.TAG_COMPOUND).map((list, index) => { + val c = list.getCompoundTagAt(index) + c.getString("address") -> c.getString("name") + }) rom.foreach(rom => rom.load(nbt.getCompoundTag("rom"))) tmp.foreach(tmp => tmp.load(nbt.getCompoundTag("tmp"))) @@ -519,23 +527,21 @@ class Machine(val owner: Machine.Owner) extends ManagedComponent with Context wi if (state.size > 0 && state.top != Machine.State.Stopped && init()) { architecture.load(nbt) - signals ++= nbt.getTagList("signals").iterator[NBTTagCompound].map(signalNbt => { + signals ++= nbt.getTagList("signals", NBT.TAG_COMPOUND).map((list, index) => { + val signalNbt = list.getCompoundTagAt(index) val argsNbt = signalNbt.getCompoundTag("args") val argsLength = argsNbt.getInteger("length") new Machine.Signal(signalNbt.getString("name"), (0 until argsLength).map("arg" + _).map(argsNbt.getTag).map { - case tag: NBTTagByte if tag.data == -1 => Unit - case tag: NBTTagByte => tag.data == 1 - case tag: NBTTagDouble => tag.data - case tag: NBTTagString => tag.data - case tag: NBTTagByteArray => tag.byteArray + case tag: NBTTagByte if tag.func_150290_f == -1 => Unit + case tag: NBTTagByte => tag.func_150290_f == 1 + case tag: NBTTagDouble => tag.func_150286_g + case tag: NBTTagString => tag.func_150285_a_ + case tag: NBTTagByteArray => tag.func_150292_c case tag: NBTTagList => val data = mutable.Map.empty[String, String] for (i <- 0 until tag.tagCount by 2) { - (tag.tagAt(i), tag.tagAt(i + 1)) match { - case (key: NBTTagString, value: NBTTagString) => data += key.data -> value.data - case _ => - } + data += tag.getStringTagAt(i) -> tag.getStringTagAt(i + 1) } data case _ => Unit @@ -565,7 +571,7 @@ class Machine(val owner: Machine.Owner) extends ManagedComponent with Context wi // Make sure the component list is up-to-date. processAddedComponents() - nbt.setNewTagList("state", state.map(_.id)) + nbt.setIntArray("state", state.map(_.id).toArray) nbt.setNewTagList("users", _users) message.foreach(nbt.setString("message", _)) @@ -675,7 +681,7 @@ class Machine(val owner: Machine.Owner) extends ManagedComponent with Context wi } private def isGamePaused = !MinecraftServer.getServer.isDedicatedServer && (MinecraftServer.getServer match { - case integrated: IntegratedServer => integrated.getServerListeningThread.isGamePaused + case integrated: IntegratedServer => Minecraft.getMinecraft.isGamePaused case _ => false }) diff --git a/src/main/java/li/cil/oc/server/driver/item/Item.scala b/src/main/java/li/cil/oc/server/driver/item/Item.scala index 450421ff5..fd131927d 100644 --- a/src/main/java/li/cil/oc/server/driver/item/Item.scala +++ b/src/main/java/li/cil/oc/server/driver/item/Item.scala @@ -21,11 +21,11 @@ trait Item extends driver.Item { object Item { def dataTag(stack: ItemStack) = { if (!stack.hasTagCompound) { - stack.setTagCompound(new NBTTagCompound("tag")) + stack.setTagCompound(new NBTTagCompound()) } val nbt = stack.getTagCompound if (!nbt.hasKey(Settings.namespace + "data")) { - nbt.setCompoundTag(Settings.namespace + "data", new NBTTagCompound()) + nbt.setTag(Settings.namespace + "data", new NBTTagCompound()) } nbt.getCompoundTag(Settings.namespace + "data") } diff --git a/src/main/java/li/cil/oc/server/fs/InputStreamFileSystem.scala b/src/main/java/li/cil/oc/server/fs/InputStreamFileSystem.scala index 5ffa75ff7..e866bc526 100644 --- a/src/main/java/li/cil/oc/server/fs/InputStreamFileSystem.scala +++ b/src/main/java/li/cil/oc/server/fs/InputStreamFileSystem.scala @@ -4,6 +4,7 @@ import java.io.{FileNotFoundException, IOException, InputStream} import li.cil.oc.api import li.cil.oc.api.fs.Mode import net.minecraft.nbt.{NBTTagList, NBTTagCompound} +import net.minecraftforge.common.util.Constants.NBT import scala.collection.mutable trait InputStreamFileSystem extends api.fs.FileSystem { @@ -11,19 +12,19 @@ trait InputStreamFileSystem extends api.fs.FileSystem { // ----------------------------------------------------------------------- // - def isReadOnly = true + override def isReadOnly = true - def delete(path: String) = false + override def delete(path: String) = false - def makeDirectory(path: String) = false + override def makeDirectory(path: String) = false - def rename(from: String, to: String) = false + override def rename(from: String, to: String) = false - def setLastModified(path: String, time: Long) = false + override def setLastModified(path: String, time: Long) = false // ----------------------------------------------------------------------- // - def open(path: String, mode: Mode) = if (mode == Mode.Read && exists(path) && !isDirectory(path)) { + override def open(path: String, mode: Mode) = if (mode == Mode.Read && exists(path) && !isDirectory(path)) { val handle = Iterator.continually((Math.random() * Int.MaxValue).toInt + 1).filterNot(handles.contains).next() openInputStream(path) match { case Some(stream) => @@ -33,9 +34,9 @@ trait InputStreamFileSystem extends api.fs.FileSystem { } } else throw new FileNotFoundException() - def getHandle(handle: Int): api.fs.Handle = handles.get(handle).orNull + override def getHandle(handle: Int): api.fs.Handle = handles.get(handle).orNull - def close() { + override def close() { for (handle <- handles.values) handle.close() handles.clear() @@ -43,9 +44,9 @@ trait InputStreamFileSystem extends api.fs.FileSystem { // ----------------------------------------------------------------------- // - def load(nbt: NBTTagCompound) { - val handlesNbt = nbt.getTagList("input") - (0 until handlesNbt.tagCount).map(handlesNbt.tagAt).map(_.asInstanceOf[NBTTagCompound]).foreach(handleNbt => { + override def load(nbt: NBTTagCompound) { + val handlesNbt = nbt.getTagList("input", NBT.TAG_COMPOUND) + (0 until handlesNbt.tagCount).map(handlesNbt.getCompoundTagAt).foreach(handleNbt => { val handle = handleNbt.getInteger("handle") val path = handleNbt.getString("path") val position = handleNbt.getLong("position") @@ -59,7 +60,7 @@ trait InputStreamFileSystem extends api.fs.FileSystem { }) } - def save(nbt: NBTTagCompound) { + override def save(nbt: NBTTagCompound) { val handlesNbt = new NBTTagList() for (file <- handles.values) { assert(!file.isClosed) @@ -82,28 +83,28 @@ trait InputStreamFileSystem extends api.fs.FileSystem { var isClosed = false var position = 0L - def length = owner.size(path) + override def length = owner.size(path) - def close() = if (!isClosed) { + override def close() = if (!isClosed) { isClosed = true owner.handles -= handle stream.close() } - def read(into: Array[Byte]) = { + override def read(into: Array[Byte]) = { val read = stream.read(into) if (read >= 0) position += read read } - def seek(to: Long) = { + override def seek(to: Long) = { stream.reset() position = stream.skip(to) position } - def write(value: Array[Byte]) = throw new IOException("bad file descriptor") + override def write(value: Array[Byte]) = throw new IOException("bad file descriptor") } } diff --git a/src/main/java/li/cil/oc/server/fs/OutputStreamFileSystem.scala b/src/main/java/li/cil/oc/server/fs/OutputStreamFileSystem.scala index ed2f7afe0..d76053b61 100644 --- a/src/main/java/li/cil/oc/server/fs/OutputStreamFileSystem.scala +++ b/src/main/java/li/cil/oc/server/fs/OutputStreamFileSystem.scala @@ -4,6 +4,7 @@ import java.io.{FileNotFoundException, IOException, OutputStream} import li.cil.oc.api import li.cil.oc.api.fs.Mode import net.minecraft.nbt.{NBTTagList, NBTTagCompound} +import net.minecraftforge.common.util.Constants.NBT import scala.collection.mutable trait OutputStreamFileSystem extends InputStreamFileSystem { @@ -42,8 +43,8 @@ trait OutputStreamFileSystem extends InputStreamFileSystem { override def load(nbt: NBTTagCompound) { super.load(nbt) - val handlesNbt = nbt.getTagList("output") - (0 until handlesNbt.tagCount).map(handlesNbt.tagAt).map(_.asInstanceOf[NBTTagCompound]).foreach(handleNbt => { + val handlesNbt = nbt.getTagList("output", NBT.TAG_COMPOUND) + (0 until handlesNbt.tagCount).map(handlesNbt.getCompoundTagAt).foreach(handleNbt => { val handle = handleNbt.getInteger("handle") val path = handleNbt.getString("path") openOutputStream(path, Mode.Append) match { diff --git a/src/main/java/li/cil/oc/server/fs/VirtualFileSystem.scala b/src/main/java/li/cil/oc/server/fs/VirtualFileSystem.scala index 6b7d300ed..1ad02cc23 100644 --- a/src/main/java/li/cil/oc/server/fs/VirtualFileSystem.scala +++ b/src/main/java/li/cil/oc/server/fs/VirtualFileSystem.scala @@ -4,6 +4,7 @@ import java.io import java.io.FileNotFoundException import li.cil.oc.api.fs.Mode import net.minecraft.nbt.{NBTTagList, NBTTagCompound} +import net.minecraftforge.common.util.Constants.NBT import scala.collection.mutable trait VirtualFileSystem extends OutputStreamFileSystem { @@ -236,8 +237,8 @@ trait VirtualFileSystem extends OutputStreamFileSystem { override def load(nbt: NBTTagCompound) { super.load(nbt) - val childrenNbt = nbt.getTagList("children") - (0 until childrenNbt.tagCount).map(childrenNbt.tagAt).map(_.asInstanceOf[NBTTagCompound]).foreach(childNbt => { + val childrenNbt = nbt.getTagList("children", NBT.TAG_COMPOUND) + (0 until childrenNbt.tagCount).map(childrenNbt.getCompoundTagAt).foreach(childNbt => { val child = if (childNbt.getBoolean("isDirectory")) new VirtualDirectory else new VirtualFile diff --git a/src/main/java/li/cil/oc/util/ExtendedNBT.scala b/src/main/java/li/cil/oc/util/ExtendedNBT.scala index 2f44737da..f94384826 100644 --- a/src/main/java/li/cil/oc/util/ExtendedNBT.scala +++ b/src/main/java/li/cil/oc/util/ExtendedNBT.scala @@ -2,27 +2,26 @@ package li.cil.oc.util import net.minecraft.nbt._ import scala.language.implicitConversions -import scala.reflect.ClassTag object ExtendedNBT { - implicit def toNbt(value: Byte) = new NBTTagByte(null, value) + implicit def toNbt(value: Byte) = new NBTTagByte(value) - implicit def toNbt(value: Short) = new NBTTagShort(null, value) + implicit def toNbt(value: Short) = new NBTTagShort(value) - implicit def toNbt(value: Int) = new NBTTagInt(null, value) + implicit def toNbt(value: Int) = new NBTTagInt(value) - implicit def toNbt(value: Array[Int]) = new NBTTagIntArray(null, value) + implicit def toNbt(value: Array[Int]) = new NBTTagIntArray(value) - implicit def toNbt(value: Long) = new NBTTagLong(null, value) + implicit def toNbt(value: Long) = new NBTTagLong(value) - implicit def toNbt(value: Float) = new NBTTagFloat(null, value) + implicit def toNbt(value: Float) = new NBTTagFloat(value) - implicit def toNbt(value: Double) = new NBTTagDouble(null, value) + implicit def toNbt(value: Double) = new NBTTagDouble(value) - implicit def toNbt(value: Array[Byte]) = new NBTTagByteArray(null, value) + implicit def toNbt(value: Array[Byte]) = new NBTTagByteArray(value) - implicit def toNbt(value: String) = new NBTTagString(null, value) + implicit def toNbt(value: String) = new NBTTagString(value) implicit def byteIterableToNbt(value: Iterable[Byte]) = value.map(toNbt) @@ -50,7 +49,7 @@ object ExtendedNBT { def setNewCompoundTag(name: String, f: (NBTTagCompound) => Any) = { val t = new NBTTagCompound() f(t) - nbt.setCompoundTag(name, t) + nbt.setTag(name, t) nbt } @@ -79,13 +78,9 @@ object ExtendedNBT { def append(values: NBTBase*): Unit = append(values) - def iterator[Tag <: NBTBase : ClassTag] = (0 until nbt.tagCount).map(nbt.tagAt).collect { - case tag: Tag => tag - } + def foreach(f: (NBTTagList, Int) => Unit): Unit = (0 until nbt.tagCount).map(f(nbt, _)) - def foreach[Tag <: NBTBase : ClassTag](f: (Tag) => Unit) = iterator[Tag].foreach(f) - - def map[Tag <: NBTBase : ClassTag, Value](f: (Tag) => Value) = iterator[Tag].map(f) + def map[Value](f: (NBTTagList, Int) => Value) = (0 until nbt.tagCount).map(f(nbt, _)) } } diff --git a/src/main/java/li/cil/oc/util/TextBuffer.scala b/src/main/java/li/cil/oc/util/TextBuffer.scala index d49b58f2f..9aa40cd51 100644 --- a/src/main/java/li/cil/oc/util/TextBuffer.scala +++ b/src/main/java/li/cil/oc/util/TextBuffer.scala @@ -2,6 +2,7 @@ package li.cil.oc.util import li.cil.oc.Settings import net.minecraft.nbt._ +import net.minecraftforge.common.util.Constants.NBT /** * This stores chars in a 2D-Array and provides some manipulation functions. @@ -170,27 +171,24 @@ class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Dept val h = nbt.getInteger("height") max 1 min Settings.screenResolutionsByTier(2)._2 size = (w, h) - val b = nbt.getTagList("buffer") + val b = nbt.getTagList("buffer", NBT.TAG_STRING) for (i <- 0 until math.min(h, b.tagCount)) { - b.tagAt(i) match { - case tag: NBTTagString => set(0, i, tag.data) - case _ => - } + set(0, i, b.getStringTagAt(i)) } _depth = PackedColor.Depth(nbt.getInteger("depth") max 0 min PackedColor.Depth.maxId) foreground = nbt.getInteger("foreground") background = nbt.getInteger("background") - val c = nbt.getTagList("color") - for (i <- 0 until h) { - val rowColor = color(i) - for (j <- 0 until w) { - val index = j + i * w - if (index < c.tagCount) { - c.tagAt(index) match { - case tag: NBTTagShort => rowColor(j) = tag.data - case _ => + // For upgrading from 1.6 - was tag list of short before. + if (nbt.hasKey("color", NBT.TAG_INT_ARRAY)) { + val c = nbt.getIntArray("color") + for (i <- 0 until h) { + val rowColor = color(i) + for (j <- 0 until w) { + val index = j + i * w + if (index < c.length) { + rowColor(j) = c(index).toShort } } } @@ -203,7 +201,7 @@ class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Dept val b = new NBTTagList() for (i <- 0 until height) { - b.appendTag(new NBTTagString(null, String.valueOf(buffer(i)))) + b.appendTag(new NBTTagString(String.valueOf(buffer(i)))) } nbt.setTag("buffer", b) @@ -211,14 +209,7 @@ class TextBuffer(var width: Int, var height: Int, initialDepth: PackedColor.Dept nbt.setInteger("foreground", _foreground) nbt.setInteger("background", _background) - val c = new NBTTagList() - for (i <- 0 until height) { - val rowColor = color(i) - for (j <- 0 until width) { - c.appendTag(new NBTTagShort(null, rowColor(j))) - } - } - nbt.setTag("color", c) + nbt.setTag("color", new NBTTagIntArray(color.flatten.map(_.toInt).toArray)) } override def toString = {