fixed gui breaking pure servers

This commit is contained in:
Florian Nücke 2013-10-08 19:37:28 +02:00
parent 7b4e15c2f2
commit 14bdba937d
8 changed files with 52 additions and 21 deletions

View File

@ -29,7 +29,7 @@ object OpenComputers {
// http://docs.scala-lang.org/overviews/reflection/thread-safety.html // http://docs.scala-lang.org/overviews/reflection/thread-safety.html
val mirror = ru.runtimeMirror(OpenComputers.getClass.getClassLoader) val mirror = ru.runtimeMirror(OpenComputers.getClass.getClassLoader)
@SidedProxy(clientSide = "li.cil.oc.client.Proxy", serverSide = "li.cil.oc.common.Proxy") @SidedProxy(clientSide = "li.cil.oc.client.Proxy", serverSide = "li.cil.oc.server.Proxy")
var proxy: Proxy = null var proxy: Proxy = null
@EventHandler @EventHandler

View File

@ -0,0 +1,17 @@
package li.cil.oc.client
import li.cil.oc.common.tileentity.{Screen, Computer}
import li.cil.oc.common.{GuiHandler => CommonGuiHandler, GuiType}
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.world.World
object GuiHandler extends CommonGuiHandler {
override def getClientGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) =
world.getBlockTileEntity(x, y, z) match {
case tileEntity: Computer if id == GuiType.Computer.id =>
new gui.Computer(player.inventory, tileEntity)
case tileEntity: Screen if id == GuiType.Screen.id =>
new gui.Screen(tileEntity)
case _ => null
}
}

View File

@ -2,8 +2,10 @@ package li.cil.oc.client
import cpw.mods.fml.client.registry.ClientRegistry import cpw.mods.fml.client.registry.ClientRegistry
import cpw.mods.fml.common.event.FMLInitializationEvent import cpw.mods.fml.common.event.FMLInitializationEvent
import cpw.mods.fml.common.network.NetworkRegistry
import cpw.mods.fml.common.registry.TickRegistry import cpw.mods.fml.common.registry.TickRegistry
import cpw.mods.fml.relauncher.Side import cpw.mods.fml.relauncher.Side
import li.cil.oc.OpenComputers
import li.cil.oc.common.tileentity.Computer import li.cil.oc.common.tileentity.Computer
import li.cil.oc.common.tileentity.Screen import li.cil.oc.common.tileentity.Screen
import li.cil.oc.common.{Proxy => CommonProxy} import li.cil.oc.common.{Proxy => CommonProxy}
@ -12,6 +14,8 @@ private[oc] class Proxy extends CommonProxy {
override def init(e: FMLInitializationEvent) = { override def init(e: FMLInitializationEvent) = {
super.init(e) super.init(e)
NetworkRegistry.instance.registerGuiHandler(OpenComputers, GuiHandler)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[Screen], ScreenRenderer) ClientRegistry.bindTileEntitySpecialRenderer(classOf[Screen], ScreenRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[Computer], ComputerRenderer) ClientRegistry.bindTileEntitySpecialRenderer(classOf[Computer], ComputerRenderer)

View File

@ -1,31 +1,15 @@
package li.cil.oc.common package li.cil.oc.common
import cpw.mods.fml.common.network.IGuiHandler import cpw.mods.fml.common.network.IGuiHandler
import li.cil.oc.client.gui
import li.cil.oc.common.tileentity.Computer import li.cil.oc.common.tileentity.Computer
import li.cil.oc.common.tileentity.Screen
import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.player.EntityPlayer
import net.minecraft.world.World import net.minecraft.world.World
object GuiType extends Enumeration { abstract class GuiHandler extends IGuiHandler {
val Computer = Value("Computer")
val Screen = Value("Screen")
}
object GuiHandler extends IGuiHandler {
override def getServerGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) = override def getServerGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) =
world.getBlockTileEntity(x, y, z) match { world.getBlockTileEntity(x, y, z) match {
case tileEntity: Computer => case tileEntity: Computer =>
new container.Computer(player.inventory, tileEntity) new container.Computer(player.inventory, tileEntity)
case _ => null case _ => null
} }
override def getClientGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) =
world.getBlockTileEntity(x, y, z) match {
case tileEntity: Computer if id == GuiType.Computer.id =>
new gui.Computer(player.inventory, tileEntity)
case tileEntity: Screen if id == GuiType.Screen.id =>
new gui.Screen(tileEntity)
case _ => null
}
} }

View File

@ -0,0 +1,6 @@
package li.cil.oc.common
object GuiType extends Enumeration {
val Computer = Value("Computer")
val Screen = Value("Screen")
}

View File

@ -1,7 +1,6 @@
package li.cil.oc.common package li.cil.oc.common
import cpw.mods.fml.common.event._ import cpw.mods.fml.common.event._
import cpw.mods.fml.common.network.NetworkRegistry
import cpw.mods.fml.common.registry.LanguageRegistry import cpw.mods.fml.common.registry.LanguageRegistry
import li.cil.oc._ import li.cil.oc._
import li.cil.oc.server.component.Computer import li.cil.oc.server.component.Computer
@ -29,8 +28,6 @@ class Proxy {
Blocks.init() Blocks.init()
Items.init() Items.init()
NetworkRegistry.instance.registerGuiHandler(OpenComputers, GuiHandler)
api.Driver.add(driver.FileSystem) api.Driver.add(driver.FileSystem)
api.Driver.add(driver.GraphicsCard) api.Driver.add(driver.GraphicsCard)
api.Driver.add(driver.Keyboard) api.Driver.add(driver.Keyboard)

View File

@ -0,0 +1,9 @@
package li.cil.oc.server
import li.cil.oc.common.{GuiHandler => CommonGuiHandler}
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.world.World
object GuiHandler extends CommonGuiHandler {
override def getClientGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) = null
}

View File

@ -0,0 +1,14 @@
package li.cil.oc.server
import cpw.mods.fml.common.event.FMLInitializationEvent
import cpw.mods.fml.common.network.NetworkRegistry
import li.cil.oc.OpenComputers
import li.cil.oc.common.{Proxy => CommonProxy}
private[oc] class Proxy extends CommonProxy {
override def init(e: FMLInitializationEvent) = {
super.init(e)
NetworkRegistry.instance.registerGuiHandler(OpenComputers, GuiHandler)
}
}