mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 03:36:47 -04:00
Convert blocks in OC inventories on load, in particular to ensure screens in robots are converted.
This commit is contained in:
parent
a6da00f4a9
commit
366c6fc476
@ -14,12 +14,12 @@ import li.cil.oc.common.tileentity.traits.power
|
|||||||
import li.cil.oc.integration.Mods
|
import li.cil.oc.integration.Mods
|
||||||
import li.cil.oc.integration.util
|
import li.cil.oc.integration.util
|
||||||
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
||||||
|
import li.cil.oc.util.ItemUtils
|
||||||
import li.cil.oc.util.LuaStateFactory
|
import li.cil.oc.util.LuaStateFactory
|
||||||
import li.cil.oc.util.SideTracker
|
import li.cil.oc.util.SideTracker
|
||||||
import li.cil.oc.util.UpdateCheck
|
import li.cil.oc.util.UpdateCheck
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.entity.player.EntityPlayerMP
|
import net.minecraft.entity.player.EntityPlayerMP
|
||||||
import net.minecraft.item.ItemStack
|
|
||||||
import net.minecraft.server.MinecraftServer
|
import net.minecraft.server.MinecraftServer
|
||||||
import net.minecraft.tileentity.TileEntity
|
import net.minecraft.tileentity.TileEntity
|
||||||
import net.minecraftforge.common.MinecraftForge
|
import net.minecraftforge.common.MinecraftForge
|
||||||
@ -159,7 +159,7 @@ object EventHandler {
|
|||||||
if (stack != null && api.Items.get(stack) == navigationUpgrade) {
|
if (stack != null && api.Items.get(stack) == navigationUpgrade) {
|
||||||
// Restore the map currently used in the upgrade.
|
// Restore the map currently used in the upgrade.
|
||||||
val nbt = driver.dataTag(stack)
|
val nbt = driver.dataTag(stack)
|
||||||
val map = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag(Settings.namespace + "map"))
|
val map = ItemUtils.loadStack(nbt.getCompoundTag(Settings.namespace + "map"))
|
||||||
if (!e.player.inventory.addItemStackToInventory(map)) {
|
if (!e.player.inventory.addItemStackToInventory(map)) {
|
||||||
e.player.dropPlayerItemWithRandomChoice(map, false)
|
e.player.dropPlayerItemWithRandomChoice(map, false)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import io.netty.buffer.ByteBufInputStream
|
|||||||
import li.cil.oc.OpenComputers
|
import li.cil.oc.OpenComputers
|
||||||
import li.cil.oc.api
|
import li.cil.oc.api
|
||||||
import li.cil.oc.common.block.RobotAfterimage
|
import li.cil.oc.common.block.RobotAfterimage
|
||||||
|
import li.cil.oc.util.ItemUtils
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.CompressedStreamTools
|
import net.minecraft.nbt.CompressedStreamTools
|
||||||
@ -84,7 +85,7 @@ abstract class PacketHandler {
|
|||||||
def readItemStack() = {
|
def readItemStack() = {
|
||||||
val haveStack = readBoolean()
|
val haveStack = readBoolean()
|
||||||
if (haveStack) {
|
if (haveStack) {
|
||||||
ItemStack.loadItemStackFromNBT(readNBT())
|
ItemUtils.loadStack(readNBT())
|
||||||
}
|
}
|
||||||
else null
|
else null
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,25 @@ object DelegatorConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def convert(stack: ItemStack, item: ItemBlock) = {
|
def convert(stack: ItemStack): ItemStack = stack.getItem match {
|
||||||
|
case item: ItemBlock =>
|
||||||
|
convert(stack, item) match {
|
||||||
|
case Some(newStack) => newStack
|
||||||
|
case _ => stack
|
||||||
|
}
|
||||||
|
case _ => stack
|
||||||
|
}
|
||||||
|
|
||||||
|
def convert(stack: ItemStack, item: ItemBlock): Option[ItemStack] = {
|
||||||
val block = item.field_150939_a
|
val block = item.field_150939_a
|
||||||
val meta = stack.getItemDamage
|
val meta = stack.getItemDamage
|
||||||
getDescriptor(block, meta) match {
|
getDescriptor(block, meta) match {
|
||||||
case Some(descriptor) => Option(descriptor.createItemStack(stack.stackSize))
|
case Some(descriptor) =>
|
||||||
|
val newStack = descriptor.createItemStack(stack.stackSize)
|
||||||
|
if (stack.hasTagCompound) {
|
||||||
|
newStack.setTagCompound(stack.getTagCompound.copy().asInstanceOf[NBTTagCompound])
|
||||||
|
}
|
||||||
|
Option(newStack)
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import li.cil.oc.common.tileentity
|
|||||||
object Blocks {
|
object Blocks {
|
||||||
def init() {
|
def init() {
|
||||||
GameRegistry.registerTileEntity(classOf[tileentity.Adapter], Settings.namespace + "adapter")
|
GameRegistry.registerTileEntity(classOf[tileentity.Adapter], Settings.namespace + "adapter")
|
||||||
GameRegistry.registerTileEntity(classOf[tileentity.Assembler], Settings.namespace + "assembler")
|
GameRegistry.registerTileEntityWithAlternatives(classOf[tileentity.Assembler], Settings.namespace + "assembler", Settings.namespace + "robotAssembler")
|
||||||
GameRegistry.registerTileEntity(classOf[tileentity.Cable], Settings.namespace + "cable")
|
GameRegistry.registerTileEntity(classOf[tileentity.Cable], Settings.namespace + "cable")
|
||||||
GameRegistry.registerTileEntity(classOf[tileentity.Capacitor], Settings.namespace + "capacitor")
|
GameRegistry.registerTileEntity(classOf[tileentity.Capacitor], Settings.namespace + "capacitor")
|
||||||
GameRegistry.registerTileEntity(classOf[tileentity.Case], Settings.namespace + "case")
|
GameRegistry.registerTileEntity(classOf[tileentity.Case], Settings.namespace + "case")
|
||||||
|
@ -2,6 +2,7 @@ package li.cil.oc.common.inventory
|
|||||||
|
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.util.ExtendedNBT._
|
import li.cil.oc.util.ExtendedNBT._
|
||||||
|
import li.cil.oc.util.ItemUtils
|
||||||
import net.minecraft.inventory.IInventory
|
import net.minecraft.inventory.IInventory
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
@ -75,7 +76,7 @@ trait Inventory extends IInventory {
|
|||||||
val slotNbt = list.getCompoundTagAt(index)
|
val slotNbt = list.getCompoundTagAt(index)
|
||||||
val slot = slotNbt.getByte("slot")
|
val slot = slotNbt.getByte("slot")
|
||||||
if (slot >= 0 && slot < items.length) {
|
if (slot >= 0 && slot < items.length) {
|
||||||
items(slot) = Option(ItemStack.loadItemStackFromNBT(slotNbt.getCompoundTag("item")))
|
items(slot) = Option(ItemUtils.loadStack(slotNbt.getCompoundTag("item")))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package li.cil.oc.common.inventory
|
package li.cil.oc.common.inventory
|
||||||
|
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
|
import li.cil.oc.util.ItemUtils
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.minecraft.nbt.NBTTagList
|
import net.minecraft.nbt.NBTTagList
|
||||||
@ -30,7 +31,7 @@ trait ItemStackInventory extends Inventory {
|
|||||||
for (i <- 0 until (list.tagCount min items.length)) {
|
for (i <- 0 until (list.tagCount min items.length)) {
|
||||||
val tag = list.getCompoundTagAt(i)
|
val tag = list.getCompoundTagAt(i)
|
||||||
if (!tag.hasNoTags) {
|
if (!tag.hasNoTags) {
|
||||||
items(i) = Option(ItemStack.loadItemStackFromNBT(tag))
|
items(i) = Option(ItemUtils.loadStack(tag))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import li.cil.oc.api.network._
|
|||||||
import li.cil.oc.common.template.AssemblerTemplates
|
import li.cil.oc.common.template.AssemblerTemplates
|
||||||
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
||||||
import li.cil.oc.util.ExtendedNBT._
|
import li.cil.oc.util.ExtendedNBT._
|
||||||
|
import li.cil.oc.util.ItemUtils
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.minecraftforge.common.util.ForgeDirection
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
@ -113,11 +114,11 @@ class Assembler extends traits.Environment with traits.PowerAcceptor with traits
|
|||||||
override def readFromNBT(nbt: NBTTagCompound) {
|
override def readFromNBT(nbt: NBTTagCompound) {
|
||||||
super.readFromNBT(nbt)
|
super.readFromNBT(nbt)
|
||||||
if (nbt.hasKey(Settings.namespace + "output")) {
|
if (nbt.hasKey(Settings.namespace + "output")) {
|
||||||
output = Option(ItemStack.loadItemStackFromNBT(nbt.getCompoundTag(Settings.namespace + "output")))
|
output = Option(ItemUtils.loadStack(nbt.getCompoundTag(Settings.namespace + "output")))
|
||||||
}
|
}
|
||||||
else if (nbt.hasKey(Settings.namespace + "robot")) {
|
else if (nbt.hasKey(Settings.namespace + "robot")) {
|
||||||
// Backwards compatibility.
|
// Backwards compatibility.
|
||||||
output = Option(ItemStack.loadItemStackFromNBT(nbt.getCompoundTag(Settings.namespace + "robot")))
|
output = Option(ItemUtils.loadStack(nbt.getCompoundTag(Settings.namespace + "robot")))
|
||||||
}
|
}
|
||||||
totalRequiredEnergy = nbt.getDouble(Settings.namespace + "total")
|
totalRequiredEnergy = nbt.getDouble(Settings.namespace + "total")
|
||||||
requiredEnergy = nbt.getDouble(Settings.namespace + "remaining")
|
requiredEnergy = nbt.getDouble(Settings.namespace + "remaining")
|
||||||
|
@ -211,9 +211,8 @@ class Disassembler extends traits.Environment with traits.PowerAcceptor with tra
|
|||||||
override def readFromNBT(nbt: NBTTagCompound) {
|
override def readFromNBT(nbt: NBTTagCompound) {
|
||||||
super.readFromNBT(nbt)
|
super.readFromNBT(nbt)
|
||||||
queue.clear()
|
queue.clear()
|
||||||
queue ++= nbt.getTagList(Settings.namespace + "queue", NBT.TAG_COMPOUND).map((list, index) => {
|
queue ++= nbt.getTagList(Settings.namespace + "queue", NBT.TAG_COMPOUND).
|
||||||
ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(index))
|
map((list, index) => ItemUtils.loadStack(list.getCompoundTagAt(index)))
|
||||||
})
|
|
||||||
buffer = nbt.getDouble(Settings.namespace + "buffer")
|
buffer = nbt.getDouble(Settings.namespace + "buffer")
|
||||||
totalRequiredEnergy = nbt.getDouble(Settings.namespace + "total")
|
totalRequiredEnergy = nbt.getDouble(Settings.namespace + "total")
|
||||||
isActive = queue.nonEmpty
|
isActive = queue.nonEmpty
|
||||||
|
@ -11,6 +11,7 @@ import li.cil.oc.common.Slot
|
|||||||
import li.cil.oc.common.Sound
|
import li.cil.oc.common.Sound
|
||||||
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
||||||
import li.cil.oc.util.ExtendedNBT._
|
import li.cil.oc.util.ExtendedNBT._
|
||||||
|
import li.cil.oc.util.ItemUtils
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
@ -76,7 +77,7 @@ class DiskDrive extends traits.Environment with traits.ComponentInventory with t
|
|||||||
override def writeToNBTForClient(nbt: NBTTagCompound) {
|
override def writeToNBTForClient(nbt: NBTTagCompound) {
|
||||||
super.writeToNBTForClient(nbt)
|
super.writeToNBTForClient(nbt)
|
||||||
if (nbt.hasKey("disk")) {
|
if (nbt.hasKey("disk")) {
|
||||||
setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("disk")))
|
setInventorySlotContents(0, ItemUtils.loadStack(nbt.getCompoundTag("disk")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,14 @@ import li.cil.oc.Settings
|
|||||||
import li.cil.oc.api
|
import li.cil.oc.api
|
||||||
import li.cil.oc.api.Network
|
import li.cil.oc.api.Network
|
||||||
import li.cil.oc.api.driver.EnvironmentHost
|
import li.cil.oc.api.driver.EnvironmentHost
|
||||||
|
import li.cil.oc.api.internal.Robot
|
||||||
import li.cil.oc.api.machine.Arguments
|
import li.cil.oc.api.machine.Arguments
|
||||||
import li.cil.oc.api.machine.Callback
|
import li.cil.oc.api.machine.Callback
|
||||||
import li.cil.oc.api.machine.Context
|
import li.cil.oc.api.machine.Context
|
||||||
import li.cil.oc.api.network._
|
import li.cil.oc.api.network._
|
||||||
import li.cil.oc.api.prefab
|
import li.cil.oc.api.prefab
|
||||||
import li.cil.oc.api.internal.Robot
|
|
||||||
import li.cil.oc.util.ExtendedNBT._
|
import li.cil.oc.util.ExtendedNBT._
|
||||||
|
import li.cil.oc.util.ItemUtils
|
||||||
import net.minecraft.entity.item.EntityItem
|
import net.minecraft.entity.item.EntityItem
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
@ -145,7 +146,7 @@ class UpgradeGenerator(val host: EnvironmentHost with Robot) extends prefab.Mana
|
|||||||
super.load(nbt)
|
super.load(nbt)
|
||||||
romGenerator.foreach(_.load(nbt.getCompoundTag("romGenerator")))
|
romGenerator.foreach(_.load(nbt.getCompoundTag("romGenerator")))
|
||||||
if (nbt.hasKey("inventory")) {
|
if (nbt.hasKey("inventory")) {
|
||||||
inventory = Option(ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("inventory")))
|
inventory = Option(ItemUtils.loadStack(nbt.getCompoundTag("inventory")))
|
||||||
}
|
}
|
||||||
remainingTicks = nbt.getInteger("remainingTicks")
|
remainingTicks = nbt.getInteger("remainingTicks")
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import li.cil.oc.Settings
|
|||||||
import li.cil.oc.api
|
import li.cil.oc.api
|
||||||
import li.cil.oc.api.Persistable
|
import li.cil.oc.api.Persistable
|
||||||
import li.cil.oc.common.Tier
|
import li.cil.oc.common.Tier
|
||||||
|
import li.cil.oc.common.block.DelegatorConverter
|
||||||
import li.cil.oc.integration.opencomputers.DriverScreen
|
import li.cil.oc.integration.opencomputers.DriverScreen
|
||||||
import li.cil.oc.integration.opencomputers.DriverUpgradeExperience
|
import li.cil.oc.integration.opencomputers.DriverUpgradeExperience
|
||||||
import li.cil.oc.util.ExtendedNBT._
|
import li.cil.oc.util.ExtendedNBT._
|
||||||
@ -28,6 +29,8 @@ object ItemUtils {
|
|||||||
else Tier.None
|
else Tier.None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def loadStack(nbt: NBTTagCompound) = DelegatorConverter.convert(ItemStack.loadItemStackFromNBT(nbt))
|
||||||
|
|
||||||
abstract class ItemData extends Persistable {
|
abstract class ItemData extends Persistable {
|
||||||
def load(stack: ItemStack) {
|
def load(stack: ItemStack) {
|
||||||
if (stack.hasTagCompound) {
|
if (stack.hasTagCompound) {
|
||||||
@ -76,12 +79,10 @@ object ItemUtils {
|
|||||||
robotEnergy = nbt.getInteger(Settings.namespace + "robotEnergy")
|
robotEnergy = nbt.getInteger(Settings.namespace + "robotEnergy")
|
||||||
if (nbt.hasKey(Settings.namespace + "components")) {
|
if (nbt.hasKey(Settings.namespace + "components")) {
|
||||||
tier = nbt.getInteger(Settings.namespace + "tier")
|
tier = nbt.getInteger(Settings.namespace + "tier")
|
||||||
components = nbt.getTagList(Settings.namespace + "components", NBT.TAG_COMPOUND).map((list, index) => {
|
components = nbt.getTagList(Settings.namespace + "components", NBT.TAG_COMPOUND).
|
||||||
ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(index))
|
map((list, index) => loadStack(list.getCompoundTagAt(index))).toArray
|
||||||
}).toArray
|
containers = nbt.getTagList(Settings.namespace + "containers", NBT.TAG_COMPOUND).
|
||||||
containers = nbt.getTagList(Settings.namespace + "containers", NBT.TAG_COMPOUND).map((list, index) => {
|
map((list, index) => loadStack(list.getCompoundTagAt(index))).toArray
|
||||||
ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(index))
|
|
||||||
}).toArray
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Old robot, upgrade to new modular model.
|
// Old robot, upgrade to new modular model.
|
||||||
@ -191,7 +192,7 @@ object ItemUtils {
|
|||||||
|
|
||||||
override def load(nbt: NBTTagCompound) {
|
override def load(nbt: NBTTagCompound) {
|
||||||
if (nbt.hasKey(Settings.namespace + "map")) {
|
if (nbt.hasKey(Settings.namespace + "map")) {
|
||||||
map = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag(Settings.namespace + "map"))
|
map = loadStack(nbt.getCompoundTag(Settings.namespace + "map"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +219,7 @@ object ItemUtils {
|
|||||||
val slotNbt = list.getCompoundTagAt(index)
|
val slotNbt = list.getCompoundTagAt(index)
|
||||||
val slot = slotNbt.getByte("slot")
|
val slot = slotNbt.getByte("slot")
|
||||||
if (slot >= 0 && slot < items.length) {
|
if (slot >= 0 && slot < items.length) {
|
||||||
items(slot) = Option(ItemStack.loadItemStackFromNBT(slotNbt.getCompoundTag("item")))
|
items(slot) = Option(loadStack(slotNbt.getCompoundTag("item")))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
isRunning = nbt.getBoolean(Settings.namespace + "isRunning")
|
isRunning = nbt.getBoolean(Settings.namespace + "isRunning")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user