Added ability for mods to cleanly define and display new creative tabs.

This commit is contained in:
LexManos 2012-10-19 08:46:39 -07:00
parent f3443d3e02
commit 34ebfcd978
2 changed files with 300 additions and 0 deletions

View file

@ -0,0 +1,99 @@
--- ../src_base/common/net/minecraft/src/CreativeTabs.java
+++ ../src_work/common/net/minecraft/src/CreativeTabs.java
@@ -2,11 +2,13 @@
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
+
+import java.util.Arrays;
import java.util.List;
public class CreativeTabs
{
- public static final CreativeTabs[] creativeTabArray = new CreativeTabs[12];
+ public static CreativeTabs[] creativeTabArray = new CreativeTabs[12];
public static final CreativeTabs tabBlock = new CreativeTabBlock(0, "buildingBlocks");
public static final CreativeTabs tabDecorations = new CreativeTabDeco(1, "decorations");
public static final CreativeTabs tabRedstone = new CreativeTabRedstone(2, "redstone");
@@ -29,11 +31,32 @@
/** Whether to draw the title in the foreground of the creative GUI */
private boolean drawTitle = true;
+ public CreativeTabs(String label)
+ {
+ this(getNextID(), label);
+ }
+
public CreativeTabs(int par1, String par2Str)
{
+ if (par1 >= creativeTabArray.length)
+ {
+ CreativeTabs[] tmp = new CreativeTabs[par1 + 1];
+ for (int x = 0; x < creativeTabArray.length; x++)
+ {
+ tmp[x] = creativeTabArray[x];
+ }
+ creativeTabArray = tmp;
+ }
this.tabIndex = par1;
this.tabLabel = par2Str;
creativeTabArray[par1] = this;
+ if (par1 == 11)
+ {
+ new CreativeTabs("1");
+ new CreativeTabs("2");
+ new CreativeTabs("3");
+ new CreativeTabs("4");
+ }
}
@SideOnly(Side.CLIENT)
@@ -117,6 +140,10 @@
*/
public int getTabColumn()
{
+ if (tabIndex > 11)
+ {
+ return ((tabIndex - 12) % 10) % 5;
+ }
return this.tabIndex % 6;
}
@@ -127,6 +154,10 @@
*/
public boolean isTabInFirstRow()
{
+ if (tabIndex > 11)
+ {
+ return ((tabIndex - 12) % 10) < 5;
+ }
return this.tabIndex < 6;
}
@@ -150,4 +181,26 @@
}
}
}
+
+ public int getTabPage()
+ {
+ if (tabIndex > 11)
+ {
+ return ((tabIndex - 12) / 10) + 1;
+ }
+ return 0;
+ }
+
+ public static int getNextID()
+ {
+ return creativeTabArray.length;
+ }
+
+ /**
+ * Get the ItemStack that will be rendered to the tab.
+ */
+ public ItemStack getIconItemStack()
+ {
+ return new ItemStack(getTabIconItem());
+ }
}

View file

