Skip to content

Instantly share code, notes, and snippets.

@JayZX535
Last active September 14, 2017 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayZX535/4bb1fff8ddddc4889c1335520f1295f5 to your computer and use it in GitHub Desktop.
Save JayZX535/4bb1fff8ddddc4889c1335520f1295f5 to your computer and use it in GitHub Desktop.
package com.wildcraft.wildcraft.client.gui;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import javax.annotation.Nullable;
import org.lwjgl.input.Keyboard;
import com.wildcraft.wildcraft.entity.canine.EntityWildCraftWolf;
import com.wildcraft.wildcraft.entity.util.container.WCWolfInventoryContainer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.achievement.GuiAchievements;
import net.minecraft.client.gui.achievement.GuiStats;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiEditCommandBlockMinecart;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerRepair;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.CPacketCustomPayload;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.TabCompleter;
import net.minecraft.util.math.BlockPos;
public class GuiWCWolfInv extends GuiContainer{
private EntityWildCraftWolf wcwolf;
private IInventory playerInv;
private final WCWolfInventoryContainer wcwolfinv;
/** The mouse x-position recorded during the last rendered frame. */
private float mousePosX;
/** The mouse y-position recorded during the last renderered frame. */
private float mousePosY;
private GuiTextField nameField;
private int tabno;
private static final ResourceLocation WOLF_GUI_INV = new ResourceLocation("wildcraft:textures/gui/entity/wolf/wolfguiinv.png");
private static final ResourceLocation WOLF_GUI_INFO = new ResourceLocation("wildcraft:textures/gui/entity/wolf/wolfguiinfo.png");
private static final ResourceLocation WOLF_GUI_TABS = new ResourceLocation("wildcraft:textures/gui/entity/wolf/wolfguitabs.png");
public GuiWCWolfInv(IInventory playerInv, EntityWildCraftWolf wcwolf) {
super(new WCWolfInventoryContainer (playerInv, wcwolf));
this.xSize = 174;
this.ySize = 157;
this.tabno = 0;
this.wcwolf = wcwolf;
this.playerInv = playerInv;
this.wcwolfinv = (WCWolfInventoryContainer)this.inventorySlots;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
super.initGui();
this.buttonList.clear();
Keyboard.enableRepeatEvents(true);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.nameField = new GuiTextField(2, this.fontRendererObj, this.width / 2 + 11, this.height / 2 - 67, 70, 12);
this.nameField.setFocused(true);
this.nameField.setText(wcwolf.getCustomNameTag());
this.nameField.setMaxStringLength(30);
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
super.onGuiClosed();
Keyboard.enableRepeatEvents(false);
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (this.nameField.textboxKeyTyped(typedChar, keyCode))
{
this.renameWolf();
}
else
{
super.keyTyped(typedChar, keyCode);
}
}
private void renameWolf()
{
String s = this.nameField.getText();
if (s != null)
{
wcwolfinv.renameWolf(s);
}
else
{
wcwolfinv.renameWolf("");
}
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.nameField.mouseClicked(mouseX, mouseY, mouseButton);
if (mouseX < this.guiLeft+205 && mouseX > this.guiLeft+175)
{
if (mouseY < this.guiTop + 32 && mouseY > this.guiTop + 4)
{
this.tabno = 0;
this.initGui();
}
if (mouseY < this.guiTop + 60 && mouseY > this.guiTop + 32)
{
this.tabno = 1;
this.initGui();
}
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
if (this.tabno == 0)
{
this.mc.getTextureManager().bindTexture(WOLF_GUI_INV);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
this.mc.getTextureManager().bindTexture(WOLF_GUI_TABS);
this.drawTexturedModalRect(this.guiLeft+175, this.guiTop + 4, 30, 0, 30, 28);
this.drawTexturedModalRect(this.guiLeft+175, this.guiTop + 32, 0, 0, 30, 28);
this.drawTexturedModalRect(this.guiLeft+175, this.guiTop + 60, 0, 0, 30, 28);
this.drawTexturedModalRect(this.guiLeft+175, this.guiTop + 88, 0, 0, 30, 28);
//this.buttonList.add(new GuiButton(0, guiLeft, guiTop - 50, 20, 20));
}
else if (this.tabno == 1)
{
this.mc.getTextureManager().bindTexture(WOLF_GUI_INFO);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
this.mc.getTextureManager().bindTexture(WOLF_GUI_TABS);
this.drawTexturedModalRect(this.guiLeft+175, this.guiTop + 4, 0, 0, 30, 28);
this.drawTexturedModalRect(this.guiLeft+175, this.guiTop + 32, 30, 0, 30, 28);
this.drawTexturedModalRect(this.guiLeft+175, this.guiTop + 60, 0, 0, 30, 28);
this.drawTexturedModalRect(this.guiLeft+175, this.guiTop + 88, 0, 0, 30, 28);
}
GuiInventory.drawEntityOnScreen(i + 37, j + 52, 40, (float)(i + 41) - this.mousePosX, (float)(j + 75 - 50) - this.mousePosY, this.wcwolf);
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
super.drawScreen(mouseX, mouseY, partialTicks);
this.mousePosX = (float)mouseX;
this.mousePosY = (float)mouseY;
GlStateManager.disableLighting();
GlStateManager.disableBlend();
this.nameField.drawTextBox();
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
/**protected void actionPerformed(GuiButton button) throws IOException
{
if (button.id == 0)
{
this.tabno = 0;
}
if (button.id == 1)
{
this.tabno = 1;
}
/**if (button.id == 2)
{
this.tabno = 2;
}
if (button.id == 3)
{
this.tabno = 3;
}*/
/**this.initGui();
}*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment