Make the Laser Amplifier actually satisfactorily functional.

Redstone controls, minimum and maximum energy thresholds, and time delays all work concurrently, removing the need for distinct modes.
This commit is contained in:
Ben Spiers 2014-09-16 02:28:37 +01:00
parent e84f176583
commit c12c54f9bf
4 changed files with 106 additions and 70 deletions

View file

@ -27,7 +27,8 @@ public class GuiLaserAmplifier extends GuiMekanism
{ {
public TileEntityLaserAmplifier tileEntity; public TileEntityLaserAmplifier tileEntity;
public GuiTextField thresholdField; public GuiTextField minField;
public GuiTextField maxField;
public GuiTextField timerField; public GuiTextField timerField;
public GuiLaserAmplifier(InventoryPlayer inventory, TileEntityLaserAmplifier tentity) public GuiLaserAmplifier(InventoryPlayer inventory, TileEntityLaserAmplifier tentity)
@ -61,6 +62,7 @@ public class GuiLaserAmplifier extends GuiMekanism
return "Stored: " + MekanismUtils.getEnergyDisplay(level); return "Stored: " + MekanismUtils.getEnergyDisplay(level);
} }
}, Type.STANDARD, this, MekanismUtils.getResource(ResourceType.GUI, "GuiBlank.png"), 6, 10)); }, Type.STANDARD, this, MekanismUtils.getResource(ResourceType.GUI, "GuiBlank.png"), 6, 10));
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiBlank.png")));
} }
@Override @Override
@ -72,7 +74,9 @@ public class GuiLaserAmplifier extends GuiMekanism
fontRendererObj.drawString(tileEntity.getInventoryName(), 55, 6, 0x404040); fontRendererObj.drawString(tileEntity.getInventoryName(), 55, 6, 0x404040);
fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize - 96) + 2, 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); super.drawGuiContainerForegroundLayer(mouseX, mouseY);
} }
@ -88,7 +92,8 @@ public class GuiLaserAmplifier extends GuiMekanism
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
thresholdField.drawTextBox(); minField.drawTextBox();
maxField.drawTextBox();
timerField.drawTextBox(); timerField.drawTextBox();
} }
@ -97,7 +102,8 @@ public class GuiLaserAmplifier extends GuiMekanism
{ {
super.updateScreen(); super.updateScreen();
thresholdField.updateCursorCounter(); minField.updateCursorCounter();
maxField.updateCursorCounter();
timerField.updateCursorCounter(); timerField.updateCursorCounter();
} }
@ -106,23 +112,28 @@ public class GuiLaserAmplifier extends GuiMekanism
{ {
super.mouseClicked(mouseX, mouseY, button); 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); timerField.mouseClicked(mouseX, mouseY, button);
} }
@Override @Override
public void keyTyped(char c, int i) 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); super.keyTyped(c, i);
} }
if(i == Keyboard.KEY_RETURN) if(i == Keyboard.KEY_RETURN)
{ {
if(thresholdField.isFocused()) if(minField.isFocused())
{ {
setThreshold(); setMinThreshold();
}
if(maxField.isFocused())
{
setMaxThreshold();
} }
if(timerField.isFocused()) 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) 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); timerField.textboxKeyTyped(c, i);
} }
} }
private void setThreshold() private void setMinThreshold()
{ {
if(!thresholdField.getText().isEmpty()) if(!minField.getText().isEmpty())
{ {
double toUse; double toUse;
try try
{ {
toUse = Math.max(0, Double.parseDouble(thresholdField.getText())); toUse = Math.max(0, Double.parseDouble(minField.getText()));
} }
catch(Exception e) 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(); ArrayList data = new ArrayList();
@ -158,7 +197,7 @@ public class GuiLaserAmplifier extends GuiMekanism
Mekanism.packetHandler.sendToServer(new TileEntityMessage(Coord4D.get(tileEntity), data)); 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 guiWidth = (width - xSize) / 2;
int guiHeight = (height - ySize) / 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() : ""; 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.setMaxStringLength(4);
timerField.setText(prevTime); 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);
} }
} }

View file

