mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
Merge branch 'master' of https://github.com/MightyPirates/OpenComputers into MC1.7
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:
commit
4c19d06c97
@ -47,24 +47,24 @@ object Blocks {
|
||||
// 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
|
||||
// must not be changed since that order determines their actual IDs.
|
||||
adapter = new Adapter(blockSimple)
|
||||
cable = new Cable(blockSpecial)
|
||||
capacitor = new Capacitor(blockSimple)
|
||||
case1 = new Case.Tier1(blockSimpleWithRedstone)
|
||||
case2 = new Case.Tier2(blockSimpleWithRedstone)
|
||||
case3 = new Case.Tier3(blockSimpleWithRedstone)
|
||||
charger = new Charger(blockSimpleWithRedstone)
|
||||
diskDrive = new DiskDrive(blockSimple)
|
||||
adapter = Recipes.addBlockDelegate(new Adapter(blockSimple), "adapter")
|
||||
cable = Recipes.addBlockDelegate(new Cable(blockSpecial), "cable")
|
||||
capacitor = Recipes.addBlockDelegate(new Capacitor(blockSimple), "capacitor")
|
||||
case1 = Recipes.addBlockDelegate(new Case.Tier1(blockSimpleWithRedstone), "case1")
|
||||
case2 = Recipes.addBlockDelegate(new Case.Tier2(blockSimpleWithRedstone), "case2")
|
||||
case3 = Recipes.addBlockDelegate(new Case.Tier3(blockSimpleWithRedstone), "case3")
|
||||
charger = Recipes.addBlockDelegate(new Charger(blockSimpleWithRedstone), "charger")
|
||||
diskDrive = Recipes.addBlockDelegate(new DiskDrive(blockSimple), "diskDrive")
|
||||
keyboardDeprecated = new KeyboardDeprecated(blockSpecial)
|
||||
powerDistributor = new PowerDistributor(blockSimple)
|
||||
powerConverter = new PowerConverter(blockSimple)
|
||||
redstone = new Redstone(blockSimpleWithRedstone)
|
||||
powerDistributor = Recipes.addBlockDelegate(new PowerDistributor(blockSimple), "powerDistributor")
|
||||
powerConverter = Recipes.addBlockDelegate(new PowerConverter(blockSimple), "powerConverter")
|
||||
redstone = Recipes.addBlockDelegate(new Redstone(blockSimpleWithRedstone), "redstone")
|
||||
robotAfterimage = new RobotAfterimage(blockSpecial)
|
||||
robotProxy = new RobotProxy(blockSpecialWithRedstone)
|
||||
router = new Router(blockSimple)
|
||||
screen1 = new Screen.Tier1(blockSimpleWithRedstone)
|
||||
screen2 = new Screen.Tier2(blockSimpleWithRedstone)
|
||||
screen3 = new Screen.Tier3(blockSimpleWithRedstone)
|
||||
robotProxy = Recipes.addBlockDelegate(new RobotProxy(blockSpecialWithRedstone), "robot")
|
||||
router = Recipes.addBlockDelegate(new Router(blockSimple), "router")
|
||||
screen1 = Recipes.addBlockDelegate(new Screen.Tier1(blockSimpleWithRedstone), "screen1")
|
||||
screen2 = Recipes.addBlockDelegate(new Screen.Tier2(blockSimpleWithRedstone), "screen2")
|
||||
screen3 = Recipes.addBlockDelegate(new Screen.Tier3(blockSimpleWithRedstone), "screen3")
|
||||
|
||||
// For automatic conversion from old format (when screens did not take
|
||||
// redstone inputs) to keep save format compatible.
|
||||
@ -73,10 +73,10 @@ object Blocks {
|
||||
blockSimple.subBlocks += screen3
|
||||
|
||||
// v1.2.0
|
||||
serverRack = new Rack(blockSpecialWithRedstone)
|
||||
serverRack = Recipes.addBlockDelegate(new Rack(blockSpecialWithRedstone), "rack")
|
||||
|
||||
// v2.0.0
|
||||
keyboard = new Keyboard()
|
||||
keyboard = Recipes.addBlock(new Keyboard(), "keyboard")
|
||||
|
||||
GameRegistry.registerBlock(keyboard, classOf[Item], Settings.namespace + "keyboard")
|
||||
|
||||
|
@ -2,8 +2,10 @@ package li.cil.oc
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import li.cil.oc.common.item
|
||||
import li.cil.oc.util.mods.StargateTech2
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
|
||||
object Items {
|
||||
var multi: item.Delegator = _
|
||||
@ -70,67 +72,74 @@ object Items {
|
||||
|
||||
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)
|
||||
ram2 = new item.Memory(multi, 1)
|
||||
ram3 = new item.Memory(multi, 2)
|
||||
ram1 = Recipes.addItemDelegate(new item.Memory(multi, 0), "ram1")
|
||||
ram2 = Recipes.addItemDelegate(new item.Memory(multi, 1), "ram2")
|
||||
ram3 = Recipes.addItemDelegate(new item.Memory(multi, 2), "ram3")
|
||||
|
||||
floppyDisk = new item.FloppyDisk(multi)
|
||||
hdd1 = new item.HardDiskDrive(multi, 0)
|
||||
hdd2 = new item.HardDiskDrive(multi, 1)
|
||||
hdd3 = new item.HardDiskDrive(multi, 2)
|
||||
floppyDisk = Recipes.addItemDelegate(new item.FloppyDisk(multi), "floppy")
|
||||
hdd1 = Recipes.addItemDelegate(new item.HardDiskDrive(multi, 0), "hdd1")
|
||||
hdd2 = Recipes.addItemDelegate(new item.HardDiskDrive(multi, 1), "hdd2")
|
||||
hdd3 = Recipes.addItemDelegate(new item.HardDiskDrive(multi, 2), "hdd3")
|
||||
|
||||
gpu1 = new item.GraphicsCard(multi, 0)
|
||||
gpu2 = new item.GraphicsCard(multi, 1)
|
||||
gpu3 = new item.GraphicsCard(multi, 2)
|
||||
lan = new item.NetworkCard(multi)
|
||||
rs = new item.RedstoneCard(multi)
|
||||
wlan = new item.WirelessNetworkCard(multi)
|
||||
gpu1 = Recipes.addItemDelegate(new item.GraphicsCard(multi, 0), "graphicsCard1")
|
||||
gpu2 = Recipes.addItemDelegate(new item.GraphicsCard(multi, 1), "graphicsCard2")
|
||||
gpu3 = Recipes.addItemDelegate(new item.GraphicsCard(multi, 2), "graphicsCard3")
|
||||
lan = Recipes.addItemDelegate(new item.NetworkCard(multi), "lanCard")
|
||||
rs = Recipes.addItemDelegate(new item.RedstoneCard(multi), "redstoneCard")
|
||||
wlan = Recipes.addItemDelegate(new item.WirelessNetworkCard(multi), "wlanCard")
|
||||
|
||||
upgradeCrafting = new item.UpgradeCrafting(multi)
|
||||
upgradeGenerator = new item.UpgradeGenerator(multi)
|
||||
upgradeCrafting = Recipes.addItemDelegate(new item.UpgradeCrafting(multi), "craftingUpgrade")
|
||||
upgradeGenerator = Recipes.addItemDelegate(new item.UpgradeGenerator(multi), "generatorUpgrade")
|
||||
|
||||
ironNugget = new item.IronNugget(multi)
|
||||
cuttingWire = new item.CuttingWire(multi)
|
||||
acid = new item.Acid(multi)
|
||||
disk = new item.Disk(multi)
|
||||
if (OreDictionary.getOres("nuggetIron").exists(ironNugget.createItemStack().isItemEqual)) {
|
||||
Recipes.addItemDelegate(ironNugget, "nuggetIron")
|
||||
}
|
||||
|
||||
buttonGroup = new item.ButtonGroup(multi)
|
||||
arrowKeys = new item.ArrowKeys(multi)
|
||||
numPad = new item.NumPad(multi)
|
||||
cuttingWire = Recipes.addItemDelegate(new item.CuttingWire(multi), "cuttingWire")
|
||||
acid = Recipes.addItemDelegate(new item.Acid(multi), "acid")
|
||||
disk = Recipes.addItemDelegate(new item.Disk(multi), "disk")
|
||||
|
||||
transistor = new item.Transistor(multi)
|
||||
chip1 = new item.Microchip(multi, 0)
|
||||
chip2 = new item.Microchip(multi, 1)
|
||||
chip3 = new item.Microchip(multi, 2)
|
||||
alu = new item.ALU(multi)
|
||||
cu = new item.ControlUnit(multi)
|
||||
cpu0 = new item.CPU(multi, 0)
|
||||
buttonGroup = Recipes.addItemDelegate(new item.ButtonGroup(multi), "buttonGroup")
|
||||
arrowKeys = Recipes.addItemDelegate(new item.ArrowKeys(multi), "arrowKeys")
|
||||
numPad = Recipes.addItemDelegate(new item.NumPad(multi), "numPad")
|
||||
|
||||
rawCircuitBoard = new item.RawCircuitBoard(multi)
|
||||
circuitBoard = new item.CircuitBoard(multi)
|
||||
pcb = new item.PrintedCircuitBoard(multi)
|
||||
card = new item.CardBase(multi)
|
||||
transistor = Recipes.addItemDelegate(new item.Transistor(multi), "transistor")
|
||||
chip1 = Recipes.addItemDelegate(new item.Microchip(multi, 0), "chip1")
|
||||
chip2 = Recipes.addItemDelegate(new item.Microchip(multi, 1), "chip2")
|
||||
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
|
||||
upgradeSolarGenerator = new item.UpgradeSolarGenerator(multi)
|
||||
upgradeSign = new item.UpgradeSign(multi)
|
||||
upgradeNavigation = new item.UpgradeNavigation(multi)
|
||||
upgradeSolarGenerator = Recipes.addItemDelegate(new item.UpgradeSolarGenerator(multi), "solarGeneratorUpgrade")
|
||||
upgradeSign = Recipes.addItemDelegate(new item.UpgradeSign(multi), "signUpgrade")
|
||||
upgradeNavigation = Recipes.addItemDelegate(new item.UpgradeNavigation(multi), "navigationUpgrade")
|
||||
|
||||
abstractBus = new item.AbstractBusCard(multi)
|
||||
if (StargateTech2.isAvailable) {
|
||||
Recipes.addItemDelegate(abstractBus, "abstractBusCard")
|
||||
}
|
||||
|
||||
ram4 = new item.Memory(multi, 3)
|
||||
ram5 = new item.Memory(multi, 4)
|
||||
ram4 = Recipes.addItemDelegate(new item.Memory(multi, 3), "ram4")
|
||||
ram5 = Recipes.addItemDelegate(new item.Memory(multi, 4), "ram5")
|
||||
|
||||
// v1.2.0
|
||||
server3 = new item.Server(multi, 2)
|
||||
terminal = new item.Terminal(multi)
|
||||
cpu1 = new item.CPU(multi, 1)
|
||||
cpu2 = new item.CPU(multi, 2)
|
||||
internet = new item.InternetCard(multi)
|
||||
server1 = new item.Server(multi, 0)
|
||||
server2 = new item.Server(multi, 1)
|
||||
server3 = Recipes.addItemDelegate(new item.Server(multi, 2), "server3")
|
||||
terminal = Recipes.addItemDelegate(new item.Terminal(multi), "terminal")
|
||||
cpu1 = Recipes.addItemDelegate(new item.CPU(multi, 1), "cpu1")
|
||||
cpu2 = Recipes.addItemDelegate(new item.CPU(multi, 2), "cpu2")
|
||||
internet = Recipes.addItemDelegate(new item.InternetCard(multi), "internetCard")
|
||||
server1 = Recipes.addItemDelegate(new item.Server(multi, 0), "server1")
|
||||
server2 = Recipes.addItemDelegate(new item.Server(multi, 1), "server2")
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
|
@ -5,18 +5,33 @@ import cpw.mods.fml.common.Loader
|
||||
import cpw.mods.fml.common.registry.GameRegistry
|
||||
import java.io.{FileReader, File}
|
||||
import java.util.logging.Level
|
||||
import li.cil.oc.common.block.Delegator
|
||||
import li.cil.oc.util.mods.{StargateTech2, GregTech}
|
||||
import li.cil.oc.util.mods.GregTech
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.crafting.FurnaceRecipes
|
||||
import net.minecraft.item.{ItemStack, Item}
|
||||
import net.minecraftforge.oredict.{OreDictionary, ShapelessOreRecipe, ShapedOreRecipe}
|
||||
import org.apache.commons.io.FileUtils
|
||||
import scala.Some
|
||||
import scala.collection.convert.wrapAsScala._
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
import scala.collection.mutable
|
||||
|
||||
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() {
|
||||
try {
|
||||
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)
|
||||
|
||||
// Try to keep this in the same order as the fields in the Items class
|
||||
// to make it easier to match them and check if anything is missing.
|
||||
addRecipe(Items.analyzer.createItemStack(), recipes, "analyzer")
|
||||
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")
|
||||
// Register all known recipes.
|
||||
for ((stack, name) <- list.map(_())) {
|
||||
addRecipe(stack, recipes, name)
|
||||
}
|
||||
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.
|
||||
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)
|
||||
|
||||
var number = -1
|
||||
var shape = ArrayBuffer.empty[String]
|
||||
val input = ArrayBuffer.empty[AnyRef]
|
||||
var shape = mutable.ArrayBuffer.empty[String]
|
||||
val input = mutable.ArrayBuffer.empty[AnyRef]
|
||||
for (row <- rows) {
|
||||
val (pattern, ingredients) = row.foldLeft((new StringBuilder, Seq.empty[AnyRef]))((acc, ingredient) => {
|
||||
val (pattern, ingredients) = acc
|
||||
@ -359,7 +295,7 @@ object Recipes {
|
||||
private def hide(value: ItemStack) {
|
||||
Items.multi.subItem(value) match {
|
||||
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 _ =>
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import li.cil.oc.server.driver.item.Item
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
import scala.collection.mutable
|
||||
|
||||
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 Some(component) =>
|
||||
// We're guaranteed to have a driver for entries.
|
||||
val driver = Registry.itemDriverFor(stack).get
|
||||
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)
|
||||
}
|
||||
save(component, Registry.itemDriverFor(stack).get, stack)
|
||||
case _ => // Nothing special to save.
|
||||
}
|
||||
}
|
||||
@ -106,7 +102,7 @@ trait ComponentInventory extends Inventory with network.Environment {
|
||||
assert(!updatingComponents.contains(component))
|
||||
updatingComponents += component
|
||||
}
|
||||
component.save(dataTag(driver, stack))
|
||||
save(component, driver, stack)
|
||||
}
|
||||
case _ => // No environment (e.g. RAM).
|
||||
}
|
||||
@ -125,11 +121,7 @@ trait ComponentInventory extends Inventory with network.Environment {
|
||||
components(slot) = None
|
||||
updatingComponents -= component
|
||||
component.node.remove()
|
||||
Registry.itemDriverFor(stack).foreach(driver => 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)
|
||||
})
|
||||
Registry.itemDriverFor(stack).foreach(driver => save(component, driver, stack))
|
||||
}
|
||||
case _ => // Nothing to do.
|
||||
}
|
||||
@ -143,4 +135,18 @@ trait ComponentInventory extends Inventory with network.Environment {
|
||||
|
||||
protected def dataTag(driver: ItemDriver, stack: ItemStack) =
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ class AbstractBus(val device: IBusDevice) extends ManagedComponent with IBusDriv
|
||||
busInterface.sendAllPackets()
|
||||
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.""")
|
||||
|
@ -53,7 +53,7 @@ abstract class GraphicsCard extends ManagedComponent {
|
||||
def bind(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val address = args.checkString(0)
|
||||
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] =>
|
||||
screenAddress = Option(address)
|
||||
screenInstance = Some(node.host.asInstanceOf[Buffer])
|
||||
@ -66,7 +66,7 @@ abstract class GraphicsCard extends ManagedComponent {
|
||||
s.background = 0x000000
|
||||
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)
|
||||
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)
|
||||
result(true)
|
||||
}
|
||||
else result(false)
|
||||
else result(Unit, "not enough energy")
|
||||
})
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ abstract class GraphicsCard extends ManagedComponent {
|
||||
result(true)
|
||||
}
|
||||
else {
|
||||
result(false)
|
||||
result(Unit, "not enough energy")
|
||||
}
|
||||
})
|
||||
else throw new Exception("invalid fill value")
|
||||
|
@ -54,12 +54,12 @@ class InternetCard extends ManagedComponent {
|
||||
}
|
||||
val address = args.checkString(0)
|
||||
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
|
||||
this.synchronized {
|
||||
if (request.isDefined || queue.isDefined) {
|
||||
return result(false, "already busy with another request")
|
||||
return result(Unit, "already busy with another request")
|
||||
}
|
||||
scheduleRequest(address, post)
|
||||
}
|
||||
@ -137,7 +137,9 @@ class InternetCard extends ManagedComponent {
|
||||
def connect(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val address = args.checkString(0)
|
||||
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) {
|
||||
throw new IOException("too many open connections")
|
||||
}
|
||||
|
@ -27,16 +27,18 @@ class UpgradeGenerator(val owner: TileEntity) extends ManagedComponent {
|
||||
val player = context.player
|
||||
val stack = player.inventory.getStackInSlot(context.selectedSlot)
|
||||
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 {
|
||||
case Some(existingStack) =>
|
||||
if (!existingStack.isItemEqual(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
|
||||
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))
|
||||
existingStack.stackSize += moveCount
|
||||
@ -134,16 +136,11 @@ class UpgradeGenerator(val owner: TileEntity) extends ManagedComponent {
|
||||
override def save(nbt: NBTTagCompound) {
|
||||
super.save(nbt)
|
||||
inventory match {
|
||||
case Some(stack) =>
|
||||
nbt.setNewCompoundTag("inventory", stack.writeToNBT)
|
||||
case Some(stack) => nbt.setNewCompoundTag("inventory", stack.writeToNBT)
|
||||
case _ =>
|
||||
nbt.removeTag("inventory")
|
||||
}
|
||||
if (remainingTicks > 0) {
|
||||
nbt.setInteger("remainingTicks", remainingTicks)
|
||||
}
|
||||
else {
|
||||
nbt.removeTag("remainingTicks")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
|
||||
val sneaky = args.isBoolean(2) && args.checkBoolean(2)
|
||||
val stack = player.robotInventory.selectedItemStack
|
||||
if (stack == null || stack.stackSize == 0) {
|
||||
return result(false, "nothing selected")
|
||||
return result(Unit, "nothing selected")
|
||||
}
|
||||
|
||||
for (side <- sides) {
|
||||
@ -499,16 +499,16 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
|
||||
if (robot.isAnimatingMove) {
|
||||
// This shouldn't really happen due to delays being enforced, but just to
|
||||
// be on the safe side...
|
||||
result(false, "already moving")
|
||||
result(Unit, "already moving")
|
||||
}
|
||||
else {
|
||||
val (something, what) = blockContent(robot.player(direction), direction)
|
||||
if (something) {
|
||||
result(false, what)
|
||||
result(Unit, what)
|
||||
}
|
||||
else {
|
||||
if (!robot.computer.node.tryChangeBuffer(-Settings.get.robotMoveCost)) {
|
||||
result(false, "not enough energy")
|
||||
result(Unit, "not enough energy")
|
||||
}
|
||||
else if (robot.move(direction)) {
|
||||
context.pause(Settings.get.moveDelay)
|
||||
@ -517,7 +517,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
|
||||
}
|
||||
else {
|
||||
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)
|
||||
}
|
||||
else {
|
||||
result(false, "not enough energy")
|
||||
result(Unit, "not enough energy")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user