Conflicts:
	src/main/scala/li/cil/oc/Blocks.scala
	src/main/scala/li/cil/oc/Items.scala
	src/main/scala/li/cil/oc/Recipes.scala
This commit is contained in:
Florian Nücke 2014-02-12 15:49:48 +01:00
commit 4c19d06c97
9 changed files with 139 additions and 189 deletions

View File

@ -47,24 +47,24 @@ object Blocks {
// IMPORTANT: the multi block must come first, since the sub blocks will // IMPORTANT: the multi block must come first, since the sub blocks will
// try to register with it. Also, the order the sub blocks are created in // try to register with it. Also, the order the sub blocks are created in
// must not be changed since that order determines their actual IDs. // must not be changed since that order determines their actual IDs.
adapter = new Adapter(blockSimple) adapter = Recipes.addBlockDelegate(new Adapter(blockSimple), "adapter")
cable = new Cable(blockSpecial) cable = Recipes.addBlockDelegate(new Cable(blockSpecial), "cable")
capacitor = new Capacitor(blockSimple) capacitor = Recipes.addBlockDelegate(new Capacitor(blockSimple), "capacitor")
case1 = new Case.Tier1(blockSimpleWithRedstone) case1 = Recipes.addBlockDelegate(new Case.Tier1(blockSimpleWithRedstone), "case1")
case2 = new Case.Tier2(blockSimpleWithRedstone) case2 = Recipes.addBlockDelegate(new Case.Tier2(blockSimpleWithRedstone), "case2")
case3 = new Case.Tier3(blockSimpleWithRedstone) case3 = Recipes.addBlockDelegate(new Case.Tier3(blockSimpleWithRedstone), "case3")
charger = new Charger(blockSimpleWithRedstone) charger = Recipes.addBlockDelegate(new Charger(blockSimpleWithRedstone), "charger")
diskDrive = new DiskDrive(blockSimple) diskDrive = Recipes.addBlockDelegate(new DiskDrive(blockSimple), "diskDrive")
keyboardDeprecated = new KeyboardDeprecated(blockSpecial) keyboardDeprecated = new KeyboardDeprecated(blockSpecial)
powerDistributor = new PowerDistributor(blockSimple) powerDistributor = Recipes.addBlockDelegate(new PowerDistributor(blockSimple), "powerDistributor")
powerConverter = new PowerConverter(blockSimple) powerConverter = Recipes.addBlockDelegate(new PowerConverter(blockSimple), "powerConverter")
redstone = new Redstone(blockSimpleWithRedstone) redstone = Recipes.addBlockDelegate(new Redstone(blockSimpleWithRedstone), "redstone")
robotAfterimage = new RobotAfterimage(blockSpecial) robotAfterimage = new RobotAfterimage(blockSpecial)
robotProxy = new RobotProxy(blockSpecialWithRedstone) robotProxy = Recipes.addBlockDelegate(new RobotProxy(blockSpecialWithRedstone), "robot")
router = new Router(blockSimple) router = Recipes.addBlockDelegate(new Router(blockSimple), "router")
screen1 = new Screen.Tier1(blockSimpleWithRedstone) screen1 = Recipes.addBlockDelegate(new Screen.Tier1(blockSimpleWithRedstone), "screen1")
screen2 = new Screen.Tier2(blockSimpleWithRedstone) screen2 = Recipes.addBlockDelegate(new Screen.Tier2(blockSimpleWithRedstone), "screen2")
screen3 = new Screen.Tier3(blockSimpleWithRedstone) screen3 = Recipes.addBlockDelegate(new Screen.Tier3(blockSimpleWithRedstone), "screen3")
// For automatic conversion from old format (when screens did not take // For automatic conversion from old format (when screens did not take
// redstone inputs) to keep save format compatible. // redstone inputs) to keep save format compatible.
@ -73,10 +73,10 @@ object Blocks {
blockSimple.subBlocks += screen3 blockSimple.subBlocks += screen3
// v1.2.0 // v1.2.0
serverRack = new Rack(blockSpecialWithRedstone) serverRack = Recipes.addBlockDelegate(new Rack(blockSpecialWithRedstone), "rack")
// v2.0.0 // v2.0.0
keyboard = new Keyboard() keyboard = Recipes.addBlock(new Keyboard(), "keyboard")
GameRegistry.registerBlock(keyboard, classOf[Item], Settings.namespace + "keyboard") GameRegistry.registerBlock(keyboard, classOf[Item], Settings.namespace + "keyboard")

View File

@ -2,8 +2,10 @@ package li.cil.oc
import cpw.mods.fml.common.registry.GameRegistry import cpw.mods.fml.common.registry.GameRegistry
import li.cil.oc.common.item import li.cil.oc.common.item
import li.cil.oc.util.mods.StargateTech2
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraftforge.oredict.OreDictionary import net.minecraftforge.oredict.OreDictionary
import scala.collection.convert.WrapAsScala._
object Items { object Items {
var multi: item.Delegator = _ var multi: item.Delegator = _
@ -70,67 +72,74 @@ object Items {
GameRegistry.registerItem(multi, Settings.namespace + "item") GameRegistry.registerItem(multi, Settings.namespace + "item")
analyzer = new item.Analyzer(multi) analyzer = Recipes.addItemDelegate(new item.Analyzer(multi), "analyzer")
ram1 = new item.Memory(multi, 0) ram1 = Recipes.addItemDelegate(new item.Memory(multi, 0), "ram1")
ram2 = new item.Memory(multi, 1) ram2 = Recipes.addItemDelegate(new item.Memory(multi, 1), "ram2")
ram3 = new item.Memory(multi, 2) ram3 = Recipes.addItemDelegate(new item.Memory(multi, 2), "ram3")
floppyDisk = new item.FloppyDisk(multi) floppyDisk = Recipes.addItemDelegate(new item.FloppyDisk(multi), "floppy")
hdd1 = new item.HardDiskDrive(multi, 0) hdd1 = Recipes.addItemDelegate(new item.HardDiskDrive(multi, 0), "hdd1")
hdd2 = new item.HardDiskDrive(multi, 1) hdd2 = Recipes.addItemDelegate(new item.HardDiskDrive(multi, 1), "hdd2")
hdd3 = new item.HardDiskDrive(multi, 2) hdd3 = Recipes.addItemDelegate(new item.HardDiskDrive(multi, 2), "hdd3")
gpu1 = new item.GraphicsCard(multi, 0) gpu1 = Recipes.addItemDelegate(new item.GraphicsCard(multi, 0), "graphicsCard1")
gpu2 = new item.GraphicsCard(multi, 1) gpu2 = Recipes.addItemDelegate(new item.GraphicsCard(multi, 1), "graphicsCard2")
gpu3 = new item.GraphicsCard(multi, 2) gpu3 = Recipes.addItemDelegate(new item.GraphicsCard(multi, 2), "graphicsCard3")
lan = new item.NetworkCard(multi) lan = Recipes.addItemDelegate(new item.NetworkCard(multi), "lanCard")
rs = new item.RedstoneCard(multi) rs = Recipes.addItemDelegate(new item.RedstoneCard(multi), "redstoneCard")
wlan = new item.WirelessNetworkCard(multi) wlan = Recipes.addItemDelegate(new item.WirelessNetworkCard(multi), "wlanCard")
upgradeCrafting = new item.UpgradeCrafting(multi) upgradeCrafting = Recipes.addItemDelegate(new item.UpgradeCrafting(multi), "craftingUpgrade")
upgradeGenerator = new item.UpgradeGenerator(multi) upgradeGenerator = Recipes.addItemDelegate(new item.UpgradeGenerator(multi), "generatorUpgrade")
ironNugget = new item.IronNugget(multi) ironNugget = new item.IronNugget(multi)
cuttingWire = new item.CuttingWire(multi) if (OreDictionary.getOres("nuggetIron").exists(ironNugget.createItemStack().isItemEqual)) {
acid = new item.Acid(multi) Recipes.addItemDelegate(ironNugget, "nuggetIron")
disk = new item.Disk(multi) }
buttonGroup = new item.ButtonGroup(multi) cuttingWire = Recipes.addItemDelegate(new item.CuttingWire(multi), "cuttingWire")
arrowKeys = new item.ArrowKeys(multi) acid = Recipes.addItemDelegate(new item.Acid(multi), "acid")
numPad = new item.NumPad(multi) disk = Recipes.addItemDelegate(new item.Disk(multi), "disk")
transistor = new item.Transistor(multi) buttonGroup = Recipes.addItemDelegate(new item.ButtonGroup(multi), "buttonGroup")
chip1 = new item.Microchip(multi, 0) arrowKeys = Recipes.addItemDelegate(new item.ArrowKeys(multi), "arrowKeys")
chip2 = new item.Microchip(multi, 1) numPad = Recipes.addItemDelegate(new item.NumPad(multi), "numPad")
chip3 = new item.Microchip(multi, 2)
alu = new item.ALU(multi)
cu = new item.ControlUnit(multi)
cpu0 = new item.CPU(multi, 0)
rawCircuitBoard = new item.RawCircuitBoard(multi) transistor = Recipes.addItemDelegate(new item.Transistor(multi), "transistor")
circuitBoard = new item.CircuitBoard(multi) chip1 = Recipes.addItemDelegate(new item.Microchip(multi, 0), "chip1")
pcb = new item.PrintedCircuitBoard(multi) chip2 = Recipes.addItemDelegate(new item.Microchip(multi, 1), "chip2")
card = new item.CardBase(multi) chip3 = Recipes.addItemDelegate(new item.Microchip(multi, 2), "chip3")
alu = Recipes.addItemDelegate(new item.ALU(multi), "alu")
cu = Recipes.addItemDelegate(new item.ControlUnit(multi), "cu")
cpu0 = Recipes.addItemDelegate(new item.CPU(multi, 0), "cpu0")
rawCircuitBoard = Recipes.addItemDelegate(new item.RawCircuitBoard(multi), "rawCircuitBoard")
circuitBoard = Recipes.addItemDelegate(new item.CircuitBoard(multi), "circuitBoard")
pcb = Recipes.addItemDelegate(new item.PrintedCircuitBoard(multi), "printedCircuitBoard")
card = Recipes.addItemDelegate(new item.CardBase(multi), "card")
// v1.1.0 // v1.1.0
upgradeSolarGenerator = new item.UpgradeSolarGenerator(multi) upgradeSolarGenerator = Recipes.addItemDelegate(new item.UpgradeSolarGenerator(multi), "solarGeneratorUpgrade")
upgradeSign = new item.UpgradeSign(multi) upgradeSign = Recipes.addItemDelegate(new item.UpgradeSign(multi), "signUpgrade")
upgradeNavigation = new item.UpgradeNavigation(multi) upgradeNavigation = Recipes.addItemDelegate(new item.UpgradeNavigation(multi), "navigationUpgrade")
abstractBus = new item.AbstractBusCard(multi) abstractBus = new item.AbstractBusCard(multi)
if (StargateTech2.isAvailable) {
Recipes.addItemDelegate(abstractBus, "abstractBusCard")
}
ram4 = new item.Memory(multi, 3) ram4 = Recipes.addItemDelegate(new item.Memory(multi, 3), "ram4")
ram5 = new item.Memory(multi, 4) ram5 = Recipes.addItemDelegate(new item.Memory(multi, 4), "ram5")
// v1.2.0 // v1.2.0
server3 = new item.Server(multi, 2) server3 = Recipes.addItemDelegate(new item.Server(multi, 2), "server3")
terminal = new item.Terminal(multi) terminal = Recipes.addItemDelegate(new item.Terminal(multi), "terminal")
cpu1 = new item.CPU(multi, 1) cpu1 = Recipes.addItemDelegate(new item.CPU(multi, 1), "cpu1")
cpu2 = new item.CPU(multi, 2) cpu2 = Recipes.addItemDelegate(new item.CPU(multi, 2), "cpu2")
internet = new item.InternetCard(multi) internet = Recipes.addItemDelegate(new item.InternetCard(multi), "internetCard")
server1 = new item.Server(multi, 0) server1 = Recipes.addItemDelegate(new item.Server(multi, 0), "server1")
server2 = new item.Server(multi, 1) server2 = Recipes.addItemDelegate(new item.Server(multi, 1), "server2")
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //

View File

@ -5,18 +5,33 @@ import cpw.mods.fml.common.Loader
import cpw.mods.fml.common.registry.GameRegistry import cpw.mods.fml.common.registry.GameRegistry
import java.io.{FileReader, File} import java.io.{FileReader, File}
import java.util.logging.Level import java.util.logging.Level
import li.cil.oc.common.block.Delegator import li.cil.oc.util.mods.GregTech
import li.cil.oc.util.mods.{StargateTech2, GregTech}
import net.minecraft.block.Block import net.minecraft.block.Block
import net.minecraft.item.crafting.FurnaceRecipes import net.minecraft.item.crafting.FurnaceRecipes
import net.minecraft.item.{ItemStack, Item} import net.minecraft.item.{ItemStack, Item}
import net.minecraftforge.oredict.{OreDictionary, ShapelessOreRecipe, ShapedOreRecipe} import net.minecraftforge.oredict.{OreDictionary, ShapelessOreRecipe, ShapedOreRecipe}
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
import scala.Some import scala.collection.convert.WrapAsScala._
import scala.collection.convert.wrapAsScala._ import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
object Recipes { object Recipes {
val list = mutable.ArrayBuffer.empty[() => (ItemStack, String)]
def addBlock[T <: Block](block: T, name: String) = {
list += (() => new ItemStack(block) -> name)
block
}
def addBlockDelegate[T <: common.block.Delegate](block: T, name: String) = {
list += (() => block.createItemStack() -> name)
block
}
def addItemDelegate[T <: common.item.Delegate](item: T, name: String) = {
list += (() => item.createItemStack() -> name)
item
}
def init() { def init() {
try { try {
val defaultRecipes = new File(Loader.instance.getConfigDir + File.separator + "opencomputers" + File.separator + "default.recipes") val defaultRecipes = new File(Loader.instance.getConfigDir + File.separator + "opencomputers" + File.separator + "default.recipes")
@ -52,89 +67,10 @@ object Recipes {
}) })
val recipes = ConfigFactory.parseFile(userRecipes, config) val recipes = ConfigFactory.parseFile(userRecipes, config)
// Try to keep this in the same order as the fields in the Items class // Register all known recipes.
// to make it easier to match them and check if anything is missing. for ((stack, name) <- list.map(_())) {
addRecipe(Items.analyzer.createItemStack(), recipes, "analyzer") addRecipe(stack, recipes, name)
addRecipe(Items.terminal.createItemStack(), recipes, "terminal")
addRecipe(Items.ram1.createItemStack(), recipes, "ram1")
addRecipe(Items.ram2.createItemStack(), recipes, "ram2")
addRecipe(Items.ram3.createItemStack(), recipes, "ram3")
addRecipe(Items.ram4.createItemStack(), recipes, "ram4")
addRecipe(Items.ram5.createItemStack(), recipes, "ram5")
addRecipe(Items.floppyDisk.createItemStack(), recipes, "floppy")
addRecipe(Items.hdd1.createItemStack(), recipes, "hdd1")
addRecipe(Items.hdd2.createItemStack(), recipes, "hdd2")
addRecipe(Items.hdd3.createItemStack(), recipes, "hdd3")
addRecipe(Items.server1.createItemStack(), recipes, "server1")
addRecipe(Items.server2.createItemStack(), recipes, "server2")
addRecipe(Items.server3.createItemStack(), recipes, "server3")
if (StargateTech2.isAvailable) {
addRecipe(Items.abstractBus.createItemStack(), recipes, "abstractBusCard")
} }
addRecipe(Items.gpu1.createItemStack(), recipes, "graphicsCard1")
addRecipe(Items.gpu2.createItemStack(), recipes, "graphicsCard2")
addRecipe(Items.gpu3.createItemStack(), recipes, "graphicsCard3")
addRecipe(Items.internet.createItemStack(), recipes, "internetCard")
addRecipe(Items.lan.createItemStack(), recipes, "lanCard")
addRecipe(Items.rs.createItemStack(), recipes, "redstoneCard")
addRecipe(Items.wlan.createItemStack(), recipes, "wlanCard")
addRecipe(Items.upgradeCrafting.createItemStack(), recipes, "craftingUpgrade")
addRecipe(Items.upgradeGenerator.createItemStack(), recipes, "generatorUpgrade")
addRecipe(Items.upgradeNavigation.createItemStack(), recipes, "navigationUpgrade")
addRecipe(Items.upgradeSign.createItemStack(), recipes, "signUpgrade")
addRecipe(Items.upgradeSolarGenerator.createItemStack(), recipes, "solarGeneratorUpgrade")
if (OreDictionary.getOres("nuggetIron").exists(Items.ironNugget.createItemStack().isItemEqual)) {
addRecipe(Items.ironNugget.createItemStack(), recipes, "nuggetIron")
}
addRecipe(Items.cuttingWire.createItemStack(), recipes, "cuttingWire")
addRecipe(Items.acid.createItemStack(), recipes, "acid")
addRecipe(Items.disk.createItemStack(), recipes, "disk")
addRecipe(Items.buttonGroup.createItemStack(), recipes, "buttonGroup")
addRecipe(Items.arrowKeys.createItemStack(), recipes, "arrowKeys")
addRecipe(Items.numPad.createItemStack(), recipes, "numPad")
addRecipe(Items.transistor.createItemStack(), recipes, "transistor")
addRecipe(Items.chip1.createItemStack(), recipes, "chip1")
addRecipe(Items.chip2.createItemStack(), recipes, "chip2")
addRecipe(Items.chip3.createItemStack(), recipes, "chip3")
addRecipe(Items.alu.createItemStack(), recipes, "alu")
addRecipe(Items.cpu0.createItemStack(), recipes, "cpu0")
addRecipe(Items.cpu1.createItemStack(), recipes, "cpu1")
addRecipe(Items.cpu2.createItemStack(), recipes, "cpu2")
addRecipe(Items.cu.createItemStack(), recipes, "cu")
addRecipe(Items.rawCircuitBoard.createItemStack(), recipes, "rawCircuitBoard")
addRecipe(Items.circuitBoard.createItemStack(), recipes, "circuitBoard")
addRecipe(Items.pcb.createItemStack(), recipes, "printedCircuitBoard")
addRecipe(Items.card.createItemStack(), recipes, "card")
// Try to keep this in the same order as the fields in the Blocks class
// to make it easier to match them and check if anything is missing.Point")
addRecipe(Blocks.adapter.createItemStack(), recipes, "adapter")
addRecipe(Blocks.cable.createItemStack(), recipes, "cable")
addRecipe(Blocks.capacitor.createItemStack(), recipes, "capacitor")
addRecipe(Blocks.charger.createItemStack(), recipes, "charger")
addRecipe(Blocks.case1.createItemStack(), recipes, "case1")
addRecipe(Blocks.case2.createItemStack(), recipes, "case2")
addRecipe(Blocks.case3.createItemStack(), recipes, "case3")
addRecipe(Blocks.diskDrive.createItemStack(), recipes, "diskDrive")
addRecipe(new ItemStack(Blocks.keyboard), recipes, "keyboard")
addRecipe(Blocks.powerConverter.createItemStack(), recipes, "powerConverter")
addRecipe(Blocks.powerDistributor.createItemStack(), recipes, "powerDistributor")
addRecipe(Blocks.redstone.createItemStack(), recipes, "redstone")
addRecipe(Blocks.robotProxy.createItemStack(), recipes, "robot")
addRecipe(Blocks.router.createItemStack(), recipes, "router")
addRecipe(Blocks.screen1.createItemStack(), recipes, "screen1")
addRecipe(Blocks.screen2.createItemStack(), recipes, "screen2")
addRecipe(Blocks.screen3.createItemStack(), recipes, "screen3")
addRecipe(Blocks.serverRack.createItemStack(), recipes, "rack")
// Navigation upgrade recrafting. // Navigation upgrade recrafting.
GameRegistry.addRecipe(new ShapelessOreRecipe(Items.upgradeNavigation.createItemStack(), Items.upgradeNavigation.createItemStack(), new ItemStack(net.minecraft.init.Items.map, 1, OreDictionary.WILDCARD_VALUE))) GameRegistry.addRecipe(new ShapelessOreRecipe(Items.upgradeNavigation.createItemStack(), Items.upgradeNavigation.createItemStack(), new ItemStack(net.minecraft.init.Items.map, 1, OreDictionary.WILDCARD_VALUE)))
@ -184,8 +120,8 @@ object Recipes {
output.stackSize = tryGetCount(recipe) output.stackSize = tryGetCount(recipe)
var number = -1 var number = -1
var shape = ArrayBuffer.empty[String] var shape = mutable.ArrayBuffer.empty[String]
val input = ArrayBuffer.empty[AnyRef] val input = mutable.ArrayBuffer.empty[AnyRef]
for (row <- rows) { for (row <- rows) {
val (pattern, ingredients) = row.foldLeft((new StringBuilder, Seq.empty[AnyRef]))((acc, ingredient) => { val (pattern, ingredients) = row.foldLeft((new StringBuilder, Seq.empty[AnyRef]))((acc, ingredient) => {
val (pattern, ingredients) = acc val (pattern, ingredients) = acc
@ -359,7 +295,7 @@ object Recipes {
private def hide(value: ItemStack) { private def hide(value: ItemStack) {
Items.multi.subItem(value) match { Items.multi.subItem(value) match {
case Some(stack) => stack.showInItemList = false case Some(stack) => stack.showInItemList = false
case _ => Delegator.subBlock(value) match { case _ => common.block.Delegator.subBlock(value) match {
case Some(block) => block.showInItemList = false case Some(block) => block.showInItemList = false
case _ => case _ =>
} }

View File

@ -10,6 +10,7 @@ import li.cil.oc.server.driver.item.Item
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity import net.minecraft.tileentity.TileEntity
import scala.collection.convert.WrapAsScala._
import scala.collection.mutable import scala.collection.mutable
trait ComponentInventory extends Inventory with network.Environment { trait ComponentInventory extends Inventory with network.Environment {
@ -75,12 +76,7 @@ trait ComponentInventory extends Inventory with network.Environment {
case (stack, slot) => components(slot) match { case (stack, slot) => components(slot) match {
case Some(component) => case Some(component) =>
// We're guaranteed to have a driver for entries. // We're guaranteed to have a driver for entries.
val driver = Registry.itemDriverFor(stack).get save(component, Registry.itemDriverFor(stack).get, stack)
try {
component.save(dataTag(driver, stack))
} catch {
case e: Throwable => OpenComputers.log.log(Level.WARNING, "An item component of type '%s' (provided by driver '%s') threw an error while saving.".format(component.getClass.getName, driver.getClass.getName), e)
}
case _ => // Nothing special to save. case _ => // Nothing special to save.
} }
} }
@ -106,7 +102,7 @@ trait ComponentInventory extends Inventory with network.Environment {
assert(!updatingComponents.contains(component)) assert(!updatingComponents.contains(component))
updatingComponents += component updatingComponents += component
} }
component.save(dataTag(driver, stack)) save(component, driver, stack)
} }
case _ => // No environment (e.g. RAM). case _ => // No environment (e.g. RAM).
} }
@ -125,11 +121,7 @@ trait ComponentInventory extends Inventory with network.Environment {
components(slot) = None components(slot) = None
updatingComponents -= component updatingComponents -= component
component.node.remove() component.node.remove()
Registry.itemDriverFor(stack).foreach(driver => try { Registry.itemDriverFor(stack).foreach(driver => save(component, driver, stack))
component.save(dataTag(driver, stack))
} catch {
case e: Throwable => OpenComputers.log.log(Level.WARNING, "An item component of type '%s' (provided by driver '%s') threw an error while saving.".format(component.getClass.getName, driver.getClass.getName), e)
})
} }
case _ => // Nothing to do. case _ => // Nothing to do.
} }
@ -143,4 +135,18 @@ trait ComponentInventory extends Inventory with network.Environment {
protected def dataTag(driver: ItemDriver, stack: ItemStack) = protected def dataTag(driver: ItemDriver, stack: ItemStack) =
Option(driver.dataTag(stack)).getOrElse(Item.dataTag(stack)) Option(driver.dataTag(stack)).getOrElse(Item.dataTag(stack))
protected def save(component: ManagedEnvironment, driver: ItemDriver, stack: ItemStack) {
try {
val tag = dataTag(driver, stack)
// Clear the tag compound before saving to get the same behavior as
// in tile entities (otherwise entries have to be cleared manually).
for (key <- tag.func_150296_c.map(_.asInstanceOf[String])) {
tag.removeTag(key)
}
component.save(tag)
} catch {
case e: Throwable => OpenComputers.log.log(Level.WARNING, "An item component of type '%s' (provided by driver '%s') threw an error while saving.".format(component.getClass.getName, driver.getClass.getName), e)
}
}
} }

View File

@ -81,7 +81,7 @@ class AbstractBus(val device: IBusDevice) extends ManagedComponent with IBusDriv
busInterface.sendAllPackets() busInterface.sendAllPackets()
result(true) result(true)
} }
else result(false, "not enough energy") else result(Unit, "not enough energy")
} }
@Callback(direct = true, doc = """function():number -- The maximum packet size that can be sent over the bus.""") @Callback(direct = true, doc = """function():number -- The maximum packet size that can be sent over the bus.""")

View File

@ -53,7 +53,7 @@ abstract class GraphicsCard extends ManagedComponent {
def bind(context: Context, args: Arguments): Array[AnyRef] = { def bind(context: Context, args: Arguments): Array[AnyRef] = {
val address = args.checkString(0) val address = args.checkString(0)
node.network.node(address) match { node.network.node(address) match {
case null => result(false, "invalid address") case null => result(Unit, "invalid address")
case node: Node if node.host.isInstanceOf[Buffer] => case node: Node if node.host.isInstanceOf[Buffer] =>
screenAddress = Option(address) screenAddress = Option(address)
screenInstance = Some(node.host.asInstanceOf[Buffer]) screenInstance = Some(node.host.asInstanceOf[Buffer])
@ -66,7 +66,7 @@ abstract class GraphicsCard extends ManagedComponent {
s.background = 0x000000 s.background = 0x000000
result(true) result(true)
}) })
case _ => result(false, "not a screen") case _ => result(Unit, "not a screen")
} }
} }
@ -166,7 +166,7 @@ abstract class GraphicsCard extends ManagedComponent {
s.set(x, y, value) s.set(x, y, value)
result(true) result(true)
} }
else result(false) else result(Unit, "not enough energy")
}) })
} }
@ -182,7 +182,7 @@ abstract class GraphicsCard extends ManagedComponent {
s.copy(x, y, w, h, tx, ty) s.copy(x, y, w, h, tx, ty)
result(true) result(true)
} }
else result(false) else result(Unit, "not enough energy")
}) })
} }
@ -200,7 +200,7 @@ abstract class GraphicsCard extends ManagedComponent {
result(true) result(true)
} }
else { else {
result(false) result(Unit, "not enough energy")
} }
}) })
else throw new Exception("invalid fill value") else throw new Exception("invalid fill value")

