diff --git a/src/net/bdew/lib/BdLib.scala b/src/net/bdew/lib/BdLib.scala index cf2fa26..761cb3e 100644 --- a/src/net/bdew/lib/BdLib.scala +++ b/src/net/bdew/lib/BdLib.scala @@ -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") diff --git a/src/net/bdew/lib/config/MachineManager.scala b/src/net/bdew/lib/config/MachineManager.scala index 7205d54..56161ed 100644 --- a/src/net/bdew/lib/config/MachineManager.scala +++ b/src/net/bdew/lib/config/MachineManager.scala @@ -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() {} diff --git a/src/net/bdew/lib/gui/Direction.scala b/src/net/bdew/lib/gui/Direction.scala index 97b2434..61d1416 100644 --- a/src/net/bdew/lib/gui/Direction.scala +++ b/src/net/bdew/lib/gui/Direction.scala @@ -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") } diff --git a/src/net/bdew/lib/gui/GuiHandler.scala b/src/net/bdew/lib/gui/GuiHandler.scala new file mode 100644 index 0000000..2b40333 --- /dev/null +++ b/src/net/bdew/lib/gui/GuiHandler.scala @@ -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) +} diff --git a/src/net/bdew/lib/gui/GuiProvider.scala b/src/net/bdew/lib/gui/GuiProvider.scala new file mode 100644 index 0000000..9a44dca --- /dev/null +++ b/src/net/bdew/lib/gui/GuiProvider.scala @@ -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) +}