refactor run for tile entities

This commit is contained in:
Florian Nücke 2013-09-29 14:57:05 +02:00
parent bb491ecf04
commit c1fd2c0144
31 changed files with 139 additions and 141 deletions

View File

@ -14,7 +14,7 @@ object Blocks {
// try to register with it. Also, the order the sub blocks are created in
// must not be changed since that order determines their actual IDs.
blockSimple = new Delegator(Config.blockId)
blockSpecial = new SpecialMulti(Config.blockSpecialId)
blockSpecial = new SpecialDelegator(Config.blockSpecialId)
computer = new Computer(blockSimple)
screen = new Screen(blockSimple)

View File

@ -19,15 +19,19 @@ object Config {
val config = new net.minecraftforge.common.Configuration(file)
Config.blockId = config.getBlock("block", Config.blockId,
"The block ID used for simple blocks.").getInt(Config.blockId)
"The block ID used for simple blocks.").
getInt(Config.blockId)
Config.blockSpecialId = config.getBlock("blockSpecial", Config.blockSpecialId,
"The block ID used for special blocks.").getInt(Config.blockSpecialId)
"The block ID used for special blocks.").
getInt(Config.blockSpecialId)
Config.itemId = config.getItem("item", Config.itemId,
"The item ID used for all items.").getInt(Config.itemId)
"The item ID used for all non-stackable items.").
getInt(Config.itemId)
Config.threads = config.get("config", "threads", Config.threads,
"The overall number of threads to use to driver computers.").getInt(Config.threads)
"The overall number of threads to use to driver computers.").
getInt(Config.threads)
if (config.hasChanged)
config.save()

View File

