Added a debug item to allow debugging OC component networks better while not in dev-env.

This commit is contained in:
Florian Nücke 2014-11-22 11:54:25 +01:00
parent aec5457739
commit a96aa6a997
9 changed files with 111 additions and 10 deletions

Binary file not shown.

View File

@ -49,6 +49,7 @@ item.oc.CPU1.name=Central Processing Unit (CPU) (Tier 2)
item.oc.CPU2.name=Central Processing Unit (CPU) (Tier 3)
item.oc.CuttingWire.name=Cutting Wire
item.oc.DebugCard.name=Debug Card
item.oc.Debugger.name=Network Debugger
item.oc.Disk.name=Disk Platter
item.oc.FloppyDisk.name=Floppy Disk
item.oc.GraphicsCard0.name=Graphics Card (Tier 1)
@ -203,6 +204,7 @@ oc:tooltip.CPU=An essential component of all computers. The clock rate is a bit
oc:tooltip.CPU.Architecture=Architecture: §f%s§7
oc:tooltip.CuttingWire=Used to cut clay blocks into circuit board shape. Breaks after one use, which probably makes it the most inefficient tool ever.
oc:tooltip.DebugCard=Creative mode item, allows manipulating the world to make testing easier. Use at your own peril.
oc:tooltip.Debugger=Can be used to output debug information on OC's internal network grid. Only use if so instructed by a dev.
oc:tooltip.Disassembler=Separates items into their original components. §lWarning§7: returned items have a %s%% chance of breaking in the process!
oc:tooltip.Disk=Primitive medium that can be used to build persistent storage devices.
oc:tooltip.DiskDrive.CC=ComputerCraft floppies are §asupported§7.

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

View File

@ -11,7 +11,6 @@
"requiredMods": [ "Forge@[10.13.0.1180,)" ],
"dependencies": [
"BuildCraft|Core",
"BuildCraft|Energy",
"ComputerCraft",
"EnderStorage",
"ForgeMultipart",

View File

@ -4,6 +4,7 @@ import com.google.common.base.Strings
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import cpw.mods.fml.relauncher.Side
import cpw.mods.fml.relauncher.SideOnly
import li.cil.oc.OpenComputers
import li.cil.oc.Settings
import li.cil.oc.api
import li.cil.oc.api.component.TextBuffer.ColorDepth
@ -24,6 +25,7 @@ import li.cil.oc.util
import li.cil.oc.util.BlockPosition
import li.cil.oc.util.PackedColor
import li.cil.oc.util.SideTracker
import net.minecraft.client.Minecraft
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.event.world.ChunkEvent
@ -551,26 +553,48 @@ object TextBuffer {
dirty = true
}
override def keyDown(character: Char, code: Int, player: EntityPlayer) =
override def keyDown(character: Char, code: Int, player: EntityPlayer) {
debug(s"{type = keyDown, char = $character, code = $code}")
ClientPacketSender.sendKeyDown(nodeAddress, character, code)
}
override def keyUp(character: Char, code: Int, player: EntityPlayer) =
override def keyUp(character: Char, code: Int, player: EntityPlayer) {
debug(s"{type = keyUp, char = $character, code = $code}")
ClientPacketSender.sendKeyUp(nodeAddress, character, code)
}
override def clipboard(value: String, player: EntityPlayer) =
override def clipboard(value: String, player: EntityPlayer) {
debug(s"{type = clipboard}")
ClientPacketSender.sendClipboard(nodeAddress, value)
}
override def mouseDown(x: Int, y: Int, button: Int, player: EntityPlayer) =
override def mouseDown(x: Int, y: Int, button: Int, player: EntityPlayer) {
debug(s"{type = mouseDown, x = $x, y = $y, button = $button}")
ClientPacketSender.sendMouseClick(nodeAddress, x, y, drag = false, button)
}
override def mouseDrag(x: Int, y: Int, button: Int, player: EntityPlayer) =
override def mouseDrag(x: Int, y: Int, button: Int, player: EntityPlayer) {
debug(s"{type = mouseDrag, x = $x, y = $y, button = $button}")
ClientPacketSender.sendMouseClick(nodeAddress, x, y, drag = true, button)
}
override def mouseUp(x: Int, y: Int, button: Int, player: EntityPlayer) =
override def mouseUp(x: Int, y: Int, button: Int, player: EntityPlayer) {
debug(s"{type = mouseUp, x = $x, y = $y, button = $button}")
ClientPacketSender.sendMouseUp(nodeAddress, x, y, button)
}
override def mouseScroll(x: Int, y: Int, delta: Int, player: EntityPlayer) =
override def mouseScroll(x: Int, y: Int, delta: Int, player: EntityPlayer) {
debug(s"{type = mouseScroll, x = $x, y = $y, delta = $delta}")
ClientPacketSender.sendMouseScroll(nodeAddress, x, y, delta)
}
private lazy val Debugger = api.Items.get("debugger")
private def debug(message: String) {
if (api.Items.get(Minecraft.getMinecraft.thePlayer.getHeldItem) == Debugger) {
OpenComputers.log.info(s"[NETWORK DEBUGGER] Sending packet to node $nodeAddress: " + message)
}
}
}
class ServerProxy(val owner: TextBuffer) extends Proxy {

View File

@ -255,5 +255,6 @@ object Items extends ItemAPI {
Recipes.addItem(new item.UpgradeDatabase(multi, Tier.One), "databaseUpgrade1", "oc:databaseUpgrade1")
Recipes.addItem(new item.UpgradeDatabase(multi, Tier.Two), "databaseUpgrade2", "oc:databaseUpgrade2")
Recipes.addItem(new item.UpgradeDatabase(multi, Tier.Three), "databaseUpgrade3", "oc:databaseUpgrade3")
registerItem(new item.Debugger(multi), "debugger")
}
}

