|
|
@@ -3,13 +3,8 @@ package com.hexdragon.enchrebirth.block;
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
-import net.minecraft.client.gui.screen.inventory.AbstractRepairScreen;
|
|
|
-import net.minecraft.client.gui.widget.TextFieldWidget;
|
|
|
+import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
|
|
import net.minecraft.entity.player.PlayerInventory;
|
|
|
-import net.minecraft.inventory.container.Container;
|
|
|
-import net.minecraft.inventory.container.Slot;
|
|
|
-import net.minecraft.item.ItemStack;
|
|
|
-import net.minecraft.network.play.client.CRenameItemPacket;
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
import net.minecraft.util.text.ITextComponent;
|
|
|
import net.minecraft.util.text.TranslationTextComponent;
|
|
|
@@ -17,61 +12,40 @@ import net.minecraftforge.api.distmarker.Dist;
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
-public class AnvilScreenRe extends AbstractRepairScreen<AnvilContainerRe> {
|
|
|
- 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");
|
|
|
- private TextFieldWidget nameField;
|
|
|
+public class AnvilScreenRe extends ContainerScreen<AnvilContainerRe> {
|
|
|
|
|
|
public AnvilScreenRe(AnvilContainerRe container, PlayerInventory playerInventory, ITextComponent title) {
|
|
|
- super(container, playerInventory, title, ANVIL_RESOURCE);
|
|
|
+ super(container, playerInventory, title);
|
|
|
+ this.playerInventoryTitleY = 1000000; // 关闭 “物品栏” 三个字的显示
|
|
|
this.titleX = 60;
|
|
|
}
|
|
|
|
|
|
- protected void initFields() {
|
|
|
- this.minecraft.keyboardListener.enableRepeatEvents(true);
|
|
|
- int i = (this.width - this.xSize) / 2;
|
|
|
- int j = (this.height - this.ySize) / 2;
|
|
|
- this.nameField = new TextFieldWidget(this.font, i + 62, j + 24, 103, 12, new TranslationTextComponent("container.repair"));
|
|
|
- this.nameField.setCanLoseFocus(false);
|
|
|
- this.nameField.setTextColor(-1);
|
|
|
- this.nameField.setDisabledTextColour(-1);
|
|
|
- this.nameField.setEnableBackgroundDrawing(false);
|
|
|
- this.nameField.setMaxStringLength(35);
|
|
|
- this.nameField.setResponder(this::renameItem);
|
|
|
- this.children.add(this.nameField);
|
|
|
- this.setFocusedDefault(this.nameField);
|
|
|
- }
|
|
|
-
|
|
|
- public void resize(Minecraft minecraft, int width, int height) {
|
|
|
- String s = this.nameField.getText();
|
|
|
- this.init(minecraft, width, height);
|
|
|
- this.nameField.setText(s);
|
|
|
- }
|
|
|
-
|
|
|
- public void onClose() {
|
|
|
- super.onClose();
|
|
|
- this.minecraft.keyboardListener.enableRepeatEvents(false);
|
|
|
+ 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 boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
|
|
- if (keyCode == 256) {
|
|
|
- this.minecraft.player.closeScreen();
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
- return !this.nameField.keyPressed(keyCode, scanCode, modifiers) && !this.nameField.canWrite() ? super.keyPressed(keyCode, scanCode, modifiers) : true;
|
|
|
}
|
|
|
|
|
|
- private void renameItem(String name) {
|
|
|
- if (!name.isEmpty()) {
|
|
|
- String s = name;
|
|
|
- Slot slot = this.container.getSlot(0);
|
|
|
- if (slot != null && slot.getHasStack() && !slot.getStack().hasDisplayName() && name.equals(slot.getStack().getDisplayName().getString())) {
|
|
|
- s = "";
|
|
|
- }
|
|
|
+ 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");
|
|
|
|
|
|
- this.container.updateItemName(s);
|
|
|
- this.minecraft.player.connection.sendPacket(new CRenameItemPacket(s));
|
|
|
- }
|
|
|
+ public void resize(Minecraft minecraft, int width, int height) {
|
|
|
+ this.init(minecraft, width, height);
|
|
|
}
|
|
|
|
|
|
protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int x, int y) {
|
|
|
@@ -103,20 +77,4 @@ public class AnvilScreenRe extends AbstractRepairScreen<AnvilContainerRe> {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void renderNameField(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
|
|
|
- this.nameField.render(matrixStack, mouseX, mouseY, partialTicks);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual
|
|
|
- * contents of that slot.
|
|
|
- */
|
|
|
- public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack) {
|
|
|
- if (slotInd == 0) {
|
|
|
- this.nameField.setText(stack.isEmpty() ? "" : stack.getDisplayName().getString());
|
|
|
- this.nameField.setEnabled(!stack.isEmpty());
|
|
|
- this.setListener(this.nameField);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
}
|