AnvilScreenRe.java 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.hexdragon.enchrebirth.block;
  2. import com.mojang.blaze3d.matrix.MatrixStack;
  3. import com.mojang.blaze3d.systems.RenderSystem;
  4. import net.minecraft.client.Minecraft;
  5. import net.minecraft.client.gui.screen.inventory.ContainerScreen;
  6. import net.minecraft.entity.player.PlayerInventory;
  7. import net.minecraft.util.ResourceLocation;
  8. import net.minecraft.util.text.ITextComponent;
  9. import net.minecraft.util.text.TranslationTextComponent;
  10. import net.minecraftforge.api.distmarker.Dist;
  11. import net.minecraftforge.api.distmarker.OnlyIn;
  12. import org.lwjgl.opengl.GL11;
  13. @OnlyIn(Dist.CLIENT)
  14. public class AnvilScreenRe extends ContainerScreen<AnvilContainerRe> {
  15. private static final ResourceLocation ANVIL_RESOURCE = new ResourceLocation("textures/gui/container/anvil.png");
  16. public AnvilScreenRe(AnvilContainerRe container, PlayerInventory playerInventory, ITextComponent title) {
  17. super(container, playerInventory, title);
  18. this.playerInventoryTitleY = 1000000; // 关闭 “物品栏” 三个字的显示
  19. this.titleX = 60;
  20. }
  21. protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) {
  22. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  23. this.minecraft.getTextureManager().bindTexture(ANVIL_RESOURCE);
  24. int i = (this.width - this.xSize) / 2;
  25. int j = (this.height - this.ySize) / 2;
  26. this.blit(matrixStack, i, j, 0, 0, this.xSize, this.ySize);
  27. // 显示无法合成的红叉:输入不为空但输出为空
  28. if ((this.container.getSlot(0).getHasStack() || this.container.getSlot(1).getHasStack()) && !this.container.getSlot(2).getHasStack()) {
  29. this.blit(matrixStack, i + 99, j + 45, this.xSize, 0, 28, 21);
  30. }
  31. }
  32. protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int x, int y) {
  33. RenderSystem.disableBlend();
  34. super.drawGuiContainerForegroundLayer(matrixStack, x, y);
  35. int maximumCost = this.container.getMaximumCost();
  36. if (maximumCost > 0) {
  37. int fontColor = 8453920;
  38. ITextComponent itextcomponent;
  39. if (maximumCost >= 100 && !this.minecraft.player.abilities.isCreativeMode) {
  40. itextcomponent = new TranslationTextComponent("container.repair.expensive");
  41. fontColor = 16736352;
  42. } else if (!this.container.getSlot(2).getHasStack()) {
  43. itextcomponent = null;
  44. } else {
  45. itextcomponent = new TranslationTextComponent("container.repair.cost", maximumCost);
  46. if (!this.container.getSlot(2).canTakeStack(this.playerInventory.player)) {
  47. fontColor = 16736352;
  48. }
  49. }
  50. if (itextcomponent != null) {
  51. int xpos = this.xSize - 8 - this.font.getStringPropertyWidth(itextcomponent) - 2;
  52. fill(matrixStack, xpos - 2, 67, this.xSize - 8, 79, 1325400064);
  53. this.font.func_243246_a(matrixStack, itextcomponent, (float) xpos, 69.0F, fontColor);
  54. }
  55. }
  56. }
  57. // 无需修改的方法
  58. public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
  59. this.renderBackground(matrixStack);
  60. super.render(matrixStack, mouseX, mouseY, partialTicks);
  61. RenderSystem.disableBlend();
  62. this.renderHoveredTooltip(matrixStack, mouseX, mouseY);
  63. }
  64. public void resize(Minecraft minecraft, int width, int height) {
  65. this.init(minecraft, width, height);
  66. }
  67. }