mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-22 12:59:49 +00:00
New, lean and mean version. No more modules. No more routing.
This commit is contained in:
1 parent
ce98be52a1
commit
9655463da7
31 files changed
+35
-948
No files matched your search
@@ -22,7 +22,7 @@ See CONTRIBUTING.md in the root of the project repository.
|
||||
|
||||
##Licenses
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2013 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6)
|
||||
Copyright (c) 2013 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6, pillbox)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
package mantle.core
|
||||
package mantle
|
||||
|
||||
import cpw.mods.fml.common.{FMLCommonHandler, Mod}
|
||||
import cpw.mods.fml.common.event.{FMLPostInitializationEvent, FMLInitializationEvent, FMLPreInitializationEvent}
|
||||
import cpw.mods.fml.common.Mod.EventHandler
|
||||
|
||||
import mantle.core.lib.CoreRepo._
|
||||
import net.minecraftforge.common.Configuration
|
||||
import mantle.core.lib.CoreConfig
|
||||
|
||||
import mantle.lib.CoreRepo._
|
||||
import mantle.lib.CoreConfig
|
||||
import cpw.mods.fml.common.network.NetworkMod
|
||||
|
||||
/**
|
||||
* Mantle-Core
|
||||
* Mantle
|
||||
*
|
||||
* Central mod object for Mantle (Core Module)
|
||||
* Central mod object for Mantle
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
@Mod(modid = modId, name = modName, version = modName, modLanguage = "scala")
|
||||
object MantleCore {
|
||||
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
|
||||
object Mantle {
|
||||
|
||||
/**
|
||||
* FML preinitialisation handler
|
||||
@@ -1,63 +0,0 @@
|
||||
package mantle.compat
|
||||
|
||||
import cpw.mods.fml.common.{FMLCommonHandler, Mod}
|
||||
import cpw.mods.fml.common.event.{FMLPostInitializationEvent, FMLInitializationEvent, FMLPreInitializationEvent}
|
||||
import cpw.mods.fml.common.Mod.EventHandler
|
||||
|
||||
import mantle.compat.lib.CompatRepo._
|
||||
import mantle.compat.plugins.{PluginDebug, PluginManager}
|
||||
import mantle.compat.lib.CompatConfig
|
||||
import net.minecraftforge.common.Configuration
|
||||
|
||||
/**
|
||||
* Mantle-Compat
|
||||
*
|
||||
* Central mod object for Mantle (Compat Module)
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
@Mod(modid = modId, name = modName, version = modName, dependencies = "required-after:Mantle-Core; required-after:Mantle-Router", modLanguage = "scala")
|
||||
object MantleCompat {
|
||||
|
||||
/**
|
||||
* FML preinitialisation handler
|
||||
*
|
||||
* This is where we load our configs and related data, preparing for main load.
|
||||
*
|
||||
* @param evt The FMLPreInitializationEvent from FML
|
||||
*/
|
||||
@EventHandler
|
||||
def preInit(evt:FMLPreInitializationEvent) {
|
||||
logger.setParent(FMLCommonHandler.instance().getFMLLogger)
|
||||
|
||||
CompatConfig.loadConfiguration(new Configuration(evt.getSuggestedConfigurationFile))
|
||||
|
||||
if (debugCompatPlugins) PluginManager.registerPluginCandidate(PluginDebug)
|
||||
PluginManager.preInitPlugins()
|
||||
}
|
||||
|
||||
/**
|
||||
* FML preinitialisation handler
|
||||
*
|
||||
* This is where we handle basic loading and populating any missing data in the Repo
|
||||
*
|
||||
* @param evt The FMLInitializationEvent from FML
|
||||
*/
|
||||
@EventHandler
|
||||
def init(evt:FMLInitializationEvent) {
|
||||
PluginManager.initPlugins()
|
||||
}
|
||||
|
||||
/**
|
||||
* FML preinitialisation handler
|
||||
*
|
||||
* Final chance for cleanup before main game launch
|
||||
*
|
||||
* @param evt The FMLPostInitializationEvent from FML
|
||||
*/
|
||||
@EventHandler
|
||||
def postInit(evt:FMLPostInitializationEvent) {
|
||||
PluginManager.postInitPlugins()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package mantle.compat.lib
|
||||
|
||||
import net.minecraftforge.common.Configuration
|
||||
|
||||
import mantle.core.lib.CoreRepo._
|
||||
|
||||
/**
|
||||
* Mantle-Compat configuration handler
|
||||
*
|
||||
* Stores configuration data for Mantle-Compat, and handles save/load.
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object CompatConfig {
|
||||
|
||||
/**
|
||||
* Loads state from a Forge configuration object, or saves a new file if it doesn't already exist.
|
||||
*
|
||||
* @param config Configuration object (usually from a location given by FML in preinit)
|
||||
*/
|
||||
def loadConfiguration(config:Configuration) {
|
||||
logger.info("Loading configuration from disk.")
|
||||
config.load()
|
||||
|
||||
// TODO: Config vars get/set here
|
||||
|
||||
config.save()
|
||||
logger.info("Configuration load completed.")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package mantle.compat.lib
|
||||
|
||||
import java.util.logging.Logger
|
||||
|
||||
/**
|
||||
* Mantle-Compat object repository
|
||||
*
|
||||
* Storage area for objects accessible throughout Compat, such as loggers
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object CompatRepo {
|
||||
|
||||
final val modId = "Mantle-Compat"
|
||||
final val modName = "Mantle Compat"
|
||||
final val modVersion = "@VERSION@"
|
||||
|
||||
val logger = Logger.getLogger(modName)
|
||||
|
||||
// Debug flags
|
||||
val debugCompatPlugins = System.getenv("MANTLE_COMPAT") != null
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package mantle.compat.minecraft.crash
|
||||
|
||||
import cpw.mods.fml.common.ICrashCallable
|
||||
|
||||
/**
|
||||
* ICrashCallable for mods to report a supported environment during crashes
|
||||
*
|
||||
* @param modLabel The name of the mod creating the callable
|
||||
* @param message A message to show this is a supported environment e.g. "Environment clean."
|
||||
*/
|
||||
class CallableSuppConfig(modLabel:String, message:String) extends ICrashCallable {
|
||||
|
||||
def getLabel = modLabel
|
||||
|
||||
def call = message
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package mantle.compat.minecraft.crash
|
||||
|
||||
import cpw.mods.fml.common.ICrashCallable
|
||||
|
||||
/**
|
||||
* ICrashCallable for mods to report an unsupported environment during crashes
|
||||
*
|
||||
* @param modIds List of guilty mod IDs
|
||||
* @param modLabel The name of the mod creating the callable
|
||||
*/
|
||||
class CallableUnsuppConfig(modIds:List[String], modLabel:String) extends ICrashCallable {
|
||||
|
||||
def getLabel = modLabel
|
||||
|
||||
def call = {
|
||||
var str: String = "DO NOT REPORT THIS CRASH! Unsupported mods in environment: "
|
||||
var firstEntry: Boolean = true
|
||||
for (id <- modIds) {
|
||||
str = str + (if (firstEntry) id else ", " + id)
|
||||
firstEntry = false
|
||||
}
|
||||
str
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package mantle.compat.minecraft.misc
|
||||
|
||||
import scala.collection.JavaConversions._
|
||||
import java.util
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.item.crafting.CraftingManager
|
||||
import net.minecraft.item.crafting.IRecipe
|
||||
import net.minecraft.item.crafting.ShapedRecipes
|
||||
import net.minecraft.item.crafting.ShapelessRecipes
|
||||
|
||||
/**
|
||||
* Utility to remove recipes from the vanilla crafting handler
|
||||
*
|
||||
* @author mDiyo
|
||||
* @author Sunstrike
|
||||
*/
|
||||
object RecipeRemover {
|
||||
|
||||
/**
|
||||
* Removes recipes of any type that return the given itemstack
|
||||
*
|
||||
* @param resultItem The result to find and remove
|
||||
*/
|
||||
def removeAnyRecipe(resultItem: ItemStack) {
|
||||
val recipes: util.List[IRecipe] = CraftingManager.getInstance.getRecipeList.asInstanceOf
|
||||
for (recipe: IRecipe <- recipes) {
|
||||
val res = recipe.getRecipeOutput
|
||||
if (ItemStack.areItemStacksEqual(resultItem, res)) recipes.remove(recipe)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes shaped recipes that return the given itemstack
|
||||
*
|
||||
* @param resultItem The result to find and remove
|
||||
*/
|
||||
def removeShapedRecipe(resultItem: ItemStack) {
|
||||
val recipes: util.List[IRecipe] = CraftingManager.getInstance.getRecipeList.asInstanceOf
|
||||
for (recipe: IRecipe <- recipes) {
|
||||
recipe match {
|
||||
case rec:ShapedRecipes =>
|
||||
if (ItemStack.areItemStacksEqual(rec.getRecipeOutput, resultItem)) recipes.remove(recipe)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes shapeless recipes that return the given itemstack
|
||||
*
|
||||
* @param resultItem The result to find and remove
|
||||
*/
|
||||
def removeShapelessRecipe(resultItem: ItemStack) {
|
||||
val recipes: util.List[IRecipe] = CraftingManager.getInstance.getRecipeList.asInstanceOf
|
||||
for (recipe: IRecipe <- recipes) {
|
||||
recipe match {
|
||||
case rec:ShapelessRecipes =>
|
||||
if (ItemStack.areItemStacksEqual(rec.getRecipeOutput, resultItem)) recipes.remove(recipe)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package mantle
|
||||
|
||||
/**
|
||||
* Mantle Compat
|
||||
*
|
||||
* Provides a plugin framework for modules that handle interaction with 'the outside world',
|
||||
* such as mod APIs and certain Minecraft functions.
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
package object compat {}
|
||||
@@ -1,44 +0,0 @@
|
||||
package mantle.compat.plugins
|
||||
|
||||
/**
|
||||
* Trait defining a Mantle-Compat plugin.
|
||||
*
|
||||
* Any plugins providing compatibility support for externals mods must follow this to be loadable.
|
||||
*
|
||||
* @note Do not implement any functionality in the constructor! Do your setup during preInit()
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
trait ICompatPlugin {
|
||||
|
||||
/**
|
||||
* Mod ID this plugin should be loaded for.
|
||||
*
|
||||
* @return A mod ID string
|
||||
*/
|
||||
def providedMod: String
|
||||
|
||||
/**
|
||||
* Called when plugin is accepted by the manager
|
||||
*
|
||||
* Use this for any critical early-stage setup.
|
||||
*/
|
||||
def accept()
|
||||
|
||||
/**
|
||||
* Called during Mantle-Compat preinit
|
||||
*/
|
||||
def preInit()
|
||||
|
||||
/**
|
||||
* Called during Mantle-Compat init
|
||||
*/
|
||||
def init()
|
||||
|
||||
/**
|
||||
* Called during Mantle-Compat postinit
|
||||
*/
|
||||
def postInit()
|
||||
|
||||
override def toString:String = s"MantleCompatPlugin(${this.getClass.getName} :: $providedMod)"
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package mantle.compat.plugins
|
||||
|
||||
import mantle.compat.lib.CompatRepo._
|
||||
|
||||
/**
|
||||
* Debug info plugin
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object PluginDebug extends ICompatPlugin {
|
||||
|
||||
def providedMod: String = "Mantle-Compat"
|
||||
|
||||
def accept() {
|
||||
log("Accepted by manager.")
|
||||
}
|
||||
|
||||
def preInit() {
|
||||
log("Reached preinit.")
|
||||
}
|
||||
|
||||
def init() {
|
||||
log("Reached init.")
|
||||
}
|
||||
|
||||
def postInit() {
|
||||
log("Reached postinit.")
|
||||
}
|
||||
|
||||
private def log(msg:String) {
|
||||
logger.info(s"[PluginDebug] $msg")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package mantle.compat.plugins
|
||||
|
||||
import scala.collection.mutable.MutableList
|
||||
import cpw.mods.fml.common.Loader
|
||||
|
||||
import mantle.compat.lib.CompatRepo._
|
||||
|
||||
/**
|
||||
* Mantle-Compat Plugin Manager
|
||||
*
|
||||
* Coordinates all compat plugins in the Mantle-Compat framework.
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object PluginManager {
|
||||
|
||||
private val activePlugins = MutableList[ICompatPlugin]()
|
||||
|
||||
/**
|
||||
* Register a candidate compat plugin
|
||||
*
|
||||
* Tests if the candidate's provided mod is actually running in the environment before adding to the active plugins list.
|
||||
*
|
||||
* @param candidate The plugin to attempt to load.
|
||||
* @return True if plugin was loaded, False if plugin was rejected.
|
||||
*/
|
||||
def registerPluginCandidate(candidate:ICompatPlugin):Boolean = {
|
||||
if (!Loader.isModLoaded(candidate.providedMod)) {
|
||||
debug(s"Rejecting: $candidate")
|
||||
return false
|
||||
}
|
||||
|
||||
debug(s"Accepting: $candidate")
|
||||
candidate.accept()
|
||||
activePlugins += candidate
|
||||
true
|
||||
}
|
||||
|
||||
/**
|
||||
* Called during Compat preinit
|
||||
*
|
||||
* @note For internal use only!
|
||||
*/
|
||||
def preInitPlugins() {
|
||||
debug(s"Performing preinit (plugins = $activePlugins)")
|
||||
activePlugins map { x => x.preInit() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Called during Compat init
|
||||
*
|
||||
* @note For internal use only!
|
||||
*/
|
||||
def initPlugins() {
|
||||
debug(s"Performing init (plugins = $activePlugins)")
|
||||
activePlugins map { x => x.init() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Called during Compat postinit
|
||||
*
|
||||
* @note For internal use only!
|
||||
*/
|
||||
def postInitPlugins() {
|
||||
debug(s"Performing postinit (plugins = $activePlugins)")
|
||||
activePlugins map { x => x.postInit() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal logging helper
|
||||
*
|
||||
* Prepends appropriate tag and only logs if debug flag MANTLE_COMPAT is active.
|
||||
*
|
||||
* @param msg String to log.
|
||||
*/
|
||||
private def debug(msg:String) {
|
||||
if (debugCompatPlugins) logger.info(s"[PluginManager] $msg")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package mantle.compat.plugins.builtin
|
||||
|
||||
import mantle.compat.plugins.ICompatPlugin
|
||||
import mantle.router.routing.RouterCoordinator
|
||||
import mantle.router.routing.builtin.UnitAppEng
|
||||
|
||||
/**
|
||||
* Applied Energistics compatibility plugin
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object PluginAppEng extends ICompatPlugin {
|
||||
|
||||
def providedMod: String = "AppliedEnergistics"
|
||||
|
||||
def accept() {
|
||||
RouterCoordinator.registerPipelineUnit(UnitAppEng) // Register AE pipeline object
|
||||
}
|
||||
|
||||
def preInit() {
|
||||
|
||||
}
|
||||
|
||||
def init() {
|
||||
|
||||
}
|
||||
|
||||
def postInit() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package mantle.compat.plugins.builtin
|
||||
|
||||
import mantle.compat.plugins.ICompatPlugin
|
||||
import mantle.router.routing.RouterCoordinator
|
||||
import mantle.router.routing.builtin.UnitBCTransport
|
||||
|
||||
/**
|
||||
* Buildcraft Transport plugin
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object PluginBCTransport extends ICompatPlugin {
|
||||
|
||||
def providedMod = "BuildCraft|Transport"
|
||||
|
||||
def accept() {
|
||||
RouterCoordinator.registerPipelineUnit(UnitBCTransport)
|
||||
}
|
||||
|
||||
def preInit() {
|
||||
|
||||
}
|
||||
|
||||
def init() {
|
||||
|
||||
}
|
||||
|
||||
def postInit() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package mantle.compat.plugins.builtin
|
||||
|
||||
import mantle.compat.plugins.ICompatPlugin
|
||||
import mantle.router.routing.RouterCoordinator
|
||||
import mantle.router.routing.builtin.UnitMystcraft
|
||||
|
||||
/**
|
||||
* Mystcraft compatibility plugin
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object PluginMystcraft extends ICompatPlugin {
|
||||
|
||||
def providedMod: String = "Mystcraft"
|
||||
|
||||
def accept() {
|
||||
RouterCoordinator.registerPipelineUnit(UnitMystcraft) // Register AE pipeline object
|
||||
}
|
||||
|
||||
def preInit() {
|
||||
|
||||
}
|
||||
|
||||
def init() {
|
||||
|
||||
}
|
||||
|
||||
def postInit() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package mantle.core.lib
|
||||
|
||||
import java.util.logging.Logger
|
||||
|
||||
/**
|
||||
* Mantle-Core object repository
|
||||
*
|
||||
* Storage area for objects accessible throughout Core, such as loggers
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object CoreRepo {
|
||||
|
||||
final val modId = "Mantle-Core"
|
||||
final val modName = "Mantle Core"
|
||||
final val modVersion = "@VERSION@"
|
||||
|
||||
val logger = Logger.getLogger(modName)
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package mantle
|
||||
|
||||
/**
|
||||
* Mantle Core
|
||||
*
|
||||
* Provides the base framework for all of the other Mantle modules in addition
|
||||
* to some basic functions of it's own.
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
package object core {}
|
||||
@@ -1,13 +1,13 @@
|
||||
package mantle.core.lib
|
||||
package mantle.lib
|
||||
|
||||
import net.minecraftforge.common.Configuration
|
||||
|
||||
import mantle.core.lib.CoreRepo._
|
||||
import mantle.lib.CoreRepo._
|
||||
|
||||
/**
|
||||
* Mantle-Core configuration handler
|
||||
* Mantle configuration handler
|
||||
*
|
||||
* Stores configuration data for Mantle-Core, and handles save/load.
|
||||
* Stores configuration data for Mantle, and handles save/load.
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
@@ -0,0 +1,20 @@
|
||||
package mantle.lib
|
||||
|
||||
import java.util.logging.Logger
|
||||
|
||||
/**
|
||||
* Mantle object repository
|
||||
*
|
||||
* Storage area for objects accessible throughout Mantle, such as loggers
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object CoreRepo {
|
||||
|
||||
final val modId = "Mantle"
|
||||
final val modName = "Mantle"
|
||||
final val modVersion = "@VERSION@"
|
||||
|
||||
val logger = Logger.getLogger(modName)
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package mantle.core.math
|
||||
package mantle.math
|
||||
|
||||
import scala.collection.mutable.MutableList
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package mantle.router
|
||||
|
||||
import cpw.mods.fml.common.{FMLCommonHandler, Mod}
|
||||
import cpw.mods.fml.common.event.{FMLPostInitializationEvent, FMLInitializationEvent, FMLPreInitializationEvent}
|
||||
import cpw.mods.fml.common.Mod.EventHandler
|
||||
|
||||
import mantle.router.lib.RouterRepo._
|
||||
import mantle.router.routing.{UnitDebugLogger, RouterCoordinator}
|
||||
import mantle.router.lib.RouterConfig
|
||||
import net.minecraftforge.common.Configuration
|
||||
|
||||
/**
|
||||
* Mantle-Router
|
||||
*
|
||||
* Central mod object for Mantle (Router Module)
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
@Mod(modid = modId, name = modName, version = modName, dependencies = "required-after:Mantle-Core", modLanguage = "scala")
|
||||
object MantleRouter {
|
||||
|
||||
/**
|
||||
* FML preinitialisation handler
|
||||
*
|
||||
* This is where we load our configs and related data, preparing for main load.
|
||||
*
|
||||
* @param evt The FMLPreInitializationEvent from FML
|
||||
*/
|
||||
@EventHandler
|
||||
def preInit(evt:FMLPreInitializationEvent) {
|
||||
logger.setParent(FMLCommonHandler.instance().getFMLLogger)
|
||||
|
||||
RouterConfig.loadConfiguration(new Configuration(evt.getSuggestedConfigurationFile))
|
||||
|
||||
registerStandardUnits()
|
||||
}
|
||||
|
||||
/**
|
||||
* FML preinitialisation handler
|
||||
*
|
||||
* This is where we handle basic loading and populating any missing data in the Repo.
|
||||
* The Router also processes events here.
|
||||
*
|
||||
* @param evt The FMLInitializationEvent from FML
|
||||
*/
|
||||
@EventHandler
|
||||
def init(evt:FMLInitializationEvent) {
|
||||
registerStandardUnits()
|
||||
RouterCoordinator.processQueue()
|
||||
}
|
||||
|
||||
/**
|
||||
* Registrar for built-in Router pipeline objects
|
||||
*/
|
||||
private def registerStandardUnits() {
|
||||
if (debugMessageSys) RouterCoordinator.registerPipelineUnit(UnitDebugLogger)
|
||||
}
|
||||
|
||||
/**
|
||||
* FML preinitialisation handler
|
||||
*
|
||||
* Final chance for cleanup before main game launch.
|
||||
* The Router also processes events here.
|
||||
*
|
||||
* @param evt The FMLPostInitializationEvent from FML
|
||||
*/
|
||||
@EventHandler
|
||||
def postInit(evt:FMLPostInitializationEvent) {
|
||||
RouterCoordinator.processQueue()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package mantle.router.lib
|
||||
|
||||
import net.minecraftforge.common.Configuration
|
||||
import mantle.router.lib.RouterRepo._
|
||||
|
||||
/**
|
||||
* Mantle-Router configuration handler
|
||||
*
|
||||
* Stores configuration data for Mantle-Router, and handles save/load.
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object RouterConfig {
|
||||
|
||||
/**
|
||||
* Loads state from a Forge configuration object, or saves a new file if it doesn't already exist.
|
||||
*
|
||||
* @param config Configuration object (usually from a location given by FML in preinit)
|
||||
*/
|
||||
def loadConfiguration(config:Configuration) {
|
||||
logger.info("Loading configuration from disk.")
|
||||
config.load()
|
||||
|
||||
// TODO: Config vars get/set here
|
||||
|
||||
config.save()
|
||||
logger.info("Configuration load completed.")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package mantle.router.lib
|
||||
|
||||
import java.util.logging.Logger
|
||||
|
||||
/**
|
||||
* Mantle-Router object repository
|
||||
*
|
||||
* Storage area for objects accessible throughout Router, such as loggers
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object RouterRepo {
|
||||
|
||||
final val modId = "Mantle-Router"
|
||||
final val modName = "Mantle Router"
|
||||
final val modVersion = "@VERSION@"
|
||||
|
||||
val logger = Logger.getLogger(modName)
|
||||
|
||||
// Debug flags
|
||||
val debugMessageSys = System.getenv("MANTLE_MSG_SYS") != null
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package mantle
|
||||
|
||||
/**
|
||||
* Mantle Router
|
||||
*
|
||||
* Provides advanced IMC message routing functionality to other mods for more convenient
|
||||
* registration with external modules.
|
||||
*
|
||||
* Planned modules/helpers:
|
||||
* * BuildCraft Transport (Facades)
|
||||
* * Forge Multipart (Microblocks)
|
||||
* * Fluid blacklist helper (Mystcraft et al.)
|
||||
* * TConstruct dimension blacklisting
|
||||
*/
|
||||
package object router {}
|
||||
@@ -1,29 +0,0 @@
|
||||
package mantle.router.routing
|
||||
|
||||
/**
|
||||
* Message pipeline unit interface
|
||||
*
|
||||
* Defines the interface for objects that can be inserted into the IMCHandler pipeline.
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
trait IPipelineUnit {
|
||||
|
||||
/**
|
||||
* Getter for the name of this unit
|
||||
*
|
||||
* @example def unitName: String = "FMP Compat"
|
||||
* @return The name of this unit (something descriptive)
|
||||
*/
|
||||
def unitName:String
|
||||
|
||||
/**
|
||||
* Handles an incoming Mantle message
|
||||
*
|
||||
* @param msg The Mantle message from Router.
|
||||
*/
|
||||
def handleMessage(msg:MantleMessage)
|
||||
|
||||
override def toString: String = s"MantlePipelineUnit($unitName)"
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package mantle.router.routing
|
||||
|
||||
/**
|
||||
* IMCMessage analogue for Mantle Router pipeline
|
||||
*
|
||||
* Instances of this are used to send messages to the Coordinator for processing through the Router pipeline.
|
||||
*
|
||||
* @param origin The mod ID the message is from
|
||||
* @param msg The message to be sent, in IMC-style form e.g. `registerDecorativeBlock`
|
||||
* @param obj (Optional) An object to attach to the message.
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
class MantleMessage(origin:String, msg:String, obj:Any) {
|
||||
|
||||
private val modId = origin
|
||||
private val message = msg
|
||||
private val attachment = obj
|
||||
|
||||
/**
|
||||
* Get the source mods modID.
|
||||
*
|
||||
* @return Mod ID of sender
|
||||
*/
|
||||
def getOrigin = modId
|
||||
|
||||
/**
|
||||
* Get the message this object contains.
|
||||
*
|
||||
* @return The message string
|
||||
*/
|
||||
def getMessage = message
|
||||
|
||||
/**
|
||||
* Get the object attached to the message.
|
||||
*
|
||||
* @note This must be null-checked as the field is permitted to be null at instantiation.
|
||||
* @return The attachment or null.
|
||||
*/
|
||||
def getAttachment = attachment
|
||||
|
||||
override def toString: String = s"(($origin) $message :: $obj)"
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package mantle.router.routing
|
||||
|
||||
import cpw.mods.fml.common.event.FMLInterModComms.{IMCMessage, IMCEvent}
|
||||
import scala.collection.mutable.{MutableList, Queue}
|
||||
|
||||
import mantle.router.lib.RouterRepo._
|
||||
|
||||
/**
|
||||
* Router Message handler
|
||||
*
|
||||
* Handles all incoming Mantle messages and their processing.
|
||||
*
|
||||
* Reserved Mantle messages:
|
||||
* * registerDecorativeBlock (Int[] - bID & meta OR tuple(bID, meta)) -- Used for FMP/BC Facades. May be hooked by other units.
|
||||
* * movableTile (String (full class path)) -- Used for AE SpatialIO. May be hooked by other units.
|
||||
* * myst_fluidSymbol (Tuple(FluidName, rarity, grammarWeight, blockInstability) OR a prebuilt NBT tag compound) -- Mystcraft fluid symbol. Should not be hooked.
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object RouterCoordinator {
|
||||
|
||||
private val messagePipeline:MutableList[IPipelineUnit] = MutableList()
|
||||
private val messageQueue:Queue[MantleMessage] = Queue[MantleMessage]()
|
||||
|
||||
/**
|
||||
* Send a message
|
||||
*
|
||||
* Adds a given MantleMessage to the message queue to be processed next round.
|
||||
*
|
||||
* @note This should be completed before Mantle-Router init!
|
||||
* @param msg The MantleMessage to queue.
|
||||
*/
|
||||
def queueMessage(msg:MantleMessage) {
|
||||
debug(s"Queue accept: $msg")
|
||||
messageQueue.enqueue(msg)
|
||||
}
|
||||
|
||||
/**
|
||||
* Processing hook
|
||||
*
|
||||
* Runs all current events through the pipeline. This is called at Router init and postinit.
|
||||
*
|
||||
* @note This should be considered an internal call; other mods should not call this!
|
||||
*/
|
||||
def processQueue() {
|
||||
debug(s"Preparing for message processing; pipeline = $messagePipeline, queue: $messageQueue")
|
||||
for ( msg <- messageQueue; handler <- messagePipeline ) {
|
||||
handler.handleMessage(msg)
|
||||
}
|
||||
|
||||
messageQueue.clear()
|
||||
debug("Message processsing completed.")
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a Pipeline unit
|
||||
*
|
||||
* Whenever Router receives an IMC message, it'll pass the message to all registered units.
|
||||
* This allows mods to register new units.
|
||||
*
|
||||
* @note Units must be registered in preinit or the Unit may miss the first processing round.
|
||||
*
|
||||
* @param unit The unit to register into the pipeline
|
||||
* @return True if successful, False if registration failed.
|
||||
*/
|
||||
def registerPipelineUnit(unit:IPipelineUnit):Boolean = {
|
||||
if (messagePipeline.contains(unit))
|
||||
return false
|
||||
|
||||
messagePipeline += unit
|
||||
true
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal log helper
|
||||
*
|
||||
* Logs input (with prepended tag) only if message system debug flag (MANTLE_MSG_SYS) is active.
|
||||
*
|
||||
* @param msg String to log.
|
||||
*/
|
||||
private def debug(msg:String) {
|
||||
if (debugMessageSys) logger.info(s"[RouterCoordinator] $msg")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package mantle.router.routing
|
||||
|
||||
import mantle.router.lib.RouterRepo._
|
||||
|
||||
/**
|
||||
* Debug logging pipeline unit
|
||||
*
|
||||
* Logs all Mantle messages to console during debug runs.
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object UnitDebugLogger extends IPipelineUnit {
|
||||
|
||||
def unitName: String = "Message Debug Unit"
|
||||
|
||||
def handleMessage(msg: MantleMessage) {
|
||||
logger.info(s"[UnitDebugLogger] Recv: $msg")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package mantle.router.routing.builtin
|
||||
|
||||
import mantle.router.routing.{MantleMessage, IPipelineUnit}
|
||||
import cpw.mods.fml.common.event.FMLInterModComms
|
||||
|
||||
/**
|
||||
* Applied Energistics pipeline unit
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object UnitAppEng extends IPipelineUnit {
|
||||
|
||||
def unitName: String = "AppEng Compat"
|
||||
|
||||
def handleMessage(msg: MantleMessage) {
|
||||
if (msg.getMessage.equals("movableTile")) {
|
||||
msg.getAttachment match {
|
||||
case s:String => FMLInterModComms.sendMessage("AppliedEnergistics", "movabletile", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package mantle.router.routing.builtin
|
||||
|
||||
import mantle.router.routing.{MantleMessage, IPipelineUnit}
|
||||
import mantle.router.lib.RouterRepo._
|
||||
import cpw.mods.fml.common.event.FMLInterModComms
|
||||
|
||||
/**
|
||||
* Buildcraft Transport pipeline unit
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object UnitBCTransport extends IPipelineUnit {
|
||||
/**
|
||||
* Getter for the name of this unit
|
||||
*
|
||||
* @example def unitName: String = "FMP Compat"
|
||||
* @return The name of this unit (something descriptive)
|
||||
*/
|
||||
def unitName = "BC Transport Compat"
|
||||
|
||||
/**
|
||||
* Handles an incoming Mantle message
|
||||
*
|
||||
* @param msg The Mantle message from Router.
|
||||
*/
|
||||
def handleMessage(msg: MantleMessage) {
|
||||
if (msg.getMessage.equals("registerDecorativeBlock")) {
|
||||
msg.getAttachment match {
|
||||
case (bID:Int, meta:Int) => sendBCFacadeMessage(bID, meta)
|
||||
case il:Array[Int] => try { sendBCFacadeMessage(il(0), il(1)) } catch { case e:Exception => logWarn("Invalid Int array received.") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def sendBCFacadeMessage(bID: Int, meta: Int) {
|
||||
FMLInterModComms.sendMessage("BuildCraft|Transport", "add-facade", s"$bID@$meta")
|
||||
}
|
||||
|
||||
private def logWarn(str:String) {
|
||||
logger.warning(s"[$unitName] $str")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package mantle.router.routing.builtin
|
||||
|
||||
import mantle.router.routing.{MantleMessage, IPipelineUnit}
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import cpw.mods.fml.common.event.FMLInterModComms
|
||||
|
||||
/**
|
||||
* Mystcraft pipeline unit
|
||||
*
|
||||
* @author Sunstrike <[email protected]>
|
||||
*/
|
||||
object UnitMystcraft extends IPipelineUnit {
|
||||
|
||||
def unitName = "Mystcraft Compat"
|
||||
|
||||
def handleMessage(msg: MantleMessage) {
|
||||
if (msg.getMessage.equals("myst_fluidSymbol")) {
|
||||
msg.getAttachment match {
|
||||
case (fName:String, rarity:Float, grammarWeight:Float, blockInstability:Float) =>
|
||||
val nbt = new NBTTagCompound()
|
||||
val fluidSym = new NBTTagCompound()
|
||||
fluidSym.setString("fluidname", fName)
|
||||
fluidSym.setFloat("rarity", rarity)
|
||||
fluidSym.setFloat("grammarweight", grammarWeight)
|
||||
fluidSym.setFloat("instabilityPerBlock", blockInstability)
|
||||
nbt.setCompoundTag("fluidsymbol", fluidSym)
|
||||
sendMystMessage("fluidsymbol", nbt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def sendMystMessage(msg: String, nbt: NBTTagCompound) {
|
||||
FMLInterModComms.sendMessage("Mystcraft", msg, nbt)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user