summaryrefslogtreecommitdiff
path: root/java/darkknight/jewelrycraft/client
diff options
context:
space:
mode:
authorOnyxDarkKnight <sor1n.iliutza16@gmail.com>2015-03-05 18:05:38 +0000
committerOnyxDarkKnight <sor1n.iliutza16@gmail.com>2015-03-05 18:05:38 +0000
commit12cb40ba14e76b999a381b1f122bfce73223fd38 (patch)
tree17eef1530cb00ab3b3b7d2898305552529e442a1 /java/darkknight/jewelrycraft/client
parent420faddca46e70e3a70def168fb4e452ef193b0d (diff)
Added tabs to the inventory
Diffstat (limited to 'java/darkknight/jewelrycraft/client')
-rw-r--r--java/darkknight/jewelrycraft/client/AbstractTab.java71
-rw-r--r--java/darkknight/jewelrycraft/client/GuiJewelry.java12
-rw-r--r--java/darkknight/jewelrycraft/client/InventoryTabVanilla.java24
-rw-r--r--java/darkknight/jewelrycraft/client/TabJewelry.java27
-rw-r--r--java/darkknight/jewelrycraft/client/TabRegistry.java86
5 files changed, 220 insertions, 0 deletions
diff --git a/java/darkknight/jewelrycraft/client/AbstractTab.java b/java/darkknight/jewelrycraft/client/AbstractTab.java
new file mode 100644
index 0000000..d0124fa
--- /dev/null
+++ b/java/darkknight/jewelrycraft/client/AbstractTab.java
@@ -0,0 +1,71 @@
+package darkknight.jewelrycraft.client;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiButton;
+import net.minecraft.client.renderer.RenderHelper;
+import net.minecraft.client.renderer.entity.RenderItem;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.ResourceLocation;
+import org.lwjgl.opengl.*;
+
+/**
+ * @author TinkersCOnstruct
+ */
+public abstract class AbstractTab extends GuiButton
+{
+ ResourceLocation texture = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
+ ItemStack renderStack;
+ RenderItem itemRenderer = new RenderItem();
+
+ public AbstractTab(int id, int posX, int posY, ItemStack renderStack)
+ {
+ super(id, posX, posY, 28, 32, "");
+ this.renderStack = renderStack;
+ }
+
+ @Override
+ public void drawButton (Minecraft mc, int mouseX, int mouseY)
+ {
+ if (this.visible)
+ {
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+
+ int yTexPos = this.enabled ? 3 : 32;
+ int ySize = this.enabled ? 25 : 32;
+ int xOffset = this.id == 2 ? 0 : 1;
+ int yPos = this.yPosition + (this.enabled ? 3 : 0);
+
+ mc.renderEngine.bindTexture(this.texture);
+ this.drawTexturedModalRect(this.xPosition, yPos, xOffset * 28, yTexPos, 28, ySize);
+
+ RenderHelper.enableGUIStandardItemLighting();
+ this.zLevel = 100.0F;
+ this.itemRenderer.zLevel = 100.0F;
+ GL11.glEnable(GL11.GL_LIGHTING);
+ GL11.glEnable(GL12.GL_RESCALE_NORMAL);
+ this.itemRenderer.renderItemAndEffectIntoGUI(mc.fontRenderer, mc.renderEngine, renderStack, xPosition + 6, yPosition + 8);
+ this.itemRenderer.renderItemOverlayIntoGUI(mc.fontRenderer, mc.renderEngine, renderStack, xPosition + 6, yPosition + 8);
+ GL11.glDisable(GL11.GL_LIGHTING);
+ this.itemRenderer.zLevel = 0.0F;
+ this.zLevel = 0.0F;
+ RenderHelper.disableStandardItemLighting();
+ }
+ }
+
+ @Override
+ public boolean mousePressed (Minecraft mc, int mouseX, int mouseY)
+ {
+ boolean inWindow = this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
+
+ if (inWindow)
+ {
+ this.onTabClicked();
+ }
+
+ return inWindow;
+ }
+
+ public abstract void onTabClicked ();
+
+ public abstract boolean shouldAddToList ();
+} \ No newline at end of file
diff --git a/java/darkknight/jewelrycraft/client/GuiJewelry.java b/java/darkknight/jewelrycraft/client/GuiJewelry.java
index 1d31770..0f8e59a 100644
--- a/java/darkknight/jewelrycraft/client/GuiJewelry.java
+++ b/java/darkknight/jewelrycraft/client/GuiJewelry.java
@@ -5,6 +5,7 @@ import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import darkknight.jewelrycraft.container.ContainerJewelryTab;
+import darkknight.jewelrycraft.container.JewelryInventory;
import darkknight.jewelrycraft.events.KeyBindings;
public class GuiJewelry extends GuiContainer
@@ -54,4 +55,15 @@ public class GuiJewelry extends GuiContainer
super.keyTyped(charecter, key);
if (key == KeyBindings.inventory.getKeyCode()) mc.thePlayer.closeScreen();
}
+
+ @Override
+ public void initGui ()
+ {
+ super.initGui();
+ int cornerX = guiLeft;
+ int cornerY = guiTop;
+ this.buttonList.clear();
+ TabRegistry.updateTabValues(cornerX, cornerY, TabJewelry.class);
+ TabRegistry.addTabsToList(this.buttonList);
+ }
}
diff --git a/java/darkknight/jewelrycraft/client/InventoryTabVanilla.java b/java/darkknight/jewelrycraft/client/InventoryTabVanilla.java
new file mode 100644
index 0000000..c8d598c
--- /dev/null
+++ b/java/darkknight/jewelrycraft/client/InventoryTabVanilla.java
@@ -0,0 +1,24 @@
+package darkknight.jewelrycraft.client;
+
+import net.minecraft.init.Blocks;
+import net.minecraft.item.ItemStack;
+
+public class InventoryTabVanilla extends AbstractTab
+{
+ public InventoryTabVanilla()
+ {
+ super(0, 0, 0, new ItemStack(Blocks.crafting_table));
+ }
+
+ @Override
+ public void onTabClicked ()
+ {
+ TabRegistry.openInventoryGui();
+ }
+
+ @Override
+ public boolean shouldAddToList ()
+ {
+ return true;
+ }
+} \ No newline at end of file
diff --git a/java/darkknight/jewelrycraft/client/TabJewelry.java b/java/darkknight/jewelrycraft/client/TabJewelry.java
new file mode 100644
index 0000000..4598962
--- /dev/null
+++ b/java/darkknight/jewelrycraft/client/TabJewelry.java
@@ -0,0 +1,27 @@
+package darkknight.jewelrycraft.client;
+
+import darkknight.jewelrycraft.JewelrycraftMod;
+import darkknight.jewelrycraft.item.ItemList;
+import darkknight.jewelrycraft.network.PacketKeyPressEvent;
+import net.minecraft.init.Items;
+import net.minecraft.item.ItemStack;
+
+public class TabJewelry extends AbstractTab
+{
+ public TabJewelry()
+ {
+ super(0, 0, 0, new ItemStack(ItemList.necklace));
+ }
+
+ @Override
+ public void onTabClicked ()
+ {
+ JewelrycraftMod.netWrapper.sendToServer(new PacketKeyPressEvent(0));
+ }
+
+ @Override
+ public boolean shouldAddToList ()
+ {
+ return true;
+ }
+} \ No newline at end of file
diff --git a/java/darkknight/jewelrycraft/client/TabRegistry.java b/java/darkknight/jewelrycraft/client/TabRegistry.java
new file mode 100644
index 0000000..2765b73
--- /dev/null
+++ b/java/darkknight/jewelrycraft/client/TabRegistry.java
@@ -0,0 +1,86 @@
+package darkknight.jewelrycraft.client;
+
+import java.util.ArrayList;
+import java.util.List;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.inventory.GuiInventory;
+import net.minecraft.network.play.client.C0DPacketCloseWindow;
+import net.minecraftforge.client.event.GuiScreenEvent;
+import cpw.mods.fml.client.FMLClientHandler;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import darkknight.jewelrycraft.client.*;
+
+/**
+ * @author TinkersConstruct
+ */
+public class TabRegistry
+{
+ private static ArrayList<AbstractTab> tabList = new ArrayList<AbstractTab>();
+
+ public static void registerTab (AbstractTab tab)
+ {
+ tabList.add(tab);
+ }
+
+ public static ArrayList<AbstractTab> getTabList ()
+ {
+ return tabList;
+ }
+
+ @SideOnly(Side.CLIENT)
+ @SubscribeEvent
+ public void guiPostInit (GuiScreenEvent.InitGuiEvent.Post event)
+ {
+ if ((event.gui instanceof GuiInventory))
+ {
+ int xSize = 176;
+ int ySize = 166;
+ int guiLeft = (event.gui.width - xSize) / 2;
+ int guiTop = (event.gui.height - ySize) / 2;
+ if(!mc.thePlayer.getActivePotionEffects().isEmpty()) guiLeft += 60;
+
+ updateTabValues(guiLeft, guiTop, InventoryTabVanilla.class);
+ addTabsToList(event.buttonList);
+ }
+ }
+
+ private static Minecraft mc = FMLClientHandler.instance().getClient();
+
+ public static void openInventoryGui ()
+ {
+ mc.thePlayer.sendQueue.addToSendQueue(new C0DPacketCloseWindow(mc.thePlayer.openContainer.windowId));
+ GuiInventory inventory = new GuiInventory(mc.thePlayer);
+ mc.displayGuiScreen(inventory);
+ }
+
+ public static void updateTabValues (int cornerX, int cornerY, Class<?> selectedButton)
+ {
+ int count = 2;
+ for (int i = 0; i < tabList.size(); i++)
+ {
+ AbstractTab t = tabList.get(i);
+
+ if (t.shouldAddToList())
+ {
+ t.id = count;
+ t.xPosition = cornerX + (count - 2) * 28;
+ t.yPosition = cornerY - 28;
+ t.enabled = !t.getClass().equals(selectedButton);
+ count++;
+ }
+ }
+ }
+
+ public static void addTabsToList (List buttonList)
+ {
+ for (AbstractTab tab : tabList)
+ {
+ if (tab.shouldAddToList())
+ {
+ buttonList.add(tab);
+ }
+ }
+ }
+} \ No newline at end of file