2014-01-26 23:55:49 +01:00
|
|
|
package mekanism.client.gui;
|
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
import java.util.ArrayList;
|
2014-01-31 22:32:13 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2014-02-01 19:48:37 +01:00
|
|
|
import mekanism.api.Coord4D;
|
2014-02-01 18:28:04 +01:00
|
|
|
import mekanism.api.EnumColor;
|
2014-01-31 22:32:13 +01:00
|
|
|
import mekanism.api.ListUtils;
|
2014-02-01 18:28:04 +01:00
|
|
|
import mekanism.api.gas.Gas;
|
2014-01-31 22:32:13 +01:00
|
|
|
import mekanism.api.gas.GasStack;
|
2014-02-01 18:28:04 +01:00
|
|
|
import mekanism.api.gas.OreGas;
|
2014-01-31 22:32:13 +01:00
|
|
|
import mekanism.client.gui.GuiEnergyInfo.IInfoHandler;
|
|
|
|
import mekanism.client.render.MekanismRenderer;
|
2014-02-01 19:48:37 +01:00
|
|
|
import mekanism.common.PacketHandler;
|
|
|
|
import mekanism.common.PacketHandler.Transmission;
|
2014-01-31 22:32:13 +01:00
|
|
|
import mekanism.common.inventory.container.ContainerChemicalCrystalizer;
|
2014-02-01 19:48:37 +01:00
|
|
|
import mekanism.common.network.PacketTileEntity;
|
2014-01-31 22:32:13 +01:00
|
|
|
import mekanism.common.tile.TileEntityChemicalCrystalizer;
|
|
|
|
import mekanism.common.util.MekanismUtils;
|
|
|
|
import mekanism.common.util.MekanismUtils.ResourceType;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2014-02-01 18:28:04 +01:00
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-01-31 22:32:13 +01:00
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2014-02-01 18:28:04 +01:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2014-01-31 22:32:13 +01:00
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
import org.apache.commons.lang3.text.WordUtils;
|
2014-01-31 22:32:13 +01:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2014-01-31 20:59:12 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2014-01-31 22:32:13 +01:00
|
|
|
public class GuiChemicalCrystalizer extends GuiMekanism
|
2014-01-26 23:55:49 +01:00
|
|
|
{
|
2014-01-31 22:32:13 +01:00
|
|
|
public TileEntityChemicalCrystalizer tileEntity;
|
2014-02-01 18:28:04 +01:00
|
|
|
|
|
|
|
public Gas prevGas;
|
|
|
|
|
|
|
|
public ItemStack renderStack;
|
|
|
|
|
|
|
|
public int stackSwitch = 0;
|
|
|
|
|
|
|
|
public int stackIndex = 0;
|
|
|
|
|
|
|
|
public List<ItemStack> iterStacks;
|
2014-01-31 22:32:13 +01:00
|
|
|
|
|
|
|
public GuiChemicalCrystalizer(InventoryPlayer inventory, TileEntityChemicalCrystalizer tentity)
|
|
|
|
{
|
|
|
|
super(tentity, new ContainerChemicalCrystalizer(inventory, tentity));
|
|
|
|
tileEntity = tentity;
|
|
|
|
|
|
|
|
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalCrystalizer.png")));
|
2014-02-01 19:48:37 +01:00
|
|
|
guiElements.add(new GuiPowerBar(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalCrystalizer.png"), 160, 23));
|
2014-01-31 22:32:13 +01:00
|
|
|
guiElements.add(new GuiEnergyInfo(new IInfoHandler() {
|
|
|
|
@Override
|
|
|
|
public List<String> getInfo()
|
|
|
|
{
|
|
|
|
String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.ENERGY_USAGE);
|
|
|
|
return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy()));
|
|
|
|
}
|
|
|
|
}, this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalCrystalizer.png")));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
fontRenderer.drawString(tileEntity.getInvName(), 37, 4, 0x404040);
|
|
|
|
|
|
|
|
if(tileEntity.inputTank.getGas() != null)
|
|
|
|
{
|
2014-02-01 19:48:37 +01:00
|
|
|
fontRenderer.drawString(tileEntity.inputTank.getGas().getGas().getLocalizedName(), 29, 15, 0x00CD00);
|
|
|
|
fontRenderer.drawString("(" + ((OreGas)tileEntity.inputTank.getGas().getGas()).getOreName() + ")", 29, 24, 0x00CD00);
|
2014-02-01 18:28:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(renderStack != null)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glEnable(GL11.GL_LIGHTING);
|
2014-02-01 19:48:37 +01:00
|
|
|
itemRenderer.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), renderStack, 131, 14);
|
2014-02-01 18:28:04 +01:00
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
} catch(Exception e) {}
|
|
|
|
}
|
2014-01-31 22:32:13 +01:00
|
|
|
|
|
|
|
if(xAxis >= 6 && xAxis <= 22 && yAxis >= 5 && yAxis <= 63)
|
|
|
|
{
|
|
|
|
drawCreativeTabHoveringText(tileEntity.inputTank.getGas() != null ? tileEntity.inputTank.getGas().getGas().getLocalizedName() + ": " + tileEntity.inputTank.getStored() : MekanismUtils.localize("gui.empty"), xAxis, yAxis);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
|
2014-02-01 19:48:37 +01:00
|
|
|
{
|
2014-01-31 22:32:13 +01:00
|
|
|
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalCrystalizer.png"));
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
int guiWidth = (width - xSize) / 2;
|
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
|
|
|
|
|
|
|
|
int xAxis = mouseX - guiWidth;
|
|
|
|
int yAxis = mouseY - guiHeight;
|
|
|
|
|
|
|
|
int displayInt;
|
|
|
|
|
|
|
|
displayInt = tileEntity.getScaledProgress(48);
|
2014-02-01 19:48:37 +01:00
|
|
|
drawTexturedModalRect(guiWidth + 53, guiHeight + 61, 176, 63, displayInt, 8);
|
2014-01-31 22:32:13 +01:00
|
|
|
|
|
|
|
if(tileEntity.getScaledInputGasLevel(58) > 0)
|
|
|
|
{
|
|
|
|
displayGauge(6, 5, tileEntity.getScaledInputGasLevel(58), null, tileEntity.inputTank.getGas());
|
|
|
|
}
|
2014-02-01 19:48:37 +01:00
|
|
|
|
|
|
|
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
|
2014-01-31 22:32:13 +01:00
|
|
|
}
|
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
private Gas getInputGas()
|
|
|
|
{
|
|
|
|
return tileEntity.inputTank.getGas() != null ? tileEntity.inputTank.getGas().getGas() : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resetStacks()
|
|
|
|
{
|
|
|
|
iterStacks.clear();
|
|
|
|
renderStack = null;
|
|
|
|
stackSwitch = 0;
|
|
|
|
stackIndex = -1;
|
|
|
|
}
|
|
|
|
|
2014-02-01 19:48:37 +01:00
|
|
|
@Override
|
|
|
|
protected void mouseClicked(int x, int y, int button)
|
|
|
|
{
|
|
|
|
super.mouseClicked(x, y, button);
|
|
|
|
|
|
|
|
if(button == 0)
|
|
|
|
{
|
|
|
|
int xAxis = (x - (width - xSize) / 2);
|
|
|
|
int yAxis = (y - (height - ySize) / 2);
|
|
|
|
|
|
|
|
if(xAxis > 24 && xAxis < 42 && yAxis > 56 && yAxis < 64)
|
|
|
|
{
|
|
|
|
ArrayList data = new ArrayList();
|
|
|
|
data.add(0);
|
|
|
|
|
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Coord4D.get(tileEntity), data));
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
@Override
|
|
|
|
public void updateScreen()
|
|
|
|
{
|
|
|
|
super.updateScreen();
|
|
|
|
|
|
|
|
if(prevGas != getInputGas())
|
|
|
|
{
|
|
|
|
prevGas = getInputGas();
|
|
|
|
|
2014-02-01 19:48:37 +01:00
|
|
|
boolean reset = false;
|
|
|
|
|
|
|
|
if(prevGas == null || !(prevGas instanceof OreGas) || !((OreGas)prevGas).isClean())
|
2014-02-01 18:28:04 +01:00
|
|
|
{
|
2014-02-01 19:48:37 +01:00
|
|
|
reset = true;
|
2014-02-01 18:28:04 +01:00
|
|
|
resetStacks();
|
|
|
|
}
|
|
|
|
|
2014-02-01 19:48:37 +01:00
|
|
|
if(!reset)
|
2014-02-01 18:28:04 +01:00
|
|
|
{
|
2014-02-01 19:48:37 +01:00
|
|
|
OreGas gas = (OreGas)prevGas;
|
|
|
|
String oreDictName = "ore" + gas.getName().substring(5);
|
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
updateStackList(oreDictName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stackSwitch > 0)
|
|
|
|
{
|
|
|
|
stackSwitch--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(stackSwitch == 0 && iterStacks != null && iterStacks.size() > 0)
|
|
|
|
{
|
|
|
|
stackSwitch = 20;
|
|
|
|
|
|
|
|
if(stackIndex == -1 || stackIndex == iterStacks.size()-1)
|
|
|
|
{
|
|
|
|
stackIndex = 0;
|
|
|
|
}
|
|
|
|
else if(stackIndex < iterStacks.size()-1)
|
|
|
|
{
|
|
|
|
stackIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderStack = iterStacks.get(stackIndex);
|
|
|
|
}
|
|
|
|
else if(iterStacks != null && iterStacks.size() == 0)
|
|
|
|
{
|
|
|
|
renderStack = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-31 22:32:13 +01:00
|
|
|
public void displayGauge(int xPos, int yPos, int scale, FluidStack fluid, GasStack gas)
|
|
|
|
{
|
|
|
|
if(fluid == null && gas == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int guiWidth = (width - xSize) / 2;
|
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
|
|
|
|
int start = 0;
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
int renderRemaining = 0;
|
|
|
|
|
|
|
|
if(scale > 16)
|
|
|
|
{
|
|
|
|
renderRemaining = 16;
|
|
|
|
scale -= 16;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
renderRemaining = scale;
|
|
|
|
scale = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mc.renderEngine.bindTexture(MekanismRenderer.getBlocksTexture());
|
|
|
|
|
|
|
|
if(fluid != null)
|
|
|
|
{
|
|
|
|
drawTexturedModelRectFromIcon(guiWidth + xPos, guiHeight + yPos + 58 - renderRemaining - start, fluid.getFluid().getIcon(), 16, 16 - (16 - renderRemaining));
|
|
|
|
}
|
|
|
|
else if(gas != null)
|
|
|
|
{
|
|
|
|
drawTexturedModelRectFromIcon(guiWidth + xPos, guiHeight + yPos + 58 - renderRemaining - start, gas.getGas().getIcon(), 16, 16 - (16 - renderRemaining));
|
|
|
|
}
|
|
|
|
|
|
|
|
start+=16;
|
|
|
|
|
|
|
|
if(renderRemaining == 0 || scale == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalCrystalizer.png"));
|
|
|
|
drawTexturedModalRect(guiWidth + xPos, guiHeight + yPos, 176, 4, 16, 59);
|
|
|
|
}
|
2014-02-01 18:28:04 +01:00
|
|
|
|
|
|
|
private void updateStackList(String oreName)
|
|
|
|
{
|
|
|
|
if(iterStacks == null)
|
|
|
|
{
|
|
|
|
iterStacks = new ArrayList<ItemStack>();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
iterStacks.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> keys = new ArrayList<String>();
|
|
|
|
|
|
|
|
for(String s : OreDictionary.getOreNames())
|
|
|
|
{
|
|
|
|
if(oreName.equals(s) || oreName.equals("*"))
|
|
|
|
{
|
|
|
|
keys.add(s);
|
|
|
|
}
|
|
|
|
else if(oreName.endsWith("*") && !oreName.startsWith("*"))
|
|
|
|
{
|
|
|
|
if(s.startsWith(oreName.substring(0, oreName.length()-1)))
|
|
|
|
{
|
|
|
|
keys.add(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(oreName.startsWith("*") && !oreName.endsWith("*"))
|
|
|
|
{
|
|
|
|
if(s.endsWith(oreName.substring(1)))
|
|
|
|
{
|
|
|
|
keys.add(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(oreName.startsWith("*") && oreName.endsWith("*"))
|
|
|
|
{
|
|
|
|
if(s.contains(oreName.substring(1, oreName.length()-1)))
|
|
|
|
{
|
|
|
|
keys.add(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(String key : keys)
|
|
|
|
{
|
|
|
|
for(ItemStack stack : OreDictionary.getOres(key))
|
|
|
|
{
|
|
|
|
ItemStack toAdd = stack.copy();
|
|
|
|
|
|
|
|
if(!iterStacks.contains(stack) && toAdd.getItem() instanceof ItemBlock)
|
|
|
|
{
|
|
|
|
iterStacks.add(stack.copy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stackSwitch = 0;
|
|
|
|
stackIndex = -1;
|
|
|
|
}
|
2014-01-26 23:55:49 +01:00
|
|
|
}
|