Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -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<CircuitRenderWrapper> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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();

Expand Down Expand Up @@ -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()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,22 @@ public boolean mousePressed(Minecraft mc, int par1, int par2) {
public List<String> getHoverInformation() {
ArrayList<String> text = new ArrayList<String>();
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Expand Down Expand Up @@ -53,14 +54,15 @@ public GuiPartChooser(int id, int x, int y, CircuitRenderWrapper current, List<C
this.parent = parent;
}

public GuiPartChooser(int id, int x, int y, List<CircuitRenderWrapper> list2, GuiCAD parent) {
public GuiPartChooser(int id, int x, int y, int above, List<CircuitRenderWrapper> list2, GuiCAD parent) {
super(id, x, y, 20, 20, "");
partsAbove = above;
if (list2.size() > 0) {
current = list2.get(0);
ArrayList<CircuitRenderWrapper> list3 = new ArrayList<CircuitRenderWrapper>(list2);
this.children = new ArrayList<GuiPartChooser>();
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);
Expand All @@ -70,6 +72,10 @@ public GuiPartChooser(int id, int x, int y, List<CircuitRenderWrapper> list2, Gu
this.parent = parent;
}

public GuiPartChooser(int id, int x, int y, List<CircuitRenderWrapper> 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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,7 @@
public class CircuitData implements Cloneable {

// cdata version
public static final int version = 1;
public static final int version = 2;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the legacy loader doesn't work at all (because it doesn't do the steps in sequence, there's a big TODO on it), so if you decide to change the version it should probably be fixed first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These steps are NBT, transform and postTransform. For what I did this is fine.
Anyway, the proper solution is to do conversion using separate "frozen" codebase that will never have to be changed. That is, no CircuitData or any other such classes. It should receive NBT and produce new NBT.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess... Still would like to see that get fixed though


private int size;
private int[][] meta;
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ public abstract class LegacyLoader implements Comparable<LegacyLoader> {

private static final List<LegacyLoader> legacyLoaders = new ArrayList<LegacyLoader>();
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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading