New chip, pulse! Now make a signal last as long as you wish, including 0 tick!

main
Astoria 1 year ago
parent b025231c6c
commit 1875a2c379

@ -33,6 +33,7 @@ public class GuiProgrammer extends GuiScrollable {
this.controlList.add(new GuiButtonExtended(i++, this.width, "Multiplication")); this.controlList.add(new GuiButtonExtended(i++, this.width, "Multiplication"));
this.controlList.add(new GuiButtonExtended(i++, this.width, "Division")); this.controlList.add(new GuiButtonExtended(i++, this.width, "Division"));
this.controlList.add(new GuiButtonExtended(i++, this.width, "Memory")); this.controlList.add(new GuiButtonExtended(i++, this.width, "Memory"));
this.controlList.add(new GuiButtonExtended(i++, this.width, "Pulse"));
i = 0; i = 0;
this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "==")); this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "=="));
this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "!=")); this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "!="));
@ -98,6 +99,7 @@ public class GuiProgrammer extends GuiScrollable {
case "<": case "<":
case "<=": case "<=":
case "<=>": case "<=>":
case "Pulse":
((ChipTileEntity) wireEntity).setMode(guibutton.displayString); ((ChipTileEntity) wireEntity).setMode(guibutton.displayString);
break; break;
} }

@ -16,17 +16,28 @@ public class GuiSettings extends GuiScreen {
//This.width / 2 - 214 is left //This.width / 2 - 214 is left
//Inputs //Inputs
if(wireEntity instanceof ChipTileEntity){ if(wireEntity instanceof ChipTileEntity){
if(((ChipTileEntity) wireEntity).mode.equals("constant")){ switch(((ChipTileEntity) wireEntity).mode){
initConst(); case "constant":
initConst();
break;
case "Pulse":
initPulse();
break;
} }
} }
} }
private void initPulse() {
this.controlList.add(new GuiButton(1, this.width /2 - 100, this.height/2 - 20 - 10, "+"));
this.controlList.add(1,new GuiButton(0, this.width /2 - 100, this.height/2 - 10, ((ChipTileEntity)wireEntity).tickAmount + ""));
this.controlList.add(new GuiButton(2, this.width /2 - 100, this.height/2 + 20 - 10, "-"));
}
public void initConst(){ public void initConst(){
this.controlList.add(new GuiButton(1, this.width /2, this.height/2 - 20, "+")); this.controlList.add(new GuiButton(1, this.width /2 - 100, this.height/2 - 20 - 10, "+"));
this.controlList.add(1,new GuiButton(0, this.width /2, this.height/2 , wireEntity.outputs[0].floatvalue + "")); this.controlList.add(1,new GuiButton(0, this.width /2 - 100, this.height/2 - 10 , wireEntity.outputs[0].floatvalue + ""));
this.controlList.add(new GuiButton(2, this.width /2, this.height/2 + 20, "-")); this.controlList.add(new GuiButton(2, this.width /2 - 100, this.height/2 + 20 - 10, "-"));
} }
public GuiSettings(EntityPlayer player, AbstractWireTileEntity wireEntity) { public GuiSettings(EntityPlayer player, AbstractWireTileEntity wireEntity) {
@ -41,10 +52,23 @@ public class GuiSettings extends GuiScreen {
case "constant": case "constant":
constAction(guiButton); constAction(guiButton);
break; break;
case "Pulse":
pulseAction(guiButton);
break;
} }
} }
} }
private void pulseAction(GuiButton guiButton) {
if(guiButton.id == 1){
((ChipTileEntity)wireEntity).tickAmount++;
}
if(guiButton.id == 2){
((ChipTileEntity)wireEntity).tickAmount--;
}
this.controlList.get(1).displayString = ((ChipTileEntity)wireEntity).tickAmount + "";
}
private void constAction(GuiButton guiButton) { private void constAction(GuiButton guiButton) {
if(guiButton.id == 1){ if(guiButton.id == 1){
wireEntity.outputs[0].floatvalue++; wireEntity.outputs[0].floatvalue++;

@ -8,6 +8,22 @@ public class ChipTileEntity extends AbstractWireTileEntity {
public String mode = "none"; public String mode = "none";
private boolean shouldIncrement = true; private boolean shouldIncrement = true;
private boolean shouldDecrement = true; private boolean shouldDecrement = true;
private int timer;
public int tickAmount = 0;
@Override
public void updateEntity(){
if(timer == 0){
switch (mode){
case "Pulse":
outputs[0].floatvalue = 0;
outputs[0].stringvalue = "";
updateIO();
}
} else{
timer--;
}
}
@Override @Override
public void update() { public void update() {
@ -112,6 +128,24 @@ public class ChipTileEntity extends AbstractWireTileEntity {
doSpaceShip(); doSpaceShip();
updateIO(); updateIO();
break; break;
case "Pulse":
doPulse();
break;
}
}
private void doPulse() {
if(inputs[0].floatvalue != 0 && timer == 0) {
outputs[0].floatvalue = inputs[0].floatvalue;
outputs[0].stringvalue = inputs[0].stringvalue;
updateIO();
if(tickAmount == 0){
outputs[0].floatvalue = 0;
outputs[0].stringvalue = "";
updateIO();
} else{
timer = tickAmount - 1;
}
} }
} }
@ -258,12 +292,14 @@ public class ChipTileEntity extends AbstractWireTileEntity {
public void readFromNBT(NBTTagCompound nbttagcompound) { public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound); super.readFromNBT(nbttagcompound);
this.mode = nbttagcompound.getString("mode"); this.mode = nbttagcompound.getString("mode");
this.tickAmount = nbttagcompound.getInteger("tickAmount");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbttagcompound) { public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound); super.writeToNBT(nbttagcompound);
nbttagcompound.setString("mode", mode); nbttagcompound.setString("mode", mode);
nbttagcompound.setInteger("tickAmount", tickAmount);
} }
public void setMode(String string) { public void setMode(String string) {
@ -304,6 +340,8 @@ public class ChipTileEntity extends AbstractWireTileEntity {
this.outputs[1] = new WiringButton(214, 210, "Output B", 1); this.outputs[1] = new WiringButton(214, 210, "Output B", 1);
this.inputs[0] = new WiringButton(214, 230, "Input", 0); this.inputs[0] = new WiringButton(214, 230, "Input", 0);
break; break;
case "Pulse":
hasSettings = true;
case "NOT": case "NOT":
this.inputs = new WiringButton[1]; this.inputs = new WiringButton[1];
this.outputs = new WiringButton[1]; this.outputs = new WiringButton[1];

Loading…
Cancel
Save