provide more ItemStack data for draconic evolution

closes #2621
This commit is contained in:
payonel 2018-10-07 10:49:08 -07:00
parent 64bcbff3b3
commit 2f27a5cc36
2 changed files with 63 additions and 17 deletions

View File

@ -33,6 +33,7 @@ object Mods {
val Waila = new SimpleMod(IDs.Waila)
val ProjectRedBase = new SimpleMod((IDs.ProjectRedCore))
val ProjectRedTransmission = new SimpleMod((IDs.ProjectRedTransmission))
val DraconicEvolution = new SimpleMod(IDs.DraconicEvolution)
// ----------------------------------------------------------------------- //
@ -92,6 +93,7 @@ object Mods {
final val Waila = "waila"
final val ProjectRedCore = "projectred-core"
final val ProjectRedTransmission = "projectred-transmission"
final val DraconicEvolution = "draconicevolution"
}
// ----------------------------------------------------------------------- //

View File

@ -4,13 +4,14 @@ import java.util
import li.cil.oc.Settings
import li.cil.oc.api
import li.cil.oc.integration.Mods
import net.minecraftforge.fml.common.Loader
import li.cil.oc.util.ExtendedNBT._
import net.minecraft.enchantment.Enchantment
import net.minecraft.enchantment.EnchantmentHelper
import li.cil.oc.util.ItemUtils
import net.minecraft.item
import net.minecraft.item.Item
import net.minecraft.nbt.NBTTagString
import net.minecraft.nbt.{NBTTagCompound, NBTTagList, NBTTagString}
import net.minecraftforge.common.util.Constants.NBT
import net.minecraftforge.oredict.OreDictionary
@ -18,6 +19,32 @@ import scala.collection.convert.WrapAsScala._
import scala.collection.mutable
object ConverterItemStack extends api.driver.Converter {
def getTagValue(tag: NBTTagCompound, key: String): AnyRef = tag.getTagId(key) match {
case NBT.TAG_INT => Int.box(tag.getInteger(key))
case NBT.TAG_STRING => tag.getString(key)
case NBT.TAG_BYTE => Byte.box(tag.getByte(key))
case NBT.TAG_COMPOUND => tag.getCompoundTag(key)
case NBT.TAG_LIST => tag.getTagList(key, NBT.TAG_STRING)
case _ => null
}
def withTag(tag: NBTTagCompound, key: String, tagId: Int, f: AnyRef => AnyRef): AnyRef = {
if (tag.hasKey(key, tagId)) {
Option(getTagValue(tag, key)) match {
case Some(value) => f(value)
case _ => null
}
} else null
}
def withCompound(tag: NBTTagCompound, key: String, f: NBTTagCompound => AnyRef): AnyRef = {
withTag(tag, key, NBT.TAG_COMPOUND, { case value: NBTTagCompound => f(value)})
}
def withList(tag: NBTTagCompound, key: String, f: NBTTagList => AnyRef): AnyRef = {
withTag(tag, key, NBT.TAG_STRING, { case value: NBTTagList => f(value)})
}
override def convert(value: AnyRef, output: util.Map[AnyRef, AnyRef]) =
value match {
case stack: item.ItemStack =>
@ -32,18 +59,39 @@ object ConverterItemStack extends api.driver.Converter {
output += "hasTag" -> Boolean.box(stack.hasTagCompound)
output += "name" -> Item.REGISTRY.getNameForObject(stack.getItem)
output += "label" -> stack.getDisplayName
if (stack.hasTagCompound &&
stack.getTagCompound.hasKey("display", NBT.TAG_COMPOUND) &&
stack.getTagCompound.getCompoundTag("display").hasKey("Lore", NBT.TAG_LIST)) {
output += "lore" -> stack.getTagCompound.
getCompoundTag("display").
getTagList("Lore", NBT.TAG_STRING).map((tag: NBTTagString) => tag.getString).
mkString("\n")
}
// IC2 reactor items custom damage
if (stack.hasTagCompound && stack.getTagCompound.hasKey("advDmg", NBT.TAG_INT)) {
output += "customDamage" -> Int.box(stack.getTagCompound.getInteger("advDmg"))
// custom mod tags
if (stack.hasTagCompound) {
val tags = stack.getTagCompound
//Lore tags
withCompound(tags, "display", withList(_, "Lore", {
output += "lore" -> _.map((tag: NBTTagString) => tag.getString).mkString("\n")
})
)
// IC2 reactor items custom damage
withTag(tags, "advDmg", NBT.TAG_INT, dmg => output += "customDamage" -> dmg)
// draconic upgrades
if (Mods.DraconicEvolution.isModAvailable) {
withCompound(tags, "DEUpgrades", de => {
output += "DEUpgrades" -> de
})
(0 until 15).foreach(n => {
val profileName: String = s"Profile_$n"
Option(getTagValue(tags, profileName)) match {
case Some(profile: NBTTagCompound) => output += profileName -> profile
case _ =>
}
})
}
withTag(tags, "Energy", NBT.TAG_INT, value => output += "Energy" -> value)
if (Settings.get.allowItemStackNBTTags) {
output += "tag" -> ItemUtils.saveTag(stack.getTagCompound)
}
}
val enchantments = mutable.ArrayBuffer.empty[mutable.Map[String, Any]]
@ -59,10 +107,6 @@ object ConverterItemStack extends api.driver.Converter {
if (enchantments.nonEmpty) {
output += "enchantments" -> enchantments
}
if (stack.hasTagCompound && Settings.get.allowItemStackNBTTags) {
output += "tag" -> ItemUtils.saveTag(stack.getTagCompound)
}
case _ =>
}
}