diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/component/GuiIO.java b/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/component/GuiIO.java index 5d4a416..43698e2 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/component/GuiIO.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/component/GuiIO.java @@ -95,18 +95,22 @@ public boolean mousePressed(Minecraft mc, int par1, int par2) { public List getHoverInformation() { ArrayList text = new ArrayList(); ForgeDirection dir = MiscUtils.getDirection(side); - if (te.getCircuitData().getProperties().getModeAtSide(side) == EnumConnectionType.ANALOG) - text.add("S: " + color); - else - text.add("F: 0x" + Integer.toHexString(color)); if (isActive) { + EnumConnectionType mode = te.getCircuitData().getProperties().getModeAtSide(side); + if (mode != EnumConnectionType.SIMPLE) { + if (mode == EnumConnectionType.ANALOG) + text.add("S: " + color); + else + text.add("F: 0x" + Integer.toHexString(color)); + } text.add("I: " + I18n.format("gui.integratedcircuits.cad.mode." + (te.getExternalInputFromSide(dir, color) ? "high" : "low"))); text.add("O: " + I18n.format("gui.integratedcircuits.cad.mode." + (te.getOutputToSide(dir, color) ? "high" : "low"))); - } + } else + text.add("N"); return text; } } diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitData.java b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitData.java index 79e6962..e96b4f2 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitData.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitData.java @@ -14,6 +14,7 @@ import moe.nightfall.vic.integratedcircuits.cp.part.PartIOBit; import moe.nightfall.vic.integratedcircuits.cp.part.PartNull; import moe.nightfall.vic.integratedcircuits.misc.CraftingAmount; +import moe.nightfall.vic.integratedcircuits.misc.MiscUtils; import moe.nightfall.vic.integratedcircuits.misc.Vec2; import net.minecraft.nbt.NBTTagCompound; @@ -155,60 +156,53 @@ private EnumConnectionType[] getAndFixModePerSide() { /** Clears the circuit and sets it up **/ public void clearAllAndSetup(int size) { clearAll(size); - setupIO(); + FixIO(); } - /** Clears the IOBits, and sets them up again. **/ - public void clearIOAndSetupIO() { - clearIO(); - setupIO(); - } - - /** Sets up the IOBits for the circuit. **/ - public void setupIO() { + /** Sets up the IOBits and clears unused ones. **/ + public void FixIO() { getAndFixModePerSide(); - int o = (supportsBundled() ? size / 2 - 8 : 1); + int o = (supportsBundled() ? size / 2 - 8 : 1); // Offset of first IOBit // Get the ID of the IOBit int cid = CircuitPart.getId(PartIOBit.class); + Vec2[] pos = new Vec2[4]; for (int i = 0; i < (supportsBundled() ? 16 : 1); i++) { // Get the positions - Vec2 pos1 = new Vec2(size - 1 - (i + o), 0); - Vec2 pos2 = new Vec2(size - 1, size - 1 - (i + o)); - Vec2 pos3 = new Vec2(i + o, size - 1); - Vec2 pos4 = new Vec2(0, i + o); - - if (prop.getModeAtSide(0) != EnumConnectionType.NONE && !(prop.getModeAtSide(0) == EnumConnectionType.SIMPLE && i >= 1)) { - // Set the part at the position to be a IOBit - setID(pos1, cid); - // Get the IOBit at that position - PartIOBit io1 = (PartIOBit) getPart(pos1); - // Set the number of the IOBit (colour / redstone strength) - io1.setFrequency(pos1, parent, i); - // The rotation is what side the IOBit is on - io1.setRotation(pos1, parent, 0); - } - - if (prop.getModeAtSide(1) != EnumConnectionType.NONE && !(prop.getModeAtSide(1) == EnumConnectionType.SIMPLE && i >= 1)) { - setID(pos2, cid); - PartIOBit io2 = (PartIOBit) getPart(pos2); - io2.setFrequency(pos2, parent, i); - io2.setRotation(pos2, parent, 1); - } + pos[0] = new Vec2(size - 1 - (i + o), 0); + pos[1] = new Vec2(size - 1, size - 1 - (i + o)); + pos[2] = new Vec2(i + o, size - 1); + pos[3] = new Vec2(0, i + o); - if (prop.getModeAtSide(2) != EnumConnectionType.NONE && !(prop.getModeAtSide(2) == EnumConnectionType.SIMPLE && i >= 1)) { - setID(pos3, cid); - PartIOBit io3 = (PartIOBit) getPart(pos3); - io3.setFrequency(pos3, parent, i); - io3.setRotation(pos3, parent, 2); - } - - if (prop.getModeAtSide(3) != EnumConnectionType.NONE && !(prop.getModeAtSide(3) == EnumConnectionType.SIMPLE && i >= 1)) { - setID(pos4, cid); - PartIOBit io4 = (PartIOBit) getPart(pos4); - io4.setFrequency(pos4, parent, i); - io4.setRotation(pos4, parent, 3); + for (int j = 0; j < 4; j++) { + if (prop.getModeAtSide(j) != EnumConnectionType.NONE && !(prop.getModeAtSide(j) == EnumConnectionType.SIMPLE && i >= 1)) { + // Set the part at the position to be a IOBit + setID(pos[j], cid); + // Get the IOBit at that position + PartIOBit io = (PartIOBit) getPart(pos[j]); + // Set the number of the IOBit (colour / redstone strength) + io.setFrequency(pos[j], parent, i); + // The rotation is what side the IOBit is on + io.setRotation(pos[j], parent, j); + // Make sure that IOBit does not stall + io.scheduleInputChange(pos[j], parent); + } else { + // Get old part at the position + CircuitPart part = getPart(pos[j]); + if (part instanceof PartIOBit) { + // There was an IOBit. Clear corresponding output signal. + PartIOBit io = (PartIOBit)part; + parent.setOutputToSide( + MiscUtils.getDirection(io.getRotation(pos[j], parent)), + io.getFrequency(pos[j], parent), false); + } + // Clear part at the position + setID(pos[j], 0); + setMeta(pos[j], 0); + // Notify neighbour parts about is + getPart(pos[j]).notifyNeighbours(pos[j], parent); + } } } } @@ -238,17 +232,6 @@ public void clearColumn(int x) { } } - public void clearIO() { - // Clear top - clearRow(0); - // Clear bottom - clearRow(this.size - 1); - // Clear left - clearColumn(0); - // Clear right - clearColumn(this.size - 1); - } - /** Clears the contents of the circuit and gives it a new size. **/ public void clearContents(int size) { this.id = new int[size][size]; diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/net/pcb/PacketPCBChangeInput.java b/src/main/java/moe/nightfall/vic/integratedcircuits/net/pcb/PacketPCBChangeInput.java index e24f86d..c2d7aeb 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/net/pcb/PacketPCBChangeInput.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/net/pcb/PacketPCBChangeInput.java @@ -76,10 +76,10 @@ public void process(EntityPlayer player, Side side) { CircuitData data = te.getCircuitData(); data.getProperties().setCon(con); - data.clearIOAndSetupIO(); + data.FixIO(); if (input && side == Side.SERVER) { - te.getCircuitData().updateInput(); + data.updateInput(); CommonProxy.networkWrapper.sendToAllAround(this, new TargetPoint(te.getWorldObj().getWorldInfo() .getVanillaDimension(), xCoord, yCoord, zCoord, 8)); }