diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/cad/GuiCAD.java b/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/cad/GuiCAD.java index 2c559e8..fecbb82 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/cad/GuiCAD.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/cad/GuiCAD.java @@ -244,7 +244,12 @@ public void initGui() { // If the part hasn't got a category, or there are no parts in the category, do not add the button for the category. if (category == CircuitPart.Category.NONE || parts.size() == 0) continue; - this.buttonList.add(new GuiPartChooser(7, toolsXPosition, currentPosition, GuiPartChooser.getRenderWrapperParts(parts), this)); + // To fit drop-down menu should have its bottom no lower than eraser button's. + List wrappers = GuiPartChooser.getRenderWrapperParts(parts); + int partsAbove = wrappers.size() - (guiBottom - 19 - currentPosition) / 21; + if (partsAbove < 0) + partsAbove = 0; + this.buttonList.add(new GuiPartChooser(7, toolsXPosition, currentPosition, partsAbove, wrappers, this)); currentPosition += 21; } diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/cad/PlaceHandler.java b/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/cad/PlaceHandler.java index bfdc225..572d2ae 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/cad/PlaceHandler.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/cad/PlaceHandler.java @@ -11,6 +11,7 @@ import moe.nightfall.vic.integratedcircuits.cp.part.PartCPGate; import moe.nightfall.vic.integratedcircuits.cp.part.PartNull; import moe.nightfall.vic.integratedcircuits.cp.part.PartWire; +import moe.nightfall.vic.integratedcircuits.cp.part.PartTunnel; import moe.nightfall.vic.integratedcircuits.misc.RenderUtils; import moe.nightfall.vic.integratedcircuits.misc.Vec2; import moe.nightfall.vic.integratedcircuits.net.pcb.PacketPCBCache; @@ -51,7 +52,7 @@ public void renderCADCursor(GuiCAD parent, double mouseX, double mouseY, int gri CircuitPartRenderer.renderPart(selectedPart, gridX * PART_SIZE, gridY * PART_SIZE); GL11.glPopMatrix(); GL11.glColor3f(1, 1, 1); - } else if (selectedPart.getPart() instanceof PartWire) { + } else if (selectedPart.getPart().allowsDragPlacement()) { PartWire wire = (PartWire) selectedPart.getPart(); switch (wire.getColor(selectedPart.getPos(), selectedPart)) { case 1: @@ -143,7 +144,7 @@ public void onMouseDown(GuiCAD parent, int mx, int my, int button) { if (gridX > 0 && gridY > 0 && gridX < w - 1 && gridY < w - 1 && !GuiScreen.isShiftKeyDown()) { parent.startX = gridX; parent.startY = gridY; - if (selectedPart.getPart() instanceof PartWire) { + if (selectedPart.getPart().allowsDragPlacement()) { parent.drag = true; } } @@ -160,7 +161,7 @@ public void onMouseUp(GuiCAD parent, int mx, int my, int button) { } if (parent.drag) { - if (selectedPart.getPart() instanceof PartWire) { + if (selectedPart.getPart().allowsDragPlacement()) { int id = CircuitPart.getId(selectedPart.getPart()); int state = selectedPart.getState(); @@ -190,7 +191,7 @@ else if (parent.startX > parent.endX) int newID = CircuitPart.getId(selectedPart.getPart()); Vec2 pos = new Vec2(parent.startX, parent.startY); - if (newID != parent.getCircuitData().getID(pos)) { + if (newID != parent.getCircuitData().getID(pos) || newID == CircuitPart.getId(PartTunnel.class)) { CommonProxy.networkWrapper.sendToServer(new PacketPCBChangePart(!(selectedPart.getPart() instanceof PartNull), parent.tileentity.xCoord, parent.tileentity.yCoord, parent.tileentity.zCoord).add(pos, newID, selectedPart.getState())); } } 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/client/gui/component/GuiPartChooser.java b/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/component/GuiPartChooser.java index 7f5e45d..b697d51 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/component/GuiPartChooser.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/client/gui/component/GuiPartChooser.java @@ -23,6 +23,7 @@ public class GuiPartChooser extends GuiButton implements IHoverable { private boolean showList = false; private GuiCAD parent; private GuiPartChooser chooserParent; + private int partsAbove = 0; public GuiPartChooser(int id, int x, int y, int mode, GuiCAD parent) { super(id, x, y, 20, 20, ""); @@ -53,14 +54,15 @@ public GuiPartChooser(int id, int x, int y, CircuitRenderWrapper current, List list2, GuiCAD parent) { + public GuiPartChooser(int id, int x, int y, int above, List list2, GuiCAD parent) { super(id, x, y, 20, 20, ""); + partsAbove = above; if (list2.size() > 0) { current = list2.get(0); ArrayList list3 = new ArrayList(list2); this.children = new ArrayList(); for (int i = 0; i < list3.size(); i++) { - GuiPartChooser child = new GuiPartChooser(i, x - 21, y + i * 21, list3.get(i), parent); + GuiPartChooser child = new GuiPartChooser(i, x - 21, y + (i - partsAbove) * 21, list3.get(i), parent); child.chooserParent = this; child.visible = false; this.children.add(child); @@ -70,6 +72,10 @@ public GuiPartChooser(int id, int x, int y, List list2, Gu this.parent = parent; } + public GuiPartChooser(int id, int x, int y, List list2, GuiCAD parent) { + this(id, x, y, 0, list2, parent); + } + public GuiPartChooser(int id, int x, int y, CircuitPart.Category category, GuiCAD parent) { this(id, x, y, getRenderWrapperParts(category), parent); } @@ -100,7 +106,7 @@ public void drawButton(Minecraft mc, int x, int y) { if (showList && children != null) { drawRect(xPosition, yPosition - 1, xPosition + width + 1, yPosition + height + 1, 180 << 24); - drawRect(xPosition - 22, yPosition - 1, xPosition, yPosition + children.size() * 21, 180 << 24); + drawRect(xPosition - 22, yPosition - 1 - partsAbove * 21, xPosition, yPosition + (children.size() - partsAbove) * 21, 180 << 24); for (GuiPartChooser child : children) { child.drawButton(mc, x, y); } 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..8d7c91f 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; @@ -31,7 +32,7 @@ public class CircuitData implements Cloneable { // cdata version - public static final int version = 1; + public static final int version = 2; private int size; private int[][] meta; @@ -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/cp/CircuitPart.java b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitPart.java index 0c01700..d4fc1f5 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitPart.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitPart.java @@ -279,7 +279,7 @@ public final CircuitPart getNeighbourOnSide(Vec2 pos, ICircuit parent, ForgeDire return parent.getCircuitData().getPart(pos.offset(side)); } - public final boolean getInput(Vec2 pos, ICircuit parent) { + public boolean getInput(Vec2 pos, ICircuit parent) { return getInputFromSide(pos, parent, ForgeDirection.NORTH) || getInputFromSide(pos, parent, ForgeDirection.EAST) || getInputFromSide(pos, parent, ForgeDirection.SOUTH) @@ -289,6 +289,11 @@ public final boolean getInput(Vec2 pos, ICircuit parent) { @SideOnly(Side.CLIENT) public abstract void renderPart(Vec2 pos, ICircuit parent, double x, double y, CircuitPartRenderer.EnumRenderType type); + @SideOnly(Side.CLIENT) + public boolean allowsDragPlacement() { + return false; + } + /** Gets called on a client update */ public void onChanged(Vec2 pos, ICircuit parent, int oldMeta) { scheduleInputChange(pos, parent); diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitPartRenderer.java b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitPartRenderer.java index 961a576..b8fb8a4 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitPartRenderer.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/CircuitPartRenderer.java @@ -60,7 +60,15 @@ public static void addQuad(double x, double y, double u, double v, double w, dou } public static void addQuad(double x, double y, double u, double v, double w, double h, double rotation) { - addQuad(x, y, u, v, w, h, w, h, 256, 256, rotation); + addQuad(x, y, u, v, w, h, rotation, false, false); + } + + public static void addQuad(double x, double y, double u, double v, double w, double h, double rotation, boolean invX, boolean invY) { + addQuad(x, y, + invX ? u + w : u, invY ? v + h : v, + w, h, + invX ? -w : w, invY ? -h : h, + 256, 256, rotation); } public static void addQuad(double x, double y, double u, double v, double w, double h, double w2, double h2, diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoader.java b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoader.java index f285e19..569cb35 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoader.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoader.java @@ -15,7 +15,11 @@ public abstract class LegacyLoader implements Comparable { private static final List legacyLoaders = new ArrayList(); static { - legacyLoaders.add(new LegacyLoader_0_8()); + legacyLoaders.add(new LegacyLoaderUnversioned()); + legacyLoaders.add(new LegacyLoader1()); + /* TODO Fix all NBT transforms being done before all Transforms + * before all PostTransforms. Be careful until then. + */ Collections.sort(legacyLoaders); } diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoader1.java b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoader1.java new file mode 100644 index 0000000..90bad23 --- /dev/null +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoader1.java @@ -0,0 +1,70 @@ +package moe.nightfall.vic.integratedcircuits.cp.legacy; + +import java.util.ArrayList; +import java.util.BitSet; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import moe.nightfall.vic.integratedcircuits.cp.CircuitData; +import moe.nightfall.vic.integratedcircuits.cp.legacy.LegacyLoader; +import moe.nightfall.vic.integratedcircuits.misc.MiscUtils; +import moe.nightfall.vic.integratedcircuits.misc.Vec2; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +public final class LegacyLoader1 extends LegacyLoader { + @Override + public int getVersion() { + return 1; + } + + { + addTransformer(new PartTransparentLatchTransformer(), 18); + addTransformer(new PartTunnelTransformer(), 27); + } + + private static class PartTransparentLatchTransformer extends PartTransformer { + protected final int oldBits = old.allocate(4 + 2 + 1); + protected final int newBits = transformed.allocate(4 + 2 + 1); + protected final int newConfig = transformed.allocate(3); + + @Override + public void transformImpl() { + setInt(newBits, getInt(oldBits)); + setInt(newConfig, 0); + } + } + + private static class PartTunnelTransformer extends PartTransformer { + // The old PartTunnel property map + // PartCPGate: + protected final int oldInput = old.allocate(4); + // PartTunnel: + protected final int oldPosX = old.allocate(8); + protected final int oldPosY = old.allocate(8); + protected final int oldIn = old.allocate(); + + // Tunnels are now derived from wires + // PartCPGate: + protected final int newInput = transformed.allocate(4); + // PartWire: + protected final int newColor = transformed.allocate(2); + // PartTunnel: + protected final int newPosX = transformed.allocate(8); + protected final int newPosY = transformed.allocate(8); + protected final int newIn = transformed.allocate(); + + @Override + public void transformImpl() { + setInt(newInput, getInt(oldInput)); + // Old tunnels are converted to green tunnels + setInt(newColor, 0); // 0 is green + setInt(newPosX, getInt(oldPosX)); + setInt(newPosY, getInt(oldPosY)); + setBit(newIn, getBit(oldIn)); + } + } + +} diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoader_0_8.java b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoaderUnversioned.java similarity index 99% rename from src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoader_0_8.java rename to src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoaderUnversioned.java index 03fa229..bd6441b 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoader_0_8.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/legacy/LegacyLoaderUnversioned.java @@ -14,7 +14,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; -public final class LegacyLoader_0_8 extends LegacyLoader { +public final class LegacyLoaderUnversioned extends LegacyLoader { @Override public int getVersion() { return 0; diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/PartTunnel.java b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/PartTunnel.java index 0bc7049..4f3859d 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/PartTunnel.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/PartTunnel.java @@ -1,5 +1,7 @@ package moe.nightfall.vic.integratedcircuits.cp.part; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import moe.nightfall.vic.integratedcircuits.Config; import moe.nightfall.vic.integratedcircuits.Content; import moe.nightfall.vic.integratedcircuits.cp.CircuitData; @@ -18,12 +20,17 @@ import net.minecraft.init.Items; import net.minecraftforge.common.util.ForgeDirection; -public class PartTunnel extends CircuitPart { +public class PartTunnel extends PartWire { public final IntProperty PROP_POS_X = new IntProperty("PROP_POS_X", stitcher, 255); public final IntProperty PROP_POS_Y = new IntProperty("PROP_POS_Y", stitcher, 255); public final BooleanProperty PROP_IN = new BooleanProperty("PROP_IN", stitcher); + @Override + public boolean getInput(Vec2 pos, ICircuit parent) { + return super.getInput(pos, parent) || getProperty(pos, parent, PROP_IN); + } + // pos is for CURRENT part public Vec2 getConnectedPos(Vec2 pos, ICircuit parent) { return new Vec2(getProperty(pos, parent, PROP_POS_X), getProperty(pos, parent, PROP_POS_Y)); @@ -80,7 +87,7 @@ public boolean getOutputToSide(Vec2 pos, ICircuit parent, ForgeDirection side) { boolean in = getProperty(pos, parent, PROP_IN); if (side == ForgeDirection.UNKNOWN) return getInput(pos, parent) && !in; - return (getInput(pos, parent) || in) && !getInputFromSide(pos, parent, side); + return (getInput(pos, parent)) && !getInputFromSide(pos, parent, side); } @Override @@ -127,22 +134,25 @@ public void onRemoved(Vec2 pos, ICircuit parent) { } @Override - public void renderPart(Vec2 pos, ICircuit parent, double x, double y, EnumRenderType type) { + public Category getCategory() { + return Category.WIRE; + } + + @Override + @SideOnly(Side.CLIENT) + public void renderPart(Vec2 pos, ICircuit parent, double x, double y, CircuitPartRenderer.EnumRenderType type) { Tessellator tes = Tessellator.instance; RenderUtils.applyColorIRGBA(tes, Config.colorGreen); - CircuitPartRenderer.addQuad(x, y, 16, 4 * 16, 16, 16); - if (getInput(pos, parent) || getProperty(pos, parent, PROP_IN)) { - RenderUtils.applyColorIRGBA(tes, Config.colorGreen); - } else { - RenderUtils.applyColorIRGBA(tes, Config.colorGreen, 0.4F); - } - CircuitPartRenderer.addQuad(x, y, 0, 4 * 16, 16, 16); + CircuitPartRenderer.addQuad(x, y, 16, 4*16, 16, 16); + + renderViaWire(pos, parent, x, y, type); } @Override - public Category getCategory() { - return Category.WIRE; + @SideOnly(Side.CLIENT) + public boolean allowsDragPlacement() { + return false; } @Override @@ -156,13 +166,15 @@ public String getLocalizedName(Vec2 pos, ICircuit parent) { @Override public void getCraftingCost(CraftingAmount amount, CircuitData parent, Vec2 pos) { + // Tunnels are twice as expensive as wires and also cost a bit of silicon. amount.add(new ItemAmount(Items.redstone, 0.1)); amount.add(new ItemAmount(Content.itemSiliconDrop, 0.1)); int data = parent.getMeta(pos); Vec2 end = new Vec2(PROP_POS_X.get(data), PROP_POS_Y.get(data)); if (isConnected(end)) { - amount.add(new ItemAmount(Items.redstone, 0.1 * pos.distanceTo(end))); + // Half the amount, because it will be added twice. + amount.add(new ItemAmount(Items.redstone, 0.05 * pos.distanceTo(end))); } } } diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/PartWire.java b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/PartWire.java index 1c7503a..86630f1 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/PartWire.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/PartWire.java @@ -33,9 +33,8 @@ public boolean getOutputToSide(Vec2 pos, ICircuit parent, ForgeDirection side) { return getInput(pos, parent) && !getInputFromSide(pos, parent, side); } - @Override @SideOnly(Side.CLIENT) - public void renderPart(Vec2 pos, ICircuit parent, double x, double y, CircuitPartRenderer.EnumRenderType type) { + public final void applyWireRenderColor(Vec2 pos, ICircuit parent, CircuitPartRenderer.EnumRenderType type) { int color = this.getColor(pos, parent); Tessellator tes = Tessellator.instance; @@ -62,25 +61,45 @@ public void renderPart(Vec2 pos, ICircuit parent, double x, double y, CircuitPar } } else RenderUtils.applyColorIRGBA(tes, Config.colorGreen, 0.4F); + } + + @SideOnly(Side.CLIENT) + // Render wire with a via + public final void renderViaWire(Vec2 pos, ICircuit parent, double x, double y, CircuitPartRenderer.EnumRenderType type) { + applyWireRenderColor(pos, parent, type); int ty = type == CircuitPartRenderer.EnumRenderType.WORLD_16x ? 3 * 16 : 0; int con = CircuitPartRenderer.checkConnections(pos, parent, this); - if ((con & 12) == 12 && (con & ~12) == 0) - CircuitPartRenderer.addQuad(x, y, 6 * 16, ty, 16, 16); - else if ((con & 3) == 3 && (con & ~3) == 0) - CircuitPartRenderer.addQuad(x, y, 5 * 16, ty, 16, 16); - else { - if ((con & 8) > 0) - CircuitPartRenderer.addQuad(x, y, 2 * 16, ty, 16, 16); - if ((con & 4) > 0) - CircuitPartRenderer.addQuad(x, y, 4 * 16, ty, 16, 16); - if ((con & 2) > 0) - CircuitPartRenderer.addQuad(x, y, 1 * 16, ty, 16, 16); - if ((con & 1) > 0) - CircuitPartRenderer.addQuad(x, y, 3 * 16, ty, 16, 16); - CircuitPartRenderer.addQuad(x, y, 0, ty, 16, 16); - } + // Connections with nearby gates / wires + if ((con & 8) > 0) + CircuitPartRenderer.addQuad(x, y, 2 * 16, ty, 16, 16); + if ((con & 4) > 0) + CircuitPartRenderer.addQuad(x, y, 4 * 16, ty, 16, 16); + if ((con & 2) > 0) + CircuitPartRenderer.addQuad(x, y, 1 * 16, ty, 16, 16); + if ((con & 1) > 0) + CircuitPartRenderer.addQuad(x, y, 3 * 16, ty, 16, 16); + // The via (circle which looks like "through pcb") + CircuitPartRenderer.addQuad(x, y, 0, ty, 16, 16); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderPart(Vec2 pos, ICircuit parent, double x, double y, CircuitPartRenderer.EnumRenderType type) { + int con = CircuitPartRenderer.checkConnections(pos, parent, this); + if (con == 12 || con == 3) { + // Render straight line wire + applyWireRenderColor(pos, parent, type); + + int ty = type == CircuitPartRenderer.EnumRenderType.WORLD_16x ? 3 * 16 : 0; + + if (con == 12) + CircuitPartRenderer.addQuad(x, y, 6 * 16, ty, 16, 16); + else + CircuitPartRenderer.addQuad(x, y, 5 * 16, ty, 16, 16); + } else + renderViaWire(pos, parent, x, y, type); } @Override @@ -105,6 +124,12 @@ public boolean canConnectToSide(Vec2 pos, ICircuit parent, ForgeDirection side) return true; } + @Override + @SideOnly(Side.CLIENT) + public boolean allowsDragPlacement() { + return true; + } + @Override public void getCraftingCost(CraftingAmount cost, CircuitData parent, Vec2 pos) { cost.add(new ItemAmount(Items.redstone, 0.05)); diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/latch/PartTransparentLatch.java b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/latch/PartTransparentLatch.java index 44c845d..088d39e 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/latch/PartTransparentLatch.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/cp/part/latch/PartTransparentLatch.java @@ -7,10 +7,22 @@ import moe.nightfall.vic.integratedcircuits.cp.part.PartCPGate; import moe.nightfall.vic.integratedcircuits.misc.Vec2; import moe.nightfall.vic.integratedcircuits.misc.PropertyStitcher.BooleanProperty; +import moe.nightfall.vic.integratedcircuits.misc.PropertyStitcher.IntProperty; import net.minecraftforge.common.util.ForgeDirection; public class PartTransparentLatch extends PartCPGate { public final BooleanProperty PROP_OUT = new BooleanProperty("OUT", stitcher); + public final IntProperty PROP_CONFIG = new IntProperty("CONFIG", stitcher, 5); + + @Override + public void onClick(Vec2 pos, ICircuit parent, int button, boolean ctrl) { + if (button == 0 && ctrl) { + cycleProperty(pos, parent, PROP_CONFIG); + scheduleInputChange(pos, parent); + notifyNeighbours(pos, parent); + } + super.onClick(pos, parent, button, ctrl); + } @Override public void onInputChange(Vec2 pos, ICircuit parent) { @@ -19,7 +31,9 @@ public void onInputChange(Vec2 pos, ICircuit parent) { @Override public void onScheduledTick(Vec2 pos, ICircuit parent) { - if (getInputFromSide(pos, parent, toExternal(pos, parent, ForgeDirection.SOUTH))) { + int cfg = getProperty(pos, parent, PROP_CONFIG); + ForgeDirection writeSide = (cfg & 1) == 0 ? ForgeDirection.SOUTH : ForgeDirection.NORTH; + if (getInputFromSide(pos, parent, toExternal(pos, parent, writeSide))) { setProperty(pos, parent, PROP_OUT, getInputFromSide(pos, parent, toExternal(pos, parent, ForgeDirection.WEST))); @@ -30,16 +44,29 @@ public void onScheduledTick(Vec2 pos, ICircuit parent) { @Override public boolean getOutputToSide(Vec2 pos, ICircuit parent, ForgeDirection side) { ForgeDirection s2 = toInternal(pos, parent, side); - if (s2 == ForgeDirection.NORTH || s2 == ForgeDirection.EAST) + int cfg = getProperty(pos, parent, PROP_CONFIG); + if ((s2 == ((cfg & 1) == 0 ? ForgeDirection.NORTH : ForgeDirection.SOUTH) && (cfg & 2) == 0) + || (s2 == ForgeDirection.EAST && (cfg & 4) == 0)) return getProperty(pos, parent, PROP_OUT); return false; } + @Override + public boolean canConnectToSide(Vec2 pos, ICircuit parent, ForgeDirection side) { + ForgeDirection s2 = toInternal(pos, parent, side); + if (s2 == ForgeDirection.WEST) + return true; + int cfg = getProperty(pos, parent, PROP_CONFIG); + if (s2 == ForgeDirection.EAST) + return (cfg & 4) == 0; + return ((cfg & 2) == 0) || (((cfg & 1) == 0) == (s2 == ForgeDirection.SOUTH)); + } + @Override public void renderPart(Vec2 pos, ICircuit parent, double x, double y, CircuitPartRenderer.EnumRenderType type) { CircuitPartRenderer.renderPartGate(pos, parent, this, x, y, type); - - CircuitPartRenderer.addQuad(x, y, 9 * 16, 16, 16, 16, this.getRotation(pos, parent)); + int cfg = getProperty(pos, parent, PROP_CONFIG); + CircuitPartRenderer.addQuad(x, y, 9 * 16, (1 + (cfg / 2)) * 16, 16, 16, this.getRotation(pos, parent), false, (cfg & 1) != 0); } @Override 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..ba47294 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)); } diff --git a/src/main/java/moe/nightfall/vic/integratedcircuits/tile/BlockSocket.java b/src/main/java/moe/nightfall/vic/integratedcircuits/tile/BlockSocket.java index e6a9617..fd6da3f 100644 --- a/src/main/java/moe/nightfall/vic/integratedcircuits/tile/BlockSocket.java +++ b/src/main/java/moe/nightfall/vic/integratedcircuits/tile/BlockSocket.java @@ -200,7 +200,7 @@ public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int s if ((side & 6) == (socket.getSide() & 6)) return 0; int rot = socket.getSideRel(side); - if (!socket.getConnectionTypeAtSide(side).isRedstone()) + if (!socket.getConnectionTypeAtSide(rot).isRedstone()) return 0; return socket.getRedstoneOutput(rot); diff --git a/src/main/resources/assets/integratedcircuits/lang/PT_BR.lang b/src/main/resources/assets/integratedcircuits/lang/PT_BR.lang index f3f16cd..4ebf9c8 100644 --- a/src/main/resources/assets/integratedcircuits/lang/PT_BR.lang +++ b/src/main/resources/assets/integratedcircuits/lang/PT_BR.lang @@ -23,7 +23,9 @@ tile.integratedcircuits.assembler.name=Montadora # parts part.integratedcircuits.iobit.name=IOBit part.integratedcircuits.torch.name=Tocha -part.integratedcircuits.tunnel.name=Tunel +part.integratedcircuits.tunnel.0.name=Tunel +part.integratedcircuits.tunnel.1.name=Tunel vermelho +part.integratedcircuits.tunnel.2.name=Tunel laranja part.integratedcircuits.wire.0.name=Fio part.integratedcircuits.wire.1.name=Fio vermelho part.integratedcircuits.wire.2.name=Fio laranja diff --git a/src/main/resources/assets/integratedcircuits/lang/en_US.lang b/src/main/resources/assets/integratedcircuits/lang/en_US.lang index 09d7da2..ecb164a 100644 --- a/src/main/resources/assets/integratedcircuits/lang/en_US.lang +++ b/src/main/resources/assets/integratedcircuits/lang/en_US.lang @@ -25,7 +25,9 @@ tile.integratedcircuits.pcbprinter.name=Printer # parts part.integratedcircuits.iobit.name=IOBit part.integratedcircuits.torch.name=Torch -part.integratedcircuits.tunnel.name=Tunnel +part.integratedcircuits.tunnel.0.name=Tunnel +part.integratedcircuits.tunnel.1.name=Red Tunnel +part.integratedcircuits.tunnel.2.name=Orange Tunnel part.integratedcircuits.wire.0.name=Wire part.integratedcircuits.wire.1.name=Red Wire part.integratedcircuits.wire.2.name=Orange Wire diff --git a/src/main/resources/assets/integratedcircuits/lang/ru_RU.lang b/src/main/resources/assets/integratedcircuits/lang/ru_RU.lang index 125878a..d6cf853 100644 --- a/src/main/resources/assets/integratedcircuits/lang/ru_RU.lang +++ b/src/main/resources/assets/integratedcircuits/lang/ru_RU.lang @@ -23,7 +23,9 @@ tile.integratedcircuits.assembler.name=Сборщик микросхем # parts part.integratedcircuits.iobit.name=Внешний вывод part.integratedcircuits.torch.name=Факел -part.integratedcircuits.tunnel.name=Перемычка +part.integratedcircuits.tunnel.0.name=Перемычка +part.integratedcircuits.tunnel.1.name=Красная Перемычка +part.integratedcircuits.tunnel.2.name=Оранжевая Перемычка part.integratedcircuits.wire.0.name=Провод part.integratedcircuits.wire.1.name=Красный провод part.integratedcircuits.wire.2.name=Оранжевый провод @@ -153,4 +155,4 @@ fdirection.east.name=ВОСТОК fdirection.south.name=ЮГ fdirection.west.name=ЗАПАД fdirection.up.name=ВЕРХ -fdirection.down.name=НИЗ \ No newline at end of file +fdirection.down.name=НИЗ diff --git a/src/main/resources/assets/integratedcircuits/textures/gui/sublogicpart.png b/src/main/resources/assets/integratedcircuits/textures/gui/sublogicpart.png index 23db946..abd94e5 100644 Binary files a/src/main/resources/assets/integratedcircuits/textures/gui/sublogicpart.png and b/src/main/resources/assets/integratedcircuits/textures/gui/sublogicpart.png differ