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.

136 lines
5.6 KiB
Java

package net.brokenmoon.afloydwiremod.tileentity;
import net.brokenmoon.afloydwiremod.api.IWireConnectable;
import net.brokenmoon.afloydwiremod.api.WireConnection;
import net.brokenmoon.afloydwiremod.gui.WiringButton;
import net.minecraft.client.Minecraft;
import net.minecraft.src.*;
import java.util.ArrayList;
public class ChipTileEntity extends TileEntity implements IWireConnectable {
public WiringButton[] inputs = null;
public WiringButton[] outputs = null;
public String mode = "none";
@Override
public void updateEntity() {
updateIO();
switch(mode){
case "count":
doIncrement();
break;
}
}
private boolean shouldIncrement = true;
public void doIncrement(){
if(this.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;
}
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.mode = nbttagcompound.getString("mode");
if(nbttagcompound.getBoolean("inputExists")){
this.inputs = new WiringButton[nbttagcompound.getInteger("inputLength")];
NBTTagList nbttaglistInputs = nbttagcompound.getTagList("Inputs");
for (int i = 0; i < nbttaglistInputs.tagCount(); ++i) {
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglistInputs.tagAt(i);
this.inputs[i] = new WiringButton();
this.inputs[i].readFromNBT(nbttagcompound1);
}
}
if(nbttagcompound.getBoolean("outputExists")){
this.outputs = new WiringButton[nbttagcompound.getInteger("outputLength")];
NBTTagList nbttaglistOutputs = nbttagcompound.getTagList("Outputs");
for (int i = 0; i < nbttaglistOutputs.tagCount(); ++i) {
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglistOutputs.tagAt(i);
this.outputs[i] = new WiringButton();
this.outputs[i].readFromNBT(nbttagcompound1);
}
}
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setString("mode", mode);
if(inputs != null){
nbttagcompound.setBoolean("inputExists", true);
nbttagcompound.setInteger("inputLength", inputs.length);
NBTTagList nbttaglistInputs = new NBTTagList();
for(int i = 0; i < this.inputs.length; ++i){
NBTTagCompound nbttagInput = new NBTTagCompound();
this.inputs[i].writeToNBT(nbttagInput);
nbttaglistInputs.setTag(nbttagInput);
}
nbttagcompound.setTag("Inputs", nbttaglistInputs);
} else {
nbttagcompound.setBoolean("inputExists", false);
}
if(outputs != null){
nbttagcompound.setBoolean("outputExists", true);
nbttagcompound.setInteger("outputLength", outputs.length);
NBTTagList nbttaglistOutputs = new NBTTagList();
for(int i = 0; i < this.outputs.length; ++i){
NBTTagCompound nbttagOutput = new NBTTagCompound();
this.outputs[i].writeToNBT(nbttagOutput);
nbttaglistOutputs.setTag(nbttagOutput);
}
nbttagcompound.setTag("Outputs", nbttaglistOutputs);
} else {
nbttagcompound.setBoolean("outputExists", false);
}
}
public void setMode(String string){
if(mode.equals("none")) {
if(string.equals("constant")) {
System.out.println(string);
mode = string;
this.inputs = new WiringButton[0];
this.outputs = new WiringButton[1];
} else if(string.equals("count")){
System.out.println(string);
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);
System.out.println("ae");
}
}
}
public void 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;
ChipTileEntity otherChip = (ChipTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z);
if(otherChip == null) break;
if(otherChip.outputs == null) break;
if(inputs[i].floatvalue != otherChip.outputs[wire.thatslot].floatvalue) {
inputs[i].floatvalue = otherChip.outputs[wire.thatslot].floatvalue;
}
if(!inputs[i].stringvalue.equals(otherChip.outputs[wire.thatslot].stringvalue)) {
inputs[i].stringvalue = otherChip.outputs[wire.thatslot].stringvalue;
}
}
}
}
}
}