Skip to content

Commit 2812b87

Browse files
committed
Improved creative inventory rendering
1 parent 1ac2701 commit 2812b87

File tree

1 file changed

+84
-52
lines changed

1 file changed

+84
-52
lines changed

client/gui/GuiCreativeInventory.java

+84-52
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import clashsoft.playerinventoryapi.lib.ButtonHashingStrategy;
2323
import clashsoft.playerinventoryapi.lib.ExtendedInventory;
2424

25+
import net.minecraft.client.gui.FontRenderer;
2526
import net.minecraft.client.gui.GuiButton;
2627
import net.minecraft.client.gui.GuiTextField;
2728
import net.minecraft.client.gui.achievement.GuiAchievements;
2829
import net.minecraft.client.gui.achievement.GuiStats;
2930
import net.minecraft.client.gui.inventory.CreativeCrafting;
31+
import net.minecraft.client.gui.inventory.GuiInventory;
3032
import net.minecraft.client.renderer.RenderHelper;
3133
import net.minecraft.client.settings.GameSettings;
3234
import net.minecraft.creativetab.CreativeTabs;
@@ -347,18 +349,27 @@ public void drawScreen(int mouseX, int mouseY, float partialTickTime)
347349
}
348350

349351
super.drawScreen(mouseX, mouseY, partialTickTime);
350-
CreativeTabs[] acreativetabs = CreativeTabs.creativeTabArray;
352+
353+
if (this.maxPages != 0)
354+
{
355+
String page = String.format("%d / %d", new Object[] { Integer.valueOf(tabPage + 1), Integer.valueOf(this.maxPages + 1) });
356+
int width = this.fontRendererObj.getStringWidth(page);
357+
GL11.glDisable(2896);
358+
this.fontRendererObj.drawString(page, this.guiLeft + (this.xSize - width) / 2, this.guiTop - 44, -1);
359+
}
360+
361+
CreativeTabs[] tabs = CreativeTabs.creativeTabArray;
351362
int start = tabPage * 10;
352-
int len1 = Math.min(acreativetabs.length, start + 12);
363+
int end = Math.min(tabs.length, start + 12);
353364
if (tabPage != 0)
354365
{
355366
start += 2;
356367
}
357368
boolean rendered = false;
358369

359-
for (int i = start; i < len1; ++i)
370+
for (int i = start; i < end; ++i)
360371
{
361-
CreativeTabs tab = acreativetabs[i];
372+
CreativeTabs tab = tabs[i];
362373
String page;
363374
int width;
364375
if (tab != null)
@@ -371,26 +382,25 @@ public void drawScreen(int mouseX, int mouseY, float partialTickTime)
371382
}
372383
}
373384

374-
if (!rendered && this.renderTabHoveringText(CreativeTabs.tabAllSearch, mouseX, mouseY))
385+
if (!rendered)
375386
{
376-
this.renderTabHoveringText(CreativeTabs.tabAllSearch, mouseX, mouseY);
387+
if (!this.renderTabHoveringText(CreativeTabs.tabAllSearch, mouseX, mouseY))
388+
{
389+
this.renderTabHoveringText(CreativeTabs.tabInventory, mouseX, mouseY);
390+
}
377391
}
378392

379393
if (this.binSlot != null && selectedTabIndex == CreativeTabs.tabInventory.getTabIndex() && this.func_146978_c(this.binSlot.xDisplayPosition, this.binSlot.yDisplayPosition, 16, 16, mouseX, mouseY))
380394
{
381-
this.drawCreativeTabHoveringText(I18n.getString("inventory.binSlot"), mouseX, mouseY);
382-
}
383-
384-
if (this.maxPages != 0)
385-
{
386-
String page = String.format("%d / %d", new Object[] { Integer.valueOf(tabPage + 1), Integer.valueOf(this.maxPages + 1) });
387-
int width = this.fontRendererObj.getStringWidth(page);
388-
GL11.glDisable(2896);
389-
this.zLevel = 300.0F;
390-
itemRender.zLevel = 300.0F;
391-
this.fontRendererObj.drawString(page, this.guiLeft + (this.xSize - width) / 2, this.guiTop - 44, -1);
392-
this.zLevel = 0.0F;
393-
itemRender.zLevel = 0.0F;
395+
String s;
396+
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
397+
{
398+
s = "Clear Inventory";
399+
}
400+
else {
401+
s = I18n.getString("inventory.binSlot");
402+
}
403+
this.drawCreativeTabHoveringText(s, mouseX, mouseY);
394404
}
395405

