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-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
|
|
|
|
|
|
|
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-03-08 02:00:25 +01:00
|
|
|
public TileEntityChemicalCrystalizer tileEntity;
|
|
|
|
|
|
|
|
public Gas prevGas;
|
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
public ItemStack renderStack;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
public int stackSwitch = 0;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
public int stackIndex = 0;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-03-01 16:50:17 +01:00
|
|
|
public List<ItemStack> iterStacks = new ArrayList<ItemStack>();
|
2014-01-31 22:32:13 +01:00
|
|
|
|
2014-03-08 02:00:25 +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")));
|
|
|
|
guiElements.add(new GuiPowerBar(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalCrystalizer.png"), 160, 23));
|
|
|
|
guiElements.add(new GuiConfigurationTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalCrystalizer.png")));
|
|
|
|
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)
|
|
|
|
{
|
2014-01-31 22:32:13 +01:00
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
fontRenderer.drawString(tileEntity.getInvName(), 37, 4, 0x404040);
|
|
|
|
|
|
|
|
if(tileEntity.inputTank.getGas() != null)
|
|
|
|
{
|
|
|
|
fontRenderer.drawString(tileEntity.inputTank.getGas().getGas().getLocalizedName(), 29, 15, 0x00CD00);
|
|
|
|
|
|
|
|
if(tileEntity.inputTank.getGas().getGas() instanceof OreGas)
|
|
|
|
{
|
|
|
|
fontRenderer.drawString("(" + ((OreGas)tileEntity.inputTank.getGas().getGas()).getOreName() + ")", 29, 24, 0x00CD00);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(renderStack != null)
|
2014-02-01 18:28:04 +01:00
|
|
|
{
|
|
|
|
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-03-08 02:00:25 +01:00
|
|
|
|
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);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
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;
|
2014-01-31 22:32:13 +01:00
|
|
|
int yAxis = mouseY - guiHeight;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
int displayInt;
|
|
|
|
|
|
|
|
displayInt = tileEntity.getScaledProgress(48);
|
|
|
|
drawTexturedModalRect(guiWidth + 53, guiHeight + 61, 176, 63, displayInt, 8);
|
|
|
|
|
|
|
|
if(tileEntity.getScaledInputGasLevel(58) > 0)
|
|
|
|
{
|
|
|
|
displayGauge(6, 5, tileEntity.getScaledInputGasLevel(58), null, tileEntity.inputTank.getGas());
|
|
|
|
}
|
|
|
|
|
|
|
|
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Gas getInputGas()
|
|
|
|
{
|
|
|
|
return tileEntity.inputTank.getGas() != null ? tileEntity.inputTank.getGas().getGas() : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resetStacks()
|
|
|
|
{
|
|
|
|
iterStacks.clear();
|
2014-02-01 18:28:04 +01:00
|
|
|
renderStack = null;
|
2014-03-08 02:00:25 +01:00
|
|
|
stackSwitch = 0;
|
|
|
|
stackIndex = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void mouseClicked(int x, int y, int button)
|
|
|
|
{
|
2014-02-01 19:48:37 +01:00
|
|
|
super.mouseClicked(x, y, button);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 19:48:37 +01:00
|
|
|
if(button == 0)
|
|
|
|
{
|
|
|
|
int xAxis = (x - (width - xSize) / 2);
|
|
|
|
int yAxis = (y - (height - ySize) / 2);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 19:48:37 +01:00
|
|
|
if(xAxis > 24 && xAxis < 42 && yAxis > 56 && yAxis < 64)
|
|
|
|
{
|
|
|
|
ArrayList data = new ArrayList();
|
|
|
|
data.add(0);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 19:48:37 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Coord4D.get(tileEntity), data));
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateScreen()
|
|
|
|
{
|
|
|
|
super.updateScreen();
|
|
|
|
|
|
|
|
if(prevGas != getInputGas())
|
|
|
|
{
|
|
|
|
prevGas = getInputGas();
|
|
|
|
|
|
|
|
boolean reset = false;
|
|
|
|
|
|
|
|
if(prevGas == null || !(prevGas instanceof OreGas) || !((OreGas)prevGas).isClean())
|
|
|
|
{
|
|
|
|
reset = true;
|
|
|
|
resetStacks();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!reset)
|
|
|
|
{
|
|
|
|
OreGas gas = (OreGas)prevGas;
|
|
|
|
String oreDictName = "ore" + gas.getName().substring(5);
|
|
|
|
|
|
|
|
updateStackList(oreDictName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
if(stackSwitch > 0)
|
|
|
|
{
|
|
|
|
stackSwitch--;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
if(stackSwitch == 0 && iterStacks != null && iterStacks.size() > 0)
|
|
|
|
{
|
|
|
|
stackSwitch = 20;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
if(stackIndex == -1 || stackIndex == iterStacks.size()-1)
|
|
|
|
{
|
|
|
|
stackIndex = 0;
|
|
|
|
}
|
|
|
|
else if(stackIndex < iterStacks.size()-1)
|
|
|
|
{
|
|
|
|
stackIndex++;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 18:28:04 +01:00
|
|
|
renderStack = iterStacks.get(stackIndex);
|
|
|
|
}
|
|
|
|
else if(iterStacks != null && iterStacks.size() == 0)
|
|
|
|
{
|
|
|
|
renderStack = null;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 22:32:13 +01:00
|
|
|
public void displayGauge(int xPos, int yPos, int scale, FluidStack fluid, GasStack gas)
|
|
|
|
{
|
2014-03-08 02:00:25 +01:00
|
|
|
if(fluid == null && gas == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int guiWidth = (width - xSize) / 2;
|
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
|
2014-01-31 22:32:13 +01:00
|
|
|
int start = 0;
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
int renderRemaining = 0;
|
|
|
|
|
2014-03-08 02:00:25 +01:00
|
|
|
if(scale > 16)
|
2014-01-31 22:32:13 +01:00
|
|
|
{
|
|
|
|
renderRemaining = 16;
|
|
|
|
scale -= 16;
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
2014-01-31 22:32:13 +01:00
|
|
|
else {
|
|
|
|
renderRemaining = scale;
|
|
|
|
scale = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mc.renderEngine.bindTexture(MekanismRenderer.getBlocksTexture());
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-31 22:32:13 +01:00
|
|
|
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));
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-31 22:32:13 +01:00
|
|
|
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-03-08 02:00:25 +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
|
|
|
}
|