Explorar o código

Add function: custom range marker.

ZRY hai 10 meses
pai
achega
9e81236d72

+ 7 - 0
README.md

@@ -44,6 +44,13 @@ ZRY制作的客户端辅助Mod,仅需客户端安装。
 默认通过V键调出WE_Panel,该快捷键可在MC的按键设置中修改,
 在面板弹出后,按相同的按键可关闭面板。
 
+### ChangeLog
+
+| 时间               | 修订                          |
+|:-----------------|:----------------------------|
+| 2023-07-29 16:24 | 发布第一个可用版本                   |
+| 2023-07-29 19:08 | 增加View Frustum Culling,优化性能 |
+
 ## en-US
 
 TODO

+ 1 - 1
build.gradle

@@ -4,7 +4,7 @@ plugins {
     id 'net.minecraftforge.gradle' version '5.1.+'
 }
 
-version = '0.1.0'
+version = '0.2.0'
 group = 'com.zjinja.mcmod.zry_client_utils_mod' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
 archivesBaseName = 'zry_client_utils_mod'
 

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

@@ -0,0 +1,129 @@
+package com.zjinja.mcmod.zry_client_utils_mod.commands;
+
+import com.mojang.brigadier.Command;
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.arguments.IntegerArgumentType;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.builder.RequiredArgumentBuilder;
+import com.mojang.brigadier.context.CommandContext;
+import com.mojang.logging.LogUtils;
+import com.zjinja.mcmod.zry_client_utils_mod.marker.MarkerMgr;
+import com.zjinja.mcmod.zry_client_utils_mod.utils.ZLogUtil;
+import net.minecraft.client.Minecraft;
+import net.minecraft.commands.CommandSourceStack;
+import net.minecraft.commands.Commands;
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.entity.player.Player;
+
+import static net.minecraft.commands.Commands.argument;
+import static net.minecraft.commands.Commands.literal;
+
+public class CommandMarker {
+    public static final String CmdName = "zcu-marker";
+
+    public void register(CommandDispatcher<CommandSourceStack> dispatcher) {
+        LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal(CmdName);
+        command
+                .then(
+                        literal("add-point")
+                                .then(argument("x1", IntegerArgumentType.integer())
+                                        .then(argument("y1", IntegerArgumentType.integer())
+                                                .then(argument("z1", IntegerArgumentType.integer())
+                                                        .executes(CommandMarker::cmdAddPoint)
+                                                )
+                                        )
+                                )
+                )
+                .then(
+                        literal("add-range")
+                                .then(argument("x1", IntegerArgumentType.integer())
+                                        .then(argument("y1", IntegerArgumentType.integer())
+                                                .then(argument("z1", IntegerArgumentType.integer())
+                                                        .then(argument("x2", IntegerArgumentType.integer())
+                                                                .then(argument("y2", IntegerArgumentType.integer())
+                                                                        .then(argument("z2", IntegerArgumentType.integer())
+                                                                                .executes(CommandMarker::cmdAddRange)
+                                                                        )
+                                                                )
+                                                        )
+                                                )
+                                        )
+                                )
+                )
+                .then(
+                        literal("clear")
+                                .executes(CommandMarker::cmdClear)
+                )
+                .executes(CommandMarker::invalidArgs);
+
+
+        dispatcher.register(command);
+    }
+
+    private static int invalidArgs(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;
+        }
+        player.sendSystemMessage(Component.translatable("chat.tip.invalid_args"));
+        return Command.SINGLE_SUCCESS;
+    }
+
+    private static int cmdAddPoint(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;
+        }
+        int x1 = context.getArgument("x1", Integer.class);
+        int y1 = context.getArgument("y1", Integer.class);
+        int z1 = context.getArgument("z1", Integer.class);
+        MarkerMgr mm = MarkerMgr.getInstance();
+        if(mm != null) mm.addPointMarker(x1, y1, z1);
+        player.sendSystemMessage(Component.translatable("chat.tip.marker_added"));
+        return Command.SINGLE_SUCCESS;
+    }
+
+    private static int cmdAddRange(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;
+        }
+        int x1 = context.getArgument("x1", Integer.class);
+        int y1 = context.getArgument("y1", Integer.class);
+        int z1 = context.getArgument("z1", Integer.class);
+        int x2 = context.getArgument("x2", Integer.class);
+        int y2 = context.getArgument("y2", Integer.class);
+        int z2 = context.getArgument("z2", Integer.class);
+        MarkerMgr mm = MarkerMgr.getInstance();
+        if(mm != null) mm.addRangeMarker(x1, y1, z1, x2, y2, z2);
+        player.sendSystemMessage(Component.translatable("chat.tip.marker_added"));
+        return Command.SINGLE_SUCCESS;
+    }
+
+    private static int cmdClear(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) mm.clearMarkerList();
+        player.sendSystemMessage(Component.translatable("chat.tip.marker_cleared"));
+        return Command.SINGLE_SUCCESS;
+    }
+}