@ -0,0 +1,201 @@
--- ../src_base/minecraft/net/minecraft/src/GuiContainerCreative.java
+++ ../src_work/minecraft/net/minecraft/src/GuiContainerCreative.java
@@ -32,6 +32,8 @@
private List field_74236_u;
private Slot field_74235_v = null;
private boolean field_74234_w = false;
+ private int tabPage = 0;
+ private int maxPages = 0;
public GuiContainerCreative(EntityPlayer par1EntityPlayer)
{
@@ -200,6 +202,14 @@
int var1 = selectedTabIndex;
selectedTabIndex = -1;
this.func_74227_b(CreativeTabs.creativeTabArray[var1]);
+ int tabCount = CreativeTabs.creativeTabArray.length;
+ if (tabCount > 12)
+ {
+ controlList.add(new GuiButton(101, guiLeft, guiTop - 50, 20, 20, "<"));
+ controlList.add(new GuiButton(102, guiLeft + xSize - 20, guiTop - 50, 20, 20, ">"));
+ tabPage = 0;
+ maxPages = ((tabCount - 12) / 10) + 1;
+ }
}
else
{
@@ -311,7 +321,7 @@
{
CreativeTabs var1 = CreativeTabs.creativeTabArray[selectedTabIndex];
- if (var1.drawInForegroundOfTab())
+ if (var1 != null && var1.drawInForegroundOfTab())
{
this.fontRenderer.drawString(var1.getTranslatedTabLabel(), 8, 6, 4210752);
}
@@ -333,7 +343,7 @@
{
CreativeTabs var9 = var6[var8];
- if (this.func_74232_a(var9, var4, var5))
+ if (var9 != null && func_74232_a(var9, var4, var5))
{
this.func_74227_b(var9);
return;
@@ -349,11 +359,17 @@
*/
private boolean needsScrollBars()
{
+ if (CreativeTabs.creativeTabArray[selectedTabIndex] == null) return false;
return selectedTabIndex != CreativeTabs.tabInventory.getTabIndex() && CreativeTabs.creativeTabArray[selectedTabIndex].shouldHidePlayerInventory() && ((ContainerCreative)this.inventorySlots).hasMoreThan1PageOfItemsInList();
}
private void func_74227_b(CreativeTabs par1CreativeTabs)
{
+ if (par1CreativeTabs == null)
+ {
+ return;
+ }
+
int var2 = selectedTabIndex;
selectedTabIndex = par1CreativeTabs.getTabIndex();
ContainerCreative var3 = (ContainerCreative)this.inventorySlots;
@@ -523,21 +539,42 @@
super.drawScreen(par1, par2, par3);
CreativeTabs[] var11 = CreativeTabs.creativeTabArray;
- int var12 = var11.length;
-
- for (int var13 = 0; var13 < var12; ++var13)
+ int start = tabPage * 10;
+ int var12 = Math.min(var11.length, ((tabPage + 1) * 10) + 2);
+ if (tabPage != 0) start += 2;
+ boolean rendered = false;
+
+ for (int var13 = start; var13 < var12; ++var13)
{
CreativeTabs var14 = var11[var13];
- if (this.renderCreativeInventoryHoveringText(var14, par1, par2))
- {
+ if (var14 != null && renderCreativeInventoryHoveringText(var14, par1, par2))
+ {
+ rendered = true;
break;
}
}
+ if (!rendered && !renderCreativeInventoryHoveringText(CreativeTabs.tabAllSearch, par1, par2))
+ {
+ renderCreativeInventoryHoveringText(CreativeTabs.tabInventory, par1, par2);
+ }
+
if (this.field_74235_v != null && selectedTabIndex == CreativeTabs.tabInventory.getTabIndex() && this.func_74188_c(this.field_74235_v.xDisplayPosition, this.field_74235_v.yDisplayPosition, 16, 16, par1, par2))
{
this.drawCreativeTabHoveringText(StringTranslate.getInstance().translateKey("inventory.binSlot"), par1, par2);
+ }
+
+ if (maxPages != 0)
+ {
+ String page = String.format("%d / %d", tabPage + 1, maxPages + 1);
+ int width = fontRenderer.getStringWidth(page);
+ GL11.glDisable(GL11.GL_LIGHTING);
+ this.zLevel = 300.0F;
+ itemRenderer.zLevel = 300.0F;
+ fontRenderer.drawString(page, guiLeft + (xSize / 2) - (width / 2), guiTop - 44, -1);
+ this.zLevel = 0.0F;
+ itemRenderer.zLevel = 0.0F;
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
@@ -558,14 +595,32 @@
int var8 = var7.length;
int var9;
- for (var9 = 0; var9 < var8; ++var9)
+ int start = tabPage * 10;
+ var8 = Math.min(var7.length, ((tabPage + 1) * 10 + 2));
+ if (tabPage != 0) start += 2;
+
+ for (var9 = start; var9 < var8; ++var9)
{
CreativeTabs var10 = var7[var9];
this.mc.renderEngine.bindTexture(var4);
- if (var10.getTabIndex() != selectedTabIndex)
+ if (var10 != null && var10.getTabIndex() != selectedTabIndex)
{
this.renderCreativeTab(var10);
+ }
+ }
+
+ if (tabPage != 0)
+ {
+ if (var5 != CreativeTabs.tabAllSearch)
+ {
+ mc.renderEngine.bindTexture(var4);
+ renderCreativeTab(CreativeTabs.tabAllSearch);
+ }
+ if (var5 != CreativeTabs.tabInventory)
+ {
+ mc.renderEngine.bindTexture(var4);
+ renderCreativeTab(CreativeTabs.tabInventory);
}
}
@@ -578,6 +633,14 @@
var9 = var8 + 112;
this.mc.renderEngine.bindTexture(var4);
+ if (var5 == null || var5.getTabPage() != tabPage)
+ {
+ if (var5 != CreativeTabs.tabAllSearch && var5 != CreativeTabs.tabInventory)
+ {
+ return;
+ }
+ }
+
if (var5.shouldHidePlayerInventory())
{
this.drawTexturedModalRect(var11, var8 + (int)((float)(var9 - var8 - 17) * this.currentScroll), 232 + (this.needsScrollBars() ? 0 : 12), 0, 12, 15);
@@ -593,6 +656,15 @@
protected boolean func_74232_a(CreativeTabs par1CreativeTabs, int par2, int par3)
{
+ if (par1CreativeTabs.getTabPage() != tabPage)
+ {
+ if (par1CreativeTabs != CreativeTabs.tabAllSearch &&
+ par1CreativeTabs != CreativeTabs.tabInventory)
+ {
+ return false;
+ }
+ }
+
int var4 = par1CreativeTabs.getTabColumn();
int var5 = 28 * var4;
byte var6 = 0;
@@ -707,7 +779,7 @@
var8 += 8 + (var3 ? 1 : -1);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
- ItemStack var10 = new ItemStack(par1CreativeTabs.getTabIconItem());
+ ItemStack var10 = par1CreativeTabs.getIconItemStack();
itemRenderer.renderItemIntoGUI(this.fontRenderer, this.mc.renderEngine, var10, var7, var8);
itemRenderer.renderItemOverlayIntoGUI(this.fontRenderer, this.mc.renderEngine, var10, var7, var8);
GL11.glDisable(GL11.GL_LIGHTING);
@@ -729,6 +801,15 @@
{
this.mc.displayGuiScreen(new GuiStats(this, this.mc.statFileWriter));
}
+
+ if (par1GuiButton.id == 101)
+ {
+ tabPage = Math.max(tabPage - 1, 0);
+ }
+ else if (par1GuiButton.id == 102)
+ {
+ tabPage = Math.min(tabPage + 1, maxPages);
+ }
}
public int func_74230_h()