Parcourir la source

Add function: add custom range marker from WorldEdit Selection. Also complete the README.md.

ZRY il y a 10 mois
Parent
commit
ca4ca3a615

+ 1 - 0
README.md

@@ -79,6 +79,7 @@ ZRY制作的客户端辅助Mod,仅需客户端安装。
 | 2023-07-29 19:08 | 增加View Frustum Culling,优化性能 |
 | 2023-07-29 20:57 | 增加自定义标记功能                   |
 | 2023-07-29 21:16 | 增加从WE选区创建自定义标记功能            |
+| 2023-07-29 23:00 | fix: WE_Panel增加对客户端命令的支持  |
 
 ## en-US
 

+ 31 - 2
src/main/java/com/zjinja/mcmod/zry_client_utils_mod/gui/GuiWEHelpPanel.java

@@ -11,6 +11,7 @@ import net.minecraft.client.Minecraft;
 import net.minecraft.client.gui.components.Button;
 import net.minecraft.client.gui.screens.Screen;
 import net.minecraft.network.chat.Component;
+import net.minecraftforge.client.ClientCommandHandler;
 import org.lwjgl.glfw.GLFW;
 import java.util.HashMap;
 
@@ -110,7 +111,7 @@ public class GuiWEHelpPanel extends Screen {
                     20,
                     backText,
                     button -> {
-                        issueCmd(i.Command);
+                        issueCmd(i.Command, i.IsClientCommand);
                     },
                     (button, poseStack, n1, n2) -> {
 
@@ -126,7 +127,35 @@ public class GuiWEHelpPanel extends Screen {
 
     public void issueCmd(String cmd) {
         if (Minecraft.getInstance().player != null) {
-            Minecraft.getInstance().player.commandUnsigned(cmd);
+            var ok = Minecraft.getInstance().player.commandUnsigned(cmd);
+            if(!ok) {
+                var sm = Component.translatable("chat.tip.cmd_failed");
+                Minecraft.getInstance().player.sendSystemMessage(sm);
+            }
+        }else{
+            ZLogUtil.log(
+                    LogUtils.getLogger(), ZLogUtil.Level.WARN,
+                    "gui/we-panel", "player is null."
+            );
+        }
+    }
+
+    public void issueCmd(String cmd, boolean isClientCommand) {
+        if(isClientCommand) {
+            boolean ok = ClientCommandHandler.runCommand(cmd);
+            if(!ok) {
+                if (Minecraft.getInstance().player != null) {
+                    var sm = Component.translatable("chat.tip.cmd_failed");
+                    Minecraft.getInstance().player.sendSystemMessage(sm);
+                }else{
+                    ZLogUtil.log(
+                            LogUtils.getLogger(), ZLogUtil.Level.WARN,
+                            "gui/we-panel", "player is null."
+                    );
+                }
+            }
+        }else{
+            issueCmd(cmd);
         }
     }
 

+ 13 - 1
src/main/java/com/zjinja/mcmod/zry_client_utils_mod/utils/ConfigMgr.java

@@ -21,6 +21,7 @@ public class ConfigMgr {
         public String Name;
         public boolean WillTranslate;
         public String Command;
+        public boolean IsClientCommand;
         public int KeyCode;
         public int Width;
 
@@ -30,6 +31,16 @@ public class ConfigMgr {
             this.Command = command;
             this.KeyCode = keycode;
             this.Width = width;
+            this.IsClientCommand = false;
+        }
+
+        public WEPanelFunctionItem(String name, boolean willTranslate, String command, int keycode, int width, boolean isClientCommand) {
+            this.Name = name;
+            this.WillTranslate = willTranslate;
+            this.Command = command;
+            this.KeyCode = keycode;
+            this.Width = width;
+            this.IsClientCommand = isClientCommand;
         }
     }
 
@@ -206,7 +217,8 @@ public class ConfigMgr {
             if(keyBind <= 0) {
                 keyBind = this.WEPanelFunctionDefaultButtonWidth;
             }
-            WEPanelFunctionItem pfi = new WEPanelFunctionItem(name, willTranslate, command, keyBind, width);
+            Boolean isClientCommand = i.getOrElse("clientCmd", false);
+            WEPanelFunctionItem pfi = new WEPanelFunctionItem(name, willTranslate, command, keyBind, width, isClientCommand);
             this.WEPanelFunctionList.add(pfi);
         }
     }

+ 1 - 0
src/main/resources/assets/zry_client_utils_mod/lang/zh_cn.json

@@ -13,6 +13,7 @@
     "chat.tip.marker_from_we_ok": "[ZRYClientUtilsMod] 标记已从WE选区添加。",
     "chat.tip.marker_from_we_fail": "[ZRYClientUtilsMod] 标记添加失败:没有有效的WE选区。",
     "chat.tip.marker_from_we_err": "[ZRYClientUtilsMod] 标记添加失败:内部错误。",
+    "chat.tip.cmd_failed": "[ZRYClientUtilsMod] 命令执行失败。",
     "gui.zry_client_utils.we_panel.title": "WE助手",
     "gui.zry_client_utils.we_panel.back": "返回",
     "gui.zry_client_utils.we_panel.func.name.distr": "选区统计",