View File

@ -54,12 +54,12 @@ class InternetCard extends ManagedComponent {
} }
val address = args.checkString(0) val address = args.checkString(0)
if (!Settings.get.httpEnabled) { if (!Settings.get.httpEnabled) {
return result(false, "http requests are unavailable") return result(Unit, "http requests are unavailable")
} }
val post = if (args.isString(1)) Option(args.checkString(1)) else None val post = if (args.isString(1)) Option(args.checkString(1)) else None
this.synchronized { this.synchronized {
if (request.isDefined || queue.isDefined) { if (request.isDefined || queue.isDefined) {
return result(false, "already busy with another request") return result(Unit, "already busy with another request")
} }
scheduleRequest(address, post) scheduleRequest(address, post)
} }
@ -137,7 +137,9 @@ class InternetCard extends ManagedComponent {
def connect(context: Context, args: Arguments): Array[AnyRef] = { def connect(context: Context, args: Arguments): Array[AnyRef] = {
val address = args.checkString(0) val address = args.checkString(0)
val port = if (args.count > 1) args.checkInteger(1) else -1 val port = if (args.count > 1) args.checkInteger(1) else -1
if (!Settings.get.tcpEnabled) return result(false, "tcp connections are unavailable") if (!Settings.get.tcpEnabled) {
return result(Unit, "tcp connections are unavailable")
}
if (connections.size >= Settings.get.maxConnections) { if (connections.size >= Settings.get.maxConnections) {
throw new IOException("too many open connections") throw new IOException("too many open connections")
} }

View File

@ -27,16 +27,18 @@ class UpgradeGenerator(val owner: TileEntity) extends ManagedComponent {
val player = context.player val player = context.player
val stack = player.inventory.getStackInSlot(context.selectedSlot) val stack = player.inventory.getStackInSlot(context.selectedSlot)
if (stack == null) throw new IllegalArgumentException("selected slot is empty") if (stack == null) throw new IllegalArgumentException("selected slot is empty")
if (!TileEntityFurnace.isItemFuel(stack)) return result(false, "selected slot does not contain fuel") if (!TileEntityFurnace.isItemFuel(stack)) {
return result(Unit, "selected slot does not contain fuel")
}
inventory match { inventory match {
case Some(existingStack) => case Some(existingStack) =>
if (!existingStack.isItemEqual(stack) || if (!existingStack.isItemEqual(stack) ||
!ItemStack.areItemStackTagsEqual(existingStack, stack)) { !ItemStack.areItemStackTagsEqual(existingStack, stack)) {
return result(false, "different fuel type already queued") return result(Unit, "different fuel type already queued")
} }
val space = existingStack.getMaxStackSize - existingStack.stackSize val space = existingStack.getMaxStackSize - existingStack.stackSize
if (space <= 0) { if (space <= 0) {
return result(false, "queue is full") return result(Unit, "queue is full")
} }
val moveCount = math.min(stack.stackSize, math.min(space, count)) val moveCount = math.min(stack.stackSize, math.min(space, count))
existingStack.stackSize += moveCount existingStack.stackSize += moveCount
@ -134,16 +136,11 @@ class UpgradeGenerator(val owner: TileEntity) extends ManagedComponent {
override def save(nbt: NBTTagCompound) { override def save(nbt: NBTTagCompound) {
super.save(nbt) super.save(nbt)
inventory match { inventory match {
case Some(stack) => case Some(stack) => nbt.setNewCompoundTag("inventory", stack.writeToNBT)
nbt.setNewCompoundTag("inventory", stack.writeToNBT)
case _ => case _ =>
nbt.removeTag("inventory")
} }
if (remainingTicks > 0) { if (remainingTicks > 0) {
nbt.setInteger("remainingTicks", remainingTicks) nbt.setInteger("remainingTicks", remainingTicks)
} }
else {
nbt.removeTag("remainingTicks")
}
} }
} }

View File

@ -228,7 +228,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
val sneaky = args.isBoolean(2) && args.checkBoolean(2) val sneaky = args.isBoolean(2) && args.checkBoolean(2)
val stack = player.robotInventory.selectedItemStack val stack = player.robotInventory.selectedItemStack
if (stack == null || stack.stackSize == 0) { if (stack == null || stack.stackSize == 0) {
return result(false, "nothing selected") return result(Unit, "nothing selected")
} }
for (side <- sides) { for (side <- sides) {
@ -499,16 +499,16 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
if (robot.isAnimatingMove) { if (robot.isAnimatingMove) {
// This shouldn't really happen due to delays being enforced, but just to // This shouldn't really happen due to delays being enforced, but just to
// be on the safe side... // be on the safe side...
result(false, "already moving") result(Unit, "already moving")
} }
else { else {
val (something, what) = blockContent(robot.player(direction), direction) val (something, what) = blockContent(robot.player(direction), direction)
if (something) { if (something) {
result(false, what) result(Unit, what)
} }
else { else {
if (!robot.computer.node.tryChangeBuffer(-Settings.get.robotMoveCost)) { if (!robot.computer.node.tryChangeBuffer(-Settings.get.robotMoveCost)) {
result(false, "not enough energy") result(Unit, "not enough energy")
} }
else if (robot.move(direction)) { else if (robot.move(direction)) {
context.pause(Settings.get.moveDelay) context.pause(Settings.get.moveDelay)
@ -517,7 +517,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
} }
else { else {
robot.computer.node.changeBuffer(Settings.get.robotMoveCost) robot.computer.node.changeBuffer(Settings.get.robotMoveCost)
result(false, "impossible move") result(Unit, "impossible move")
} }
} }
} }
@ -534,7 +534,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
result(true) result(true)
} }
else { else {
result(false, "not enough energy") result(Unit, "not enough energy")
} }
} }