2013-10-26 06:02:57 +02:00
|
|
|
package mekanism.client.gui;
|
|
|
|
|
2013-12-01 05:19:24 +01:00
|
|
|
import mekanism.api.Object3D;
|
2013-11-30 06:28:02 +01:00
|
|
|
import mekanism.common.EnumColor;
|
2013-10-26 19:25:51 +02:00
|
|
|
import mekanism.common.PacketHandler;
|
|
|
|
import mekanism.common.PacketHandler.Transmission;
|
|
|
|
import mekanism.common.inventory.container.ContainerFilter;
|
2013-11-19 23:39:16 +01:00
|
|
|
import mekanism.common.miner.MItemStackFilter;
|
2013-11-20 00:16:26 +01:00
|
|
|
import mekanism.common.network.PacketDigitalMinerGui;
|
|
|
|
import mekanism.common.network.PacketDigitalMinerGui.MinerGuiPacket;
|
2013-10-27 22:47:17 +01:00
|
|
|
import mekanism.common.network.PacketEditFilter;
|
2013-10-27 02:23:38 +02:00
|
|
|
import mekanism.common.network.PacketNewFilter;
|
2013-11-19 23:39:16 +01:00
|
|
|
import mekanism.common.tileentity.TileEntityDigitalMiner;
|
2013-10-26 19:25:51 +02:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
|
|
|
import mekanism.common.util.MekanismUtils.ResourceType;
|
2013-11-21 20:35:33 +01:00
|
|
|
import net.minecraft.block.Block;
|
2013-10-26 19:25:51 +02:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-11-20 04:13:35 +01:00
|
|
|
import net.minecraft.item.ItemBlock;
|
2013-10-26 19:25:51 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2013-10-26 06:02:57 +02:00
|
|
|
|
2013-11-07 01:32:00 +01:00
|
|
|
import org.lwjgl.input.Keyboard;
|
2013-10-26 19:25:51 +02:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2013-11-19 23:39:16 +01:00
|
|
|
public class GuiMItemStackFilter extends GuiMekanism
|
2013-10-26 19:25:51 +02:00
|
|
|
{
|
2013-11-19 23:39:16 +01:00
|
|
|
public TileEntityDigitalMiner tileEntity;
|
2013-10-26 19:25:51 +02:00
|
|
|
|
2013-10-27 02:23:38 +02:00
|
|
|
public boolean isNew = false;
|
|
|
|
|
2013-11-19 23:39:16 +01:00
|
|
|
public MItemStackFilter origFilter;
|
2013-10-27 23:24:16 +01:00
|
|
|
|
2013-11-19 23:39:16 +01:00
|
|
|
public MItemStackFilter filter = new MItemStackFilter();
|
2013-10-26 19:25:51 +02:00
|
|
|
|
|
|
|
public String status = EnumColor.DARK_GREEN + "All OK";
|
2013-11-07 15:16:11 +01:00
|
|
|
|
2013-10-27 01:04:33 +02:00
|
|
|
public int ticker;
|
|
|
|
|
2013-11-19 23:39:16 +01:00
|
|
|
public GuiMItemStackFilter(EntityPlayer player, TileEntityDigitalMiner tentity, int index)
|
2013-10-27 01:04:33 +02:00
|
|
|
{
|
2013-11-20 21:15:02 +01:00
|
|
|
super(new ContainerFilter(player.inventory, tentity));
|
2013-10-27 01:04:33 +02:00
|
|
|
tileEntity = tentity;
|
|
|
|
|
2013-11-19 23:39:16 +01:00
|
|
|
origFilter = (MItemStackFilter)tileEntity.filters.get(index);
|
|
|
|
filter = ((MItemStackFilter)tileEntity.filters.get(index)).clone();
|
2013-10-27 01:04:33 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 23:39:16 +01:00
|
|
|
public GuiMItemStackFilter(EntityPlayer player, TileEntityDigitalMiner tentity)
|
2013-10-26 19:25:51 +02:00
|
|
|
{
|
2013-11-20 21:15:02 +01:00
|
|
|
super(new ContainerFilter(player.inventory, tentity));
|
2013-10-26 19:25:51 +02:00
|
|
|
tileEntity = tentity;
|
|
|
|
|
2013-10-27 02:23:38 +02:00
|
|
|
isNew = true;
|
2013-10-26 19:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initGui()
|
|
|
|
{
|
|
|
|
super.initGui();
|
|
|
|
|
|
|
|
int guiWidth = (width - xSize) / 2;
|
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
|
|
|
|
buttonList.clear();
|
2013-10-27 22:29:34 +01:00
|
|
|
buttonList.add(new GuiButton(0, guiWidth + 27, guiHeight + 62, 60, 20, "Save"));
|
|
|
|
buttonList.add(new GuiButton(1, guiWidth + 89, guiHeight + 62, 60, 20, "Delete"));
|
|
|
|
|
|
|
|
if(isNew)
|
|
|
|
{
|
|
|
|
((GuiButton)buttonList.get(1)).enabled = false;
|
|
|
|
}
|
2013-10-26 19:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton guibutton)
|
|
|
|
{
|
|
|
|
super.actionPerformed(guibutton);
|
|
|
|
|
|
|
|
if(guibutton.id == 0)
|
|
|
|
{
|
2013-11-19 23:39:16 +01:00
|
|
|
if(filter.itemType != null)
|
2013-10-27 02:23:38 +02:00
|
|
|
{
|
2013-11-19 23:39:16 +01:00
|
|
|
if(isNew)
|
2013-11-07 15:16:11 +01:00
|
|
|
{
|
2013-11-19 23:39:16 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketNewFilter().setParams(Object3D.get(tileEntity), filter));
|
2013-11-07 15:16:11 +01:00
|
|
|
}
|
2013-11-19 23:39:16 +01:00
|
|
|
else {
|
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketEditFilter().setParams(Object3D.get(tileEntity), false, origFilter, filter));
|
2013-10-27 22:47:17 +01:00
|
|
|
}
|
2013-11-19 23:39:16 +01:00
|
|
|
|
2013-11-20 00:16:26 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketDigitalMinerGui().setParams(MinerGuiPacket.SERVER, Object3D.get(tileEntity), 0));
|
2013-10-27 02:23:38 +02:00
|
|
|
}
|
2013-11-07 01:32:00 +01:00
|
|
|
else if(filter.itemType == null)
|
|
|
|
{
|
2013-10-27 02:23:38 +02:00
|
|
|
status = EnumColor.DARK_RED + "No item";
|
|
|
|
ticker = 20;
|
|
|
|
}
|
2013-10-26 19:25:51 +02:00
|
|
|
}
|
2013-10-27 22:47:17 +01:00
|
|
|
else if(guibutton.id == 1)
|
|
|
|
{
|
2013-10-27 23:24:16 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketEditFilter().setParams(Object3D.get(tileEntity), true, origFilter));
|
2013-11-20 00:16:26 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketDigitalMinerGui().setParams(MinerGuiPacket.SERVER, Object3D.get(tileEntity), 0));
|
2013-10-27 22:47:17 +01:00
|
|
|
}
|
2013-10-26 19:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
|
|
|
|
2013-10-31 04:48:50 +01:00
|
|
|
fontRenderer.drawString((isNew ? "New" : "Edit") + " Item Filter", 43, 6, 0x404040);
|
2013-10-26 19:25:51 +02:00
|
|
|
fontRenderer.drawString("Status: " + status, 35, 20, 0x00CD00);
|
|
|
|
fontRenderer.drawString("ItemStack Details:", 35, 32, 0x00CD00);
|
|
|
|
|
|
|
|
if(filter.itemType != null)
|
|
|
|
{
|
2013-11-12 04:52:12 +01:00
|
|
|
fontRenderer.drawString("Item: " + filter.itemType.getDisplayName(), 35, 41, 0x00CD00);
|
2013-10-26 19:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(filter.itemType != null)
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glEnable(GL11.GL_LIGHTING);
|
2013-10-27 16:44:19 +01:00
|
|
|
itemRenderer.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), filter.itemType, 12, 19);
|
2013-10-26 19:25:51 +02:00
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
|
|
|
}
|
2013-10-27 01:04:33 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateScreen()
|
|
|
|
{
|
|
|
|
super.updateScreen();
|
|
|
|
|
|
|
|
if(ticker > 0)
|
|
|
|
{
|
|
|
|
ticker--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
status = EnumColor.DARK_GREEN + "All OK";
|
|
|
|
}
|
|
|
|
}
|
2013-10-26 19:25:51 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
|
|
|
|
|
2013-11-21 00:17:10 +01:00
|
|
|
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiMItemStackFilter.png"));
|
2013-10-26 19:25:51 +02: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);
|
|
|
|
|
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
|
|
|
|
|
|
|
if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16)
|
|
|
|
{
|
|
|
|
drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 0, 11, 11);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
drawTexturedModalRect(guiWidth + 5, guiHeight + 5, 176, 11, 11, 11);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 19 && yAxis <= 35)
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
|
|
|
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
int x = guiWidth + 12;
|
|
|
|
int y = guiHeight + 19;
|
|
|
|
drawGradientRect(x, y, x + 16, y + 16, -2130706433, -2130706433);
|
|
|
|
|
|
|
|
GL11.glEnable(GL11.GL_LIGHTING);
|
|
|
|
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void mouseClicked(int mouseX, int mouseY, int button)
|
|
|
|
{
|
|
|
|
super.mouseClicked(mouseX, mouseY, button);
|
2013-11-07 01:32:00 +01:00
|
|
|
|
2013-10-26 19:25:51 +02:00
|
|
|
if(button == 0)
|
|
|
|
{
|
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
|
|
|
|
|
|
|
if(xAxis >= 5 && xAxis <= 16 && yAxis >= 5 && yAxis <= 16)
|
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
2013-11-20 00:16:26 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketDigitalMinerGui().setParams(MinerGuiPacket.SERVER, Object3D.get(tileEntity), 0));
|
2013-10-26 19:25:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(xAxis >= 12 && xAxis <= 28 && yAxis >= 19 && yAxis <= 35)
|
|
|
|
{
|
|
|
|
ItemStack stack = mc.thePlayer.inventory.getItemStack();
|
|
|
|
|
2013-11-11 00:54:30 +01:00
|
|
|
if(stack != null && !Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
|
2013-10-26 19:25:51 +02:00
|
|
|
{
|
2013-11-20 04:13:35 +01:00
|
|
|
if(stack.getItem() instanceof ItemBlock)
|
|
|
|
{
|
2013-11-21 20:35:33 +01:00
|
|
|
if(stack.itemID != Block.bedrock.blockID)
|
|
|
|
{
|
|
|
|
filter.itemType = stack.copy();
|
|
|
|
filter.itemType.stackSize = 1;
|
|
|
|
}
|
2013-11-20 04:13:35 +01:00
|
|
|
}
|
2013-10-26 19:25:51 +02:00
|
|
|
}
|
2013-11-11 00:54:30 +01:00
|
|
|
else if(stack == null && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
|
|
|
|
{
|
|
|
|
filter.itemType = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
2013-10-26 19:25:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-26 06:02:57 +02:00
|
|
|
}
|