diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java index 93b0620..2cdccb6 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java @@ -109,11 +109,26 @@ public abstract class AbstractWireTileEntity extends TileEntity { if (outputs[i].wire != null && outputs[i].wire.thisslot > -1) { WireConnection wire = outputs[i].wire; AbstractWireTileEntity otherChip = (AbstractWireTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z); - if(otherChip != null && otherChip.inputs != null) { + if(otherChip != null && otherChip.outputs != null) { outputs[i].floatvalue = 0; outputs[i].stringvalue = ""; + outputs[i].wire.isMade = false; this.updateIO(); - otherChip.update(); + otherChip.updateIO(); + } + } + } + } + if(inputs != null) { + for (int i = 0; i < inputs.length; ++i) { + if (inputs[i].wire != null && inputs[i].wire.thisslot > -1) { + WireConnection wire = inputs[i].wire; + AbstractWireTileEntity otherChip = (AbstractWireTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z); + if(otherChip != null && otherChip.outputs != null) { + otherChip.outputs[wire.thatslot].floatvalue = 0; + otherChip.outputs[wire.thatslot].stringvalue = ""; + otherChip.outputs[wire.thatslot].wire.isMade = false; + otherChip.updateIO(); } } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java b/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java index b99f0cf..b7698ae 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java @@ -46,6 +46,15 @@ public class WireConnection { this.isMade = true; } + public WireConnection(int xCoord, int yCoord, int zCoord, int slot, int slot1) { + this.x = xCoord; + this.y = yCoord; + this.z = zCoord; + this.thisslot = slot; + this.thatslot = slot1; + this.isMade = true; + } + public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setInteger("wx", this.x); nbttagcompound.setInteger("wy", this.y); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java index b78b4d3..6e622d6 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java @@ -14,6 +14,7 @@ public class GuiProgrammer extends GuiScrollable { //This.width / 2 this.controlList.add(new GuiButtonExtended(1, this.width, "Constant")); this.controlList.add(new GuiButtonExtended(2, this.width, "Count")); + this.controlList.add(new GuiButtonExtended(3, this.width, "Addition")); } public GuiProgrammer(EntityPlayer player, AbstractWireTileEntity wireEntity) { @@ -24,10 +25,16 @@ public class GuiProgrammer extends GuiScrollable { @Override protected void actionPerformed(GuiButton guibutton) { if(wireEntity instanceof ChipTileEntity) { - if (guibutton.id == 1) { - ((ChipTileEntity) wireEntity).setMode("constant"); - } else if (guibutton.id == 2) { - ((ChipTileEntity) wireEntity).setMode("count"); + switch(guibutton.id){ + case 1: + ((ChipTileEntity) wireEntity).setMode("constant"); + break; + case 2: + ((ChipTileEntity) wireEntity).setMode("count"); + break; + case 3: + ((ChipTileEntity) wireEntity).setMode("add"); + break; } } this.mc.displayGuiScreen(null); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java index 519bde6..295bbb7 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java @@ -16,6 +16,7 @@ public class GuiWiring extends GuiScrollable { private int y; private int z; private AbstractWireTileEntity wireEntity; + private AbstractWireTileEntity otherEntity; @Override public void initGui() { //this.height - 240 is top @@ -41,6 +42,7 @@ public class GuiWiring extends GuiScrollable { this.y = y; this.z = z; this.wireEntity = wireEntity; + otherEntity = (AbstractWireTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(tool.x, tool.y, tool.z); } @Override @@ -71,18 +73,19 @@ public class GuiWiring extends GuiScrollable { tool.sideadd = new ArrayList(); } } else if(!this.tool.type.equals("unpaired")) { - if(this.tool.type.equals("input")) { + if(this.tool.type.equals("input") && this.wireEntity.inputs[tool.slot].wire.isMade != true) { wireEntity.outputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, false, tool.red, tool.green, tool.blue, tool.alpha, tool.width); + otherEntity.inputs[tool.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot); wireEntity.updateIO(); tool.xadd = new ArrayList(); tool.yadd = new ArrayList(); tool.zadd = new ArrayList(); tool.sideadd = new ArrayList(); tool.type = "unpaired"; - } else if(this.tool.type.equals("output")) { - AbstractWireTileEntity otherEntity = (AbstractWireTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(tool.x, tool.y, tool.z); + } else if(this.tool.type.equals("output") && otherEntity.outputs[tool.slot].wire.isMade != true) { if(otherEntity != null) { otherEntity.outputs[tool.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, true, tool.red, tool.green, tool.blue, tool.alpha, tool.width); + wireEntity.inputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot); otherEntity.updateIO(); } tool.xadd = new ArrayList(); @@ -90,6 +93,12 @@ public class GuiWiring extends GuiScrollable { tool.zadd = new ArrayList(); tool.sideadd = new ArrayList(); tool.type = "unpaired"; + } else{ + tool.xadd = new ArrayList(); + tool.yadd = new ArrayList(); + tool.zadd = new ArrayList(); + tool.sideadd = new ArrayList(); + tool.type = "unpaired"; } } this.mc.displayGuiScreen(null); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java index babbfb0..8097194 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java @@ -15,9 +15,17 @@ public class ChipTileEntity extends AbstractWireTileEntity { doIncrement(); updateIO(); break; + case "add": + doAdd(); + updateIO(); + break; } } + private void doAdd() { + outputs[0].floatvalue = inputs[0].floatvalue + inputs[1].floatvalue; + } + public void doIncrement() { if (inputs[2].floatvalue > 0) { this.outputs[0].floatvalue = 0; @@ -26,7 +34,6 @@ public class ChipTileEntity extends AbstractWireTileEntity { if (this.inputs[1].floatvalue > 0 && shouldIncrement) { this.outputs[0].floatvalue = this.outputs[0].floatvalue + this.inputs[0].floatvalue; shouldIncrement = false; - System.out.println("Incrementing to " + this.outputs[0].floatvalue); } else if (this.inputs[1].floatvalue == 0.0 && !shouldIncrement) { shouldIncrement = true; } @@ -46,26 +53,30 @@ public class ChipTileEntity extends AbstractWireTileEntity { public void setMode(String string) { if (mode.equals("none")) { + mode = string; switch(string) { case "constant": - mode = string; this.inputs = new WiringButton[0]; this.outputs = new WiringButton[1]; this.outputs[0] = new WiringButton(214, 240, "Output", 0); - initialized = true; hasSettings = true; break; case "count": - mode = string; this.inputs = new WiringButton[3]; this.outputs = new WiringButton[1]; this.outputs[0] = new WiringButton(214, 240, "Output", 0); this.inputs[0] = new WiringButton(214, 220, "Source", 0); this.inputs[1] = new WiringButton(214, 200, "Clock", 1); this.inputs[2] = new WiringButton(214, 180, "Reset", 2); - initialized = true; break; + case "add": + this.inputs = new WiringButton[2]; + this.outputs = new WiringButton[1]; + this.outputs[0] = new WiringButton(214, 230, "Output", 0); + this.inputs[0] = new WiringButton(214, 210, "Input A", 0); + this.inputs[1] = new WiringButton(214, 190, "Input B", 1); } + initialized = true; } } }