You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
6.5 KiB
Java

package net.brokenmoon.afloydwiremod.tileentity;
import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity;
import net.brokenmoon.afloydwiremod.gui.WiringButton;
import net.minecraft.src.NBTTagCompound;
public class ChipTileEntity extends AbstractWireTileEntity {
public String mode = "none";
private boolean shouldIncrement = true;
private boolean shouldDecrement = true;
@Override
public void update() {
switch (mode) {
case "inc":
doIncrement();
updateIO();
break;
case "dec":
doDecrement();
updateIO();
break;
case "incdec":
doIncrementDecrement();
updateIO();
break;
1 year ago
case "dup":
doDup();
updateIO();
break;
case "add":
doAdd();
updateIO();
break;
1 year ago
case "sub":
doSub();
updateIO();
break;
case "mult":
doMult();
updateIO();
break;
case "div":
doDiv();
updateIO();
break;
}
}
private void doIncrementDecrement() {
if (inputs[3].floatvalue > 0) {
this.outputs[0].floatvalue = 0;
return;
}
if (this.inputs[1].floatvalue > 0 && shouldIncrement) {
this.outputs[0].floatvalue = this.outputs[0].floatvalue + this.inputs[0].floatvalue;
shouldIncrement = false;
} else if (this.inputs[1].floatvalue == 0.0 && !shouldIncrement) {
shouldIncrement = true;
}
if (this.inputs[2].floatvalue > 0 && shouldDecrement) {
this.outputs[0].floatvalue = this.outputs[0].floatvalue - this.inputs[0].floatvalue;
shouldDecrement = false;
} else if (this.inputs[1].floatvalue == 0.0 && !shouldDecrement) {
shouldDecrement = true;
}
}
private void doDecrement() {
if (inputs[2].floatvalue > 0) {
this.outputs[0].floatvalue = 0;
return;
}
if (this.inputs[1].floatvalue > 0 && shouldIncrement) {
this.outputs[0].floatvalue = this.outputs[0].floatvalue - this.inputs[0].floatvalue;
shouldIncrement = false;
} else if (this.inputs[1].floatvalue == 0.0 && !shouldIncrement) {
shouldIncrement = true;
}
}
1 year ago
private void doDiv() {
outputs[0].floatvalue = inputs[0].floatvalue / inputs[1].floatvalue;
}
private void doMult() {
outputs[0].floatvalue = inputs[0].floatvalue * inputs[1].floatvalue;
}
private void doSub() {
outputs[0].floatvalue = inputs[0].floatvalue - inputs[1].floatvalue;
}
private void doDup() {
outputs[0].floatvalue = inputs[0].floatvalue;
outputs[1].floatvalue = inputs[0].floatvalue;
outputs[0].stringvalue = inputs[0].stringvalue;
outputs[1].stringvalue = inputs[0].stringvalue;
}
private void doAdd() {
outputs[0].floatvalue = inputs[0].floatvalue + inputs[1].floatvalue;
1 year ago
outputs[0].stringvalue = inputs[0].stringvalue + inputs[1].stringvalue;
}
public void doIncrement() {
if (inputs[2].floatvalue > 0) {
this.outputs[0].floatvalue = 0;
return;
}
if (this.inputs[1].floatvalue > 0 && shouldIncrement) {
this.outputs[0].floatvalue = this.outputs[0].floatvalue + this.inputs[0].floatvalue;
shouldIncrement = false;
} else if (this.inputs[1].floatvalue == 0.0 && !shouldIncrement) {
shouldIncrement = true;
}
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.mode = nbttagcompound.getString("mode");
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setString("mode", mode);
}
public void setMode(String string) {
if (mode.equals("none")) {
mode = string;
switch(string) {
case "constant":
this.inputs = new WiringButton[0];
this.outputs = new WiringButton[1];
this.outputs[0] = new WiringButton(214, 240, "Output", 0);
hasSettings = true;
break;
case "inc":
case "dec":
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);
break;
case "incdec":
this.inputs = new WiringButton[4];
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, 220, "Increment", 1);
this.inputs[2] = new WiringButton(214, 200, "Decrement", 2);
this.inputs[3] = new WiringButton(214, 180, "Reset", 3);
break;
1 year ago
case "dup":
this.inputs = new WiringButton[1];
this.outputs = new WiringButton[2];
this.outputs[0] = new WiringButton(214, 230, "Output A", 0);
this.outputs[1] = new WiringButton(214, 210, "Output B", 1);
this.inputs[0] = new WiringButton(214, 230, "Input", 0);
break;
case "add":
1 year ago
case "sub":
case "mult":
case "div":
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);
break;
}
initialized = true;
}
}
}