From 1875a2c379fe39dc25b02ac4d792006ad88d64b1 Mon Sep 17 00:00:00 2001 From: Astoria Date: Tue, 4 Apr 2023 19:01:34 -0500 Subject: [PATCH] New chip, pulse! Now make a signal last as long as you wish, including 0 tick! --- .../afloydwiremod/gui/GuiProgrammer.java | 2 + .../afloydwiremod/gui/GuiSettings.java | 34 ++++++++++++++--- .../tileentity/ChipTileEntity.java | 38 +++++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java index f6f1397..a20abc6 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java @@ -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; } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiSettings.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiSettings.java index fa1533b..9eebea5 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiSettings.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiSettings.java @@ -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++; diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java index f988d20..ce75b84 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java @@ -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];