+ 4 - 1
src/main/java/com/zjinja/mcmod/zry_client_utils_mod/events/ClientEvents.java

@@ -4,10 +4,12 @@ import com.mojang.blaze3d.vertex.PoseStack;
 import com.mojang.logging.LogUtils;
 import com.zjinja.mcmod.zry_client_utils_mod.ZRYClientUtilsMod;
 import com.zjinja.mcmod.zry_client_utils_mod.commands.CommandGetWESelPos;
+import com.zjinja.mcmod.zry_client_utils_mod.commands.CommandMarker;
 import com.zjinja.mcmod.zry_client_utils_mod.commands.CommandReloadConfig;
 import com.zjinja.mcmod.zry_client_utils_mod.cui.CUIRegionManager;
 import com.zjinja.mcmod.zry_client_utils_mod.gui.GuiWEHelpPanel;
 import com.zjinja.mcmod.zry_client_utils_mod.keybinds.KeyBindings;
+import com.zjinja.mcmod.zry_client_utils_mod.marker.MarkerMgr;
 import com.zjinja.mcmod.zry_client_utils_mod.networking.NetworkHandlerWECUI;
 import com.zjinja.mcmod.zry_client_utils_mod.renderer.RenderContext;
 import com.zjinja.mcmod.zry_client_utils_mod.utils.ConfigMgr;
@@ -48,6 +50,7 @@ public class ClientEvents {
         public static void registerClientCommand(RegisterClientCommandsEvent event) {
             new CommandGetWESelPos().register(event.getDispatcher());
             new CommandReloadConfig().register(event.getDispatcher());
+            new CommandMarker().register(event.getDispatcher());
         }
 
         @SubscribeEvent
@@ -77,7 +80,7 @@ public class ClientEvents {
                 Frustum fr = event.getFrustum();
                 RenderContext rctx = new RenderContext(ps, fr);
                 CUIRegionManager.render(rctx);
-                //MarkerMgr.render(rctx);
+                MarkerMgr.render(rctx);
             }
         }
 

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

@@ -0,0 +1,47 @@
+package com.zjinja.mcmod.zry_client_utils_mod.marker;
+
+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;
+import net.minecraft.world.phys.AABB;
+
+import java.util.ArrayList;
+
+public class MarkerMgr {
+    public final static MarkerMgr INSTANCE = new MarkerMgr();
+
+
+    public static MarkerMgr getInstance() {
+        return INSTANCE;
+    }
+
+    private ArrayList<AABB> markerList = new ArrayList<>();
+
+    public MarkerMgr() {
+
+    }
+
+    public void clearMarkerList() {
+        this.markerList.clear();
+    }
+
+    public void addPointMarker(int x, int y, int z){
+        AABB marker = new AABB(x, y, z, x+1, y+1, z+1);
+        this.markerList.add(marker);
+    }
+
+    public void addRangeMarker(int x1, int y1, int z1, int x2, int y2, int z2){
+        AABB marker = new AABB(x1, y1, z1, x2, y2, z2);
+        this.markerList.add(marker);
+    }
+
+    public static void render(RenderContext rctx){
+        var inst = getInstance();
+        if (inst != null) {
+            for(AABB i: inst.markerList) {
+                RenderUtils.drawOutlineBox(rctx, i, new RGBA(0.8476F, 0.6367F, 0.2617F, 1.0F));
+            }
+        }
+    }
+
+}

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

@@ -7,6 +7,9 @@
     "chat.tip.not_support_polyhedron_yet": "[ZRYClientUtilsMod] 当前版本不支持对Polyhedron类型WorldEdit选区可视化。",
     "chat.tip.reload_config_ok": "[ZRYClientUtilsMod] 配置文件已重新载入",
     "chat.tip.reload_config_fail": "[ZRYClientUtilsMod] 重新载入配置文件失败,详细信息请查看日志。",
+    "chat.tip.invalid_args": "[ZRYClientUtilsMod] 命令参数无效。",
+    "chat.tip.marker_cleared": "[ZRYClientUtilsMod] 标记已清空。",
+    "chat.tip.marker_added": "[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": "选区统计",