| package li.cil.oc.common |
| |
| import cpw.mods.fml.common.event._ |
| import cpw.mods.fml.common.network.NetworkRegistry |
| import cpw.mods.fml.common.registry.GameRegistry |
| import li.cil.oc._ |
| import li.cil.oc.common.init.Blocks |
| import li.cil.oc.common.init.Items |
| import li.cil.oc.common.recipe.Recipes |
| import li.cil.oc.integration.Mods |
| import li.cil.oc.server._ |
| import li.cil.oc.server.machine.luac.NativeLuaArchitecture |
| import li.cil.oc.server.machine.luaj.LuaJLuaArchitecture |
| import li.cil.oc.util.LuaStateFactory |
| import net.minecraft.item.ItemStack |
| import net.minecraftforge.oredict.OreDictionary |
| |
| import scala.collection.convert.WrapAsScala._ |
| |
| class Proxy { |
| def preInit(e: FMLPreInitializationEvent) { |
| Settings.load(e.getSuggestedConfigurationFile) |
| |
| OpenComputers.log.info("Initializing blocks and items.") |
| |
| Blocks.init() |
| Items.init() |
| |
| OpenComputers.log.info("Initializing additional OreDict entries.") |
| |
| registerExclusive("craftingPiston", new ItemStack(net.minecraft.init.Blocks.piston), new ItemStack(net.minecraft.init.Blocks.sticky_piston)) |
| registerExclusive("torchRedstoneActive", new ItemStack(net.minecraft.init.Blocks.redstone_torch)) |
| registerExclusive("nuggetGold", new ItemStack(net.minecraft.init.Items.gold_nugget)) |
| registerExclusive("nuggetIron", Items.ironNugget.createItemStack()) |
| |
| if (OreDictionary.getOres("nuggetIron").exists(Items.ironNugget.createItemStack().isItemEqual)) { |
| Recipes.addItem(Items.ironNugget, "nuggetIron") |
| Recipes.addItem(net.minecraft.init.Items.iron_ingot, "ingotIron") |
| } |
| |
| OpenComputers.log.info("Initializing OpenComputers API.") |
| |
| api.CreativeTab.instance = CreativeTab |
| api.API.driver = driver.Registry |
| api.API.fileSystem = fs.FileSystem |
| api.API.items = Items |
| api.API.machine = machine.Machine |
| api.API.network = network.Network |
| |
| api.Machine.LuaArchitecture = |
| if (LuaStateFactory.isAvailable && !Settings.get.forceLuaJ) classOf[NativeLuaArchitecture] |
| else classOf[LuaJLuaArchitecture] |
| api.Machine.add(api.Machine.LuaArchitecture) |
| if (Settings.get.registerLuaJArchitecture) |
| api.Machine.add(classOf[LuaJLuaArchitecture]) |
| } |
| |
| def init(e: FMLInitializationEvent) { |
| OpenComputers.channel = NetworkRegistry.INSTANCE.newEventDrivenChannel("OpenComputers") |
| OpenComputers.channel.register(server.PacketHandler) |
| |
| OpenComputers.log.info("Initializing mod integration.") |
| Mods.init() |
| } |
| |
| def postInit(e: FMLPostInitializationEvent) { |
| // Don't allow driver registration after this point, to avoid issues. |
| driver.Registry.locked = true |
| } |
| |
| private def registerExclusive(name: String, items: ItemStack*) { |
| if (OreDictionary.getOres(name).isEmpty) { |
| for (item <- items) { |
| OreDictionary.registerOre(name, item) |
| } |
| } |
| } |
| |
| // Yes, this could be boiled down even further, but I like to keep it |
| // explicit like this, because it makes it a) clearer, b) easier to |
| // extend, in case that should ever be needed. |
| |
| private val blockRenames = Map( |
| OpenComputers.ID + ":" + Settings.namespace + "simple" -> "simple", |
| OpenComputers.ID + ":" + Settings.namespace + "simple_redstone" -> "simple_redstone", |
| OpenComputers.ID + ":" + Settings.namespace + "special" -> "special", |
| OpenComputers.ID + ":" + Settings.namespace + "special_redstone" -> "special_redstone", |
| OpenComputers.ID + ":" + Settings.namespace + "keyboard" -> "keyboard", |
| OpenComputers.ID + ":rack" -> "serverRack" |
| ) |
| |
| private val itemRenames = Map( |
| OpenComputers.ID + ":" + Settings.namespace + "item" -> "item", |
| OpenComputers.ID + ":" + Settings.namespace + "simple" -> "simple", |
| OpenComputers.ID + ":" + Settings.namespace + "simple_redstone" -> "simple_redstone", |
| OpenComputers.ID + ":" + Settings.namespace + "special" -> "special", |
| OpenComputers.ID + ":" + Settings.namespace + "special_redstone" -> "special_redstone", |
| OpenComputers.ID + ":" + Settings.namespace + "keyboard" -> "keyboard", |
| OpenComputers.ID + ":rack" -> "serverRack" |
| ) |
| |
| def missingMappings(e: FMLMissingMappingsEvent) { |
| for (missing <- e.get()) { |
| if (missing.`type` == GameRegistry.Type.BLOCK) { |
| blockRenames.get(missing.name) match { |
| case Some(name) => missing.remap(GameRegistry.findBlock(OpenComputers.ID, name)) |
| case _ => missing.fail() |
| } |
| } |
| else if (missing.`type` == GameRegistry.Type.ITEM) { |
| itemRenames.get(missing.name) match { |
| case Some(name) => missing.remap(GameRegistry.findItem(OpenComputers.ID, name)) |
| case _ => missing.fail() |
| } |
| } |
| else missing.fail() |
| } |
| } |
| } |