396406
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
@@ -421,54 +431,68 @@ protected void drawGuiContainerBackgroundLayer(float partialTickTime, int mouseX
421431
{
422432
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
423433
RenderHelper.enableGUIStandardItemLighting();
424-
CreativeTabs[] acreativetabs = CreativeTabs.creativeTabArray;
425-
CreativeTabs tab = acreativetabs[selectedTabIndex];
426-
int k = acreativetabs.length;
434+
CreativeTabs[] tabs = CreativeTabs.creativeTabArray;
435+
CreativeTabs tab = tabs[selectedTabIndex];
427436

428437
int start = tabPage * 10;
429-
k = Math.min(k, start + 12);
438+
int end = Math.min(tabs.length, start + 12);
439+
430440
if (tabPage != 0)
431-
{
432441
start += 2;
433-
}
434442

435-
for (int l = start; l < k; ++l)
443+
for (int i = start; i < end; ++i)
436444
{
437-
CreativeTabs tab1 = acreativetabs[l];
445+
CreativeTabs tab1 = tabs[i];
446+
this.mc.getTextureManager().bindTexture(background);
438447

439448
if (tab1 != null && tab1.getTabIndex() != selectedTabIndex)
440449
{
441-
this.drawCreativeTab(tab1);
450+
drawCreativeTab(tab1);
442451
}
443452
}
444453

445-
if (tab == CreativeTabs.tabInventory)
454+
if (tabPage != 0)
446455
{
447-
this.renderInventoryTab(mouseX, mouseY, partialTickTime);
456+
if (tab != CreativeTabs.tabAllSearch)
457+
{
458+
this.mc.getTextureManager().bindTexture(background);
459+
this.drawCreativeTab(CreativeTabs.tabAllSearch);
460+
}
461+
if (tab != CreativeTabs.tabInventory)
462+
{
463+
this.mc.getTextureManager().bindTexture(background);
464+
this.drawCreativeTab(CreativeTabs.tabInventory);
465+
}
448466
}
449-
else
467+
468+
this.mc.getTextureManager().bindTexture(new ResourceLocation("textures/gui/container/creative_inventory/tab_" + tab.getBackgroundImageName()));
469+
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
470+
this.searchField.drawTextBox();
471+
472+
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
473+
this.mc.getTextureManager().bindTexture(background);
474+
475+
if (tab.shouldHidePlayerInventory())
450476
{
451-
this.mc.getTextureManager().bindTexture(new ResourceLocation("textures/gui/container/creative_inventory/tab_" + tab.getBackgroundImageName()));
452-
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
453-
this.searchField.drawTextBox();
454-
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
455-
int i1 = this.guiLeft + 175;
456-
k = this.guiTop + 18;
457-
int l = k + 112;
458-
this.mc.getTextureManager().bindTexture(background);
459-
460-
if (tab.shouldHidePlayerInventory())
477+
if (this.needsScrollBars())
461478
{
462-
this.drawTexturedModalRect(i1, k + (int) ((l - k - 17) * this.currentScroll), 232 + (this.needsScrollBars() ? 0 : 12), 0, 12, 15);
479+
this.drawTexturedModalRect(this.guiLeft + 175, this.guiTop + 18 + (int) (95 * this.currentScroll), 232, 0, 12, 15);
463480
}
464-
465-
if (tab.getTabPage() != tabPage && tab != CreativeTabs.tabAllSearch)
481+
else
466482
{
467-
return;
483+
this.drawTexturedModalRect(this.guiLeft + 175, this.guiTop + 18, 244, 0, 12, 15);
468484
}
469485
}
470486

471-
this.drawCreativeTab(tab);
487+
if ((tab == CreativeTabs.tabInventory))
488+
{
489+
this.renderInventoryTab(mouseX, mouseY, partialTickTime);
490+
this.drawCreativeTab(tab);
491+
}
492+
else if (tab.getTabPage() == tabPage || tab == CreativeTabs.tabAllSearch)
493+
{
494+
this.drawCreativeTab(tab);
495+
}
472496
}
473497

474498
protected void renderInventoryTab(int mouseX, int mouseY, float partialTickTime)
@@ -584,16 +608,15 @@ protected void renderToolTip(ItemStack stack, int x, int y)
584608

585609
for (int i = 0; i < len; ++i)
586610
{
587-
CreativeTabs creativetabs1 = tabs[i];
611+
CreativeTabs tab1 = tabs[i];
588612

589-
if (creativetabs1.func_111226_a(enchantment.type))
613+
if (tab1.func_111226_a(enchantment.type))
590614
{
591-
tab = creativetabs1;
615+
tab = tab1;
592616
break;
593617
}
594618
}
595619
}
596-
597620
}
598621

599622
if (tab != null)
@@ -613,11 +636,20 @@ protected void renderToolTip(ItemStack stack, int x, int y)
613636
}
614637
}
615638

616-
this.func_146283_a(list, x, y);
639+
this.drawHoveringText(list, x, y, this.fontRendererObj);
617640
}
618641
else
619642
{
620-
super.renderToolTip(stack, x, y);
643+
List<String> list = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
644+
645+
list.set(0, stack.getRarity().rarityColor + list.get(0));
646+
for (int k = 1; k < list.size(); ++k)
647+
{
648+
list.set(k, EnumChatFormatting.GRAY + list.get(k));
649+
}
650+
651+
FontRenderer font = stack.getItem().getFontRenderer(stack);
652+
this.drawHoveringText(list, x, y, font == null ? this.fontRendererObj : font);
621653
}
622654
}
623655

0 commit comments

Comments
 (0)