Fixed crafting of Lua BIOS and OpenOS floppy using "initialized" items (i.e. EEPROM or floppy that had been installed in a computer/disk drive before). Closes #1199.

This commit is contained in:
Florian Nücke 2015-06-07 10:58:55 +02:00
parent 6c7c28d550
commit bc29a0b70d
5 changed files with 28 additions and 23 deletions

View File

@ -51,9 +51,8 @@ object ExtendedRecipe {
def addNBTToResult(recipe: IRecipe, craftedStack: ItemStack, inventory: InventoryCrafting): ItemStack = {
if (api.Items.get(craftedStack) == navigationUpgrade) {
Option(api.Driver.driverFor(craftedStack)).foreach(driver =>
for (slot <- 0 until inventory.getSizeInventory) {
val stack = inventory.getStackInSlot(slot)
if (stack != null && stack.getItem == net.minecraft.init.Items.filled_map) {
for (stack <- getItems(inventory)) {
if (stack.getItem == net.minecraft.init.Items.filled_map) {
// Store information of the map used for crafting in the result.
val nbt = driver.dataTag(craftedStack)
nbt.setNewCompoundTag(Settings.namespace + "map", stack.writeToNBT)
@ -79,9 +78,8 @@ object ExtendedRecipe {
if (recipe.getRecipeSize == 1) {
// Formatting / loot to normal disk conversion, only keep coloring.
val colorKey = Settings.namespace + "color"
for (slot <- 0 until inventory.getSizeInventory) {
val stack = inventory.getStackInSlot(slot)
if (stack != null && api.Items.get(stack) != null && (api.Items.get(stack) == floppy || api.Items.get(stack).name == "lootDisk") && stack.hasTagCompound) {
for (stack <- getItems(inventory)) {
if (api.Items.get(stack) != null && (api.Items.get(stack) == floppy || api.Items.get(stack).name == "lootDisk") && stack.hasTagCompound) {
val oldData = stack.getTagCompound
if (oldData.hasKey(colorKey) && oldData.getInteger(colorKey) != Color.dyes.indexOf("lightGray")) {
nbt.setTag(colorKey, oldData.getTag(colorKey).copy())
@ -92,10 +90,10 @@ object ExtendedRecipe {
craftedStack.setTagCompound(null)
}
}
else {
for (slot <- 0 until inventory.getSizeInventory) {
val stack = inventory.getStackInSlot(slot)
if (stack != null && api.Items.get(stack) == floppy && stack.hasTagCompound) {
else if (getItems(inventory).forall(api.Items.get(_) == floppy)) {
// Copy operation.
for (stack <- getItems(inventory)) {
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())
@ -111,7 +109,7 @@ object ExtendedRecipe {
recipe.asInstanceOf[ExtendedShapelessOreRecipe].getInput.size == 2) {
// First, copy old data.
val data = new PrintData(craftedStack)
val inputs = (0 until inventory.getSizeInventory).map(inventory.getStackInSlot).filter(_ != null)
val inputs = getItems(inventory)
for (stack <- inputs) {
if (api.Items.get(stack) == print) {
data.load(stack)
@ -158,13 +156,12 @@ object ExtendedRecipe {
// EEPROM copying.
if (api.Items.get(craftedStack) == eeprom &&
api.Items.get(craftedStack) != luaBios &&
craftedStack.stackSize == 2 &&
recipe.isInstanceOf[ExtendedShapelessOreRecipe] &&
recipe.asInstanceOf[ExtendedShapelessOreRecipe].getInput != null &&
recipe.asInstanceOf[ExtendedShapelessOreRecipe].getInput.size == 2) breakable {
for (slot <- 0 until inventory.getSizeInventory) {
val stack = inventory.getStackInSlot(slot)
if (stack != null && api.Items.get(stack) == eeprom && stack.hasTagCompound) {
for (stack <- getItems(inventory)) {
if (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")
@ -183,10 +180,12 @@ object ExtendedRecipe {
craftedStack
}
private def getItems(inventory: InventoryCrafting) = (0 until inventory.getSizeInventory).map(inventory.getStackInSlot).filter(_ != null)
private def recraft(craftedStack: ItemStack, inventory: InventoryCrafting, descriptor: ItemInfo, dataFactory: (ItemStack) => ItemDataWrapper) {
if (api.Items.get(craftedStack) == descriptor) {
// Find old Microcontroller.
(0 until inventory.getSizeInventory).map(inventory.getStackInSlot).find(api.Items.get(_) == descriptor) match {
getItems(inventory).find(api.Items.get(_) == descriptor) match {
case Some(oldMcu) =>
val data = dataFactory(oldMcu)
@ -195,8 +194,7 @@ object ExtendedRecipe {
data.components = data.components.diff(oldRom)
// Insert new EEPROM.
for (slot <- 0 until inventory.getSizeInventory) {
val stack = inventory.getStackInSlot(slot)
for (stack <- getItems(inventory)) {
if (api.Items.get(stack) == eeprom) {
data.components :+= stack
}

View File

@ -0,0 +1,8 @@
package li.cil.oc.common.recipe
import net.minecraft.item.ItemStack
import net.minecraftforge.oredict.ShapedOreRecipe
class NBTIgnoringShapedRecipe(result: ItemStack, recipe: AnyRef*) extends ShapedOreRecipe(result, recipe: _*) {
}

View File

@ -7,7 +7,6 @@ import com.typesafe.config.ConfigValue
import li.cil.oc.common.recipe.Recipes
import li.cil.oc.common.recipe.Recipes.RecipeException
import net.minecraft.item.ItemStack
import net.minecraftforge.fluids.FluidStack
import net.minecraftforge.oredict.OreDictionary
import scala.collection.convert.WrapAsScala._

View File

@ -43,7 +43,7 @@ object RecipeHandler {
shape += pattern.toString
input ++= ingredients
}
if (input.size > 0 && output.stackSize > 0) {
if (input.nonEmpty && output.stackSize > 0) {
GameRegistry.addRecipe(new ExtendedShapedOreRecipe(output, shape ++ input: _*))
}
}
@ -55,7 +55,7 @@ object RecipeHandler {
}
output.stackSize = Recipes.tryGetCount(recipe)
if (input.size > 0 && output.stackSize > 0) {
if (input.nonEmpty && output.stackSize > 0) {
GameRegistry.addRecipe(new ExtendedShapelessOreRecipe(output, input: _*))
}
}

View File

@ -625,7 +625,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
}
private def processAddedComponents() {
if (addedComponents.size > 0) {
if (addedComponents.nonEmpty) {
for (component <- addedComponents) {
if (component.canBeSeenFrom(node)) {
_components.synchronized(_components += component.address -> component.name)
@ -684,7 +684,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach
else fs.load(SaveHandler.loadNBT(nbt, node.address + "_tmp"))
})
if (state.size > 0 && isRunning && init()) try {
if (state.nonEmpty && isRunning && init()) try {
architecture.load(nbt)
signals ++= nbt.getTagList("signals", NBT.TAG_COMPOUND).map((signalNbt: NBTTagCompound) => {