From b025231c6c5181afe311e6a2abde9bfa94d749e2 Mon Sep 17 00:00:00 2001 From: Astoria Date: Tue, 4 Apr 2023 10:40:35 -0500 Subject: [PATCH] Comparisons! Memory! --- .../afloydwiremod/gui/GuiProgrammer.java | 19 +++++ .../tileentity/ChipTileEntity.java | 81 +++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java index aae113f..f6f1397 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java @@ -32,6 +32,15 @@ public class GuiProgrammer extends GuiScrollable { this.controlList.add(new GuiButtonExtended(i++, this.width, "Subtraction")); this.controlList.add(new GuiButtonExtended(i++, this.width, "Multiplication")); this.controlList.add(new GuiButtonExtended(i++, this.width, "Division")); + this.controlList.add(new GuiButtonExtended(i++, this.width, "Memory")); + i = 0; + this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "==")); + this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "!=")); + this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, ">")); + this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, ">=")); + this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "<")); + this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "<=")); + this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "<=>")); } public GuiProgrammer(EntityPlayer player, AbstractWireTileEntity wireEntity) { @@ -70,6 +79,9 @@ public class GuiProgrammer extends GuiScrollable { case "Increment/Decrement": ((ChipTileEntity) wireEntity).setMode("incdec"); break; + case "Memory": + ((ChipTileEntity) wireEntity).setMode("mem"); + break; case "TRUE": case "FALSE": case "NOT": @@ -79,6 +91,13 @@ public class GuiProgrammer extends GuiScrollable { case "NAND": case "NOR": case "XNOR": + case "==": + case "!=": + case ">": + case ">=": + case "<": + case "<=": + case "<=>": ((ChipTileEntity) wireEntity).setMode(guibutton.displayString); break; } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java index 00529a1..f988d20 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java @@ -24,6 +24,10 @@ public class ChipTileEntity extends AbstractWireTileEntity { doIncrementDecrement(); updateIO(); break; + case "mem": + doMemory(); + updateIO(); + break; case "dup": doDup(); updateIO(); @@ -80,9 +84,65 @@ public class ChipTileEntity extends AbstractWireTileEntity { outputs[0].floatvalue = 0.0f; updateIO(); break; + case "==": + doEquals(); + updateIO(); + break; + case "!=": + doNotEquals(); + updateIO(); + break; + case ">": + doGreater(); + updateIO(); + break; + case ">=": + doGreaterEq(); + updateIO(); + break; + case "<": + doLess(); + updateIO(); + break; + case "<=": + doLessEq(); + updateIO(); + break; + case "<=>": + doSpaceShip(); + updateIO(); + break; } } + private void doSpaceShip() { + outputs[0].floatvalue = Float.compare(inputs[0].floatvalue, inputs[1].floatvalue); + } + + private void doLessEq() { + outputs[0].floatvalue = inputs[0].floatvalue <= inputs[1].floatvalue ? 1.0f : 0.0f; + } + + private void doLess() { + outputs[0].floatvalue = inputs[0].floatvalue < inputs[1].floatvalue ? 1.0f : 0.0f; + } + + private void doGreaterEq() { + outputs[0].floatvalue = inputs[0].floatvalue >= inputs[1].floatvalue ? 1.0f : 0.0f; + } + + private void doGreater() { + outputs[0].floatvalue = inputs[0].floatvalue > inputs[1].floatvalue ? 1.0f : 0.0f; + } + + private void doNotEquals() { + outputs[0].floatvalue = inputs[0].floatvalue != inputs[1].floatvalue ? 1.0f : 0.0f; + } + + private void doEquals() { + outputs[0].floatvalue = inputs[0].floatvalue == inputs[1].floatvalue ? 1.0f : 0.0f; + } + private void doXNOR() { outputs[0].floatvalue = inputs[0].floatvalue != 0 ^ inputs[1].floatvalue != 0 ? 0.0f : 1.0f; } @@ -181,6 +241,19 @@ public class ChipTileEntity extends AbstractWireTileEntity { } } + private void doMemory() { + if (inputs[2].floatvalue > 0) { + this.outputs[0].floatvalue = 0; + return; + } + if (this.inputs[1].floatvalue > 0 && shouldIncrement) { + this.outputs[0].floatvalue = this.inputs[0].floatvalue; + shouldIncrement = false; + } else if (this.inputs[1].floatvalue == 0.0 && !shouldIncrement) { + shouldIncrement = true; + } + } + @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); @@ -207,6 +280,7 @@ public class ChipTileEntity extends AbstractWireTileEntity { break; case "inc": case "dec": + case "mem": this.inputs = new WiringButton[3]; this.outputs = new WiringButton[1]; this.outputs[0] = new WiringButton(214, 240, "Output", 0); @@ -246,6 +320,13 @@ public class ChipTileEntity extends AbstractWireTileEntity { case "sub": case "mult": case "div": + case "==": + case "!=": + case ">": + case ">=": + case "<": + case "<=": + case "<=>": this.inputs = new WiringButton[2]; this.outputs = new WiringButton[1]; this.outputs[0] = new WiringButton(214, 230, "Output", 0);