diff --git a/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java b/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java index 50c8dd187..413ed4eb2 100644 --- a/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java +++ b/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java @@ -27,7 +27,8 @@ public class GuiLaserAmplifier extends GuiMekanism { public TileEntityLaserAmplifier tileEntity; - public GuiTextField thresholdField; + public GuiTextField minField; + public GuiTextField maxField; public GuiTextField timerField; public GuiLaserAmplifier(InventoryPlayer inventory, TileEntityLaserAmplifier tentity) @@ -61,6 +62,7 @@ public class GuiLaserAmplifier extends GuiMekanism return "Stored: " + MekanismUtils.getEnergyDisplay(level); } }, Type.STANDARD, this, MekanismUtils.getResource(ResourceType.GUI, "GuiBlank.png"), 6, 10)); + guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiBlank.png"))); } @Override @@ -72,7 +74,9 @@ public class GuiLaserAmplifier extends GuiMekanism fontRendererObj.drawString(tileEntity.getInventoryName(), 55, 6, 0x404040); fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize - 96) + 2, 0x404040); - fontRendererObj.drawString(MekanismUtils.localize("gui.threshold" + ": " + MekanismUtils.getEnergyDisplay(tileEntity.threshold)), 75, 45, 0x404040); + fontRendererObj.drawString(tileEntity.time > 0 ? MekanismUtils.localize("gui.delay") + ": " + tileEntity.time + "t" : MekanismUtils.localize("gui.noDelay"), 26, 30, 0x404040); + fontRendererObj.drawString(MekanismUtils.localize("gui.min") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.minThreshold), 26, 45, 0x404040); + fontRendererObj.drawString(MekanismUtils.localize("gui.max") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.maxThreshold), 26, 60, 0x404040); super.drawGuiContainerForegroundLayer(mouseX, mouseY); } @@ -88,7 +92,8 @@ public class GuiLaserAmplifier extends GuiMekanism super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); - thresholdField.drawTextBox(); + minField.drawTextBox(); + maxField.drawTextBox(); timerField.drawTextBox(); } @@ -97,7 +102,8 @@ public class GuiLaserAmplifier extends GuiMekanism { super.updateScreen(); - thresholdField.updateCursorCounter(); + minField.updateCursorCounter(); + maxField.updateCursorCounter(); timerField.updateCursorCounter(); } @@ -106,23 +112,28 @@ public class GuiLaserAmplifier extends GuiMekanism { super.mouseClicked(mouseX, mouseY, button); - thresholdField.mouseClicked(mouseX, mouseY, button); + minField.mouseClicked(mouseX, mouseY, button); + maxField.mouseClicked(mouseX, mouseY, button); timerField.mouseClicked(mouseX, mouseY, button); } @Override public void keyTyped(char c, int i) { - if(!(thresholdField.isFocused() || timerField.isFocused()) || i == Keyboard.KEY_ESCAPE) + if(!(minField.isFocused() || maxField.isFocused() || timerField.isFocused()) || i == Keyboard.KEY_ESCAPE) { super.keyTyped(c, i); } if(i == Keyboard.KEY_RETURN) { - if(thresholdField.isFocused()) + if(minField.isFocused()) { - setThreshold(); + setMinThreshold(); + } + if(maxField.isFocused()) + { + setMaxThreshold(); } if(timerField.isFocused()) { @@ -132,24 +143,52 @@ public class GuiLaserAmplifier extends GuiMekanism if(Character.isDigit(c) || c == '.' || c == 'E' || i == Keyboard.KEY_BACK || i == Keyboard.KEY_DELETE || i == Keyboard.KEY_LEFT || i == Keyboard.KEY_RIGHT) { - thresholdField.textboxKeyTyped(c, i); + minField.textboxKeyTyped(c, i); + maxField.textboxKeyTyped(c, i); timerField.textboxKeyTyped(c, i); } } - private void setThreshold() + private void setMinThreshold() { - if(!thresholdField.getText().isEmpty()) + if(!minField.getText().isEmpty()) { double toUse; try { - toUse = Math.max(0, Double.parseDouble(thresholdField.getText())); + toUse = Math.max(0, Double.parseDouble(minField.getText())); } catch(Exception e) { - toUse = 0; + minField.setText(""); + return; + } + + ArrayList data = new ArrayList(); + data.add(0); + data.add(toUse); + + Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data)); + + minField.setText(""); + } + } + + private void setMaxThreshold() + { + if(!maxField.getText().isEmpty()) + { + double toUse; + + try + { + toUse = Math.max(0, Double.parseDouble(maxField.getText())); + } + catch(Exception e) + { + maxField.setText(""); + return; } ArrayList data = new ArrayList(); @@ -158,7 +197,7 @@ public class GuiLaserAmplifier extends GuiMekanism Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data)); - thresholdField.setText(""); + maxField.setText(""); } } @@ -186,16 +225,21 @@ public class GuiLaserAmplifier extends GuiMekanism int guiWidth = (width - xSize) / 2; int guiHeight = (height - ySize) / 2; - String prevThresh = thresholdField != null ? thresholdField.getText() : ""; - - thresholdField = new GuiTextField(fontRendererObj, guiWidth + 75, guiHeight + 55, 96, 11); - thresholdField.setMaxStringLength(10); - thresholdField.setText(prevThresh); - String prevTime = timerField != null ? timerField.getText() : ""; - timerField = new GuiTextField(fontRendererObj, guiWidth + 75, guiHeight + 15, 26, 11); + timerField = new GuiTextField(fontRendererObj, guiWidth + 96, guiHeight + 28, 36, 11); timerField.setMaxStringLength(4); timerField.setText(prevTime); + + String prevMin = minField != null ? minField.getText() : ""; + minField = new GuiTextField(fontRendererObj, guiWidth + 96, guiHeight + 43, 72, 11); + minField.setMaxStringLength(10); + minField.setText(prevMin); + + String prevMax = maxField != null ? maxField.getText() : ""; + + maxField = new GuiTextField(fontRendererObj, guiWidth + 96, guiHeight + 58, 72, 11); + maxField.setMaxStringLength(10); + maxField.setText(prevMax); } } diff --git a/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java b/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java index 689ea71cf..e3bd61f8b 100644 --- a/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java +++ b/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java @@ -7,7 +7,10 @@ import mekanism.api.MekanismConfig.general; import mekanism.api.lasers.ILaserReceptor; import mekanism.common.LaserManager; import mekanism.common.Mekanism; +import mekanism.common.base.IRedstoneControl; import mekanism.common.network.PacketTileEntity.TileEntityMessage; +import mekanism.common.tile.component.TileComponentUpgrade; +import mekanism.common.util.MekanismUtils; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -18,19 +21,19 @@ import net.minecraftforge.common.util.ForgeDirection; import io.netty.buffer.ByteBuf; -public class TileEntityLaserAmplifier extends TileEntityContainerBlock implements ILaserReceptor +public class TileEntityLaserAmplifier extends TileEntityContainerBlock implements ILaserReceptor, IRedstoneControl { public static final double MAX_ENERGY = 5E9; public double collectedEnergy = 0; public double lastFired = 0; - public double threshold = 0; + public double minThreshold = 0; + public double maxThreshold = 5E9; public int ticks = 0; public int time = 0; - public LaserEmitterMode mode = LaserEmitterMode.THRESHOLD; - public boolean poweredNow = false; - public boolean poweredLastTick = false; + public RedstoneControl controlType = RedstoneControl.DISABLED; + public boolean on = false; public Coord4D digging; @@ -66,8 +69,6 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement } else { - poweredNow = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); - if(ticks < time) { ticks++; @@ -77,7 +78,7 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement ticks = 0; } - if(shouldFire() && toFire() > 0) + if(toFire() > 0) { double firing = toFire(); @@ -125,8 +126,6 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement on = false; Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50D)); } - - poweredLastTick = poweredNow; } } @@ -142,34 +141,12 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement public boolean shouldFire() { - switch(mode) - { - case THRESHOLD: - return collectedEnergy >= threshold; - case REDSTONE: - return poweredNow; - case REDSTONE_PULSE: - return poweredNow && !poweredLastTick; - case TIMER: - return ticks == time; - } - return false; + return collectedEnergy >= minThreshold && ticks >= time && MekanismUtils.canFunction(this); } public double toFire() { - switch(mode) - { - case THRESHOLD: - return collectedEnergy; - case REDSTONE: - return collectedEnergy; - case REDSTONE_PULSE: - return collectedEnergy; - case TIMER: - return collectedEnergy; - } - return 0; + return shouldFire() ? Math.min(collectedEnergy, maxThreshold) : 0; } @Override @@ -178,11 +155,12 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement super.getNetworkedData(data); data.add(on); - data.add(mode.ordinal()); - data.add(threshold); + data.add(minThreshold); + data.add(maxThreshold); data.add(time); data.add(collectedEnergy); data.add(lastFired); + data.add(controlType.ordinal()); return data; } @@ -196,35 +174,45 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement on = dataStream.readBoolean(); - mode = LaserEmitterMode.values()[dataStream.readInt()]; - - threshold = dataStream.readDouble(); + minThreshold = dataStream.readDouble(); + maxThreshold = dataStream.readDouble(); time = dataStream.readInt(); collectedEnergy = dataStream.readDouble(); lastFired = dataStream.readDouble(); + controlType = RedstoneControl.values()[dataStream.readInt()]; return; } switch(dataStream.readInt()) { - case(0): - mode = LaserEmitterMode.values()[dataStream.readInt()]; + case 0: + minThreshold = dataStream.readDouble(); break; - case(1): - threshold = dataStream.readDouble(); + case 1: + maxThreshold = dataStream.readDouble(); break; - case(2): + case 2: time = dataStream.readInt(); break; } } - public static enum LaserEmitterMode + @Override + public RedstoneControl getControlType() { - THRESHOLD, - REDSTONE, - REDSTONE_PULSE, - TIMER; + return controlType; + } + + @Override + public void setControlType(RedstoneControl type) + { + controlType = type; + } + + @Override + public boolean canPulse() + { + return true; } } diff --git a/src/main/resources/assets/mekanism/gui/elements/GuiRedstoneControl.png b/src/main/resources/assets/mekanism/gui/elements/GuiRedstoneControl.png index 19e2b358d..6801bcc9c 100644 Binary files a/src/main/resources/assets/mekanism/gui/elements/GuiRedstoneControl.png and b/src/main/resources/assets/mekanism/gui/elements/GuiRedstoneControl.png differ diff --git a/src/main/resources/assets/mekanism/lang/en_US.lang b/src/main/resources/assets/mekanism/lang/en_US.lang index ef9251c7f..26d7e5d96 100644 --- a/src/main/resources/assets/mekanism/lang/en_US.lang +++ b/src/main/resources/assets/mekanism/lang/en_US.lang @@ -360,6 +360,10 @@ gui.finished=Finished gui.well=All is well! gui.upgrade=Upgrade gui.infinite=Infinite +gui.min=Min +gui.max=Max +gui.delay=Delay +gui.noDelay=No Delay gui.upgrades=Upgrades gui.upgrades.supported=Supported