Files
TinkersConstruct/src/main/java/tconstruct/client/gui/StencilTableGui.java
T

132 lines
4.8 KiB
Java
Raw Normal View History

package tconstruct.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
2014-02-05 10:28:54 -05:00
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
2014-02-05 10:28:54 -05:00
import org.lwjgl.opengl.GL11;
2014-02-05 10:28:54 -05:00
2014-02-01 17:28:41 +11:00
import tconstruct.TConstruct;
import tconstruct.blocks.logic.StencilTableLogic;
2013-12-01 21:42:03 +00:00
import tconstruct.common.TRepo;
import tconstruct.inventory.PatternShaperContainer;
2014-02-01 17:28:41 +11:00
import tconstruct.util.network.packet.PacketStencilTable;
public class StencilTableGui extends GuiContainer
{
StencilTableLogic logic;
int patternIndex;
public StencilTableGui(InventoryPlayer inventoryplayer, StencilTableLogic shaper, World world, int x, int y, int z)
{
super(new PatternShaperContainer(inventoryplayer, shaper));
logic = shaper;
patternIndex = 0;
}
2014-02-17 00:31:43 -05:00
@Override
2014-02-05 08:28:53 -05:00
public void onGuiClosed ()
{
2014-02-05 08:28:53 -05:00
super.onGuiClosed();
}
@Override
2014-02-05 08:28:53 -05:00
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
2014-02-05 08:28:53 -05:00
fontRendererObj.drawString(StatCollector.translateToLocal("crafters.PatternShaper"), 50, 6, 0x404040);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
}
2013-08-31 05:13:31 -07:00
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/patternshaper.png");
2014-02-17 00:31:43 -05:00
@Override
2014-02-05 08:28:53 -05:00
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2014-02-05 08:28:53 -05:00
this.mc.getTextureManager().bindTexture(background);
int cornerX = (this.width - this.xSize) / 2;
int cornerY = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(cornerX, cornerY, 0, 0, this.xSize, this.ySize);
if (!logic.isStackInSlot(0))
{
this.drawTexturedModalRect(cornerX + 47, cornerY + 34, 176, 0, 18, 18);
}
}
2014-02-17 00:31:43 -05:00
@Override
public void initGui ()
{
super.initGui();
2014-02-05 08:28:53 -05:00
int cornerX = (this.width - this.xSize) / 2;
int cornerY = (this.height - this.ySize) / 2;
2014-02-05 08:28:53 -05:00
this.buttonList.clear();
2014-02-16 14:23:50 -05:00
/*
* ToolGuiElement repair = TConstruct.toolButtons.get(0); GuiButtonTool
* repairButton = new GuiButtonTool(0, cornerX - 110, cornerY,
* repair.buttonIconX, repair.buttonIconY, repair.texture); // Repair
* repairButton.enabled = false; this.buttonList.add(repairButton);
*/
2014-02-15 00:29:24 -05:00
this.buttonList.add(new GuiButton(0, cornerX - 120, cornerY, 120, 20, (StatCollector.translateToLocal("gui.stenciltable1"))));
this.buttonList.add(new GuiButton(1, cornerX - 120, cornerY + 20, 120, 20, (StatCollector.translateToLocal("gui.stenciltable2"))));
2014-02-16 14:23:50 -05:00
// for (int iter = 0; iter < TConstructContent.patternOutputs.length;
// iter++)
// {
/*
* ToolGuiElement element = TConstruct.toolButtons.get(iter);
* GuiButtonTool button = new GuiButtonTool(iter, cornerX - 110 + 22 *
* (iter % 5), cornerY + 22 * (iter / 5), element.buttonIconX,
* element.buttonIconY, element.texture); // Repair
* this.buttonList.add(button);
*/
// }
}
2014-02-17 00:31:43 -05:00
@Override
protected void actionPerformed (GuiButton button)
{
ItemStack pattern = logic.getStackInSlot(0);
2013-12-01 21:42:03 +00:00
if (pattern != null && pattern.getItem() == TRepo.blankPattern)
{
int meta = pattern.getItemDamage();
if (meta == 0)
{
2014-02-05 08:28:53 -05:00
if (button.id == 0)
{
patternIndex++;
2013-11-25 19:40:43 -05:00
if (patternIndex == 21)
patternIndex++;
2013-12-01 21:42:03 +00:00
if (patternIndex >= TRepo.patternOutputs.length - 1)
patternIndex = 0;
}
2014-02-05 08:28:53 -05:00
else if (button.id == 1)
{
patternIndex--;
if (patternIndex < 0)
2013-12-01 21:42:03 +00:00
patternIndex = TRepo.patternOutputs.length - 2;
2013-11-25 19:40:43 -05:00
if (patternIndex == 21)
patternIndex--;
}
2013-12-01 21:42:03 +00:00
ItemStack stack = new ItemStack(TRepo.woodPattern, 1, patternIndex + 1);
logic.setInventorySlotContents(1, stack);
updateServer(stack);
}
2014-02-16 14:23:50 -05:00
/*
* else if (meta == 1 || meta == 2) { ItemStack stack = new
* ItemStack(TContent.metalPattern, 1, 0);
* logic.setInventorySlotContents(1, stack); updateServer(stack); }
*/
}
}
void updateServer (ItemStack stack)
{
2014-02-05 08:28:53 -05:00
TConstruct.packetPipeline.sendToServer(new PacketStencilTable(logic.xCoord, logic.yCoord, logic.zCoord, stack));
}
2014-02-15 00:29:24 -05:00
}