Some refactoring to get rid of the use of 'router' instead of 'switch' for consistency.

This commit is contained in:
Florian Nücke 2014-07-15 16:24:40 +02:00
parent d4618e6d6d
commit 828213ceb7
17 changed files with 44 additions and 45 deletions

View File

@ -14,7 +14,7 @@ import net.minecraftforge.common.ForgeDirection;
* It is used to determine which neighbors a tile entity can connect to when
* calling {@link li.cil.oc.api.Network#joinOrCreateNetwork(TileEntity)}. It is
* used by the keyboard to only interface with the side on which it is attached,
* as well as the router to offer a different node for each side.
* as well as the switch to offer a different node for each side.
*/
public interface SidedEnvironment {
/**

View File

@ -41,10 +41,10 @@ object Blocks {
GameRegistry.registerTileEntity(classOf[tileentity.Redstone], Settings.namespace + "redstone")
GameRegistry.registerTileEntity(classOf[tileentity.RobotProxy], Settings.namespace + "robot")
GameRegistry.registerTileEntity(classOf[tileentity.RobotAssembler], Settings.namespace + "robotAssembler")
GameRegistry.registerTileEntity(classOf[tileentity.Router], Settings.namespace + "router")
GameRegistry.registerTileEntity(classOf[tileentity.Switch], Settings.namespace + "router")
GameRegistry.registerTileEntity(classOf[tileentity.Screen], Settings.namespace + "screen")
GameRegistry.registerTileEntity(classOf[tileentity.Rack], Settings.namespace + "serverRack")
GameRegistry.registerTileEntity(classOf[tileentity.WirelessRouter], Settings.namespace + "wireless_router")
GameRegistry.registerTileEntity(classOf[tileentity.AccessPoint], Settings.namespace + "wireless_router")
// IMPORTANT: the multi block must come first, since the sub blocks will
// try to register with it. Also, the order the sub blocks are created in

View File

@ -1,13 +1,13 @@
package li.cil.oc.client
import li.cil.oc.api.component.TextBuffer
import li.cil.oc.common.inventory.ServerInventory
import li.cil.oc.common.item.Tablet
import li.cil.oc.common.{GuiType, item, tileentity, GuiHandler => CommonGuiHandler}
import li.cil.oc.{Items, Localization, Settings}
import net.minecraft.client.Minecraft
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.world.World
import li.cil.oc.api.component.TextBuffer
import li.cil.oc.common.item.Tablet
object GuiHandler extends CommonGuiHandler {
override def getClientGuiElement(id: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): AnyRef =
@ -26,8 +26,8 @@ object GuiHandler extends CommonGuiHandler {
new gui.RobotAssembler(player.inventory, assembler)
case screen: tileentity.Screen if id == GuiType.Screen.id =>
new gui.Screen(screen.origin.buffer, screen.tier > 0, () => screen.origin.hasKeyboard, () => screen.origin.buffer.isRenderingEnabled)
case router: tileentity.Router if id == GuiType.Router.id =>
new gui.Router(player.inventory, router)
case switch: tileentity.Switch if id == GuiType.Switch.id =>
new gui.Switch(player.inventory, switch)
case _ => Items.multi.subItem(player.getCurrentEquippedItem) match {
case Some(server: item.Server) if id == GuiType.Server.id =>
new gui.Server(player.inventory, new ServerInventory {

View File

@ -44,7 +44,7 @@ class PacketHandler extends CommonPacketHandler {
case PacketType.RobotMove => onRobotMove(p)
case PacketType.RobotSelectedSlotChange => onRobotSelectedSlotChange(p)
case PacketType.RotatableState => onRotatableState(p)
case PacketType.RouterActivity => onRouterActivity(p)
case PacketType.SwitchActivity => onSwitchActivity(p)
case PacketType.TextBufferColorChange => onTextBufferColorChange(p)
case PacketType.TextBufferCopy => onTextBufferCopy(p)
case PacketType.TextBufferDepthChange => onTextBufferDepthChange(p)
@ -265,8 +265,8 @@ class PacketHandler extends CommonPacketHandler {
case _ => // Invalid packet.
}
def onRouterActivity(p: PacketParser) =
p.readTileEntity[Router]() match {
def onSwitchActivity(p: PacketParser) =
p.readTileEntity[Switch]() match {
case Some(t) => t.lastMessage = System.currentTimeMillis()
case _ => // Invalid packet.
}

View File

@ -42,8 +42,8 @@ private[oc] class Proxy extends CommonProxy {
ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.PowerDistributor], PowerDistributorRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Rack], RackRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.RobotAssembler], RobotAssemblerRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Router], RouterRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.WirelessRouter], RouterRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Switch], SwitchRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.AccessPoint], SwitchRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.RobotProxy], RobotRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Screen], ScreenRenderer)

View File

@ -4,11 +4,11 @@ import li.cil.oc.common.{container, tileentity}
import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.util.StatCollector
class Router(playerInventory: InventoryPlayer, val router: tileentity.Router) extends DynamicGuiContainer(new container.Router(playerInventory, router)) {
class Switch(playerInventory: InventoryPlayer, val switch: tileentity.Switch) extends DynamicGuiContainer(new container.Switch(playerInventory, switch)) {
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) = {
super.drawGuiContainerForegroundLayer(mouseX, mouseY)
fontRenderer.drawString(
StatCollector.translateToLocal(router.getInvName),
StatCollector.translateToLocal(switch.getInvName),
8, 6, 0x404040)
}
}

View File

@ -9,12 +9,12 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
import org.lwjgl.opengl.GL11
object RouterRenderer extends TileEntitySpecialRenderer {
object SwitchRenderer extends TileEntitySpecialRenderer {
override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) {
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
val router = tileEntity.asInstanceOf[tileentity.Router]
val activity = math.max(0, 1 - (System.currentTimeMillis() - router.lastMessage) / 1000.0)
val switch = tileEntity.asInstanceOf[tileentity.Switch]
val activity = math.max(0, 1 - (System.currentTimeMillis() - switch.lastMessage) / 1000.0)
if (activity > 0) {
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS)

View File

@ -21,8 +21,8 @@ abstract class GuiHandler extends IGuiHandler {
new container.Rack(player.inventory, rack)
case assembler: tileentity.RobotAssembler if id == GuiType.RobotAssembler.id =>
new container.RobotAssembler(player.inventory, assembler)
case router: tileentity.Router if id == GuiType.Router.id =>
new container.Router(player.inventory, router)
case switch: tileentity.Switch if id == GuiType.Switch.id =>
new container.Switch(player.inventory, switch)
case _ => Items.multi.subItem(player.getCurrentEquippedItem) match {
case Some(server: item.Server) if id == GuiType.Server.id =>
new container.Server(player.inventory, new ServerInventory {

View File

@ -25,7 +25,7 @@ object PacketType extends Enumeration {
RobotMove,
RobotSelectedSlotChange,
RotatableState,
RouterActivity,
SwitchActivity,
TextBufferColorChange,
TextBufferCopy,
TextBufferDepthChange,

View File

@ -52,5 +52,5 @@ class AccessPoint(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.WirelessRouter)
override def createTileEntity(world: World) = Some(new tileentity.AccessPoint)
}

View File

@ -2,10 +2,10 @@ package li.cil.oc.common.block
import java.util
import li.cil.oc.{OpenComputers, Settings}
import li.cil.oc.client.Textures
import li.cil.oc.common.{GuiType, tileentity}
import li.cil.oc.util.Tooltip
import li.cil.oc.{OpenComputers, Settings}
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.world.World
@ -40,12 +40,12 @@ class Switch(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Router)
override def createTileEntity(world: World) = Some(new tileentity.Switch)
override def rightClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
world.getBlockTileEntity(x, y, z) match {
case switch: tileentity.Router =>
case switch: tileentity.Switch =>
if (!player.isSneaking) {
if (!world.isRemote) {
player.openGui(OpenComputers, GuiType.Switch.id, world, x, y, z)
@ -53,7 +53,6 @@ class Switch(val parent: SimpleDelegator) extends SimpleDelegate {
true
}
else false
}
}
}

View File

@ -4,7 +4,7 @@ import li.cil.oc.api
import li.cil.oc.common.tileentity
import net.minecraft.entity.player.InventoryPlayer
class Router(playerInventory: InventoryPlayer, router: tileentity.Router) extends Player(playerInventory, router) {
class Switch(playerInventory: InventoryPlayer, switch: tileentity.Switch) extends Player(playerInventory, switch) {
addSlotToContainer(60, 35, api.driver.Slot.Processor)
addSlotToContainer(95, 35, api.driver.Slot.Memory)
addPlayerInventorySlots(8, 84)

View File

@ -10,7 +10,7 @@ import net.minecraftforge.common.ForgeDirection
import scala.collection.convert.WrapAsScala._
class WirelessRouter extends Router with WirelessEndpoint {
class AccessPoint extends Switch with WirelessEndpoint {
var strength = Settings.get.maxWirelessRange
val componentNodes = Array.fill(6)(api.Network.newNode(this, Visibility.Network).withComponent("access_point").create())

View File

@ -28,7 +28,7 @@ import li.cil.oc.api.driver.{Processor, Memory, Slot}
// old API, so there should be no ClassNotFoundExceptions anyway.
@Optional.Interface(iface = "dan200.computer.api.IPeripheral", modid = "ComputerCraft")
class Router extends traits.Hub with traits.NotAnalyzable with IPeripheral with traits.ComponentInventory {
class Switch extends traits.Hub with traits.NotAnalyzable with IPeripheral with traits.ComponentInventory {
var lastMessage = 0L
val computers = mutable.Map.empty[AnyRef, ComputerWrapper]
@ -94,7 +94,7 @@ class Router extends traits.Hub with traits.NotAnalyzable with IPeripheral with
val data = Seq(Int.box(answerPort)) ++ arguments.drop(2)
val packet = api.Network.newPacket(s"cc${computerId}_$attachmentName", null, sendPort, data.toArray)
result(tryEnqueuePacket(ForgeDirection.UNKNOWN, packet))
case "isWireless" => result(this.isInstanceOf[WirelessRouter])
case "isWireless" => result(this.isInstanceOf[AccessPoint])
case _ => null
}
@ -127,7 +127,7 @@ class Router extends traits.Hub with traits.NotAnalyzable with IPeripheral with
val now = System.currentTimeMillis()
if (now - lastMessage >= (relayDelay - 1) * 50) {
lastMessage = now
PacketSender.sendRouterActivity(this)
PacketSender.sendSwitchActivity(this)
}
}

View File

@ -243,8 +243,8 @@ object PacketSender {
pb.sendToNearbyPlayers(t)
}
def sendRouterActivity(t: tileentity.Router) {
val pb = new PacketBuilder(PacketType.RouterActivity)
def sendSwitchActivity(t: tileentity.Switch) {
val pb = new PacketBuilder(PacketType.SwitchActivity)
pb.writeTileEntity(t)

View File

@ -6,7 +6,7 @@ import dan200.computercraft.api.lua.ILuaContext
import dan200.computercraft.api.media.IMedia
import dan200.computercraft.api.peripheral.{IComputerAccess, IPeripheral, IPeripheralProvider}
import li.cil.oc
import li.cil.oc.common.tileentity.{ComputerWrapper, Router}
import li.cil.oc.common.tileentity.{ComputerWrapper, Switch}
import li.cil.oc.server.fs.{CC16FileSystem, CC16WritableFileSystem}
import net.minecraft.item.ItemStack
import net.minecraft.world.World
@ -17,7 +17,7 @@ object ComputerCraft16 {
def init() {
ComputerCraftAPI.registerPeripheralProvider(new IPeripheralProvider {
override def getPeripheral(world: World, x: Int, y: Int, z: Int, side: Int) = world.getBlockTileEntity(x, y, z) match {
case router: Router => new RouterPeripheral(router)
case switch: Switch => new RouterPeripheral(switch)
case _ => null
}
})
@ -33,32 +33,32 @@ object ComputerCraft16 {
case ro: IMount => new CC16FileSystem(ro)
}
class RouterPeripheral(val router: Router) extends IPeripheral {
override def getType = router.getType
class RouterPeripheral(val switch: Switch) extends IPeripheral {
override def getType = switch.getType
override def attach(computer: IComputerAccess) {
router.computers += computer -> new ComputerWrapper {
switch.computers += computer -> new ComputerWrapper {
override def id = computer.getID
override def attachmentName = computer.getAttachmentName
override def queueEvent(name: String, args: Array[AnyRef]) = computer.queueEvent(name, args)
}
router.openPorts += computer -> mutable.Set.empty
switch.openPorts += computer -> mutable.Set.empty
}
override def detach(computer: IComputerAccess) {
router.computers -= computer
router.openPorts -= computer
switch.computers -= computer
switch.openPorts -= computer
}
override def getMethodNames = router.getMethodNames
override def getMethodNames = switch.getMethodNames
override def callMethod(computer: IComputerAccess, context: ILuaContext, method: Int, arguments: Array[AnyRef]) =
router.callMethod(computer, computer.getID, computer.getAttachmentName, method, arguments)
switch.callMethod(computer, computer.getID, computer.getAttachmentName, method, arguments)
override def equals(other: IPeripheral) = other match {
case rp: RouterPeripheral => rp.router == router
case peripheral: RouterPeripheral => peripheral.switch == switch
case _ => false
}
}

View File

@ -18,8 +18,8 @@ object Waila {
registrar.registerSyncedNBTKey(Settings.namespace + "node", classOf[tileentity.Hologram])
registrar.registerSyncedNBTKey(Settings.namespace + "keyboard", classOf[tileentity.Keyboard])
registrar.registerSyncedNBTKey("node", classOf[tileentity.Screen])
registrar.registerSyncedNBTKey(Settings.namespace + "componentNodes", classOf[tileentity.WirelessRouter])
registrar.registerSyncedNBTKey(Settings.namespace + "strength", classOf[tileentity.WirelessRouter])
registrar.registerSyncedNBTKey(Settings.namespace + "componentNodes", classOf[tileentity.AccessPoint])
registrar.registerSyncedNBTKey(Settings.namespace + "strength", classOf[tileentity.AccessPoint])
}
def isSavingForTooltip = new Exception().getStackTrace.exists(_.getClassName.startsWith("mcp.mobius.waila"))