mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
Made power support more stable (checking if methods are implemented before injecting the interfaces, to prevent crashes if APIs change, e.g.)
This commit is contained in:
parent
7fb44f578a
commit
9f304bda4f
@ -64,8 +64,20 @@ class ClassTransformer extends IClassTransformer {
|
||||
|
||||
// Inject available power interfaces into power acceptors.
|
||||
if (classNode.interfaces.contains("li/cil/oc/common/tileentity/traits/PowerAcceptor")) {
|
||||
def missingImplementations(interfaceName: String) = {
|
||||
val node = classNodeFor(interfaceName)
|
||||
if (node == null) Seq(s"Interface ${interfaceName.replaceAll("/", ".")} not found.")
|
||||
else node.methods.filterNot(im => classNode.methods.exists(cm => im.name == cm.name && im.desc == cm.desc)).map(method => s"Missing implementation of ${method.name + method.desc}")
|
||||
}
|
||||
for ((mod, interfaces) <- powerTypes if mod.isAvailable) {
|
||||
interfaces.foreach(classNode.interfaces.add)
|
||||
val missing = interfaces.flatMap(missingImplementations)
|
||||
if (missing.isEmpty) {
|
||||
interfaces.foreach(classNode.interfaces.add)
|
||||
}
|
||||
else {
|
||||
log.warning(s"Skipping power support for mod ${mod.id}.")
|
||||
missing.foreach(log.warning)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,8 @@ object Mods {
|
||||
})
|
||||
}
|
||||
val ComputerCraft = new Mod {
|
||||
def id = IDs.ComputerCraft
|
||||
|
||||
override def isAvailable = ComputerCraft15.isAvailable || ComputerCraft16.isAvailable
|
||||
}
|
||||
val Factorization = new SimpleMod(IDs.Factorization, providesPower = true)
|
||||
@ -63,6 +65,8 @@ object Mods {
|
||||
val ProjectRedTransmission = new SimpleMod(IDs.ProjectRedTransmission)
|
||||
val RedLogic = new SimpleMod(IDs.RedLogic)
|
||||
val StargateTech2 = new Mod {
|
||||
def id = IDs.StargateTech2
|
||||
|
||||
val isAvailable = Loader.isModLoaded(IDs.StargateTech2) && {
|
||||
val mod = Loader.instance.getIndexedModList.get(IDs.StargateTech2)
|
||||
mod.getVersion.startsWith("0.7.")
|
||||
@ -78,6 +82,8 @@ object Mods {
|
||||
trait Mod {
|
||||
knownMods += this
|
||||
|
||||
def id: String
|
||||
|
||||
def isAvailable: Boolean
|
||||
|
||||
def providesPower: Boolean = false
|
||||
|
Loading…
x
Reference in New Issue
Block a user