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, "Division"));
this.controlList.add(new GuiButtonExtended(i++, this.width, "Memory"));
this.controlList.add(new GuiButtonExtended(i++, this.width, "Pulse"));
i = 0;
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 "Pulse":
((ChipTileEntity) wireEntity).setMode(guibutton.displayString);
break;
}

@ -16,17 +16,28 @@ public class GuiSettings extends GuiScreen {
//This.width / 2 - 214 is left
//Inputs
if(wireEntity instanceof ChipTileEntity){
if(((ChipTileEntity) wireEntity).mode.equals("constant")){
initConst();
switch(((ChipTileEntity) wireEntity).mode){
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(){
this.controlList.add(new GuiButton(1, this.width /2, this.height/2 - 20, "+"));
this.controlList.add(1,new GuiButton(0, this.width /2, this.height/2 , wireEntity.outputs[0].floatvalue + ""));
this.controlList.add(new GuiButton(2, 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 - 100, this.height/2 - 10 , wireEntity.outputs[0].floatvalue + ""));
this.controlList.add(new GuiButton(2, this.width /2 - 100, this.height/2 + 20 - 10, "-"));
}
public GuiSettings(EntityPlayer player, AbstractWireTileEntity wireEntity) {
@ -41,10 +52,23 @@ public class GuiSettings extends GuiScreen {
case "constant":
constAction(guiButton);
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) {
if(guiButton.id == 1){
wireEntity.outputs[0].floatvalue++;

@ -8,6 +8,22 @@ public class ChipTileEntity extends AbstractWireTileEntity {
public String mode = "none";
private boolean shouldIncrement = 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
public void update() {
@ -112,6 +128,24 @@ public class ChipTileEntity extends AbstractWireTileEntity {
doSpaceShip();
updateIO();
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) {
super.readFromNBT(nbttagcompound);
this.mode = nbttagcompound.getString("mode");
this.tickAmount = nbttagcompound.getInteger("tickAmount");
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setString("mode", mode);
nbttagcompound.setInteger("tickAmount", tickAmount);
}
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.inputs[0] = new WiringButton(214, 230, "Input", 0);
break;
case "Pulse":
hasSettings = true;
case "NOT":
this.inputs = new WiringButton[1];
this.outputs = new WiringButton[1];

Loading…
Cancel
Save