From e24e2dfc766ed915a1d77248c6e4a1ff58c6c2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 5 Apr 2015 14:23:13 +0200 Subject: [PATCH] Floppy disks can no longer be "formatted" by shift-rightclicking, added crafting as alternative. Simply recrafting a single floppy (no other items in the crafting grid) will now format it. Same for loot disk, they can be converted to normal floppies the same way. In general, this removes the "shift-right-click to remove NBT tag" functionality, so you also can't format HHDs like this anymore - use `rm /*` or such. If you notice any items that needed the old functionality (looked through the list, didn't see one), let me know. --- .../scala/li/cil/oc/common/init/Items.scala | 5 ---- .../li/cil/oc/common/item/Delegate.scala | 10 +------ .../cil/oc/common/recipe/ExtendedRecipe.scala | 28 ++++++++++++------- .../recipe/ExtendedShapedOreRecipe.scala | 2 +- .../recipe/ExtendedShapelessOreRecipe.scala | 2 +- .../li/cil/oc/common/recipe/Recipes.scala | 13 ++++++--- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/init/Items.scala b/src/main/scala/li/cil/oc/common/init/Items.scala index d656918a6..e6ac8bdd1 100644 --- a/src/main/scala/li/cil/oc/common/init/Items.scala +++ b/src/main/scala/li/cil/oc/common/init/Items.scala @@ -370,11 +370,6 @@ object Items extends ItemAPI { // v1.2.3 registerItem(new item.FloppyDisk(multi) { showInItemList = false - - override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer) = { - if (player.isSneaking) get("floppy").createItemStack(1) - else super.onItemRightClick(stack, world, player) - } }, "lootDisk") // v1.2.6 diff --git a/src/main/scala/li/cil/oc/common/item/Delegate.scala b/src/main/scala/li/cil/oc/common/item/Delegate.scala index 95f45035c..d50e5e7fa 100644 --- a/src/main/scala/li/cil/oc/common/item/Delegate.scala +++ b/src/main/scala/li/cil/oc/common/item/Delegate.scala @@ -46,15 +46,7 @@ trait Delegate { def onItemUse(stack: ItemStack, player: EntityPlayer, position: BlockPosition, side: Int, hitX: Float, hitY: Float, hitZ: Float): Boolean = false - def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = { - if (player.isSneaking) { - if (stack.hasTagCompound && stack.getTagCompound.hasKey(Settings.namespace + "data")) { - stack.setTagCompound(null) - player.swingItem() - } - } - stack - } + def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = stack def getItemUseAction(stack: ItemStack): EnumAction = EnumAction.none 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 cd58408a1..8eb8686e7 100644 --- a/src/main/scala/li/cil/oc/common/recipe/ExtendedRecipe.scala +++ b/src/main/scala/li/cil/oc/common/recipe/ExtendedRecipe.scala @@ -16,6 +16,7 @@ import li.cil.oc.util.SideTracker import net.minecraft.init.Blocks import net.minecraft.inventory.InventoryCrafting import net.minecraft.item.ItemStack +import net.minecraft.item.crafting.IRecipe import net.minecraft.nbt.NBTTagCompound import scala.collection.convert.WrapAsScala._ @@ -29,6 +30,7 @@ object ExtendedRecipe { private lazy val navigationUpgrade = api.Items.get("navigationUpgrade") private lazy val linkedCard = api.Items.get("linkedCard") private lazy val floppy = api.Items.get("floppy") + private lazy val lootDisk = api.Items.get("lootDisk") private lazy val robot = api.Items.get("robot") private lazy val tablet = api.Items.get("tablet") private lazy val print = api.Items.get("print") @@ -40,7 +42,7 @@ object ExtendedRecipe { stack } - def addNBTToResult(craftedStack: ItemStack, inventory: InventoryCrafting): ItemStack = { + 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) { @@ -64,16 +66,22 @@ object ExtendedRecipe { } if (api.Items.get(craftedStack) == floppy) { - if (!craftedStack.hasTagCompound) { - craftedStack.setTagCompound(new NBTTagCompound()) + if (recipe.getRecipeSize == 1) { + // Formatting / loot to normal disk conversion. + craftedStack.setTagCompound(null) } - val nbt = craftedStack.getTagCompound - for (slot <- 0 until inventory.getSizeInventory) { - val stack = inventory.getStackInSlot(slot) - 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()) + else { + if (!craftedStack.hasTagCompound) { + craftedStack.setTagCompound(new NBTTagCompound()) + } + val nbt = craftedStack.getTagCompound + for (slot <- 0 until inventory.getSizeInventory) { + val stack = inventory.getStackInSlot(slot) + 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()) + } } } } diff --git a/src/main/scala/li/cil/oc/common/recipe/ExtendedShapedOreRecipe.scala b/src/main/scala/li/cil/oc/common/recipe/ExtendedShapedOreRecipe.scala index 3672d8ed7..552d82a9b 100644 --- a/src/main/scala/li/cil/oc/common/recipe/ExtendedShapedOreRecipe.scala +++ b/src/main/scala/li/cil/oc/common/recipe/ExtendedShapedOreRecipe.scala @@ -6,5 +6,5 @@ import net.minecraftforge.oredict.ShapedOreRecipe class ExtendedShapedOreRecipe(result: ItemStack, ingredients: AnyRef*) extends ShapedOreRecipe(result, ingredients: _*) { override def getCraftingResult(inventory: InventoryCrafting) = - ExtendedRecipe.addNBTToResult(super.getCraftingResult(inventory), inventory) + ExtendedRecipe.addNBTToResult(this, super.getCraftingResult(inventory), inventory) } diff --git a/src/main/scala/li/cil/oc/common/recipe/ExtendedShapelessOreRecipe.scala b/src/main/scala/li/cil/oc/common/recipe/ExtendedShapelessOreRecipe.scala index d94e04caa..afd700ff2 100644 --- a/src/main/scala/li/cil/oc/common/recipe/ExtendedShapelessOreRecipe.scala +++ b/src/main/scala/li/cil/oc/common/recipe/ExtendedShapelessOreRecipe.scala @@ -6,5 +6,5 @@ import net.minecraftforge.oredict.ShapelessOreRecipe class ExtendedShapelessOreRecipe(result: ItemStack, ingredients: AnyRef*) extends ShapelessOreRecipe(result, ingredients: _*) { override def getCraftingResult(inventory: InventoryCrafting) = - ExtendedRecipe.addNBTToResult(super.getCraftingResult(inventory), inventory) + ExtendedRecipe.addNBTToResult(this, super.getCraftingResult(inventory), inventory) } 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 d630348db..99b6bc206 100644 --- a/src/main/scala/li/cil/oc/common/recipe/Recipes.scala +++ b/src/main/scala/li/cil/oc/common/recipe/Recipes.scala @@ -125,6 +125,7 @@ object Recipes { val navigationUpgrade = api.Items.get("navigationUpgrade") val mcu = api.Items.get("microcontroller") val floppy = api.Items.get("floppy") + val lootDisk = api.Items.get("lootDisk") val drone = api.Items.get("drone") val eeprom = api.Items.get("eeprom") val robot = api.Items.get("robot") @@ -203,6 +204,10 @@ object Recipes { beaconPrint, print.createItemStack(1), new ItemStack(block))) } + + // Floppy disk formatting. + GameRegistry.addRecipe(new ExtendedShapelessOreRecipe(floppy.createItemStack(1), floppy.createItemStack(1))) + GameRegistry.addRecipe(new ExtendedShapelessOreRecipe(floppy.createItemStack(1), lootDisk.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) @@ -328,10 +333,10 @@ object Recipes { (inputs, inputCount).zipped.foreach((stacks, count) => stacks.foreach(stack => if (stack != null && count > 0) stack.stackSize = stack.getMaxStackSize min count)) inputs.padTo(2, null) - if (inputs(0) != null) { - for (input1 <- inputs(0)) { - if (inputs(1) != null) { - for (input2 <- inputs(1)) + if (inputs.head != null) { + for (input1 <- inputs.head) { + if (inputs.last != null) { + for (input2 <- inputs.last) gregtech.api.GregTech_API.sRecipeAdder.addAssemblerRecipe(input1, input2, output, duration, eu) } else gregtech.api.GregTech_API.sRecipeAdder.addAssemblerRecipe(input1, null, output, duration, eu)