Переглянути джерело

初步整理铁砧代码,将最大等级限制提高到 99 级

LTCatt 6 роки тому
батько
коміт
e2c0d87af4

+ 147 - 174
src/main/java/com/hexdragon/enchrebirth/block/AnvilContainerRe.java

@@ -11,7 +11,6 @@ import net.minecraft.inventory.CraftResultInventory;
 import net.minecraft.inventory.IInventory;
 import net.minecraft.inventory.Inventory;
 import net.minecraft.inventory.container.Container;
-import net.minecraft.inventory.container.ContainerType;
 import net.minecraft.inventory.container.Slot;
 import net.minecraft.item.EnchantedBookItem;
 import net.minecraft.item.ItemStack;
@@ -23,178 +22,80 @@ import net.minecraftforge.api.distmarker.Dist;
 import net.minecraftforge.api.distmarker.OnlyIn;
 import net.minecraftforge.common.MinecraftForge;
 import net.minecraftforge.event.AnvilUpdateEvent;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 
 import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 import java.util.Map;
 
 public class AnvilContainerRe extends Container {
-    protected final CraftResultInventory field_234642_c_ = new CraftResultInventory();
-    protected final IInventory field_234643_d_ = new Inventory(2) {
-        /**
-         * For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think
-         * it hasn't changed and skip it.
-         */
+
+    // 本次合成消耗的物品合成原料个数
+    public int materialCost;
+
+    // 输入与输出物品槽
+    private final IInventory inputInventory = new Inventory(2) {
         public void markDirty() {
             super.markDirty();
             AnvilContainerRe.this.onCraftMatrixChanged(this);
         }
     };
-    protected final IWorldPosCallable field_234644_e_;
-    protected final PlayerEntity field_234645_f_;
-
-    public AnvilContainerRe(@Nullable ContainerType<?> p_i231587_1_, int p_i231587_2_, PlayerInventory p_i231587_3_, IWorldPosCallable p_i231587_4_) {
-        super(p_i231587_1_, p_i231587_2_);
-        this.field_234644_e_ = p_i231587_4_;
-        this.field_234645_f_ = p_i231587_3_.player;
-        this.addSlot(new Slot(this.field_234643_d_, 0, 27, 47));
-        this.addSlot(new Slot(this.field_234643_d_, 1, 76, 47));
-        this.addSlot(new Slot(this.field_234642_c_, 2, 134, 47) {
-            /**
-             * Check if the stack is allowed to be placed in this slot, used for armor slots as well as furnace fuel.
-             */
+    private final CraftResultInventory outputInventory = new CraftResultInventory();
+
+    // 构造页面槽位
+    private void Constuct(PlayerInventory playerInventory) {
+        this.addSlot(new Slot(this.inputInventory, 0, 27, 47));
+        this.addSlot(new Slot(this.inputInventory, 1, 76, 47));
+        this.addSlot(new Slot(this.outputInventory, 2, 134, 47) {
+            // 禁止将物品放在输出格
             public boolean isItemValid(ItemStack stack) {
                 return false;
             }
-
-            /**
-             * Return whether this slot's stack can be taken from this slot.
-             */
-            public boolean canTakeStack(PlayerEntity playerIn) {
-                return AnvilContainerRe.this.func_230303_b_(playerIn, this.getHasStack());
+            // 确认玩家能否拿走物品
+            public boolean canTakeStack(PlayerEntity player) {
+                return (player.abilities.isCreativeMode || player.experienceLevel >= maximumCost.get()) && maximumCost.get() > 0;
             }
-
+            // 触发玩家拿走物品的事件
             public ItemStack onTake(PlayerEntity thePlayer, ItemStack stack) {
-                return AnvilContainerRe.this.func_230301_a_(thePlayer, stack);
+                return AnvilContainerRe.this.onTakeOutput(thePlayer, stack);
             }
         });
 
+        // 增加物品栏与快捷栏槽位
+        int yPositionStart = 84;
         for (int i = 0; i < 3; ++i) {
             for (int j = 0; j < 9; ++j) {
-                this.addSlot(new Slot(p_i231587_3_, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
+                this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, yPositionStart + i * 18));
             }
         }
-
         for (int k = 0; k < 9; ++k) {
-            this.addSlot(new Slot(p_i231587_3_, k, 8 + k * 18, 152)); // 142
+            this.addSlot(new Slot(playerInventory, k, 8 + k * 18, 58 + yPositionStart));
         }
-
-    }
-
-    public AnvilContainerRe(int id, PlayerInventory playerInventory) {
-        this(id, playerInventory, IWorldPosCallable.DUMMY);
-    }
-
-    public AnvilContainerRe(int id, PlayerInventory playerInventory, IWorldPosCallable worldPosCallable) {
-        this(RegMain.containerAnvil.get(), id, playerInventory, worldPosCallable);
-        this.trackInt(this.maximumCost);
     }
 
-    /**
-     * Callback for when the crafting matrix is changed.
-     */
-    public void onCraftMatrixChanged(IInventory inventoryIn) {
-        super.onCraftMatrixChanged(inventoryIn);
-        if (inventoryIn == this.field_234643_d_) {
-            this.updateRepairOutput();
+    // 在玩家从输出格拿走物品时触发:铁砧损坏、减少经验等
+    private ItemStack onTakeOutput(PlayerEntity player, ItemStack itemStack) {
+        if (!player.abilities.isCreativeMode) {
+            player.addExperienceLevel(-this.maximumCost.get());
         }
 
-    }
-
-    /**
-     * Called when the container is closed.
-     */
-    public void onContainerClosed(PlayerEntity playerIn) {
-        super.onContainerClosed(playerIn);
-        this.field_234644_e_.consume((p_234647_2_, p_234647_3_) -> this.clearContainer(playerIn, p_234647_2_, this.field_234643_d_));
-    }
-
-    /**
-     * Determines whether supplied player can use this container
-     */
-    public boolean canInteractWith(PlayerEntity playerIn) {
-        return this.field_234644_e_.applyOrElse((p_234646_2_, p_234646_3_) -> this.func_230302_a_(p_234646_2_.getBlockState(p_234646_3_)) && playerIn.getDistanceSq((double) p_234646_3_.getX() + 0.5D, (double) p_234646_3_.getY() + 0.5D, (double) p_234646_3_.getZ() + 0.5D) <= 64.0D, true);
-    }
+        float breakChance = net.minecraftforge.common.ForgeHooks.onAnvilRepair(player, itemStack, AnvilContainerRe.this.inputInventory.getStackInSlot(0), AnvilContainerRe.this.inputInventory.getStackInSlot(1));
 
-    /**
-     * Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
-     * inventory and the other inventory(s).
-     */
-    public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
-        ItemStack itemstack = ItemStack.EMPTY;
-        Slot slot = this.inventorySlots.get(index);
-        if (slot != null && slot.getHasStack()) {
-            ItemStack itemstack1 = slot.getStack();
-            itemstack = itemstack1.copy();
-            if (index == 2) {
-                if (!this.mergeItemStack(itemstack1, 3, 39, true)) {
-                    return ItemStack.EMPTY;
-                }
-
-                slot.onSlotChange(itemstack1, itemstack);
-            } else if (index != 0 && index != 1) {
-                if (index < 39) {
-                    if (!this.mergeItemStack(itemstack1, 0, 2, false)) {
-                        return ItemStack.EMPTY;
-                    }
-                }
-            } else if (!this.mergeItemStack(itemstack1, 3, 39, false)) {
-                return ItemStack.EMPTY;
-            }
-
-            if (itemstack1.isEmpty()) {
-                slot.putStack(ItemStack.EMPTY);
-            } else {
-                slot.onSlotChanged();
-            }
-
-            if (itemstack1.getCount() == itemstack.getCount()) {
-                return ItemStack.EMPTY;
-            }
-
-            slot.onTake(playerIn, itemstack1);
-        }
-
-        return itemstack;
-    }
-    private static final Logger LOGGER = LogManager.getLogger();
-    public int materialCost;
-    private final IntReferenceHolder maximumCost = IntReferenceHolder.single();
-
-    protected boolean func_230302_a_(BlockState p_230302_1_) {
-        return p_230302_1_.isIn(BlockTags.ANVIL);
-    }
-
-    protected boolean func_230303_b_(PlayerEntity p_230303_1_, boolean p_230303_2_) {
-        return (p_230303_1_.abilities.isCreativeMode || p_230303_1_.experienceLevel >= this.maximumCost.get()) && this.maximumCost.get() > 0;
-    }
-
-    protected ItemStack func_230301_a_(PlayerEntity p_230301_1_, ItemStack p_230301_2_) {
-        if (!p_230301_1_.abilities.isCreativeMode) {
-            p_230301_1_.addExperienceLevel(-this.maximumCost.get());
-        }
-
-        float breakChance = net.minecraftforge.common.ForgeHooks.onAnvilRepair(p_230301_1_, p_230301_2_, AnvilContainerRe.this.field_234643_d_.getStackInSlot(0), AnvilContainerRe.this.field_234643_d_.getStackInSlot(1));
-
-        this.field_234643_d_.setInventorySlotContents(0, ItemStack.EMPTY);
+        this.inputInventory.setInventorySlotContents(0, ItemStack.EMPTY);
         if (this.materialCost > 0) {
-            ItemStack itemstack = this.field_234643_d_.getStackInSlot(1);
+            ItemStack itemstack = this.inputInventory.getStackInSlot(1);
             if (!itemstack.isEmpty() && itemstack.getCount() > this.materialCost) {
                 itemstack.shrink(this.materialCost);
-                this.field_234643_d_.setInventorySlotContents(1, itemstack);
+                this.inputInventory.setInventorySlotContents(1, itemstack);
             } else {
-                this.field_234643_d_.setInventorySlotContents(1, ItemStack.EMPTY);
+                this.inputInventory.setInventorySlotContents(1, ItemStack.EMPTY);
             }
         } else {
-            this.field_234643_d_.setInventorySlotContents(1, ItemStack.EMPTY);
+            this.inputInventory.setInventorySlotContents(1, ItemStack.EMPTY);
         }
 
         this.maximumCost.set(0);
-        this.field_234644_e_.consume((p_234633_1_, p_234633_2_) -> {
+        this.worldPosCallable.consume((p_234633_1_, p_234633_2_) -> {
             BlockState blockstate = p_234633_1_.getBlockState(p_234633_2_);
-            if (!p_230301_1_.abilities.isCreativeMode && blockstate.isIn(BlockTags.ANVIL) && p_230301_1_.getRNG().nextFloat() < breakChance) {
+            if (!player.abilities.isCreativeMode && blockstate.isIn(BlockTags.ANVIL) && player.getRNG().nextFloat() < breakChance) {
                 BlockState blockstate1 = AnvilBlock.damage(blockstate);
                 if (blockstate1 == null) {
                     p_234633_1_.removeBlock(p_234633_2_, false);
@@ -208,37 +109,35 @@ public class AnvilContainerRe extends Container {
             }
 
         });
-        return p_230301_2_;
+        return itemStack;
     }
 
-    /**
-     * called when the Anvil Input Slot changes, calculates the new result and puts it in the output slot
-     */
+    // 当输入物品改变时更新输出
     public void updateRepairOutput() {
-        ItemStack itemstack = this.field_234643_d_.getStackInSlot(0);
+        ItemStack itemstack = this.inputInventory.getStackInSlot(0);
         this.maximumCost.set(1);
-        int i = 0;
+        int cost = 0;
         int j = 0;
         int k = 0;
         if (itemstack.isEmpty()) {
-            this.field_234642_c_.setInventorySlotContents(0, ItemStack.EMPTY);
+            this.outputInventory.setInventorySlotContents(0, ItemStack.EMPTY);
             this.maximumCost.set(0);
         } else {
             ItemStack itemstack1 = itemstack.copy();
-            ItemStack itemstack2 = this.field_234643_d_.getStackInSlot(1);
+            ItemStack itemstack2 = this.inputInventory.getStackInSlot(1);
             Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(itemstack1);
             j = j + itemstack.getRepairCost() + (itemstack2.isEmpty() ? 0 : itemstack2.getRepairCost());
             this.materialCost = 0;
             boolean flag = false;
 
             if (!itemstack2.isEmpty()) {
-                if (!onAnvilChange(this, itemstack, itemstack2, field_234642_c_, itemstack.getDisplayName().getString(), j))
+                if (!onAnvilChange(this, itemstack, itemstack2, outputInventory, itemstack.getDisplayName().getString(), j))
                     return;
                 flag = itemstack2.getItem() == Items.ENCHANTED_BOOK && !EnchantedBookItem.getEnchantments(itemstack2).isEmpty();
                 if (itemstack1.isDamageable() && itemstack1.getItem().getIsRepairable(itemstack, itemstack2)) {
                     int l2 = Math.min(itemstack1.getDamage(), itemstack1.getMaxDamage() / 4);
                     if (l2 <= 0) {
-                        this.field_234642_c_.setInventorySlotContents(0, ItemStack.EMPTY);
+                        this.outputInventory.setInventorySlotContents(0, ItemStack.EMPTY);
                         this.maximumCost.set(0);
                         return;
                     }
@@ -247,14 +146,14 @@ public class AnvilContainerRe extends Container {
                     for (i3 = 0; l2 > 0 && i3 < itemstack2.getCount(); ++i3) {
                         int j3 = itemstack1.getDamage() - l2;
                         itemstack1.setDamage(j3);
-                        ++i;
+                        ++cost;
                         l2 = Math.min(itemstack1.getDamage(), itemstack1.getMaxDamage() / 4);
                     }
 
                     this.materialCost = i3;
                 } else {
                     if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.isDamageable())) {
-                        this.field_234642_c_.setInventorySlotContents(0, ItemStack.EMPTY);
+                        this.outputInventory.setInventorySlotContents(0, ItemStack.EMPTY);
                         this.maximumCost.set(0);
                         return;
                     }
@@ -271,7 +170,7 @@ public class AnvilContainerRe extends Container {
 
                         if (l1 < itemstack1.getDamage()) {
                             itemstack1.setDamage(l1);
-                            i += 2;
+                            cost += 2;
                         }
                     }
 
@@ -285,14 +184,14 @@ public class AnvilContainerRe extends Container {
                             int j2 = map1.get(enchantment1);
                             j2 = i2 == j2 ? j2 + 1 : Math.max(j2, i2);
                             boolean flag1 = enchantment1.canApply(itemstack);
-                            if (this.field_234645_f_.abilities.isCreativeMode || itemstack.getItem() == Items.ENCHANTED_BOOK) {
+                            if (this.player.abilities.isCreativeMode || itemstack.getItem() == Items.ENCHANTED_BOOK) {
                                 flag1 = true;
                             }
 
                             for (Enchantment enchantment : map.keySet()) {
                                 if (enchantment != enchantment1 && !enchantment1.isCompatibleWith(enchantment)) {
                                     flag1 = false;
-                                    ++i;
+                                    ++cost;
                                 }
                             }
 
@@ -324,16 +223,16 @@ public class AnvilContainerRe extends Container {
                                     k3 = Math.max(1, k3 / 2);
                                 }
 
-                                i += k3 * j2;
+                                cost += k3 * j2;
                                 if (itemstack.getCount() > 1) {
-                                    i = 40;
+                                    cost = 100;
                                 }
                             }
                         }
                     }
 
                     if (flag3 && !flag2) {
-                        this.field_234642_c_.setInventorySlotContents(0, ItemStack.EMPTY);
+                        this.outputInventory.setInventorySlotContents(0, ItemStack.EMPTY);
                         this.maximumCost.set(0);
                         return;
                     }
@@ -342,12 +241,12 @@ public class AnvilContainerRe extends Container {
 
             if (flag && !itemstack1.isBookEnchantable(itemstack2)) itemstack1 = ItemStack.EMPTY;
 
-            this.maximumCost.set(j + i);
-            if (i <= 0) {
+            this.maximumCost.set(j + cost);
+            if (cost <= 0) {
                 itemstack1 = ItemStack.EMPTY;
             }
 
-            if (this.maximumCost.get() >= 40 && !this.field_234645_f_.abilities.isCreativeMode) {
+            if (this.maximumCost.get() >= 100 && !this.player.abilities.isCreativeMode) {
                 itemstack1 = ItemStack.EMPTY;
             }
 
@@ -357,42 +256,116 @@ public class AnvilContainerRe extends Container {
                     k2 = itemstack2.getRepairCost();
                 }
 
-                k2 = getNewRepairCost(k2);
+                k2 = k2 * 2 + 1; // new repair cost
 
                 itemstack1.setRepairCost(k2);
                 EnchantmentHelper.setEnchantments(map, itemstack1);
             }
 
-            this.field_234642_c_.setInventorySlotContents(0, itemstack1);
+            this.outputInventory.setInventorySlotContents(0, itemstack1);
             this.detectAndSendChanges();
         }
     }
 
-    // 从 ForgeHooks 中复制
+    // 关于 maximumCost 的 I/O
+    private final IntReferenceHolder maximumCost = IntReferenceHolder.single();
+    @OnlyIn(Dist.CLIENT) public int getMaximumCost() {
+        return this.maximumCost.get();
+    }
+    public void setMaximumCost(int value) {
+        this.maximumCost.set(value);
+    }
+
+
+
+    /*
+     * --------------------------------------------------------------
+     *  以下方法直接使用原本的代码,不需要进行修改
+     * --------------------------------------------------------------
+     */
+
+    // 构造函数
+    private final IWorldPosCallable worldPosCallable;
+    private final PlayerEntity player;
+    public AnvilContainerRe(int id, PlayerInventory playerInventory) {
+        this(id, playerInventory, IWorldPosCallable.DUMMY);
+    }
+    public AnvilContainerRe(int id, PlayerInventory playerInventory, IWorldPosCallable worldPosCallable) {
+        super(RegMain.containerAnvil.get(), id);
+        this.worldPosCallable = worldPosCallable;
+        this.player = playerInventory.player;
+        Constuct(playerInventory);
+        this.trackInt(this.maximumCost);
+    }
+
+    // 接口: 当输入物品改变时触发更新
+    public void onCraftMatrixChanged(IInventory inventoryIn) {
+        super.onCraftMatrixChanged(inventoryIn);
+        if (inventoryIn == this.inputInventory) {
+            this.updateRepairOutput();
+        }
+
+    }
+
+    // 接口: 决定玩家是否可以使用该方块
+    public boolean canInteractWith(PlayerEntity playerIn) {
+        return this.worldPosCallable.applyOrElse((world, blockPos) -> world.getBlockState(blockPos).isIn(BlockTags.ANVIL) && playerIn.getDistanceSq((double) blockPos.getX() + 0.5D, (double) blockPos.getY() + 0.5D, (double) blockPos.getZ() + 0.5D) <= 64.0D, true);
+    }
+
+    // 接口: 当玩家使用 Shift+左键 快速转移物品时触发,需要尝试转移物品
+    public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
+        ItemStack itemstack = ItemStack.EMPTY;
+        Slot slot = this.inventorySlots.get(index);
+        if (slot != null && slot.getHasStack()) {
+            ItemStack itemstack1 = slot.getStack();
+            itemstack = itemstack1.copy();
+            if (index == 2) {
+                if (!this.mergeItemStack(itemstack1, 3, 39, true)) {
+                    return ItemStack.EMPTY;
+                }
+
+                slot.onSlotChange(itemstack1, itemstack);
+            } else if (index != 0 && index != 1) {
+                if (index < 39) {
+                    if (!this.mergeItemStack(itemstack1, 0, 2, false)) {
+                        return ItemStack.EMPTY;
+                    }
+                }
+            } else if (!this.mergeItemStack(itemstack1, 3, 39, false)) {
+                return ItemStack.EMPTY;
+            }
+
+            if (itemstack1.isEmpty()) {
+                slot.putStack(ItemStack.EMPTY);
+            } else {
+                slot.onSlotChanged();
+            }
+
+            if (itemstack1.getCount() == itemstack.getCount()) {
+                return ItemStack.EMPTY;
+            }
+
+            slot.onTake(playerIn, itemstack1);
+        }
+
+        return itemstack;
+    }
+
+    // 接口: 当页面关闭时触发,尝试返还物品
+    public void onContainerClosed(PlayerEntity playerIn) {
+        super.onContainerClosed(playerIn);
+        this.worldPosCallable.consume((p_234647_2_, p_234647_3_) -> this.clearContainer(playerIn, p_234647_2_, this.inputInventory));
+    }
+
+    // 铁砧输入改变时 Forge 触发的钩子事件(从 ForgeHooks.java 中复制)
     public static boolean onAnvilChange(AnvilContainerRe container, @Nonnull ItemStack left, @Nonnull ItemStack right, IInventory outputSlot, String name, int baseCost) {
         AnvilUpdateEvent e = new AnvilUpdateEvent(left, right, name, baseCost);
         if (MinecraftForge.EVENT_BUS.post(e)) return false;
         if (e.getOutput().isEmpty()) return true;
-
         outputSlot.setInventorySlotContents(0, e.getOutput());
         container.setMaximumCost(e.getCost());
         container.materialCost = e.getMaterialCost();
         return false;
     }
 
-    public static int getNewRepairCost(int oldRepairCost) {
-        return oldRepairCost * 2 + 1;
-    }
-
-    /**
-     * Get's the maximum xp cost
-     */
-    @OnlyIn(Dist.CLIENT)
-    public int getMaximumCost() {
-        return this.maximumCost.get();
-    }
-
-    public void setMaximumCost(int value) {
-        this.maximumCost.set(value);
-    }
 }

+ 25 - 31
src/main/java/com/hexdragon/enchrebirth/block/AnvilScreenRe.java

@@ -10,9 +10,11 @@ import net.minecraft.util.text.ITextComponent;
 import net.minecraft.util.text.TranslationTextComponent;
 import net.minecraftforge.api.distmarker.Dist;
 import net.minecraftforge.api.distmarker.OnlyIn;
+import org.lwjgl.opengl.GL11;
 
 @OnlyIn(Dist.CLIENT)
 public class AnvilScreenRe extends ContainerScreen<AnvilContainerRe> {
+    private static final ResourceLocation ANVIL_RESOURCE = new ResourceLocation("textures/gui/container/anvil.png");
 
     public AnvilScreenRe(AnvilContainerRe container, PlayerInventory playerInventory, ITextComponent title) {
         super(container, playerInventory, title);
@@ -20,61 +22,53 @@ public class AnvilScreenRe extends ContainerScreen<AnvilContainerRe> {
         this.titleX = 60;
     }
 
-    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
-        this.renderBackground(matrixStack);
-        super.render(matrixStack, mouseX, mouseY, partialTicks);
-        RenderSystem.disableBlend();
-        this.renderHoveredTooltip(matrixStack, mouseX, mouseY);
-    }
-
     protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) {
-        RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
-        this.minecraft.getTextureManager().bindTexture(this.ANVIL_RESOURCE);
+        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+        this.minecraft.getTextureManager().bindTexture(ANVIL_RESOURCE);
         int i = (this.width - this.xSize) / 2;
         int j = (this.height - this.ySize) / 2;
         this.blit(matrixStack, i, j, 0, 0, this.xSize, this.ySize);
-        // this.blit(matrixStack, i + 59, j + 20, 0, this.ySize + (this.container.getSlot(0).getHasStack() ? 0 : 16), 110, 16);
         // 显示无法合成的红叉:输入不为空但输出为空
         if ((this.container.getSlot(0).getHasStack() || this.container.getSlot(1).getHasStack()) && !this.container.getSlot(2).getHasStack()) {
             this.blit(matrixStack, i + 99, j + 45, this.xSize, 0, 28, 21);
         }
-
-    }
-
-    private static final ResourceLocation ANVIL_RESOURCE = new ResourceLocation("textures/gui/container/anvil.png");
-    private static final ITextComponent field_243333_B = new TranslationTextComponent("container.repair.expensive");
-
-    public void resize(Minecraft minecraft, int width, int height) {
-        this.init(minecraft, width, height);
     }
 
     protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int x, int y) {
         RenderSystem.disableBlend();
         super.drawGuiContainerForegroundLayer(matrixStack, x, y);
-        int i = this.container.getMaximumCost();
-        if (i > 0) {
-            int j = 8453920;
+        int maximumCost = this.container.getMaximumCost();
+        if (maximumCost > 0) {
+            int fontColor = 8453920;
             ITextComponent itextcomponent;
-            if (i >= 40 && !this.minecraft.player.abilities.isCreativeMode) {
-                itextcomponent = field_243333_B;
-                j = 16736352;
+            if (maximumCost >= 100 && !this.minecraft.player.abilities.isCreativeMode) {
+                itextcomponent = new TranslationTextComponent("container.repair.expensive");
+                fontColor = 16736352;
             } else if (!this.container.getSlot(2).getHasStack()) {
                 itextcomponent = null;
             } else {
-                itextcomponent = new TranslationTextComponent("container.repair.cost", i);
+                itextcomponent = new TranslationTextComponent("container.repair.cost", maximumCost);
                 if (!this.container.getSlot(2).canTakeStack(this.playerInventory.player)) {
-                    j = 16736352;
+                    fontColor = 16736352;
                 }
             }
-
             if (itextcomponent != null) {
-                int k = this.xSize - 8 - this.font.getStringPropertyWidth(itextcomponent) - 2;
-                int l = 69;
-                fill(matrixStack, k - 2, 67, this.xSize - 8, 79, 1325400064);
-                this.font.func_243246_a(matrixStack, itextcomponent, (float) k, 69.0F, j);
+                int xpos = this.xSize - 8 - this.font.getStringPropertyWidth(itextcomponent) - 2;
+                fill(matrixStack, xpos - 2, 67, this.xSize - 8, 79, 1325400064);
+                this.font.func_243246_a(matrixStack, itextcomponent, (float) xpos, 69.0F, fontColor);
             }
         }
+    }
 
+    // 无需修改的方法
+    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
+        this.renderBackground(matrixStack);
+        super.render(matrixStack, mouseX, mouseY, partialTicks);
+        RenderSystem.disableBlend();
+        this.renderHoveredTooltip(matrixStack, mouseX, mouseY);
+    }
+    public void resize(Minecraft minecraft, int width, int height) {
+        this.init(minecraft, width, height);
     }
 
 }

+ 1 - 1
src/main/java/com/hexdragon/enchrebirth/block/GrindstoneContainerRe.java

@@ -175,7 +175,7 @@ public class GrindstoneContainerRe extends Container {
 
     /*
      * --------------------------------------------------------------
-     *  以下方法直接使用原本的代码,不需要也未曾进行过修改
+     *  以下方法直接使用原本的代码,不需要进行修改
      * --------------------------------------------------------------
      */