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.

69 lines
2.3 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;
@Override
public void updateEntity() {
switch (mode) {
case "count":
doIncrement();
break;
}
updateIO();
}
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;
System.out.println("Incrementing to " + this.outputs[0].floatvalue);
} 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")) {
if (string.equals("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;
} else if (string.equals("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;
}
}
}
}