Skip to content

Commit

Permalink
component inventory now clears the tag items are saved to before call…
Browse files Browse the repository at this point in the history
…ing their save method, to behave like tile entities when saving (i.e. get a clean tag, so old stuff doesn't have to be deleted manually); reworked recipe registration to add a pre-registration step that's done right in the item instantiation, keeping things in one place (less likely to forget adding recipes)
  • Loading branch information
fnuecke committed Feb 12, 2014
1 parent f639ecb commit 4f9dbf3
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 177 deletions.
40 changes: 20 additions & 20 deletions src/main/java/li/cil/oc/Blocks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package li.cil.oc

import cpw.mods.fml.common.registry.GameRegistry
import li.cil.oc.common.block._
import li.cil.oc.common.{block, tileentity}
import li.cil.oc.common.tileentity
import net.minecraft.block.Block
import net.minecraft.item.ItemStack
import net.minecraftforge.oredict.OreDictionary
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.oredict.OreDictionary

object Blocks {
var blockSimple: SimpleDelegator = _
Expand Down Expand Up @@ -67,24 +67,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)
keyboard = new Keyboard(blockSpecial)
powerDistributor = new PowerDistributor(blockSimple)
powerConverter = new PowerConverter(blockSimple)
redstone = new Redstone(blockSimpleWithRedstone)
adapter = Recipes.addBlock(new Adapter(blockSimple), "adapter")
cable = Recipes.addBlock(new Cable(blockSpecial), "cable")
capacitor = Recipes.addBlock(new Capacitor(blockSimple), "capacitor")
case1 = Recipes.addBlock(new Case.Tier1(blockSimpleWithRedstone), "case1")
case2 = Recipes.addBlock(new Case.Tier2(blockSimpleWithRedstone), "case2")
case3 = Recipes.addBlock(new Case.Tier3(blockSimpleWithRedstone), "case3")
charger = Recipes.addBlock(new Charger(blockSimpleWithRedstone), "charger")
diskDrive = Recipes.addBlock(new DiskDrive(blockSimple), "diskDrive")
keyboard = Recipes.addBlock(new Keyboard(blockSpecial), "keyboard")
powerDistributor = Recipes.addBlock(new PowerDistributor(blockSimple), "powerDistributor")
powerConverter = Recipes.addBlock(new PowerConverter(blockSimple), "powerConverter")
redstone = Recipes.addBlock(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.addBlock(new RobotProxy(blockSpecialWithRedstone), "robot")
router = Recipes.addBlock(new Router(blockSimple), "router")
screen1 = Recipes.addBlock(new Screen.Tier1(blockSimpleWithRedstone), "screen1")
screen2 = Recipes.addBlock(new Screen.Tier2(blockSimpleWithRedstone), "screen2")
screen3 = Recipes.addBlock(new Screen.Tier3(blockSimpleWithRedstone), "screen3")

// For automatic conversion from old format (when screens did not take
// redstone inputs) to keep save format compatible.
Expand All @@ -93,7 +93,7 @@ object Blocks {
blockSimple.subBlocks += screen3

// v1.2.0
serverRack = new Rack(blockSpecialWithRedstone)
serverRack = Recipes.addBlock(new Rack(blockSpecialWithRedstone), "rack")

register("oc:craftingCable", cable.createItemStack())
register("oc:craftingCapacitor", capacitor.createItemStack())
Expand Down
105 changes: 57 additions & 48 deletions src/main/java/li/cil/oc/Items.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ 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.block.Block
import net.minecraft.item.{Item, ItemStack}
import net.minecraftforge.oredict.OreDictionary
import scala.collection.convert.WrapAsScala._

object Items {
var multi: item.Delegator = _
Expand Down Expand Up @@ -71,67 +73,74 @@ object Items {

GameRegistry.registerItem(multi, Settings.namespace + "item")

analyzer = new item.Analyzer(multi)
analyzer = Recipes.addItem(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.addItem(new item.Memory(multi, 0), "ram1")
ram2 = Recipes.addItem(new item.Memory(multi, 1), "ram2")
ram3 = Recipes.addItem(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.addItem(new item.FloppyDisk(multi), "floppy")
hdd1 = Recipes.addItem(new item.HardDiskDrive(multi, 0), "hdd1")
hdd2 = Recipes.addItem(new item.HardDiskDrive(multi, 1), "hdd2")
hdd3 = Recipes.addItem(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.addItem(new item.GraphicsCard(multi, 0), "graphicsCard1")
gpu2 = Recipes.addItem(new item.GraphicsCard(multi, 1), "graphicsCard2")
gpu3 = Recipes.addItem(new item.GraphicsCard(multi, 2), "graphicsCard3")
lan = Recipes.addItem(new item.NetworkCard(multi), "lanCard")
rs = Recipes.addItem(new item.RedstoneCard(multi), "redstoneCard")
wlan = Recipes.addItem(new item.WirelessNetworkCard(multi), "wlanCard")

upgradeCrafting = new item.UpgradeCrafting(multi)
upgradeGenerator = new item.UpgradeGenerator(multi)
upgradeCrafting = Recipes.addItem(new item.UpgradeCrafting(multi), "craftingUpgrade")
upgradeGenerator = Recipes.addItem(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)

buttonGroup = new item.ButtonGroup(multi)
arrowKeys = new item.ArrowKeys(multi)
numPad = new item.NumPad(multi)

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)

rawCircuitBoard = new item.RawCircuitBoard(multi)
circuitBoard = new item.CircuitBoard(multi)
pcb = new item.PrintedCircuitBoard(multi)
card = new item.CardBase(multi)
if (OreDictionary.getOres("nuggetIron").exists(ironNugget.createItemStack().isItemEqual)) {
Recipes.addItem(ironNugget, "nuggetIron")
}

cuttingWire = Recipes.addItem(new item.CuttingWire(multi), "cuttingWire")
acid = Recipes.addItem(new item.Acid(multi), "acid")
disk = Recipes.addItem(new item.Disk(multi), "disk")

buttonGroup = Recipes.addItem(new item.ButtonGroup(multi), "buttonGroup")
arrowKeys = Recipes.addItem(new item.ArrowKeys(multi), "arrowKeys")
numPad = Recipes.addItem(new item.NumPad(multi), "numPad")

transistor = Recipes.addItem(new item.Transistor(multi), "transistor")
chip1 = Recipes.addItem(new item.Microchip(multi, 0), "chip1")
chip2 = Recipes.addItem(new item.Microchip(multi, 1), "chip2")
chip3 = Recipes.addItem(new item.Microchip(multi, 2), "chip3")
alu = Recipes.addItem(new item.ALU(multi), "alu")
cu = Recipes.addItem(new item.ControlUnit(multi), "cu")
cpu0 = Recipes.addItem(new item.CPU(multi, 0), "cpu0")

rawCircuitBoard = Recipes.addItem(new item.RawCircuitBoard(multi), "rawCircuitBoard")
circuitBoard = Recipes.addItem(new item.CircuitBoard(multi), "circuitBoard")
pcb = Recipes.addItem(new item.PrintedCircuitBoard(multi), "printedCircuitBoard")
card = Recipes.addItem(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.addItem(new item.UpgradeSolarGenerator(multi), "solarGeneratorUpgrade")
upgradeSign = Recipes.addItem(new item.UpgradeSign(multi), "signUpgrade")
upgradeNavigation = Recipes.addItem(new item.UpgradeNavigation(multi), "navigationUpgrade")

abstractBus = new item.AbstractBusCard(multi)
if (StargateTech2.isAvailable) {
Recipes.addItem(abstractBus, "abstractBusCard")
}

ram4 = new item.Memory(multi, 3)
ram5 = new item.Memory(multi, 4)
ram4 = Recipes.addItem(new item.Memory(multi, 3), "ram4")
ram5 = Recipes.addItem(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.addItem(new item.Server(multi, 2), "server3")
terminal = Recipes.addItem(new item.Terminal(multi), "terminal")
cpu1 = Recipes.addItem(new item.CPU(multi, 1), "cpu1")
cpu2 = Recipes.addItem(new item.CPU(multi, 2), "cpu2")
internet = Recipes.addItem(new item.InternetCard(multi), "internetCard")
server1 = Recipes.addItem(new item.Server(multi, 0), "server1")
server2 = Recipes.addItem(new item.Server(multi, 1), "server2")

// ----------------------------------------------------------------------- //

Expand Down
111 changes: 21 additions & 90 deletions src/main/java/li/cil/oc/Recipes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@ 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.LinkedHashMap.empty[ItemStack, String]

def addBlock[T <: common.block.Delegate](block: T, name: String) = {
list += block.createItemStack() -> name
block
}

def addItem[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")
Expand Down Expand Up @@ -52,89 +62,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")
}
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")
// Register all known recipes.
for ((stack, name) <- list) {
addRecipe(stack, recipes, name)
}
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(Blocks.keyboard.createItemStack(), 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(Item.map, 1, OreDictionary.WILDCARD_VALUE)))
Expand Down Expand Up @@ -184,8 +115,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
Expand Down Expand Up @@ -344,7 +275,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 _ =>
}
Expand Down
Loading

0 comments on commit 4f9dbf3

Please sign in to comment.