Merge pull request #1853 from pwestling/add_dump_excess_to_gas_tank
add "dump excess" option to gas tank
This commit is contained in:
commit
68f6348c31
5 changed files with 69 additions and 21 deletions
|
@ -2,6 +2,8 @@ package mekanism.client.gui;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.common.Mekanism;
|
||||
|
@ -11,12 +13,8 @@ import mekanism.common.tile.TileEntityGasTank;
|
|||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiGasTank extends GuiMekanism
|
||||
{
|
||||
|
@ -37,17 +35,18 @@ public class GuiGasTank extends GuiMekanism
|
|||
|
||||
String capacityInfo = tileEntity.gasTank.getStored() + "/" + tileEntity.MAX_GAS;
|
||||
|
||||
fontRendererObj.drawString(tileEntity.getInventoryName(), (xSize/2)-(fontRendererObj.getStringWidth(tileEntity.getInventoryName())/2), 6, 0x404040);
|
||||
fontRendererObj.drawString(tileEntity.getInventoryName(), (xSize / 2) - (fontRendererObj.getStringWidth(tileEntity.getInventoryName()) / 2), 6, 0x404040);
|
||||
fontRendererObj.drawString(capacityInfo, 45, 40, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.gas") + ": " + (tileEntity.gasTank.getGas() != null ? tileEntity.gasTank.getGas().getGas().getLocalizedName() : MekanismUtils.localize("gui.none")), 45, 49, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, ySize - 96 + 2, 0x404040);
|
||||
|
||||
String name = tileEntity.dumping ? MekanismUtils.localize("gui.dumping") + "..." : MekanismUtils.localize("gui.idle");
|
||||
fontRendererObj.drawString(name, 156-fontRendererObj.getStringWidth(name), 73, 0x404040);
|
||||
String name = chooseByMode(tileEntity.dumping, MekanismUtils.localize("gui.idle"), MekanismUtils.localize("gui.dumping"), MekanismUtils.localize("gui.dumping_excess"));
|
||||
fontRendererObj.drawString(name, 156 - fontRendererObj.getStringWidth(name), 73, 0x404040);
|
||||
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
|
||||
{
|
||||
|
@ -59,7 +58,7 @@ public class GuiGasTank extends GuiMekanism
|
|||
int guiHeight = (height - ySize) / 2;
|
||||
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
|
||||
|
||||
int displayInt = tileEntity.dumping ? 18 : 10;
|
||||
int displayInt = chooseByMode(tileEntity.dumping, 10, 18, 26);
|
||||
drawTexturedModalRect(guiWidth + 160, guiHeight + 73, 176, displayInt, 8, 8);
|
||||
|
||||
if(tileEntity.gasTank.getGas() != null)
|
||||
|
@ -86,4 +85,21 @@ public class GuiGasTank extends GuiMekanism
|
|||
SoundHandler.playSound("gui.button.press");
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T chooseByMode(TileEntityGasTank.Mode dumping, T idleOption, T dumpingOption, T dumpingExcessOption)
|
||||
{
|
||||
if(dumping.equals(TileEntityGasTank.Mode.IDLE))
|
||||
{
|
||||
return idleOption;
|
||||
}
|
||||
if(dumping.equals(TileEntityGasTank.Mode.DUMPING))
|
||||
{
|
||||
return dumpingOption;
|
||||
}
|
||||
if(dumping.equals(TileEntityGasTank.Mode.DUMPING_EXCESS))
|
||||
{
|
||||
return dumpingExcessOption;
|
||||
}
|
||||
return idleOption; //should not happen;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasRegistry;
|
||||
|
@ -26,6 +25,13 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
|
||||
public class TileEntityGasTank extends TileEntityContainerBlock implements IGasHandler, ITubeConnection, IRedstoneControl
|
||||
{
|
||||
public enum Mode
|
||||
{
|
||||
IDLE,
|
||||
DUMPING,
|
||||
DUMPING_EXCESS
|
||||
}
|
||||
|
||||
/** The type of gas stored in this tank. */
|
||||
public GasTank gasTank = new GasTank(MAX_GAS);
|
||||
|
||||
|
@ -34,7 +40,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
|
|||
/** How fast this tank can output gas. */
|
||||
public int output = 256;
|
||||
|
||||
public boolean dumping;
|
||||
public Mode dumping;
|
||||
|
||||
/** This machine's current RedstoneControl type. */
|
||||
public RedstoneControl controlType;
|
||||
|
@ -43,6 +49,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
|
|||
{
|
||||
super("GasTank");
|
||||
inventory = new ItemStack[2];
|
||||
dumping = Mode.IDLE;
|
||||
controlType = RedstoneControl.DISABLED;
|
||||
}
|
||||
|
||||
|
@ -74,10 +81,15 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
|
|||
}
|
||||
}
|
||||
|
||||
if(!worldObj.isRemote && dumping)
|
||||
if(!worldObj.isRemote && dumping.equals(Mode.DUMPING))
|
||||
{
|
||||
gasTank.draw(8, true);
|
||||
}
|
||||
|
||||
if(!worldObj.isRemote && dumping.equals(Mode.DUMPING_EXCESS) && gasTank.getNeeded() < output)
|
||||
{
|
||||
gasTank.draw(output, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,7 +102,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
|
|||
else if(slotID == 0)
|
||||
{
|
||||
return (itemstack.getItem() instanceof IGasItem && ((IGasItem)itemstack.getItem()).getGas(itemstack) != null &&
|
||||
((IGasItem)itemstack.getItem()).getGas(itemstack).amount == ((IGasItem)itemstack.getItem()).getMaxGas(itemstack));
|
||||
((IGasItem)itemstack.getItem()).getGas(itemstack).amount == ((IGasItem)itemstack.getItem()).getMaxGas(itemstack));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -114,7 +126,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
|
|||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side)
|
||||
{
|
||||
return side == 1 ? new int[] {0} : new int[] {1};
|
||||
return side == 1 ? new int[]{0} : new int[]{1};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,7 +167,8 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
|
|||
|
||||
if(type == 0)
|
||||
{
|
||||
dumping = !dumping;
|
||||
int index = (dumping.ordinal() + 1)%dumping.values().length;
|
||||
dumping = Mode.values()[index];
|
||||
}
|
||||
|
||||
for(EntityPlayer player : playersUsing)
|
||||
|
@ -172,11 +185,12 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
|
|||
{
|
||||
gasTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
gasTank.setGas(null);
|
||||
}
|
||||
|
||||
dumping = dataStream.readBoolean();
|
||||
dumping = Mode.values()[dataStream.readInt()];
|
||||
controlType = RedstoneControl.values()[dataStream.readInt()];
|
||||
|
||||
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
|
||||
|
@ -188,7 +202,22 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
|
|||
super.readFromNBT(nbtTags);
|
||||
|
||||
gasTank.read(nbtTags.getCompoundTag("gasTank"));
|
||||
dumping = nbtTags.getBoolean("dumping");
|
||||
if(nbtTags.hasKey("dumpingMode"))
|
||||
{
|
||||
dumping = Mode.valueOf(nbtTags.getString("dumpingMode"));
|
||||
}
|
||||
else //For backwards compatibility
|
||||
{
|
||||
boolean dumpingBool = nbtTags.getBoolean("dumping");
|
||||
if(dumpingBool)
|
||||
{
|
||||
dumping = Mode.DUMPING;
|
||||
}
|
||||
else
|
||||
{
|
||||
dumping = Mode.IDLE;
|
||||
}
|
||||
}
|
||||
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
|
||||
}
|
||||
|
||||
|
@ -198,7 +227,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
|
|||
super.writeToNBT(nbtTags);
|
||||
|
||||
nbtTags.setTag("gasTank", gasTank.write(new NBTTagCompound()));
|
||||
nbtTags.setBoolean("dumping", dumping);
|
||||
nbtTags.setString("dumpingMode", dumping.name());
|
||||
nbtTags.setInteger("controlType", controlType.ordinal());
|
||||
}
|
||||
|
||||
|
@ -213,11 +242,12 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
|
|||
data.add(gasTank.getGas().getGas().getID());
|
||||
data.add(gasTank.getStored());
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
data.add(false);
|
||||
}
|
||||
|
||||
data.add(dumping);
|
||||
data.add(dumping.ordinal());
|
||||
data.add(controlType.ordinal());
|
||||
|
||||
return data;
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 2.3 KiB |
|
@ -338,6 +338,7 @@ gui.newFilter=Neuer Filter
|
|||
gui.energy=Energie
|
||||
gui.gas=Gas
|
||||
gui.dumping=Ausleeren
|
||||
gui.dumping_excess=Ausleeren Über
|
||||
gui.modID=Mod-ID
|
||||
gui.key=Key
|
||||
gui.id=ID
|
||||
|
|
|
@ -338,6 +338,7 @@ gui.newFilter=New Filter
|
|||
gui.energy=Energy
|
||||
gui.gas=Gas
|
||||
gui.dumping=Dumping
|
||||
gui.dumping_excess=Dumping Excess
|
||||
gui.modID=Mod ID
|
||||
gui.key=Key
|
||||
gui.id=ID
|
||||
|
|
Loading…
Reference in a new issue