CustomInventoryScreen.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package me.km.networking;
  2. import com.mojang.blaze3d.matrix.MatrixStack;
  3. import com.mojang.blaze3d.systems.RenderSystem;
  4. import me.km.KajetansMod;
  5. import me.km.inventory.CustomContainer;
  6. import me.km.inventory.ModInventory;
  7. import net.minecraft.client.gui.screen.inventory.ContainerScreen;
  8. import net.minecraft.entity.player.PlayerInventory;
  9. import net.minecraft.util.ResourceLocation;
  10. import net.minecraft.util.text.ITextComponent;
  11. import net.minecraftforge.api.distmarker.Dist;
  12. import net.minecraftforge.api.distmarker.OnlyIn;
  13. @OnlyIn(Dist.CLIENT)
  14. public class CustomInventoryScreen extends ContainerScreen<CustomContainer> {
  15. private static final ResourceLocation CHEST_GUI_TEXTURE =
  16. new ResourceLocation("textures/gui/container/generic_54.png");
  17. private static final ResourceLocation EMPTY_TILE =
  18. new ResourceLocation(KajetansMod.MODID, "textures/gui/container/empty_tile.png");
  19. private final int inventoryRows;
  20. public CustomInventoryScreen(CustomContainer cc, PlayerInventory pInv, ITextComponent title) {
  21. super(cc, pInv, title);
  22. passEvents = false;
  23. inventoryRows = cc.getInventoryBase().getRows();
  24. imageHeight = 114 + inventoryRows * 18;
  25. }
  26. @Override
  27. public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
  28. this.renderBackground(matrixStack);
  29. super.render(matrixStack, mouseX, mouseY, partialTicks);
  30. this.renderTooltip(matrixStack, mouseX, mouseY);
  31. }
  32. @Override
  33. protected void renderLabels(MatrixStack matrixStack, int x, int y) {
  34. this.font.draw(matrixStack, title.getString(), 8.0f, 6.0f, 4210752);
  35. this.font.draw(matrixStack, inventory.getDisplayName().getString(), 8.0f, imageHeight - 94,
  36. 4210752);
  37. }
  38. @SuppressWarnings("deprecation")
  39. @Override
  40. protected void renderBg(MatrixStack matrixStack, float partialTicks, int ix, int iy) {
  41. RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  42. this.minecraft.getTextureManager().bind(CHEST_GUI_TEXTURE);
  43. int i = (width - imageWidth) / 2;
  44. int j = (height - imageHeight) / 2;
  45. blit(matrixStack, i, j, 0, 0, imageWidth, inventoryRows * 18 + 17);
  46. blit(matrixStack, i, j + inventoryRows * 18 + 17, 0, 126, imageWidth, 96);
  47. i += 7;
  48. j += 17;
  49. minecraft.getTextureManager().bind(EMPTY_TILE);
  50. ModInventory base = this.getMenu().getInventoryBase();
  51. for(int x = 0; x < 9; x++) {
  52. for(int y = 0; y < inventoryRows; y++) {
  53. if(base.shouldRenderOverlay(x, y)) {
  54. blit(matrixStack, i + 18 * x, j + 18 * y, 0, 0, 18, 18, 64, 64);
  55. } else if(base.shouldRenderDarker(x, y)) {
  56. blit(matrixStack, i + 18 * x, j + 18 * y, 18, 0, 18, 18, 64, 64);
  57. }
  58. }
  59. }
  60. }
  61. }