From 30128f6850eceaaadbc0838e246989ebf783296e Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Tue, 15 Oct 2013 11:42:33 -0400 Subject: [PATCH] Set up IF command --- .../dark/api/al/armbot/IProgram.java | 17 +++++++++++--- .../common/armbot/command/CommandIF.java | 23 ++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/minecraft/dark/api/al/armbot/IProgram.java b/src/minecraft/dark/api/al/armbot/IProgram.java index 953fb43f9..3e12657a9 100644 --- a/src/minecraft/dark/api/al/armbot/IProgram.java +++ b/src/minecraft/dark/api/al/armbot/IProgram.java @@ -2,14 +2,25 @@ package dark.api.al.armbot; import java.util.HashMap; +import universalelectricity.core.vector.Vector2; + +/** Flow chart style program. Each command in the program needs to have a stored location so it can + * be saved and loaded with its correct connections. Though the location only need to be a simple + * Column and row based system. + * + * @author DarkGuardsman */ public interface IProgram { - /** Called when the program is added to an encoder, machine, or devices. - * memory values. */ + /** Called when the program is added to an encoder, machine, or devices. */ public void init(); - /** Variables this program has to operate. Is still limited by the actual machine */ + /** Variables this program has to operate. Is still limited by the actual machine. String is the + * name, Object is the starting value and data type */ public HashMap getDeclairedVarables(); + /** Next task in the set. Its up to the program to increment down the list */ public IArmbotTask getNextTask(); + + /** Gets a task at the given x y location in the program */ + public IArmbotTask getTaskAt(Vector2 vector2); } diff --git a/src/minecraft/dark/assembly/common/armbot/command/CommandIF.java b/src/minecraft/dark/assembly/common/armbot/command/CommandIF.java index a9770ff8e..3a88f46c9 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/CommandIF.java +++ b/src/minecraft/dark/assembly/common/armbot/command/CommandIF.java @@ -1,5 +1,6 @@ package dark.assembly.common.armbot.command; +import universalelectricity.core.vector.Vector2; import net.minecraft.nbt.NBTTagCompound; import dark.api.al.armbot.Command; import dark.api.al.armbot.IArmbotTask; @@ -17,10 +18,12 @@ public class CommandIF extends Command implements ISplitArmbotTask super("IF"); } - public CommandIF(IArmbotTask entryPoint, IArmbotTask left, IArmbotTask right) + public CommandIF(IArmbotTask entryPoint, IArmbotTask trueExit, IArmbotTask falseExit) { this(); this.setEntryPoint(this.entryPoint); + this.exitTruePoint = trueExit; + this.exitFalsePoint = falseExit; } @@ -70,6 +73,9 @@ public class CommandIF extends Command implements ISplitArmbotTask public Command readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); + this.entryPoint = this.program.getTaskAt(new Vector2(nbt.getDouble("entryX"), (nbt.getDouble("entryY")))); + this.exitFalsePoint = this.program.getTaskAt(new Vector2(nbt.getDouble("exitFalseX"), (nbt.getDouble("exitFalseY")))); + this.exitTruePoint = this.program.getTaskAt(new Vector2(nbt.getDouble("exitTrueX"), (nbt.getDouble("exitTrueY")))); return this; } @@ -77,6 +83,21 @@ public class CommandIF extends Command implements ISplitArmbotTask public NBTTagCompound writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); + if (this.entryPoint != null) + { + nbt.setDouble("entryX", this.entryPoint.getPosition().x); + nbt.setDouble("entryY", this.entryPoint.getPosition().y); + } + if (this.exitFalsePoint != null) + { + nbt.setDouble("exitFalseX", this.exitFalsePoint.getPosition().x); + nbt.setDouble("exitFalseY", this.exitFalsePoint.getPosition().y); + } + if (this.exitTruePoint != null) + { + nbt.setDouble("exitTrueX", this.exitTruePoint.getPosition().x); + nbt.setDouble("exitTrueY", this.exitTruePoint.getPosition().y); + } return nbt; }