Added command to generate debug nanomachine configuration (/oc_debugNanomachines or /oc_dn).

This commit is contained in:
Florian Nücke 2015-09-21 20:54:02 +02:00
parent f3f7fb559e
commit 2b970bc65a
4 changed files with 68 additions and 0 deletions

View File

@ -290,6 +290,13 @@ class ControllerImpl(val player: EntityPlayer) extends Controller with WirelessE
}
}
def debug(): Unit = {
if (isServer) {
configuration.debug()
activeBehaviorsDirty = true
}
}
// ----------------------------------------------------------------------- //
def save(nbt: NBTTagCompound): Unit = configuration.synchronized {

View File

@ -1,5 +1,6 @@
package li.cil.oc.common.nanomachines
import li.cil.oc.OpenComputers
import li.cil.oc.Settings
import li.cil.oc.api
import li.cil.oc.api.Persistable
@ -83,6 +84,29 @@ class NeuralNetwork(controller: ControllerImpl) extends Persistable {
behaviorMap ++= behaviors.map(n => n.behavior -> n)
}
// Enter debug configuration, one input -> one behavior, and list mapping in console.
def debug(): Unit = {
OpenComputers.log.info(s"Creating debug configuration for nanomachines in player ${controller.player.getDisplayName}.")
behaviors.clear()
behaviors ++= api.Nanomachines.getProviders.
map(p => (p, Option(p.createBehaviors(controller.player)).map(_.filter(_ != null)).orNull)). // Remove null behaviors.
filter(_._2 != null). // Remove null lists..
flatMap(pb => pb._2.map(b => new BehaviorNeuron(pb._1, b)))
connectors.clear()
triggers.clear()
for (i <- behaviors.indices) {
val behavior = behaviors(i)
val trigger = new TriggerNeuron()
triggers += trigger
behavior.inputs += trigger
OpenComputers.log.info(s"$i -> ${behavior.behavior.getNameHint} (${behavior.behavior.getClass.toString})")
}
}
override def save(nbt: NBTTagCompound): Unit = {
nbt.setNewTagList("triggers", triggers.map(t => {
val nbt = new NBTTagCompound()

View File

@ -4,6 +4,7 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent
object CommandHandler {
def register(e: FMLServerStartingEvent) {
e.registerServerCommand(DebugNanomachinesCommand)
e.registerServerCommand(NonDisassemblyAgreementCommand)
e.registerServerCommand(WirelessRenderingCommand)
e.registerServerCommand(SpawnComputerCommand)

View File

@ -0,0 +1,36 @@
package li.cil.oc.server.command
import li.cil.oc.api
import li.cil.oc.common.command.SimpleCommand
import li.cil.oc.common.nanomachines.ControllerImpl
import net.minecraft.command.ICommandSender
import net.minecraft.command.WrongUsageException
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.ChatComponentText
object DebugNanomachinesCommand extends SimpleCommand("oc_debugNanomachines") {
aliases += "oc_dn"
override def getCommandUsage(source: ICommandSender): String = name
override def processCommand(source: ICommandSender, command: Array[String]) {
source match {
case player: EntityPlayer =>
api.Nanomachines.installController(player) match {
case controller: ControllerImpl =>
controller.debug()
player.addChatMessage(new ChatComponentText("Debug configuration created, see log for mappings."))
case _ => // Someone did something.
}
case _ => throw new WrongUsageException("Can only be used by players.")
}
}
// OP levels for reference:
// 1 - Ops can bypass spawn protection.
// 2 - Ops can use /clear, /difficulty, /effect, /gamemode, /gamerule, /give, /summon, /setblock and /tp, and can edit command blocks.
// 3 - Ops can use /ban, /deop, /kick, and /op.
// 4 - Ops can use /stop.
override def getRequiredPermissionLevel = 2
}