Prechádzať zdrojové kódy

完整的命名牌 GUI,只是还不能发包

LTCatt 6 rokov pred
rodič
commit
714a4b7fec

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

@@ -109,7 +109,6 @@ public class GrindstoneContainerRe extends Container {
     // TODO : GUI 左侧的图片对应换成渲染的 3D 物品模型
     // TODO : 添加方块的使用音效
     // TODO : 添加一个特殊配方,将命名过的命名牌与任意非命名牌的物品合成,即可重命名物品
-    // TODO : 右键命名牌可以打开一个带文本框的 GUI,可以直接修改命名牌的名字
 
     // 对砂轮的单个物品进行预处理:例如移除非诅咒附魔、重置修复消耗等
     private ItemStack prepareNewItem(ItemStack stack) {

+ 11 - 3
src/main/java/com/hexdragon/enchrebirth/item/name_tag/NameTagScreen.java

@@ -10,8 +10,11 @@ import org.lwjgl.opengl.GL11;
 
 public class NameTagScreen extends Screen {
 
-    // 标题、背景、文本框声明
-    public NameTagScreen() {super(new TranslationTextComponent("gui.name_tag.title"));}
+    String defaultName;
+    public NameTagScreen(String defaultName) {
+        super(new TranslationTextComponent("gui.name_tag.title"));
+        this.defaultName = defaultName;
+    }
     final ResourceLocation GUI_TEXTURE = new ResourceLocation(Main.MODID, "textures/gui/name_tag.png");
     TextFieldWidget textField;
 
@@ -21,7 +24,8 @@ public class NameTagScreen extends Screen {
         this.guiLeft = (this.width - this.xSize) / 2;
         this.guiTop = (this.height - this.ySize) / 2;
         // (x,y), (width, height)
-        this.textField = new TextFieldWidget(this.font, guiLeft + 60, guiTop + 33, 100, 20, new TranslationTextComponent("item.name_tag.name"));
+        this.textField = new TextFieldWidget(this.font, guiLeft + 61, guiTop + 27, 95, 16, new TranslationTextComponent("item.name_tag.name"));
+        this.textField.setText(defaultName);
         this.children.add(this.textField);
         super.init();
     }
@@ -60,4 +64,8 @@ public class NameTagScreen extends Screen {
         this.minecraft.player.closeScreen();
         super.closeScreen();
     }
+    public void onClose() {
+        Main.LOGGER.warn("CLOSE: " + textField.getText());
+
+    }
 }

+ 5 - 1
src/main/java/com/hexdragon/enchrebirth/mixin/item/NameTagItemMixin.java

@@ -8,6 +8,7 @@ import net.minecraft.item.ItemStack;
 import net.minecraft.item.NameTagItem;
 import net.minecraft.util.ActionResult;
 import net.minecraft.util.Hand;
+import net.minecraft.util.text.ITextComponent;
 import net.minecraft.world.World;
 import net.minecraftforge.api.distmarker.Dist;
 import net.minecraftforge.fml.DistExecutor;
@@ -19,7 +20,10 @@ public abstract class NameTagItemMixin extends Item {
 
     @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
         if (worldIn.isRemote) {
-            DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().displayGuiScreen(new NameTagScreen()));
+            DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
+                ITextComponent defaultName = getDisplayName(playerIn.getHeldItem(handIn));
+                Minecraft.getInstance().displayGuiScreen(new NameTagScreen(defaultName.getString()));
+            });
         }
         return super.onItemRightClick(worldIn, playerIn, handIn);
     }