1-1 wire connections

main
Astoria 1 year ago
parent 8a6accae6f
commit 9c336b4f36

@ -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();
}
}
}

@ -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);

@ -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);

@ -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<Integer>();
}
} 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<Integer>();
tool.yadd = new ArrayList<Integer>();
tool.zadd = new ArrayList<Integer>();
tool.sideadd = new ArrayList<Integer>();
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<Integer>();
@ -90,6 +93,12 @@ public class GuiWiring extends GuiScrollable {
tool.zadd = new ArrayList<Integer>();
tool.sideadd = new ArrayList<Integer>();
tool.type = "unpaired";
} else{
tool.xadd = new ArrayList<Integer>();
tool.yadd = new ArrayList<Integer>();
tool.zadd = new ArrayList<Integer>();
tool.sideadd = new ArrayList<Integer>();
tool.type = "unpaired";
}
}
this.mc.displayGuiScreen(null);

@ -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;
}
}
}

Loading…
Cancel
Save