View File

@ -0,0 +1,73 @@
package li.cil.oc.common.item
import li.cil.oc.OpenComputers
import li.cil.oc.api
import li.cil.oc.api.network._
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.item.ItemStack
import net.minecraft.world.World
import net.minecraftforge.common.util.ForgeDirection
class Debugger(val parent: Delegator) extends Delegate {
override def onItemUse(stack: ItemStack, player: EntityPlayer, world: World, x: Int, y: Int, z: Int, side: Int, hitX: Float, hitY: Float, hitZ: Float) = {
player match {
case realPlayer: EntityPlayerMP =>
world.getTileEntity(x, y, z) match {
case host: SidedEnvironment =>
if (!world.isRemote) {
Debugger.reconnect(Array(host.sidedNode(ForgeDirection.getOrientation(side))))
}
true
case host: Environment =>
if (!world.isRemote) {
Debugger.reconnect(Array(host.node))
}
true
case _ =>
if (!world.isRemote) {
Debugger.node.remove()
}
true
}
case _ => false
}
}
}
object Debugger extends Environment {
var node = api.Network.newNode(this, Visibility.Network).create()
override def onConnect(node: Node) {
OpenComputers.log.info(s"[NETWORK DEBUGGER] New node in network: ${nodeInfo(node)}")
}
override def onDisconnect(node: Node) {
OpenComputers.log.info(s"[NETWORK DEBUGGER] Node removed from network: ${nodeInfo(node)}")
}
override def onMessage(message: Message) {
OpenComputers.log.info(s"[NETWORK DEBUGGER] Received message: ${messageInfo(message)}.")
}
def reconnect(nodes: Array[Node]) {
node.remove()
api.Network.joinNewNetwork(node)
for (node <- nodes if node != null) {
this.node.connect(node)
}
}
private def nodeInfo(node: Node) = s"{address = ${node.address}, reachability = ${node.reachability.name}" + (node match {
case componentConnector: ComponentConnector => componentInfo(componentConnector) + connectorInfo(componentConnector)
case component: Component => componentInfo(component)
case connector: Connector => connectorInfo(connector)
case _ =>
}) + "}"
private def componentInfo(component: Component) = s", type = component, name = ${component.name}, visibility = ${component.visibility.name}"
private def connectorInfo(connector: Connector) = s", type = connector, buffer = ${connector.localBuffer}, bufferSize = ${connector.localBufferSize}"
private def messageInfo(message: Message) = s"{name = ${message.name()}, source = ${nodeInfo(message.source)}, data = [${message.data.mkString(", ")}]}"
}

View File

@ -108,10 +108,10 @@ object Mods {
val isBlacklisted = Settings.get.modBlacklist.contains(mod.getMod.id)
val alwaysEnabled = mod.getMod == null || mod.getMod == Mods.Minecraft
if (!isBlacklisted && (alwaysEnabled || mod.getMod.isAvailable) && handlers.add(mod)) {
li.cil.oc.OpenComputers.log.info(String.format("Initializing mod integration for '%s'.", mod.getMod.id))
li.cil.oc.OpenComputers.log.info(s"Initializing mod integration for '${mod.getMod.id}'.")
try mod.initialize() catch {
case e: Throwable =>
li.cil.oc.OpenComputers.log.warn(String.format("Error initializing integration for '%s'", mod.getMod.id), e)
li.cil.oc.OpenComputers.log.warn(s"Error initializing integration for '${mod.getMod.id}'", e)
}
}
}

View File

@ -679,6 +679,8 @@ object Network extends api.detail.NetworkAPI {
case value => OpenComputers.log.warn("Unexpected type while saving network packet: " + value.getClass.getName)
}
}
override def toString = s"{source = $source, destination = $destination, port = $port, data = [${data.mkString(", ")}}]}"
}
// ----------------------------------------------------------------------- //