2013-08-27 00:49:32 +02:00
|
|
|
package mekanism.client.gui;
|
2013-04-13 02:25:21 +02:00
|
|
|
|
2013-12-01 06:03:40 +01:00
|
|
|
import mekanism.api.EnumColor;
|
2013-12-20 22:09:09 +01:00
|
|
|
import mekanism.api.Coord4D;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.api.energy.IEnergizedItem;
|
2013-04-13 02:25:21 +02:00
|
|
|
import mekanism.common.IElectricChest;
|
|
|
|
import mekanism.common.Mekanism;
|
|
|
|
import mekanism.common.PacketHandler;
|
2013-06-13 23:37:30 +02:00
|
|
|
import mekanism.common.PacketHandler.Transmission;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.inventory.container.ContainerElectricChest;
|
2013-06-13 23:37:30 +02:00
|
|
|
import mekanism.common.network.PacketElectricChest;
|
|
|
|
import mekanism.common.network.PacketElectricChest.ElectricChestPacketType;
|
2014-01-08 02:55:50 +01:00
|
|
|
import mekanism.common.tile.TileEntityElectricChest;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
|
|
|
import mekanism.common.util.MekanismUtils.ResourceType;
|
2013-04-13 02:25:21 +02:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2013-04-13 16:33:37 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-01-05 02:50:16 +01:00
|
|
|
public class GuiElectricChest extends GuiMekanism
|
2013-04-13 02:25:21 +02:00
|
|
|
{
|
|
|
|
public TileEntityElectricChest tileEntity;
|
|
|
|
public IInventory itemInventory;
|
|
|
|
public boolean isBlock;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
public GuiElectricChest(InventoryPlayer inventory, TileEntityElectricChest tentity)
|
2014-03-08 02:00:25 +01:00
|
|
|
{
|
|
|
|
super(new ContainerElectricChest(inventory, tentity, null, true));
|
|
|
|
|
|
|
|
xSize+=26;
|
|
|
|
ySize+=64;
|
|
|
|
tileEntity = tentity;
|
|
|
|
isBlock = true;
|
|
|
|
}
|
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
public GuiElectricChest(InventoryPlayer inventory, IInventory inv)
|
2014-03-08 02:00:25 +01:00
|
|
|
{
|
|
|
|
super(new ContainerElectricChest(inventory, null, inv, false));
|
|
|
|
|
|
|
|
xSize+=26;
|
|
|
|
ySize+=64;
|
|
|
|
itemInventory = inv;
|
|
|
|
isBlock = false;
|
|
|
|
}
|
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public void onGuiClosed()
|
2013-04-13 02:25:21 +02:00
|
|
|
{
|
|
|
|
super.onGuiClosed();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
if(!isBlock)
|
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.chestclosed", 1.0F, 1.0F);
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
@Override
|
|
|
|
public void initGui()
|
|
|
|
{
|
|
|
|
super.initGui();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
int guiWidth = (width - xSize) / 2;
|
2014-03-08 02:00:25 +01:00
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
buttonList.clear();
|
2013-11-30 06:28:02 +01:00
|
|
|
buttonList.add(new GuiButton(0, guiWidth + 93, guiHeight + 4, 76, 20, MekanismUtils.localize("gui.electricChest.editPassword")));
|
2013-04-13 02:25:21 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton guibutton)
|
|
|
|
{
|
|
|
|
if(guibutton.id == 0)
|
|
|
|
{
|
|
|
|
if(isBlock)
|
|
|
|
{
|
|
|
|
mc.thePlayer.openGui(Mekanism.instance, 20, mc.theWorld, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
|
|
|
}
|
|
|
|
else {
|
2013-04-19 21:43:00 +02:00
|
|
|
FMLClientHandler.instance().displayGuiScreen(mc.thePlayer, new GuiPasswordModify(mc.thePlayer.getCurrentEquippedItem()));
|
2013-04-13 02:25:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-07-31 23:00:30 +02:00
|
|
|
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
2014-03-08 02:00:25 +01:00
|
|
|
{
|
2013-07-31 23:00:30 +02:00
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
fontRenderer.drawString(MekanismUtils.localize("tile.MachineBlock.ElectricChest.name"), 8, 6, 0x404040);
|
|
|
|
fontRenderer.drawString(getLocked() ? EnumColor.DARK_RED + "Locked" : EnumColor.BRIGHT_GREEN + "Unlocked", 97, 137, 0x404040);
|
|
|
|
fontRenderer.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
|
|
|
|
|
|
|
|
if(xAxis >= 180 && xAxis <= 184 && yAxis >= 32 && yAxis <= 84)
|
2013-07-31 23:00:30 +02:00
|
|
|
{
|
2013-11-23 02:58:49 +01:00
|
|
|
drawCreativeTabHoveringText(MekanismUtils.getEnergyDisplay(getEnergy()), xAxis, yAxis);
|
2013-07-31 23:00:30 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
|
|
|
}
|
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
@Override
|
|
|
|
protected void mouseClicked(int mouseX, int mouseY, int button)
|
|
|
|
{
|
|
|
|
super.mouseClicked(mouseX, mouseY, button);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
if(button == 0)
|
|
|
|
{
|
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
if(xAxis >= 179 && xAxis <= 197 && yAxis >= 88 && yAxis <= 106)
|
2014-03-08 02:00:25 +01:00
|
|
|
{
|
2013-04-13 02:25:21 +02:00
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-06-13 23:37:30 +02:00
|
|
|
if(isBlock)
|
2013-04-13 02:25:21 +02:00
|
|
|
{
|
2013-12-20 22:09:09 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketElectricChest().setParams(ElectricChestPacketType.LOCK, !getLocked(), true, Coord4D.get(tileEntity)));
|
2013-06-13 23:37:30 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketElectricChest().setParams(ElectricChestPacketType.LOCK, !getLocked(), false));
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-19 21:43:00 +02:00
|
|
|
ItemStack stack = mc.thePlayer.getCurrentEquippedItem();
|
2013-04-13 02:25:21 +02:00
|
|
|
((IElectricChest)stack.getItem()).setLocked(stack, !getLocked());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
|
|
|
|
{
|
2013-09-28 03:59:47 +02:00
|
|
|
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiElectricChest.png"));
|
2014-03-08 02:00:25 +01:00
|
|
|
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);
|
|
|
|
|
2013-11-27 02:11:26 +01:00
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
if(xAxis >= 179 && xAxis <= 197 && yAxis >= 88 && yAxis <= 106)
|
|
|
|
{
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 88, 176 + 26, 52, 18, 18);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 88, 176 + 26, 70, 18, 18);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
int displayInt = getScale();
|
|
|
|
drawTexturedModalRect(guiWidth + 180, guiHeight + 32 + 52 - displayInt, 176 + 26, 52 - displayInt, 4, displayInt);
|
|
|
|
}
|
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
public boolean getLocked()
|
|
|
|
{
|
|
|
|
if(isBlock)
|
|
|
|
{
|
|
|
|
return tileEntity.locked;
|
|
|
|
}
|
|
|
|
else {
|
2013-04-19 21:43:00 +02:00
|
|
|
ItemStack stack = mc.thePlayer.getCurrentEquippedItem();
|
2013-04-13 02:25:21 +02:00
|
|
|
return ((IElectricChest)stack.getItem()).getLocked(stack);
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
public int getScale()
|
|
|
|
{
|
|
|
|
if(isBlock)
|
|
|
|
{
|
|
|
|
return tileEntity.getScaledEnergyLevel(52);
|
|
|
|
}
|
|
|
|
else {
|
2013-04-19 21:43:00 +02:00
|
|
|
ItemStack stack = mc.thePlayer.getCurrentEquippedItem();
|
2013-04-23 21:36:43 +02:00
|
|
|
return (int)(((IEnergizedItem)stack.getItem()).getEnergy(stack)*52 / ((IEnergizedItem)stack.getItem()).getMaxEnergy(stack));
|
2013-04-13 02:25:21 +02:00
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-07-31 23:00:30 +02:00
|
|
|
public double getEnergy()
|
|
|
|
{
|
|
|
|
if(isBlock)
|
|
|
|
{
|
|
|
|
return tileEntity.getEnergy();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ItemStack stack = mc.thePlayer.getCurrentEquippedItem();
|
|
|
|
return ((IEnergizedItem)stack.getItem()).getEnergy(stack);
|
|
|
|
}
|
|
|
|
}
|
2013-04-13 02:25:21 +02:00
|
|
|
}
|