@ -1,6 +1,6 @@
package li.cil.oc.client
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity.Computer
import net.minecraft.client.renderer.OpenGlHelper
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
@ -13,7 +13,7 @@ object ComputerRenderer extends TileEntitySpecialRenderer {
private val frontOn = new ResourceLocation("opencomputers", "textures/blocks/computer_front_on.png")
override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) = {
val computer = tileEntity.asInstanceOf[TileEntityComputer]
val computer = tileEntity.asInstanceOf[Computer]
if (computer.isOn) {
GL11.glPushAttrib(0xFFFFFF)
GL11.glPushMatrix()

View File

@ -2,9 +2,9 @@ package li.cil.oc.client
import cpw.mods.fml.common.network.Player
import li.cil.oc.common.PacketType
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity.TileEntityRotatable
import li.cil.oc.common.tileentity.TileEntityScreen
import li.cil.oc.common.tileentity.Computer
import li.cil.oc.common.tileentity.Rotatable
import li.cil.oc.common.tileentity.Screen
import li.cil.oc.common.{PacketHandler => CommonPacketHandler}
import net.minecraft.entity.player.EntityPlayer
@ -28,7 +28,7 @@ class PacketHandler extends CommonPacketHandler {
}
def onScreenResolutionChange(p: PacketParser) =
p.readTileEntity[TileEntityScreen]() match {
p.readTileEntity[Screen]() match {
case None => // Invalid packet.
case Some(t) => {
val w = p.readInt()
@ -38,7 +38,7 @@ class PacketHandler extends CommonPacketHandler {
}
def onScreenSet(p: PacketParser) =
p.readTileEntity[TileEntityScreen]() match {
p.readTileEntity[Screen]() match {
case None => // Invalid packet.
case Some(t) => {
val col = p.readInt()
@ -49,7 +49,7 @@ class PacketHandler extends CommonPacketHandler {
}
def onScreenFill(p: PacketParser) =
p.readTileEntity[TileEntityScreen]() match {
p.readTileEntity[Screen]() match {
case None => // Invalid packet.
case Some(t) => {
val col = p.readInt()
@ -62,7 +62,7 @@ class PacketHandler extends CommonPacketHandler {
}
def onScreenCopy(p: PacketParser) =
p.readTileEntity[TileEntityScreen]() match {
p.readTileEntity[Screen]() match {
case None => // Invalid packet.
case Some(t) => {
val col = p.readInt()
@ -76,7 +76,7 @@ class PacketHandler extends CommonPacketHandler {
}
def onScreenBufferResponse(p: PacketParser) =
p.readTileEntity[TileEntityScreen]() match {
p.readTileEntity[Screen]() match {
case None => // Invalid packet.
case Some(t) =>
p.readUTF.split('\n').zipWithIndex.foreach {
@ -85,7 +85,7 @@ class PacketHandler extends CommonPacketHandler {
}
def onComputerStateResponse(p: PacketParser) =
p.readTileEntity[TileEntityComputer]() match {
p.readTileEntity[Computer]() match {
case None => // Invalid packet.
case Some(t) => {
t.isOn = p.readBoolean()
@ -93,7 +93,7 @@ class PacketHandler extends CommonPacketHandler {
}
def onRotatableStateResponse(p: PacketParser) =
p.readTileEntity[TileEntityRotatable]() match {
p.readTileEntity[Rotatable]() match {
case None => // Invalid packet.
case Some(t) =>
t.pitch = p.readDirection()

View File

@ -3,25 +3,25 @@ package li.cil.oc.client
import li.cil.oc.api.network.Node
import li.cil.oc.common.PacketBuilder
import li.cil.oc.common.PacketType
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity.TileEntityRotatable
import li.cil.oc.common.tileentity.TileEntityScreen
import li.cil.oc.common.tileentity.Computer
import li.cil.oc.common.tileentity.Rotatable
import li.cil.oc.common.tileentity.Screen
import net.minecraft.tileentity.TileEntity
object PacketSender {
def sendScreenBufferRequest(t: TileEntityScreen) = {
def sendScreenBufferRequest(t: Screen) = {
val pb = new PacketBuilder(PacketType.ScreenBufferRequest)
pb.writeTileEntity(t)
pb.sendToServer()
}
def sendComputerStateRequest(t: TileEntityComputer) = {
def sendComputerStateRequest(t: Computer) = {
val pb = new PacketBuilder(PacketType.ComputerStateRequest)
pb.writeTileEntity(t)
pb.sendToServer()
}
def sendRotatableStateRequest(t: TileEntityRotatable) = {
def sendRotatableStateRequest(t: Rotatable) = {
val pb = new PacketBuilder(PacketType.RotatableStateRequest)
pb.writeTileEntity(t)
pb.sendToServer()

View File

@ -2,15 +2,15 @@ package li.cil.oc.client
import cpw.mods.fml.client.registry.ClientRegistry
import cpw.mods.fml.common.event.FMLInitializationEvent
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity.TileEntityScreen
import li.cil.oc.common.tileentity.Computer
import li.cil.oc.common.tileentity.Screen
import li.cil.oc.common.{Proxy => CommonProxy}
private[oc] class Proxy extends CommonProxy {
override def init(e: FMLInitializationEvent) = {
super.init(e)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[TileEntityScreen], ScreenRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[TileEntityComputer], ComputerRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[Screen], ScreenRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[Computer], ComputerRenderer)
}
}

View File

@ -1,7 +1,7 @@
package li.cil.oc.client
import li.cil.oc.client.gui.MonospaceFontRenderer
import li.cil.oc.common.tileentity.TileEntityScreen
import li.cil.oc.common.tileentity.Screen
import net.minecraft.client.renderer.OpenGlHelper
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
@ -10,7 +10,7 @@ import org.lwjgl.opengl.GL11
object ScreenRenderer extends TileEntitySpecialRenderer {
override def renderTileEntityAt(t: TileEntity, x: Double, y: Double, z: Double, f: Float) = {
val tileEntity = t.asInstanceOf[TileEntityScreen]
val tileEntity = t.asInstanceOf[Screen]
GL11.glPushAttrib(0xFFFFFF)
GL11.glPushMatrix()

View File

@ -1,4 +1,4 @@
package li.cil.oc.client.computer
package li.cil.oc.client.component
import li.cil.oc.common.component
import net.minecraft.nbt.NBTTagCompound

View File

@ -1,7 +1,7 @@
package li.cil.oc.client.gui
import li.cil.oc.common.container
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.client.renderer.Tessellator
import net.minecraft.entity.player.InventoryPlayer
@ -10,7 +10,7 @@ import net.minecraft.util.ResourceLocation
import net.minecraft.util.StatCollector
import org.lwjgl.opengl.GL11
class Computer(inventory: InventoryPlayer, val tileEntity: TileEntityComputer) extends GuiContainer(new container.Computer(inventory, tileEntity)) {
class Computer(inventory: InventoryPlayer, val tileEntity: tileentity.Computer) extends GuiContainer(new container.Computer(inventory, tileEntity)) {
private val background = new ResourceLocation("opencomputers", "textures/gui/computer.png")
private val iconPsu = new ResourceLocation("opencomputers", "textures/gui/icon_psu.png")

View File

@ -1,7 +1,7 @@
package li.cil.oc.client.gui
import li.cil.oc.client.PacketSender
import li.cil.oc.common.tileentity.TileEntityScreen
import li.cil.oc.common.tileentity
import net.minecraft.client.gui.{GuiScreen => MCGuiScreen}
import net.minecraft.client.renderer.GLAllocation
import net.minecraft.client.renderer.Tessellator
@ -21,8 +21,8 @@ import org.lwjgl.opengl.GL11
* called whenever the text actually changes, otherwise there will be no change
* in the text displayed in the GUI.
*/
class Screen(val tileEntity: TileEntityScreen) extends MCGuiScreen {
tileEntity.gui = Some(this)
class Screen(val tileEntity: tileentity.Screen) extends MCGuiScreen {
tileEntity.guiScreen = Some(this)
var (x, y, innerWidth, innerHeight, scale) = (0, 0, 0, 0, 0.0)
@ -71,7 +71,7 @@ class Screen(val tileEntity: TileEntityScreen) extends MCGuiScreen {
override def onGuiClosed() = {
super.onGuiClosed()
tileEntity.gui = None
tileEntity.guiScreen = None
}
override def drawScreen(mouseX: Int, mouseY: Int, dt: Float): Unit = {

View File

@ -2,8 +2,8 @@ package li.cil.oc.common
import cpw.mods.fml.common.network.IGuiHandler
import li.cil.oc.client.gui
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity.TileEntityScreen
import li.cil.oc.common.tileentity.Computer
import li.cil.oc.common.tileentity.Screen
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.world.World
@ -15,16 +15,16 @@ object GuiType extends Enumeration {
object GuiHandler extends IGuiHandler {
override def getServerGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int) =
world.getBlockTileEntity(x, y, z) match {
case tileEntity: TileEntityComputer =>
case tileEntity: Computer =>
new container.Computer(player.inventory, tileEntity)
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: TileEntityComputer if id == GuiType.Computer.id =>
case tileEntity: Computer if id == GuiType.Computer.id =>
new gui.Computer(player.inventory, tileEntity)
case tileEntity: TileEntityScreen if id == GuiType.Screen.id =>
case tileEntity: Screen if id == GuiType.Screen.id =>
new gui.Screen(tileEntity)
case _ => null
}

View File

@ -3,14 +3,12 @@ package li.cil.oc.common
import cpw.mods.fml.common.event._
import cpw.mods.fml.common.network.NetworkRegistry
import cpw.mods.fml.common.registry.LanguageRegistry
import li.cil.oc._
import li.cil.oc.api.Driver
import li.cil.oc.api.Network
import li.cil.oc.server.driver
import li.cil.oc.server.driver.Registry
import li.cil.oc.server.network
import net.minecraftforge.common.MinecraftForge
import li.cil.oc.api
import li.cil.oc.server.component.Computer
import li.cil.oc.server.driver
import li.cil.oc.server.network
import li.cil.oc.{OpenComputers, Items, Blocks, Config}
import net.minecraftforge.common.MinecraftForge
class Proxy {
def preInit(e: FMLPreInitializationEvent): Unit = {
@ -19,8 +17,8 @@ class Proxy {
LanguageRegistry.instance.loadLocalization(
"/assets/opencomputers/lang/en_US.lang", "en_US", false)
Driver.registry = Some(driver.Registry)
Network.network = Some(network.Network)
api.Driver.registry = Some(driver.Registry)
api.Network.network = Some(network.Network)
}
def init(e: FMLInitializationEvent): Unit = {
@ -29,11 +27,11 @@ class Proxy {
NetworkRegistry.instance.registerGuiHandler(OpenComputers, GuiHandler)
Driver.add(driver.GraphicsCard)
Driver.add(driver.Keyboard)
Driver.add(driver.Memory)
Driver.add(driver.Redstone)
Driver.add(driver.Disk)
api.Driver.add(driver.Disk)
api.Driver.add(driver.GraphicsCard)
api.Driver.add(driver.Keyboard)
api.Driver.add(driver.Memory)
api.Driver.add(driver.Redstone)
MinecraftForge.EVENT_BUS.register(Computer)
MinecraftForge.EVENT_BUS.register(network.Network)
@ -43,6 +41,6 @@ class Proxy {
// Lock the driver registry to avoid drivers being added after computers
// may have already started up. This makes sure the driver API won't change
// over the course of a game, since that could lead to weird effects.
Registry.locked = true
driver.Registry.locked = true
}
}

View File

@ -3,7 +3,7 @@ package li.cil.oc.common.block
import cpw.mods.fml.common.registry.GameRegistry
import li.cil.oc.OpenComputers
import li.cil.oc.common.GuiType
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity
import net.minecraft.client.renderer.texture.IconRegister
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.Icon
@ -12,7 +12,7 @@ import net.minecraft.world.World
import net.minecraftforge.common.ForgeDirection
class Computer(val parent: Delegator) extends Delegate {
GameRegistry.registerTileEntity(classOf[TileEntityComputer], "oc.computer")
GameRegistry.registerTileEntity(classOf[tileentity.Computer], "oc.computer")
val unlocalizedName = "Computer"
@ -27,7 +27,7 @@ class Computer(val parent: Delegator) extends Delegate {
override def getBlockTextureFromSide(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) = {
getIcon(localSide, world.getBlockTileEntity(x, y, z) match {
case computer: TileEntityComputer => computer.isOn
case computer: tileentity.Computer => computer.isOn
case _ => false
})
}
@ -35,7 +35,7 @@ class Computer(val parent: Delegator) extends Delegate {
override def icon(side: ForgeDirection) = getIcon(side, isOn = false)
private def getIcon(side: ForgeDirection, isOn: Boolean) =
if (isOn) Icons.on(side.ordinal) else Icons.off(side.ordinal)
Some(if (isOn) Icons.on(side.ordinal) else Icons.off(side.ordinal))
override def registerIcons(iconRegister: IconRegister) = {
Icons.off(ForgeDirection.DOWN.ordinal) = iconRegister.registerIcon("opencomputers:computer_top")
@ -61,14 +61,14 @@ class Computer(val parent: Delegator) extends Delegate {
override def hasTileEntity = true
override def createTileEntity(world: World, metadata: Int) = new TileEntityComputer(world.isRemote)
override def createTileEntity(world: World, metadata: Int) = Some(new tileentity.Computer(world.isRemote))
// ----------------------------------------------------------------------- //
// Destruction / Interaction
// ----------------------------------------------------------------------- //
override def breakBlock(world: World, x: Int, y: Int, z: Int, blockId: Int, metadata: Int) = {
world.getBlockTileEntity(x, y, z).asInstanceOf[TileEntityComputer].turnOff()
world.getBlockTileEntity(x, y, z).asInstanceOf[tileentity.Computer].turnOff()
super.breakBlock(world, x, y, z, blockId, metadata)
}
@ -76,7 +76,7 @@ class Computer(val parent: Delegator) extends Delegate {
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
if (!player.isSneaking) {
// Start the computer if it isn't already running and open the GUI.
world.getBlockTileEntity(x, y, z).asInstanceOf[TileEntityComputer].turnOn()
world.getBlockTileEntity(x, y, z).asInstanceOf[tileentity.Computer].turnOn()
player.openGui(OpenComputers, GuiType.Computer.id, world, x, y, z)
true
}

View File

@ -29,14 +29,14 @@ trait Delegate {
def canConnectRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
def createTileEntity(world: World, metadata: Int): TileEntity = null
def createTileEntity(world: World, metadata: Int): Option[TileEntity] = None
def getBlockTextureFromSide(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection): Icon = icon(localSide)
def getBlockTextureFromSide(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection): Option[Icon] = icon(localSide)
def getCollisionBoundingBoxFromPool(world: World, x: Int, y: Int, z: Int) =
AxisAlignedBB.getAABBPool.getAABB(x, y, z, x + 1, y + 1, z + 1)
def icon(side: ForgeDirection): Icon = null
def icon(side: ForgeDirection): Option[Icon] = None
def getLightOpacity(world: World, x: Int, y: Int, z: Int) = 255

View File

@ -6,7 +6,7 @@ import li.cil.oc.Config
import li.cil.oc.CreativeTab
import li.cil.oc.api.Network
import li.cil.oc.api.network.Node
import li.cil.oc.common.tileentity.TileEntityRotatable
import li.cil.oc.common.tileentity.Rotatable
import net.minecraft.block.Block
import net.minecraft.block.material.Material
import net.minecraft.client.renderer.texture.IconRegister
@ -41,7 +41,7 @@ import scala.collection.mutable
class Delegator(id: Int) extends Block(id, Material.iron) {
setHardness(2f)
setCreativeTab(CreativeTab)
GameRegistry.registerBlock(this, classOf[ItemBlockMulti], "oc.block." + id)
GameRegistry.registerBlock(this, classOf[Item], "oc.block." + id)
// ----------------------------------------------------------------------- //
// SubBlock
@ -71,27 +71,27 @@ class Delegator(id: Int) extends Block(id, Material.iron) {
def getFacing(world: IBlockAccess, x: Int, y: Int, z: Int) =
world.getBlockTileEntity(x, y, z) match {
case tileEntity: TileEntityRotatable => tileEntity.facing
case tileEntity: Rotatable => tileEntity.facing
case _ => ForgeDirection.UNKNOWN
}
def setFacing(world: World, x: Int, y: Int, z: Int, value: ForgeDirection) =
world.getBlockTileEntity(x, y, z) match {
case rotatable: TileEntityRotatable =>
case rotatable: Rotatable =>
rotatable.setFromFacing(value); true
case _ => false
}
def setRotationFromEntityPitchAndYaw(world: World, x: Int, y: Int, z: Int, value: Entity) =
world.getBlockTileEntity(x, y, z) match {
case rotatable: TileEntityRotatable =>
case rotatable: Rotatable =>
rotatable.setFromEntityPitchAndYaw(value); true
case _ => false
}
private def toLocal(world: IBlockAccess, x: Int, y: Int, z: Int, value: ForgeDirection) =
world.getBlockTileEntity(x, y, z) match {
case rotatable: TileEntityRotatable => rotatable.translate(value)
case rotatable: Rotatable => rotatable.translate(value)
case _ => value
}
@ -128,7 +128,7 @@ class Delegator(id: Int) extends Block(id, Material.iron) {
override def createTileEntity(world: World, metadata: Int): TileEntity =
subBlock(metadata) match {
case None => null
case Some(subBlock) => subBlock.createTileEntity(world, metadata)
case Some(subBlock) => subBlock.createTileEntity(world, metadata).orNull
}
override def getCollisionBoundingBoxFromPool(world: World, x: Int, y: Int, z: Int) =
@ -143,8 +143,8 @@ class Delegator(id: Int) extends Block(id, Material.iron) {
case None => super.getBlockTexture(world, x, y, z, side)
case Some(subBlock) => subBlock.getBlockTextureFromSide(
world, x, y, z, ForgeDirection.getOrientation(side), toLocal(world, x, y, z, ForgeDirection.getOrientation(side))) match {
case null => super.getBlockTexture(world, x, y, z, side)
case icon => icon
case None => super.getBlockTexture(world, x, y, z, side)
case Some(icon) => icon
}
}
@ -152,8 +152,8 @@ class Delegator(id: Int) extends Block(id, Material.iron) {
subBlock(metadata) match {
case None => super.getIcon(side, metadata)
case Some(subBlock) => subBlock.icon(ForgeDirection.getOrientation(side)) match {
case null => super.getIcon(side, metadata)
case icon => icon
case None => super.getIcon(side, metadata)
case Some(icon) => icon
}
}
@ -166,7 +166,7 @@ class Delegator(id: Int) extends Block(id, Material.iron) {
override def getRenderType = Config.blockRenderId
override def getSubBlocks(itemId: Int, creativeTab: CreativeTabs, list: util.List[_]) = {
// Workaround for MC's untyped lists... I'm too tired to rage anymore.
// Workaround for MC's untyped lists...
def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T])
(0 until subBlocks.length).
foreach(id => add(list, new ItemStack(this, 1, id)))
@ -225,7 +225,7 @@ class Delegator(id: Int) extends Block(id, Material.iron) {
val valid = getValidRotations(world, x, y, z)
if (valid.length > 1 && canWrench)
world.getBlockTileEntity(x, y, z) match {
case rotatable: TileEntityRotatable => {
case rotatable: Rotatable => {
if (player.isSneaking) {
// Rotate pitch. Get the valid pitch rotations.
val validPitch = valid.collect {

View File

@ -1,6 +1,6 @@
package li.cil.oc.common.block
import li.cil.oc.common.tileentity.TileEntityRotatable
import li.cil.oc.common.tileentity.Rotatable
import net.minecraft.block.Block
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemBlock
@ -8,7 +8,7 @@ import net.minecraft.item.ItemStack
import net.minecraft.world.World
/** Used to represent multiblocks when in item form. */
class ItemBlockMulti(id: Int) extends ItemBlock(id) {
class Item(id: Int) extends ItemBlock(id) {
setHasSubtypes(true)
override def getMetadata(itemDamage: Int) = itemDamage
@ -27,7 +27,7 @@ class ItemBlockMulti(id: Int) extends ItemBlock(id) {
if (super.placeBlockAt(item, player, world, x, y, z, side, hitX, hitY, hitZ, metadata)) {
// If it's a rotatable block try to make it face the player.
world.getBlockTileEntity(x, y, z) match {
case rotatable: TileEntityRotatable =>
case rotatable: Rotatable =>
rotatable.setFromEntityPitchAndYaw(player).invertRotation()
}
true

View File

@ -1,12 +1,12 @@
package li.cil.oc.common.block
import cpw.mods.fml.common.registry.GameRegistry
import li.cil.oc.common.tileentity.TileEntityKeyboard
import li.cil.oc.common.tileentity
import net.minecraft.world.World
import net.minecraftforge.common.ForgeDirection
class Keyboard(val parent: Delegator) extends Delegate {
GameRegistry.registerTileEntity(classOf[TileEntityKeyboard], "oc.keyboard")
GameRegistry.registerTileEntity(classOf[tileentity.Keyboard], "oc.keyboard")
val unlocalizedName = "Keyboard"
@ -16,7 +16,7 @@ class Keyboard(val parent: Delegator) extends Delegate {
override def hasTileEntity = true
override def createTileEntity(world: World, metadata: Int) = new TileEntityKeyboard
override def createTileEntity(world: World, metadata: Int) = Some(new tileentity.Keyboard)
// ----------------------------------------------------------------------- //
// Block rotation

View File

@ -3,7 +3,7 @@ package li.cil.oc.common.block
import cpw.mods.fml.common.registry.GameRegistry
import li.cil.oc.OpenComputers
import li.cil.oc.common.GuiType
import li.cil.oc.common.tileentity.TileEntityScreen
import li.cil.oc.common.tileentity
import net.minecraft.client.renderer.texture.IconRegister
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.Icon
@ -12,7 +12,7 @@ import net.minecraft.world.World
import net.minecraftforge.common.ForgeDirection
class Screen(val parent: Delegator) extends Delegate {
GameRegistry.registerTileEntity(classOf[TileEntityScreen], "oc.screen")
GameRegistry.registerTileEntity(classOf[tileentity.Screen], "oc.screen")
val unlocalizedName = "Screen"
@ -29,17 +29,17 @@ class Screen(val parent: Delegator) extends Delegate {
override def getBlockTextureFromSide(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) = {
worldSide match {
case f if f == parent.getFacing(world, x, y, z) => icon(ForgeDirection.SOUTH)
case ForgeDirection.DOWN | ForgeDirection.UP => Icons.top
case _ => Icons.side
case ForgeDirection.DOWN | ForgeDirection.UP => Some(Icons.top)
case _ => Some(Icons.side)
}
}
override def icon(side: ForgeDirection) =
side match {
Some(side match {
case ForgeDirection.SOUTH => Icons.front
case ForgeDirection.DOWN | ForgeDirection.UP => Icons.top
case _ => Icons.side
}
})
override def registerIcons(iconRegister: IconRegister) = {
Icons.front = iconRegister.registerIcon("opencomputers:screen_front")
@ -53,7 +53,7 @@ class Screen(val parent: Delegator) extends Delegate {
override def hasTileEntity = true
override def createTileEntity(world: World, metadata: Int) = new TileEntityScreen
override def createTileEntity(world: World, metadata: Int) = Some(new tileentity.Screen)
// ----------------------------------------------------------------------- //
// Interaction

View File

@ -6,7 +6,7 @@ import net.minecraft.world.World
import net.minecraftforge.common.ForgeDirection
/** Used for sub blocks that need special rendering. */
class SpecialMulti(id: Int) extends Delegator(id) {
class SpecialDelegator(id: Int) extends Delegator(id) {
override def getRenderType = Config.blockRenderId
override def isBlockNormalCube(world: World, x: Int, y: Int, z: Int) =

View File

@ -1,11 +1,11 @@
package li.cil.oc.common.container
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity
import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.inventory.Slot
import net.minecraft.item.ItemStack
class Computer(playerInventory: InventoryPlayer, computer: TileEntityComputer) extends Player(playerInventory, computer) {
class Computer(playerInventory: InventoryPlayer, computer: tileentity.Computer) extends Player(playerInventory, computer) {
// PSU
addSlotToContainer(new Slot(computer, 0, 58, 17) {
override def isItemValid(item: ItemStack) = {

View File

@ -17,7 +17,7 @@ trait Delegate {
// Item
// ----------------------------------------------------------------------- //
def icon: Icon = null
def icon: Option[Icon] = None
def onItemRightClick(item: ItemStack, world: World, player: EntityPlayer): ItemStack = item

View File

@ -49,8 +49,8 @@ class Delegator(id: Int) extends Item(id) {
subItem(damage) match {
case None => super.getIconFromDamage(damage)
case Some(subItem) => subItem.icon match {
case null => super.getIconFromDamage(damage)
case icon => icon
case None => super.getIconFromDamage(damage)
case Some(icon) => icon
}
}

View File

@ -1,19 +1,19 @@
package li.cil.oc.common.tileentity
import li.cil.oc.api.driver.Slot
import li.cil.oc.api.network.Node
import li.cil.oc.common.component
import li.cil.oc.server.driver.Registry
import net.minecraft.inventory.IInventory
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.nbt.NBTTagList
import net.minecraft.world.World
import li.cil.oc.api.driver.Slot
import li.cil.oc.common.component.Computer
import li.cil.oc.server.driver.Registry
trait ItemComponentProxy extends IInventory with Node {
trait ComponentInventory extends IInventory with Node {
protected val inventory = new Array[ItemStack](8)
protected val computer: Computer
protected val computer: component.Computer
def world: World

View File

@ -2,20 +2,22 @@ package li.cil.oc.common.tileentity
import java.util.concurrent.atomic.AtomicBoolean
import li.cil.oc.api.network.Message
import li.cil.oc.client.computer.{Computer => ClientComputer}
import li.cil.oc.client.component.{Computer => ClientComputer}
import li.cil.oc.client.{PacketSender => ClientPacketSender}
import li.cil.oc.server.component.{Computer, RedstoneEnabled}
import li.cil.oc.server.component.Computer.{Environment => ComputerEnvironment}
import li.cil.oc.server.component.RedstoneEnabled
import li.cil.oc.server.component.{Computer => ServerComputer}
import li.cil.oc.server.{PacketSender => ServerPacketSender}
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.ForgeDirection
class TileEntityComputer(isClient: Boolean) extends TileEntityRotatable with Computer.Environment with ItemComponentProxy with RedstoneEnabled {
class Computer(isClient: Boolean) extends Rotatable with ComputerEnvironment with ComponentInventory with RedstoneEnabled {
def this() = this(false)
protected val computer =
if (isClient) new ClientComputer(this)
else new Computer(this)
else new ServerComputer(this)
private val hasChanged = new AtomicBoolean(true)

View File

@ -5,7 +5,7 @@ import li.cil.oc.api.network.{Visibility, Node, Message}
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.nbt.NBTTagCompound
class TileEntityKeyboard extends TileEntityRotatable with Node {
class Keyboard extends Rotatable with Node {
override def name = "keyboard"
override def visibility = Visibility.Network

View File

@ -9,7 +9,7 @@ import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.ForgeDirection
/** TileEntity base class for rotatable blocks. */
abstract class TileEntityRotatable extends TileEntity {
abstract class Rotatable extends TileEntity {
// ----------------------------------------------------------------------- //
// Lookup tables
// ----------------------------------------------------------------------- //

View File

@ -1,13 +1,13 @@
package li.cil.oc.common.tileentity
import li.cil.oc.client.gui.Screen
import li.cil.oc.client.gui
import li.cil.oc.client.{PacketSender => ClientPacketSender}
import li.cil.oc.common.component.ScreenEnvironment
import li.cil.oc.server.{PacketSender => ServerPacketSender}
import net.minecraft.nbt.NBTTagCompound
class TileEntityScreen extends TileEntityRotatable with ScreenEnvironment {
var gui: Option[Screen] = None
class Screen extends Rotatable with ScreenEnvironment {
var guiScreen: Option[gui.Screen] = None
override def readFromNBT(nbt: NBTTagCompound) = {
super.readFromNBT(nbt)
@ -35,7 +35,7 @@ class TileEntityScreen extends TileEntityRotatable with ScreenEnvironment {
override def onScreenResolutionChange(w: Int, h: Int) = {
super.onScreenResolutionChange(w, h)
if (worldObj.isRemote) {
gui.foreach(_.setSize(w, h))
guiScreen.foreach(_.setSize(w, h))
}
else {
markAsChanged()
@ -46,7 +46,7 @@ class TileEntityScreen extends TileEntityRotatable with ScreenEnvironment {
override def onScreenSet(col: Int, row: Int, s: String) = {
super.onScreenSet(col, row, s)
if (worldObj.isRemote) {
gui.foreach(_.updateText())
guiScreen.foreach(_.updateText())
}
else {
markAsChanged()
@ -57,7 +57,7 @@ class TileEntityScreen extends TileEntityRotatable with ScreenEnvironment {
override def onScreenFill(col: Int, row: Int, w: Int, h: Int, c: Char) = {
super.onScreenFill(col, row, w, h, c)
if (worldObj.isRemote) {
gui.foreach(_.updateText())
guiScreen.foreach(_.updateText())
}
else {
markAsChanged()
@ -68,7 +68,7 @@ class TileEntityScreen extends TileEntityRotatable with ScreenEnvironment {
override def onScreenCopy(col: Int, row: Int, w: Int, h: Int, tx: Int, ty: Int) = {
super.onScreenCopy(col, row, w, h, tx, ty)
if (worldObj.isRemote) {
gui.foreach(_.updateText())
guiScreen.foreach(_.updateText())
}
else {
markAsChanged()

View File

@ -4,9 +4,9 @@ import cpw.mods.fml.common.network.Player
import li.cil.oc.api.network.Node
import li.cil.oc.common.PacketBuilder
import li.cil.oc.common.PacketType
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity.TileEntityRotatable
import li.cil.oc.common.tileentity.TileEntityScreen
import li.cil.oc.common.tileentity.Computer
import li.cil.oc.common.tileentity.Rotatable
import li.cil.oc.common.tileentity.Screen
import li.cil.oc.common.{PacketHandler => CommonPacketHandler}
import net.minecraftforge.common.DimensionManager
@ -26,7 +26,7 @@ class PacketHandler extends CommonPacketHandler {
}
def onScreenBufferRequest(p: PacketParser) =
p.readTileEntity[TileEntityScreen]() match {
p.readTileEntity[Screen]() match {
case None => // Invalid packet.
case Some(t) => {
val pb = new PacketBuilder(PacketType.ScreenBufferResponse)
@ -39,7 +39,7 @@ class PacketHandler extends CommonPacketHandler {
}
def onComputerStateRequest(p: PacketParser) =
p.readTileEntity[TileEntityComputer]() match {
p.readTileEntity[Computer]() match {
case None => // Invalid packet.
case Some(t) => {
val pb = new PacketBuilder(PacketType.ComputerStateResponse)
@ -52,7 +52,7 @@ class PacketHandler extends CommonPacketHandler {
}
def onRotatableStateRequest(p: PacketParser) =
p.readTileEntity[TileEntityRotatable]() match {
p.readTileEntity[Rotatable]() match {
case None => // Invalid packet.
case Some(t) => {
val pb = new PacketBuilder(PacketType.RotatableStateResponse)

View File

@ -2,7 +2,7 @@ package li.cil.oc.server
import li.cil.oc.common.PacketBuilder
import li.cil.oc.common.PacketType
import li.cil.oc.common.tileentity.TileEntityRotatable
import li.cil.oc.common.tileentity.Rotatable
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.ForgeDirection
@ -65,7 +65,7 @@ object PacketSender {
pb.sendToAllPlayers()
}
def sendRotatableRotate(t: TileEntityRotatable, pitch: ForgeDirection, yaw: ForgeDirection) = {
def sendRotatableRotate(t: Rotatable, pitch: ForgeDirection, yaw: ForgeDirection) = {
val pb = new PacketBuilder(PacketType.RotatableStateResponse)
pb.writeTileEntity(t)

View File

@ -1,15 +1,15 @@
package li.cil.oc.server.component
import com.naef.jnlua._
import com.naef.jnlua.{LuaRuntimeException, LuaMemoryAllocationException, LuaType, LuaState}
import java.lang.Thread.UncaughtExceptionHandler
import java.util.concurrent._
import java.util.concurrent.atomic.AtomicInteger
import java.util.logging.Level
import li.cil.oc.api.network.{Visibility, Node}
import li.cil.oc.common.component
import li.cil.oc.common.tileentity.TileEntityComputer
import li.cil.oc.common.tileentity
import li.cil.oc.server.driver
import li.cil.oc.util.ExtendedLuaState._
import li.cil.oc.util.ExtendedLuaState.extendLuaState
import li.cil.oc.util.LuaStateFactory
import li.cil.oc.{OpenComputers, Config}
import net.minecraft.nbt._
@ -191,11 +191,11 @@ class Computer(val owner: Computer.Environment) extends component.Computer with
// Check if we should switch states.
stateMonitor.synchronized(state match {
// Resume from pauses based on signal underflow.
case Computer.State.Suspended if signals.nonEmpty => {
case Computer.State.Suspended if !signals.isEmpty => {
assert(future.isEmpty)
execute(Computer.State.Yielded)
}
case Computer.State.Sleeping if lastUpdate >= sleepUntil || signals.nonEmpty => {
case Computer.State.Sleeping if lastUpdate >= sleepUntil || !signals.isEmpty => {
assert(future.isEmpty)
execute(Computer.State.Yielded)
}
@ -793,8 +793,8 @@ object Computer {
private def onUnload(w: World, tileEntities: Iterable[TileEntity]) = if (!w.isRemote) {
tileEntities.
filter(_.isInstanceOf[TileEntityComputer]).
map(_.asInstanceOf[TileEntityComputer]).
filter(_.isInstanceOf[tileentity.Computer]).
map(_.asInstanceOf[tileentity.Computer]).
foreach(_.turnOff())
}

View File

@ -2,16 +2,10 @@ package li.cil.oc.util
import com.naef.jnlua.{JavaFunction, LuaState}
class ExtendedLuaState(val state: LuaState) {
def pushScalaFunction(f: (LuaState) => Int) = state.pushJavaFunction(new ExtendedLuaState.ScalaFunction(f))
}
object ExtendedLuaState {
implicit def extendLuaState(lua: LuaState) = new ExtendedLuaState(lua)
private class ScalaFunction(val f: (LuaState) => Int) extends JavaFunction {
override def invoke(state: LuaState) = f(state)
implicit def extendLuaState(state: LuaState) = new {
def pushScalaFunction(f: (LuaState) => Int) = state.pushJavaFunction(new JavaFunction {
override def invoke(state: LuaState) = f(state)
})
}
}