|
|
|
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;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update() {
|
|
|
|
switch (mode) {
|
|
|
|
case "count":
|
|
|
|
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;
|
|
|
|
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 "count":
|
|
|
|
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 "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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|