Added BC7 library integration for EEPROMs.

This commit is contained in:
Florian Nücke 2015-03-15 23:50:47 +01:00
parent 92a3b8f93f
commit 154ad9e1d0
4 changed files with 75 additions and 1 deletions

View File

@ -24,6 +24,7 @@ object Mods {
val BloodMagic = new SimpleMod(IDs.BloodMagic)
val BluePower = new SimpleMod(IDs.BluePower, version = "@[0.2.928,)")
val BuildCraft = new SimpleMod(IDs.BuildCraft)
val BuildCraftLibrary = new SimpleMod(IDs.BuildCraftLibrary, version = "@[7.0,)")
val BuildCraftTiles = new SimpleMod(IDs.BuildCraftTiles)
val BuildCraftTools = new SimpleMod(IDs.BuildCraftTools)
val BuildCraftTransport = new SimpleMod(IDs.BuildCraftTransport)
@ -82,6 +83,7 @@ object Mods {
integration.appeng.ModAppEng,
integration.bloodmagic.ModBloodMagic,
integration.bluepower.ModBluePower,
integration.buildcraft.library.ModBuildCraftAPILibrary,
integration.buildcraft.tools.ModBuildCraftAPITools,
integration.buildcraft.tiles.ModBuildCraftAPITiles,
integration.buildcraft.transport.ModBuildCraftAPITransport,
@ -152,7 +154,7 @@ object Mods {
final val BloodMagic = "AWWayofTime"
final val BluePower = "bluepowerAPI"
final val BuildCraft = "BuildCraft|Core"
final val BuildCraftPower = "BuildCraftAPI|power"
final val BuildCraftLibrary = "BuildCraftAPI|library"
final val BuildCraftTiles = "BuildCraftAPI|tiles"
final val BuildCraftTools = "BuildCraftAPI|tools"
final val BuildCraftTransport = "BuildCraftAPI|transport"

View File

@ -0,0 +1,48 @@
package li.cil.oc.integration.buildcraft.library
import buildcraft.api.library.LibraryTypeHandler.HandlerType
import buildcraft.api.library.LibraryTypeHandlerNBT
import li.cil.oc.Settings
import li.cil.oc.api
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.EnumChatFormatting
import scala.collection.convert.WrapAsScala._
object EEPROMHandler extends LibraryTypeHandlerNBT("ocrom") {
override def isHandler(stack: ItemStack, handlerType: HandlerType) = api.Items.get(stack) == api.Items.get("eeprom")
override def getTextColor = 0xCCFFCC
override def getName(stack: ItemStack) = {
val driver = api.Driver.driverFor(stack)
if (driver != null) {
driver.dataTag(stack).getString(Settings.namespace + "label")
}
else EnumChatFormatting.OBFUSCATED.toString + "?????"
}
override def load(stack: ItemStack, nbt: NBTTagCompound): ItemStack = {
val driver = api.Driver.driverFor(stack)
if (driver != null) {
val stackData = driver.dataTag(stack)
nbt.func_150296_c().foreach {
case key: String => stackData.setTag(key, nbt.getTag(key))
}
}
stack
}
override def store(stack: ItemStack, nbt: NBTTagCompound): Boolean = {
val driver = api.Driver.driverFor(stack)
if (driver != null) {
val stackData = driver.dataTag(stack)
stackData.func_150296_c().foreach {
case key: String => nbt.setTag(key, stackData.getTag(key))
}
true
}
else false
}
}

View File

@ -0,0 +1,12 @@
package li.cil.oc.integration.buildcraft.library
import buildcraft.api.library.LibraryAPI
// Extra layer of indirection to avoid class not found errors, because Java
// tries to resolve interfaces in method calls even if the referencing code is
// never reached when loading the containing class.
object HandlerRegistry {
def init(): Unit = {
LibraryAPI.registerHandler(EEPROMHandler)
}
}

View File

@ -0,0 +1,12 @@
package li.cil.oc.integration.buildcraft.library
import li.cil.oc.integration.ModProxy
import li.cil.oc.integration.Mods
object ModBuildCraftAPILibrary extends ModProxy {
override def getMod = Mods.BuildCraftLibrary
override def initialize(): Unit = {
HandlerRegistry.init()
}
}