More refactoring and cleanup

This commit is contained in:
bdew committed 2013-12-23 15:08:19 +02:00
1 parent 302429f340
commit bed3149880
5 files changed
+71 -6

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ package net.bdew.lib
import cpw.mods.fml.common.Mod
import cpw.mods.fml.common.event.FMLPreInitializationEvent
@Mod(modid = "bdlib", name="BD lib", version = "BDLIB_VER", modLanguage = "scala")
@Mod(modid = "bdlib", name = "BD lib", version = "BDLIB_VER", modLanguage = "scala")
object BdLib {
def preInit(ev: FMLPreInitializationEvent) {
ev.getModLog.info("bdlib BDLIB_VER loaded")
+6 -2
View File
@@ -11,12 +11,16 @@ package net.bdew.lib.config
import net.bdew.lib.recipes.gencfg.ConfigSection
import net.bdew.lib.machine.Machine
import net.bdew.lib.gui.{GuiProvider, GuiHandler}
class MachineManager(ids: IdManager, val tuning: ConfigSection) {
class MachineManager(ids: IdManager, val tuning: ConfigSection, guiHandler: GuiHandler) {
def registerMachine[R <: Machine[_]](machine: R): R = {
machine.tuning = tuning.getSection(machine.name)
if (machine.tuning.getBoolean("Enabled"))
if (machine.tuning.getBoolean("Enabled")) {
machine.regBlock(ids)
if (machine.isInstanceOf[GuiProvider])
guiHandler.register(machine.asInstanceOf[GuiProvider])
}
return machine
}
def load() {}
+3 -3
View File
@@ -12,7 +12,7 @@ package net.bdew.lib.gui
object Direction extends Enumeration {
type Direction = Value
val UP = Value("UP")
val DOWN = Value("UP")
val LEFT = Value("UP")
val RIGHT = Value("UP")
val DOWN = Value("DOWN")
val LEFT = Value("LEFT")
val RIGHT = Value("RIGHT")
}
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright (c) bdew, 2013
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
*/
package net.bdew.lib.gui
import cpw.mods.fml.common.network.IGuiHandler
import scala.collection.mutable
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.world.World
class GuiHandler extends IGuiHandler {
val guis = mutable.Map.empty[Int, GuiProvider]
def register(p: GuiProvider) = {
if (guis.isDefinedAt(p.guiId))
sys.error("GUI ID Collision - %d was registered for %s and attemted to register by %s".format(p.guiId, guis(p.guiId), p))
guis += (p.guiId -> p)
}
def getServerGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
guis(ID).getContainer(world.getBlockTileEntity(x, y, z), player)
def getClientGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
guis(ID).getGui(world.getBlockTileEntity(x, y, z), player)
}
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright (c) bdew, 2013
* https://github.com/bdew/bdlib
*
* This mod is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
*/
package net.bdew.lib.gui
import net.minecraft.tileentity.TileEntity
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.inventory.Container
import cpw.mods.fml.relauncher.{Side, SideOnly}
trait GuiProvider {
def guiId: Int
type TEClass
@SideOnly(Side.CLIENT)
def getGui(te: TEClass, player: EntityPlayer): GuiContainer
def getContainer(te: TEClass, player: EntityPlayer): Container
@SideOnly(Side.CLIENT)
def getGui(te: TileEntity, player: EntityPlayer): GuiContainer = getGui(te.asInstanceOf[TEClass], player)
def getContainer(te: TileEntity, player: EntityPlayer): Container = getContainer(te.asInstanceOf[TEClass], player)
}