From 859224180265d1e2eefee68c1a44a35a4472b3ca Mon Sep 17 00:00:00 2001 From: payonel Date: Sat, 29 Jun 2019 18:47:44 -0700 Subject: [PATCH] Add limited support for Thaumcraft essentia containers Item stacks of Thaumcraft items, such as esssentia jars, are a pain to work with if you can't see their contents. The contents are not hidden by Thaumcraft, so showing them isn't cheaty. Making these available makes it possible to use OC to sort essentia jars by contents, which is SUPER USEFUL since everything else I have which sorts inventory ignores them. this work was adjusted from PR #2942 by user @seebs --- .../scala/li/cil/oc/integration/Mods.scala | 3 ++ .../thaumcraft/ConverterThaumcraftItems.scala | 47 +++++++++++++++++++ .../thaumcraft/ModThaumcraft.scala | 13 +++++ 3 files changed, 63 insertions(+) create mode 100644 src/main/scala/li/cil/oc/integration/thaumcraft/ConverterThaumcraftItems.scala create mode 100644 src/main/scala/li/cil/oc/integration/thaumcraft/ModThaumcraft.scala diff --git a/src/main/scala/li/cil/oc/integration/Mods.scala b/src/main/scala/li/cil/oc/integration/Mods.scala index 0b184af84..59bb25871 100644 --- a/src/main/scala/li/cil/oc/integration/Mods.scala +++ b/src/main/scala/li/cil/oc/integration/Mods.scala @@ -35,6 +35,7 @@ object Mods { val ProjectRedTransmission = new SimpleMod((IDs.ProjectRedTransmission)) val DraconicEvolution = new SimpleMod(IDs.DraconicEvolution) val EnderStorage = new SimpleMod(IDs.EnderStorage) + val Thaumcraft = new SimpleMod(IDs.Thaumcraft) // ----------------------------------------------------------------------- // @@ -52,6 +53,7 @@ object Mods { integration.projectred.ModProjectRed, integration.computercraft.ModComputerCraft, integration.enderstorage.ModEnderStorage, + integration.thaumcraft.ModThaumcraft, // We go late to ensure all other mod integration is done, e.g. to // allow properly checking if wireless redstone is present. @@ -97,6 +99,7 @@ object Mods { final val ProjectRedTransmission = "projectred-transmission" final val DraconicEvolution = "draconicevolution" final val EnderStorage = "enderstorage" + final val Thaumcraft = "thaumcraft" } // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/integration/thaumcraft/ConverterThaumcraftItems.scala b/src/main/scala/li/cil/oc/integration/thaumcraft/ConverterThaumcraftItems.scala new file mode 100644 index 000000000..6adf8baff --- /dev/null +++ b/src/main/scala/li/cil/oc/integration/thaumcraft/ConverterThaumcraftItems.scala @@ -0,0 +1,47 @@ +package li.cil.oc.integration.thaumcraft + +import java.util + +import li.cil.oc.api.driver.Converter +import net.minecraft.item.{Item, ItemStack} +import net.minecraft.nbt.NBTTagCompound +import net.minecraftforge.common.util.Constants.NBT + +import scala.collection.convert.WrapAsScala._ +import scala.collection.mutable + +object ConverterThaumcraftItems extends Converter { + override def convert(value: scala.Any, output: util.Map[AnyRef, AnyRef]): Unit = value match { + case stack: ItemStack => + val name = Item.REGISTRY.getNameForObject(stack.getItem).toString + + // Handle essentia/vis contents for Thaumcraft jars, phials, and crystals + if ((name == "thaumcraft:jar_normal") || + (name == "thaumcraft:jar_void") || + (name == "thaumcraft:phial") || + (name == "thaumcraft:crystal_essence")) { + if (stack.hasTagCompound && + stack.getTagCompound.hasKey("Aspects", NBT.TAG_LIST)) { + val aspects = mutable.ArrayBuffer.empty[mutable.Map[String, Any]] + val nbtAspects = stack.getTagCompound.getTagList("Aspects", NBT.TAG_COMPOUND).map { + case tag: NBTTagCompound => tag + } + for (nbtAspect <- nbtAspects) { + val key = nbtAspect.getString("key") + val amount = nbtAspect.getInteger("amount") + val aspect = mutable.Map[String, Any]( + "aspect" -> key, + "amount" -> amount + ) + aspects += aspect + } + output += "aspects" -> aspects + } + if (stack.hasTagCompound && stack.getTagCompound.hasKey("AspectFilter", NBT.TAG_STRING)) { + output += "aspectFilter" -> stack.getTagCompound.getString("AspectFilter") + } + } + + case _ => + } +} diff --git a/src/main/scala/li/cil/oc/integration/thaumcraft/ModThaumcraft.scala b/src/main/scala/li/cil/oc/integration/thaumcraft/ModThaumcraft.scala new file mode 100644 index 000000000..4e1954adf --- /dev/null +++ b/src/main/scala/li/cil/oc/integration/thaumcraft/ModThaumcraft.scala @@ -0,0 +1,13 @@ +package li.cil.oc.integration.thaumcraft + +import li.cil.oc.api.Driver +import li.cil.oc.integration.ModProxy +import li.cil.oc.integration.Mods + +object ModThaumcraft extends ModProxy { + override def getMod: Mods.ModBase = Mods.Thaumcraft + + override def initialize() { + Driver.add(ConverterThaumcraftItems) + } +}