@ -7,7 +7,10 @@ import mekanism.api.MekanismConfig.general;
import mekanism.api.lasers.ILaserReceptor; import mekanism.api.lasers.ILaserReceptor;
import mekanism.common.LaserManager; import mekanism.common.LaserManager;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.network.PacketTileEntity.TileEntityMessage; 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.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -18,19 +21,19 @@ import net.minecraftforge.common.util.ForgeDirection;
import io.netty.buffer.ByteBuf; 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 static final double MAX_ENERGY = 5E9;
public double collectedEnergy = 0; public double collectedEnergy = 0;
public double lastFired = 0; public double lastFired = 0;
public double threshold = 0; public double minThreshold = 0;
public double maxThreshold = 5E9;
public int ticks = 0; public int ticks = 0;
public int time = 0; public int time = 0;
public LaserEmitterMode mode = LaserEmitterMode.THRESHOLD; public RedstoneControl controlType = RedstoneControl.DISABLED;
public boolean poweredNow = false;
public boolean poweredLastTick = false;
public boolean on = false; public boolean on = false;
public Coord4D digging; public Coord4D digging;
@ -66,8 +69,6 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
} }
else else
{ {
poweredNow = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
if(ticks < time) if(ticks < time)
{ {
ticks++; ticks++;
@ -77,7 +78,7 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
ticks = 0; ticks = 0;
} }
if(shouldFire() && toFire() > 0) if(toFire() > 0)
{ {
double firing = toFire(); double firing = toFire();
@ -125,8 +126,6 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
on = false; on = false;
Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50D)); 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() public boolean shouldFire()
{ {
switch(mode) return collectedEnergy >= minThreshold && ticks >= time && MekanismUtils.canFunction(this);
{
case THRESHOLD:
return collectedEnergy >= threshold;
case REDSTONE:
return poweredNow;
case REDSTONE_PULSE:
return poweredNow && !poweredLastTick;
case TIMER:
return ticks == time;
}
return false;
} }
public double toFire() public double toFire()
{ {
switch(mode) return shouldFire() ? Math.min(collectedEnergy, maxThreshold) : 0;
{
case THRESHOLD:
return collectedEnergy;
case REDSTONE:
return collectedEnergy;
case REDSTONE_PULSE:
return collectedEnergy;
case TIMER:
return collectedEnergy;
}
return 0;
} }
@Override @Override
@ -178,11 +155,12 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
super.getNetworkedData(data); super.getNetworkedData(data);
data.add(on); data.add(on);
data.add(mode.ordinal()); data.add(minThreshold);
data.add(threshold); data.add(maxThreshold);
data.add(time); data.add(time);
data.add(collectedEnergy); data.add(collectedEnergy);
data.add(lastFired); data.add(lastFired);
data.add(controlType.ordinal());
return data; return data;
} }
@ -196,35 +174,45 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
on = dataStream.readBoolean(); on = dataStream.readBoolean();
mode = LaserEmitterMode.values()[dataStream.readInt()]; minThreshold = dataStream.readDouble();
maxThreshold = dataStream.readDouble();
threshold = dataStream.readDouble();
time = dataStream.readInt(); time = dataStream.readInt();
collectedEnergy = dataStream.readDouble(); collectedEnergy = dataStream.readDouble();
lastFired = dataStream.readDouble(); lastFired = dataStream.readDouble();
controlType = RedstoneControl.values()[dataStream.readInt()];
return; return;
} }
switch(dataStream.readInt()) switch(dataStream.readInt())
{ {
case(0): case 0:
mode = LaserEmitterMode.values()[dataStream.readInt()]; minThreshold = dataStream.readDouble();
break; break;
case(1): case 1:
threshold = dataStream.readDouble(); maxThreshold = dataStream.readDouble();
break; break;
case(2): case 2:
time = dataStream.readInt(); time = dataStream.readInt();
break; break;
} }
} }
public static enum LaserEmitterMode @Override
public RedstoneControl getControlType()
{ {
THRESHOLD, return controlType;
REDSTONE, }
REDSTONE_PULSE,
TIMER; @Override
public void setControlType(RedstoneControl type)
{
controlType = type;
}
@Override
public boolean canPulse()
{
return true;
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -360,6 +360,10 @@ gui.finished=Finished
gui.well=All is well! gui.well=All is well!
gui.upgrade=Upgrade gui.upgrade=Upgrade
gui.infinite=Infinite gui.infinite=Infinite
gui.min=Min
gui.max=Max
gui.delay=Delay
gui.noDelay=No Delay
gui.upgrades=Upgrades gui.upgrades=Upgrades
gui.upgrades.supported=Supported gui.upgrades.supported=Supported