ItemStackDisplayGui.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package me.km.networking;
  2. import com.mojang.blaze3d.systems.RenderSystem;
  3. import me.km.KajetansMod;
  4. import me.km.utils.ClientReflectionUtils;
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.client.gui.AbstractGui;
  7. import net.minecraft.client.gui.FontRenderer;
  8. import net.minecraft.util.ResourceLocation;
  9. import net.minecraftforge.api.distmarker.Dist;
  10. import net.minecraftforge.api.distmarker.OnlyIn;
  11. @OnlyIn(Dist.CLIENT)
  12. public class ItemStackDisplayGui extends AbstractGui
  13. {
  14. private static final ResourceLocation CUSTOM_ICONS = new ResourceLocation(KajetansMod.MODID, "textures/gui/itemstacks.png");
  15. public final static ItemStackDisplayGui INSTANCE = new ItemStackDisplayGui(Minecraft.getInstance());
  16. private static class Stack
  17. {
  18. private int x = -1;
  19. private int y = 0;
  20. private int width = 0;
  21. private int height = 0;
  22. private String text = "";
  23. public void setIcon(int index, int c)
  24. {
  25. if(index < 0)
  26. {
  27. clear();
  28. }
  29. else if(index >= 0 && index < 104)
  30. {
  31. x = (index % 52) * 16 + 192;
  32. y = (index / 52) * 16;
  33. width = 16;
  34. height = 16;
  35. text = (c == 0) ? "" : String.valueOf(c);
  36. }
  37. else
  38. {
  39. index -= 104;
  40. x = (index % 16) * 64;
  41. y = (index / 16) * 64 + 32;
  42. width = 64;
  43. height = 64;
  44. text = null;
  45. }
  46. }
  47. public void clear()
  48. {
  49. x = -1;
  50. }
  51. }
  52. private final Minecraft mc;
  53. private final Stack[] icons = new Stack[9];
  54. private boolean inactive = true;
  55. public ItemStackDisplayGui(Minecraft mc)
  56. {
  57. this.mc = mc;
  58. for(int i = 0; i < icons.length; i++)
  59. {
  60. icons[i] = new Stack();
  61. }
  62. }
  63. public void setActive(boolean active)
  64. {
  65. this.inactive = !active;
  66. }
  67. public void setIcon(int index, int i, int count)
  68. {
  69. if(index >= 0 && index < 9)
  70. {
  71. icons[index].setIcon(i, count);
  72. }
  73. }
  74. public final void clear()
  75. {
  76. for(Stack stack : icons)
  77. {
  78. stack.clear();
  79. }
  80. }
  81. public void paint(KeyManager km)
  82. {
  83. if(inactive)
  84. {
  85. return;
  86. }
  87. RenderSystem.enableBlend();
  88. RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  89. mc.getTextureManager().bindTexture(CUSTOM_ICONS);
  90. int screenWidth = (mc.getMainWindow().getScaledWidth() >> 1) - 91;
  91. int y = 3;
  92. if(ClientReflectionUtils.isRenderingBossBar())
  93. {
  94. y += 20;
  95. }
  96. blit(screenWidth, y - 3, 0, 0, 182, 22, 1024, 1024);
  97. int i = 0;
  98. for(int x = 3; x < 164; x += 20)
  99. {
  100. Stack s = icons[i];
  101. if(s.x != -1)
  102. {
  103. blit(screenWidth + x, y, 16, 16, s.x, s.y, s.width, s.height, 1024, 1024);
  104. }
  105. i++;
  106. }
  107. RenderSystem.disableBlend();
  108. FontRenderer fr = mc.fontRenderer;
  109. i = 0;
  110. for(int x = 20; x < 181; x += 20)
  111. {
  112. if(icons[i].x != -1)
  113. {
  114. if(icons[i].text == null)
  115. {
  116. String s = km.getKeyDescription(i);
  117. fr.drawStringWithShadow(s, (float)(screenWidth + x - fr.getStringWidth(s)), y + 9, 16777215);
  118. }
  119. else if(!icons[i].text.isEmpty())
  120. {
  121. fr.drawStringWithShadow(icons[i].text, (float)(screenWidth + x - fr.getStringWidth(icons[i].text)), y + 9, 16777215);
  122. }
  123. }
  124. i++;
  125. }
  126. }
  127. }