Explorar el Código

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

ZRY hace 10 meses
padre
commit
7329b920f1

+ 29 - 0
README.md

@@ -10,6 +10,7 @@ ZRY制作的客户端辅助Mod,仅需客户端安装。
 
 * 类似WorldEdit CUI的WorldEdit选区高亮功能
 * 一个GUI面板 WE_Panel,默认按V键调出,可设定快捷命令
+* 自定义标记功能,可以自行标记一块区域并高亮
 
 ### 功能介绍
 
@@ -44,12 +45,40 @@ ZRY制作的客户端辅助Mod,仅需客户端安装。
 默认通过V键调出WE_Panel,该快捷键可在MC的按键设置中修改,
 在面板弹出后,按相同的按键可关闭面板。
 
+#### 自定义标记
+
+该功能可以创建一个自定义的点或者区域,
+并高亮显示这个点或者区域。
+作为纯客户端Mod,自定义标记不会持久保存,
+断开当前会话重新连接后,
+自定义标记消失。
+
+该功能设计动机为,进行建筑规划时提供辅助参考。
+
+命令说明:
+
+* 清除所有自定义标记:
+`/zcu-marker clear`
+
+* 从WorldEdit选区创建自定义标记:
+`/zcu-marker from-we`
+
+* 创建单个方块的选区:
+`/zcu-marker add-point <x> <y> <z>`
+
+* 创建AABB盒选区:
+`/zcu-marker add-range <x1> <y1> <z1> <x2> <y2> <z2>`
+
+注意:从WorldEdit选区创建自定义标记时,仅支持方形WE选区。
+
 ### ChangeLog
 
 | 时间               | 修订                          |
 |:-----------------|:----------------------------|
 | 2023-07-29 16:24 | 发布第一个可用版本                   |
 | 2023-07-29 19:08 | 增加View Frustum Culling,优化性能 |
+| 2023-07-29 20:57 | 增加自定义标记功能                   |
+| 2023-07-29 21:16 | 增加从WE选区创建自定义标记功能            |
 
 ## en-US
 

+ 27 - 0
src/main/java/com/zjinja/mcmod/zry_client_utils_mod/commands/CommandMarker.java

@@ -54,6 +54,10 @@ public class CommandMarker {
                         literal("clear")
                                 .executes(CommandMarker::cmdClear)
                 )
+                .then(
+                        literal("from-we")
+                                .executes(CommandMarker::fromWE)
+                )
                 .executes(CommandMarker::invalidArgs);
 
 
@@ -126,4 +130,27 @@ public class CommandMarker {
         player.sendSystemMessage(Component.translatable("chat.tip.marker_cleared"));
         return Command.SINGLE_SUCCESS;
     }
+
+    private static int fromWE(final CommandContext<CommandSourceStack> context) {
+        Player player = Minecraft.getInstance().player;
+        if(player == null){
+            ZLogUtil.log(
+                    LogUtils.getLogger(), ZLogUtil.Level.WARN,
+                    "cmd/zcu-marker", "player is null"
+            );
+            return Command.SINGLE_SUCCESS;
+        }
+        MarkerMgr mm = MarkerMgr.getInstance();
+        if(mm == null) {
+            player.sendSystemMessage(Component.translatable("chat.tip.marker_from_we_err"));
+            return Command.SINGLE_SUCCESS;
+        }
+        boolean res = mm.addRangeFromWE();
+        if (res) {
+            player.sendSystemMessage(Component.translatable("chat.tip.marker_from_we_ok"));
+        }else {
+            player.sendSystemMessage(Component.translatable("chat.tip.marker_from_we_fail"));
+        }
+        return Command.SINGLE_SUCCESS;
+    }
 }

+ 14 - 0
src/main/java/com/zjinja/mcmod/zry_client_utils_mod/cui/CUIRegionManager.java

