From b13f319018ef28c57a3d97fafc27bb732a634667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 11 Jan 2015 14:27:29 +0100 Subject: [PATCH] Added EEPROM cloning recipe (EEPROM + EEPROM -> 2x EEPROM with same data). If one is empty, the one with data is preferred. If both have data, the first one gets copied onto the second. Closes #756. --- .../cil/oc/common/recipe/ExtendedRecipe.scala | 24 ++++++++++---- .../li/cil/oc/common/recipe/Recipes.scala | 32 +++++++++++++------ 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/recipe/ExtendedRecipe.scala b/src/main/scala/li/cil/oc/common/recipe/ExtendedRecipe.scala index 7568bb794..ead527217 100644 --- a/src/main/scala/li/cil/oc/common/recipe/ExtendedRecipe.scala +++ b/src/main/scala/li/cil/oc/common/recipe/ExtendedRecipe.scala @@ -15,6 +15,7 @@ import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import scala.collection.convert.WrapAsScala._ +import scala.util.control.Breaks._ object ExtendedRecipe { private lazy val drone = api.Items.get("drone") @@ -61,17 +62,28 @@ object ExtendedRecipe { val nbt = craftedStack.getTagCompound for (slot <- 0 until inventory.getSizeInventory) { val stack = inventory.getStackInSlot(slot) - if (stack != null) { - if (api.Items.get(stack) == floppy && stack.hasTagCompound) { - val oldData = stack.getTagCompound - for (oldTagName <- oldData.func_150296_c().map(_.asInstanceOf[String])) { - nbt.setTag(oldTagName, oldData.getTag(oldTagName).copy()) - } + if (stack != null && api.Items.get(stack) == floppy && stack.hasTagCompound) { + val oldData = stack.getTagCompound + for (oldTagName <- oldData.func_150296_c().map(_.asInstanceOf[String])) { + nbt.setTag(oldTagName, oldData.getTag(oldTagName).copy()) } } } } + if (api.Items.get(craftedStack) == eeprom) breakable { + for (slot <- 0 until inventory.getSizeInventory) { + val stack = inventory.getStackInSlot(slot) + if (stack != null && api.Items.get(stack) == eeprom && stack.hasTagCompound) { + val copy = stack.getTagCompound.copy.asInstanceOf[NBTTagCompound] + // Erase node address, just in case. + copy.getCompoundTag(Settings.namespace + "data").getCompoundTag("node").removeTag("address") + craftedStack.setTagCompound(copy) + break() + } + } + } + recraftMCU(craftedStack, inventory, mcu) recraftMCU(craftedStack, inventory, drone) diff --git a/src/main/scala/li/cil/oc/common/recipe/Recipes.scala b/src/main/scala/li/cil/oc/common/recipe/Recipes.scala index 4595b2b3c..0e76e7e1c 100644 --- a/src/main/scala/li/cil/oc/common/recipe/Recipes.scala +++ b/src/main/scala/li/cil/oc/common/recipe/Recipes.scala @@ -119,27 +119,41 @@ object Recipes { addRecipe(stack, recipes, name) } + // Recrafting operations. + val navigationUpgrade = api.Items.get("navigationUpgrade") + val mcu = api.Items.get("microcontroller") + val floppy = api.Items.get("floppy") + val drone = api.Items.get("drone") + val eeprom = api.Items.get("eeprom") + // Navigation upgrade recrafting. - val navigationUpgrade = api.Items.get("navigationUpgrade").createItemStack(1) - GameRegistry.addRecipe(new ExtendedShapelessOreRecipe(navigationUpgrade, navigationUpgrade, new ItemStack(net.minecraft.init.Items.filled_map, 1, OreDictionary.WILDCARD_VALUE))) + GameRegistry.addRecipe(new ExtendedShapelessOreRecipe( + navigationUpgrade.createItemStack(1), + navigationUpgrade.createItemStack(1), new ItemStack(net.minecraft.init.Items.filled_map, 1, OreDictionary.WILDCARD_VALUE))) // Floppy disk coloring. - val floppy = api.Items.get("floppy").createItemStack(1) for (dye <- Color.dyes) { - val result = api.Items.get("floppy").createItemStack(1) + val result = floppy.createItemStack(1) val tag = new NBTTagCompound() tag.setInteger(Settings.namespace + "color", Color.dyes.indexOf(dye)) result.setTagCompound(tag) - GameRegistry.addRecipe(new ExtendedShapelessOreRecipe(result, floppy, dye)) + GameRegistry.addRecipe(new ExtendedShapelessOreRecipe(result, floppy.createItemStack(1), dye)) } // Microcontroller recrafting. - val mcu = api.Items.get("microcontroller").createItemStack(1) - GameRegistry.addRecipe(new ExtendedShapelessOreRecipe(mcu, mcu, api.Items.get("eeprom").createItemStack(1))) + GameRegistry.addRecipe(new ExtendedShapelessOreRecipe( + mcu.createItemStack(1), + mcu.createItemStack(1), eeprom.createItemStack(1))) // Drone recrafting. - val drone = api.Items.get("drone").createItemStack(1) - GameRegistry.addRecipe(new ExtendedShapelessOreRecipe(drone, drone, api.Items.get("eeprom").createItemStack(1))) + GameRegistry.addRecipe(new ExtendedShapelessOreRecipe( + drone.createItemStack(1), + drone.createItemStack(1), eeprom.createItemStack(1))) + + // EEPROM copying via crafting. + GameRegistry.addRecipe(new ExtendedShapelessOreRecipe( + eeprom.createItemStack(2), + eeprom.createItemStack(1), eeprom.createItemStack(1))) } catch { case e: Throwable => OpenComputers.log.error("Error parsing recipes, you may not be able to craft any items from this mod!", e)