@@ -6,8 +6,10 @@ import com.zjinja.mcmod.zry_client_utils_mod.renderer.RenderContext;
 import com.zjinja.mcmod.zry_client_utils_mod.utils.ZLogUtil;
 import net.minecraft.client.Minecraft;
 import net.minecraft.network.chat.Component;
+import net.minecraft.world.phys.AABB;
 
 import java.util.HashMap;
+import java.util.Optional;
 import java.util.UUID;
 
 public class CUIRegionManager {
@@ -321,6 +323,18 @@ public class CUIRegionManager {
         return this.selRegion.describe();
     }
 
+    public Optional<AABB> getSelectionAABB() {
+        IRegion ir = this.selRegion;
+        if(ir == null){
+            return Optional.empty();
+        }
+        if(ir instanceof CuboidRegion cr) {
+            return cr.getRegionAABB();
+        }else{
+            return Optional.empty();
+        }
+    }
+
     private boolean checkArgsCount(String[] params, int min, int max, String mtype) {
         if (max == min)
         {

+ 16 - 0
src/main/java/com/zjinja/mcmod/zry_client_utils_mod/cui/CuboidRegion.java

@@ -50,6 +50,22 @@ public class CuboidRegion extends EmptyRegion {
         }
     }
 
+    public Optional<AABB> getRegionAABB() {
+        if(this.point1.isEmpty() || this.point2.isEmpty()) {
+            return Optional.empty();
+        }
+        Vec3 p1 = this.point1.get();
+        Vec3 p2 = this.point2.get();
+        double aX = Math.min(p1.x, p2.x);
+        double bX = Math.max(p1.x, p2.x) + 1;
+        double aY = Math.min(p1.y, p2.y);
+        double bY = Math.max(p1.y, p2.y) + 1;
+        double aZ = Math.min(p1.z, p2.z);
+        double bZ = Math.max(p1.z, p2.z) + 1;
+        AABB aabbMain = new AABB(aX, aY, aZ, bX, bY, bZ);
+        return Optional.of(aabbMain);
+    }
+
     @Override
     public void render(RenderContext rctx, boolean mainSelection) {
         if(this.point1.isEmpty() || this.point2.isEmpty()) {

+ 14 - 0
src/main/java/com/zjinja/mcmod/zry_client_utils_mod/marker/MarkerMgr.java

@@ -1,5 +1,6 @@
 package com.zjinja.mcmod.zry_client_utils_mod.marker;
 
+import com.zjinja.mcmod.zry_client_utils_mod.cui.CUIRegionManager;
 import com.zjinja.mcmod.zry_client_utils_mod.renderer.RGBA;
 import com.zjinja.mcmod.zry_client_utils_mod.renderer.RenderContext;
 import com.zjinja.mcmod.zry_client_utils_mod.renderer.RenderUtils;
@@ -35,6 +36,19 @@ public class MarkerMgr {
         this.markerList.add(marker);
     }
 
+    public boolean addRangeFromWE() {
+        var crm = CUIRegionManager.getInstance();
+        if(crm == null) {
+            return false;
+        }
+        var aabb = crm.getSelectionAABB();
+        if(aabb.isEmpty()) {
+            return false;
+        }
+        this.markerList.add(aabb.get());
+        return true;
+    }
+
     public static void render(RenderContext rctx){
         var inst = getInstance();
         if (inst != null) {

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

@@ -10,6 +10,9 @@
     "chat.tip.invalid_args": "[ZRYClientUtilsMod] 命令参数无效。",
     "chat.tip.marker_cleared": "[ZRYClientUtilsMod] 标记已清空。",
     "chat.tip.marker_added": "[ZRYClientUtilsMod] 标记已添加。",
+    "chat.tip.marker_from_we_ok": "[ZRYClientUtilsMod] 标记已从WE选区添加。",
+    "chat.tip.marker_from_we_fail": "[ZRYClientUtilsMod] 标记添加失败:没有有效的WE选区。",
+    "chat.tip.marker_from_we_err": "[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": "选区统计",