From a56182ab6da3a9164ccac34c55bdc245497f4f02 Mon Sep 17 00:00:00 2001 From: xTracr Date: Mon, 29 Apr 2024 20:52:31 +0800 Subject: [PATCH] Fixed some ui issues --- build.gradle | 2 +- changelog.md | 237 ------------------ .../com/xtracr/realcamera/KeyBindings.java | 25 +- .../com/xtracr/realcamera/RealCameraCore.java | 29 +-- .../realcamera/compat/DisableHelper.java | 11 +- .../xtracr/realcamera/config/ConfigFile.java | 8 +- .../realcamera/config/ConfigScreen.java | 2 +- .../xtracr/realcamera/config/ModConfig.java | 74 +++--- .../xtracr/realcamera/gui/ModelAnalyser.java | 15 +- .../realcamera/gui/ModelViewScreen.java | 10 +- .../xtracr/realcamera/mixin/MixinCamera.java | 2 +- .../mixin/MixinClientPlayerEntity.java | 2 +- .../realcamera/mixin/MixinGameRenderer.java | 6 +- .../realcamera/mixin/MixinInGameHud.java | 4 +- .../xtracr/realcamera/mixin/MixinItem.java | 2 +- .../MixinStuckObjectsFeatureRenderer.java | 2 +- .../realcamera/mixin/MixinWorldRenderer.java | 2 +- .../com/xtracr/realcamera/util/MathUtil.java | 4 - .../realcamera/util/VertexRecorder.java | 44 ++-- .../assets/realcamera/lang/en_us.json | 3 +- .../assets/realcamera/lang/zh_cn.json | 5 +- .../assets/realcamera/textures/gui/icon.png | Bin 5430 -> 5422 bytes .../com/xtracr/realcamera/EventHandler.java | 2 +- .../com/xtracr/realcamera/EventHandler.java | 2 +- gradle.properties | 2 +- jitpack.yml | 5 - 26 files changed, 113 insertions(+), 387 deletions(-) delete mode 100644 changelog.md delete mode 100644 jitpack.yml diff --git a/build.gradle b/build.gradle index 3ec0201..4f18588 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false } architectury { diff --git a/changelog.md b/changelog.md deleted file mode 100644 index e244de5..0000000 --- a/changelog.md +++ /dev/null @@ -1,237 +0,0 @@ -# Change Log # - -## English ## - -### Releases ### - -### Test Versions ### - -* 0.6: -* 0.6.0-alpha: - * Added model view screen - * Allowed to select the model part you want to bind directly in the screen - * Fixed #41, #46 and #48 - * Fix minor grammar errors (#44) - * Optimized the GUI display and changed logic of selection button - * Changed the way to render player - * Added pause button and show cube button - * Allowed to disable rendering vertices based on depth relative to screen - * Added 'AutoBind' feature - * Changed to bind based on UV coordinates and improved GUI - * Fixed #54 - * Improved Gui and Fixed a bug that would cause crash - * Added more icons and allowed selection or deletion of saved configs in the gui - * Changed the 'Offset Model' option to 'Bind X/Y/Z Coordinate' options - * Improved logic for 'Auto Bind' mode - * Combined the 'Bind Pitch/Yaw/Roll' options - * Added 'preview' feature - * Removed commands - * Improved default configs and reformatted code - * Removed deprecated code - * Added 'priority' to binding targets - * Fixed #59 - * Fixed #60 -* 0.6.0-beta: - * Optimized some codes - - -* 0.5: -* 0.5.0-beta: - * Redesigned config screen - * Removed commands because it's no longer useful - * Allowed disabling rendering partial model -* 0.5.1-beta: - * Divided `Bind Rotation` option into three options -* 0.5.2-beta: - * Fixed #7, #8 and clipping issue -* 0.5.3-beta: - * Compatible with Physics Mod ocean physics (#6) - * Allowed disabling when holding a specific item - * Added support for 1.19.2 - * Upgraded to 1.20 -* 0.5.4-beta: - * Added feature #15, fixed #35 - * Changed the way of clipping to space to avoid #23 and #32 -* 0.5.5-beta: - * Changed the way of clipping to space to avoid #37 - * Deleted the option of disabling "clip to space" - * Separate the part that modifies camera from the part that computes it - - -* 0.4: -* 0.4.0-alpha: - * Fixed an issue where the camera would not follow the model action when the player started/ended sneaking - * Compatible with Pehkui - * API for others to compat with -* 0.4.1-alpha: - * Compatible with EpicFight - * Added commands for debugging -* 0.4.2-alpha: - * Fixed an issue where extra camera rotation cannot be applied correctly in specific situations - * Allowed adjusting camera rotation with hotkeys -* 0.4.3-alpha: - * Allowed adjusting camera rotation in classic mode - * Improved calculation of crosshair hit result - * Bug fixes: - * model sometimes isn't rendered when flying with elytra - * leash position isn't correct -* 0.4.4-alpha: - * Added "dynamic crosshair" feature - * Added "clip to space" feature - - -* 0.3: -* 0.3.0-alpha: - * Made the hit result of the player's crosshair match the actual position of the crosshair - * Attempted to implement the effect of binding mode -* 0.3.1-alpha: - * Added camera position correction for other actions - * Improved the effect of binding mode -* 0.3.2-alpha: - * Added more binding mode configurations - * Attempted to bind camera direction to the model part -* 0.3.3-alpha: - * Allowed camera direction to be bound to the model part -* 0.3.4-alpha: - * Allowed crosshair direction to follow the camera - * Changed the mod's name - * Fixed two binding mode issues: - * Camera and model animation are not completely synchronized - * When the inventory is opened, the camera follows the character model in the inventory -* 0.3.5-alpha: - * Optimized code logic - * Allowed to disable in specfic conditions -* 0.3.6-alpha: - * Optimized code logic - * Upgraded to 1.19.4 - * Supported Fabric - - -* 0.2: -* 0.2.0-alpha: - * Added player model rendering mode -* 0.2.1-alpha: - * Added camera position correction for sneaking action - * Can render crosshairs in model rendering mode - - -* 0.1.0-alpha: - * Added feature to move camera and its rotation center - -## 中文 ## - -### 正式版 ### - -### 测试版 ### - -* 0.6: -* 0.6.0-alpha: - * 添加了模型视图界面 - * 允许在界面中选择想要绑定的模型部位 - * 修复了#41、#46和#48 - * 修复了一些语法问题(#44) - * 优化了GUI显示效果以及修改了选择按钮的逻辑 - * 修改了渲染玩家的方式 - * 添加了暂停按钮和显示立方体按钮 - * 允许根据相对于屏幕的距离禁用渲染部分顶点 - * 添加了'自动绑定'功能 - * 改为基于UV坐标绑定并且改进了GUI - * 修复了#54 - * 改进了GUI,修复了一个会导致崩溃的问题 - * 添加了更多图标,允许在GUI内选择和删除已保存的配置 - * 将'偏移模型'选项改为'绑定X/Y/Z坐标'选项 - * 改进了'自动绑定'的逻辑 - * 合并了'绑定俯仰角/偏航角/翻滚角'选项 - * 添加了'预览'功能 - * 移除了命令 - * 改进了默认配置,重新格式化代码 - * 移除了已弃用的代码 - * 为绑定目标添加了'优先级' - * 修复了#59 - * 修复了#60 -* 0.6.0-beta: - * 优化了部分代码 - - -* 0.5: -* 0.5.0-beta: - * 重新设计了配置屏幕 - * 删除了命令,因为它不再有用 - * 允许禁用渲染部分模型 -* 0.5.1-beta: - * 把`绑定旋转`选项分为了三个选项 -* 0.5.2-beta: - * 修复了#7, #8以及clip的问题 -* 0.5.3-beta: - * 兼容Physics Mod的海洋物理 (#6) - * 允许在手持特定物品时禁用 - * 添加了对1.19.2的支持 - * 更新至1.20 -* 0.5.4-beta: - * 添加了功能#15, 修复#35 - * 修改了clip to space的方式来避免#23和#32 -* 0.5.5-beta: - * 修改了clip to space的方式来避免#37 - * 删除了禁用"clip to space"的选项 - * 将修改摄像头的部分与计算它的部分分离开来 - - -* 0.4: -* 0.4.0-alpha: - * 修复了玩家开始/结束潜行时摄像头未跟上模型动作的问题 - * 兼容Pehkui - * 用于兼容的API -* 0.4.1-alpha: - * 兼容EpicFight - * 新增用于调试的命令 -* 0.4.2-alpha: - * 修复了额外的摄像头旋转在特定情况下无法正确应用的问题 - * 允许用按键调整摄像头旋转 -* 0.4.3-alpha: - * 允许调整经典模式下的摄像头旋转 - * 改进了准心命中结果的计算 - * Bug修复: - * 鞘翅飞行时模型有时不渲染 - * 缰绳位置不正确 -* 0.4.4-alpha: - * 添加了动态十字准心功能 - * 添加了防止摄像头进入方块内部(Clip to space)的功能 - - -* 0.3: -* 0.3.0-alpha: - * 使玩家十字准心的命中结果与十字准心的实际位置相匹配 - * 尝试实现绑定模式的效果 -* 0.3.1-alpha: - * 添加了对其余动作的摄像头位置修正 - * 初步完善了绑定模式 -* 0.3.2-alpha: - * 添加了更多绑定模式的配置 - * 尝试将摄像头方向绑定在模型上 -* 0.3.3-alpha: - * 允许将摄像头方向绑定在模型上 -* 0.3.4-alpha: - * 允许让十字准心的方向跟随摄像头 - * 修改了MOD名字 - * 修复了两个绑定模式下的问题: - * 摄像头与模型动画不完全同步 - * 开启物品栏时摄像头跟随物品栏内人物模型转动 -* 0.3.5-alpha: - * 代码逻辑优化 - * 允许在特定情况下禁用mod部分功能 -* 0.3.6-alpha: - * 代码逻辑优化 - * 更新至1.19.4 - * 支持Fabric - - -* 0.2: -* 0.2.0-alpha: - * 添加了玩家模型渲染模式 -* 0.2.1-alpha: - * 添加了对潜行动作的摄像头位置的修正 - * 可以在玩家模型渲染模式下渲染十字准心 - - -* 0.1.0-alpha: - * 添加了移动摄像头及其旋转中心的功能 diff --git a/common/src/main/java/com/xtracr/realcamera/KeyBindings.java b/common/src/main/java/com/xtracr/realcamera/KeyBindings.java index 6b99f8f..adbfbd2 100644 --- a/common/src/main/java/com/xtracr/realcamera/KeyBindings.java +++ b/common/src/main/java/com/xtracr/realcamera/KeyBindings.java @@ -1,7 +1,6 @@ package com.xtracr.realcamera; import com.xtracr.realcamera.config.ConfigFile; -import com.xtracr.realcamera.config.ModConfig; import com.xtracr.realcamera.gui.ModelViewScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.KeyBinding; @@ -19,23 +18,19 @@ public final class KeyBindings { static { createKeyBinding("modelViewGui", client -> client.setScreen(new ModelViewScreen())); createKeyBinding("togglePerspective", GLFW.GLFW_KEY_F6, client -> { - boolean enabled = config().enabled(); + boolean enabled = ConfigFile.config().enabled(); ConfigFile.load(); - config().setEnabled(!enabled); + ConfigFile.config().setEnabled(!enabled); RealCameraCore.readyToSendMessage(); }); - createKeyBinding("toggleAdjustMode", client -> config().cycleAdjustMode()); - createKeyBinding("toggleCameraMode", client -> config().setClassic(!config().isClassic())); - createKeyBinding("adjustFRONT", client -> config().adjustOffsetX(1)); - createKeyBinding("adjustBACK", client -> config().adjustOffsetX(-1)); - createKeyBinding("adjustUP", client -> config().adjustOffsetY(1)); - createKeyBinding("adjustDOWN", client -> config().adjustOffsetY(-1)); - createKeyBinding("adjustLEFT", client -> config().adjustOffsetZ(1)); - createKeyBinding("adjustRIGHT", client -> config().adjustOffsetZ(-1)); - } - - private static ModConfig config() { - return ConfigFile.modConfig; + createKeyBinding("toggleAdjustMode", client -> ConfigFile.config().cycleAdjustMode()); + createKeyBinding("toggleCameraMode", client -> ConfigFile.config().setClassic(!ConfigFile.config().isClassic())); + createKeyBinding("adjustFRONT", client -> ConfigFile.config().adjustOffsetX(1)); + createKeyBinding("adjustBACK", client -> ConfigFile.config().adjustOffsetX(-1)); + createKeyBinding("adjustUP", client -> ConfigFile.config().adjustOffsetY(1)); + createKeyBinding("adjustDOWN", client -> ConfigFile.config().adjustOffsetY(-1)); + createKeyBinding("adjustLEFT", client -> ConfigFile.config().adjustOffsetZ(1)); + createKeyBinding("adjustRIGHT", client -> ConfigFile.config().adjustOffsetZ(-1)); } private static void createKeyBinding(String id, Consumer whenPressed) { diff --git a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java index 1ddc7ba..268b46c 100644 --- a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java +++ b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java @@ -3,7 +3,6 @@ import com.xtracr.realcamera.compat.DisableHelper; import com.xtracr.realcamera.config.BindingTarget; import com.xtracr.realcamera.config.ConfigFile; -import com.xtracr.realcamera.config.ModConfig; import com.xtracr.realcamera.util.MathUtil; import com.xtracr.realcamera.util.VertexRecorder; import net.minecraft.client.MinecraftClient; @@ -18,6 +17,7 @@ import net.minecraft.util.math.Vec3d; import org.joml.Matrix3f; import org.joml.Matrix4f; +import org.joml.Vector3f; import java.util.function.BiFunction; @@ -39,7 +39,7 @@ public static float getYaw(float f) { } public static float getRoll(float f) { - if (config().isClassic()) return f + config().getClassicRoll(); + if (ConfigFile.config().isClassic()) return f + ConfigFile.config().getClassicRoll(); if (currentTarget.bindRotation) return roll; return f; } @@ -58,12 +58,12 @@ public static void setCameraPos(Vec3d vec3d) { public static void init(MinecraftClient client) { Entity entity = client.getCameraEntity(); - active = config().enabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null && entity != null && !DisableHelper.isDisabled("mainFeature", entity); - rendering = active && config().renderModel() && !DisableHelper.isDisabled("renderModel", entity); + active = ConfigFile.config().enabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null && entity != null && !DisableHelper.isDisabled("mainFeature", entity); + rendering = active && ConfigFile.config().renderModel() && !DisableHelper.isDisabled("renderModel", entity); } public static void readyToSendMessage() { - readyToSendMessage = config().enabled(); + readyToSendMessage = ConfigFile.config().enabled(); } public static boolean isActive() { @@ -71,7 +71,7 @@ public static boolean isActive() { } public static boolean isRendering() { - return rendering; + return active && rendering; } public static void updateModel(MinecraftClient client, float tickDelta) { @@ -114,13 +114,12 @@ public static void renderCameraEntity(VertexConsumerProvider vertexConsumers) { public static void computeCamera() { currentTarget = new BindingTarget(); Matrix3f normal = new Matrix3f(); - for (BindingTarget target : config().getTargetList()) { - try { - pos = recorder.getTargetPosAndRot(target, normal).add(offset); - currentTarget = target; - break; - } catch (Exception ignored) { - } + for (BindingTarget target : ConfigFile.config().getTargetList()) { + Vector3f position = new Vector3f(); + if (recorder.getTargetPosAndRot(target, normal, position) == null || !(Math.abs(normal.determinant() - 1) <= 0.01f)) continue; + pos = new Vec3d(position).add(offset); + currentTarget = target; + break; } if (currentTarget.isEmpty()) { Entity player = MinecraftClient.getInstance().player; @@ -135,8 +134,4 @@ public static void computeCamera() { yaw = (float) -eulerAngle.getY(); roll = (float) eulerAngle.getZ(); } - - private static ModConfig config() { - return ConfigFile.modConfig; - } } diff --git a/common/src/main/java/com/xtracr/realcamera/compat/DisableHelper.java b/common/src/main/java/com/xtracr/realcamera/compat/DisableHelper.java index 3d38ac5..144cce0 100644 --- a/common/src/main/java/com/xtracr/realcamera/compat/DisableHelper.java +++ b/common/src/main/java/com/xtracr/realcamera/compat/DisableHelper.java @@ -1,7 +1,6 @@ package com.xtracr.realcamera.compat; import com.xtracr.realcamera.config.ConfigFile; -import com.xtracr.realcamera.config.ModConfig; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; @@ -17,8 +16,8 @@ public final class DisableHelper { public static void initialize() { registerOr("mainFeature", LivingEntity::isSleeping); registerOr("renderModel", entity -> entity instanceof PlayerEntity player && player.isUsingSpyglass()); - registerOr("renderModel", entity -> config().getDisableRenderItems().contains(Registries.ITEM.getId(entity.getMainHandStack().getItem()).toString())); - registerOr("renderModel", entity -> config().getDisableRenderItems().contains(Registries.ITEM.getId(entity.getOffHandStack().getItem()).toString())); + registerOr("renderModel", entity -> ConfigFile.config().getDisableRenderItems().contains(Registries.ITEM.getId(entity.getMainHandStack().getItem()).toString())); + registerOr("renderModel", entity -> ConfigFile.config().getDisableRenderItems().contains(Registries.ITEM.getId(entity.getOffHandStack().getItem()).toString())); } public static void registerOr(String type, Predicate predicate) { @@ -27,11 +26,7 @@ public static void registerOr(String type, Predicate predicate) { public static boolean isDisabled(String type, Entity cameraEntity) { Predicate predicate = predicates.get(type); - if (config().isClassic() || predicate == null) return false; + if (ConfigFile.config().isClassic() || predicate == null) return false; return cameraEntity instanceof LivingEntity entity && predicate.test(entity); } - - private static ModConfig config() { - return ConfigFile.modConfig; - } } diff --git a/common/src/main/java/com/xtracr/realcamera/config/ConfigFile.java b/common/src/main/java/com/xtracr/realcamera/config/ConfigFile.java index 971e342..3bf1cda 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ConfigFile.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ConfigFile.java @@ -12,10 +12,10 @@ import java.nio.file.Path; public class ConfigFile { - public static final ModConfig modConfig = new ModConfig(); + private static final ModConfig modConfig = new ModConfig(); private static final String FILE_NAME = RealCamera.MODID + ".json"; - private static final Path PATH; private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private static final Path PATH; static { final File configDir = new File(MinecraftClient.getInstance().runDirectory, "config"); @@ -23,6 +23,10 @@ public class ConfigFile { PATH = configDir.toPath().resolve(FILE_NAME); } + public static ModConfig config() { + return modConfig; + } + public static void load() { try (BufferedReader reader = Files.newBufferedReader(PATH)) { modConfig.set(GSON.fromJson(reader, ModConfig.class)); diff --git a/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java b/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java index 2c380f1..a5b1c12 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java @@ -16,7 +16,7 @@ public class ConfigScreen { public static Screen create(Screen parent) { ConfigFile.load(); - final ModConfig config = ConfigFile.modConfig; + final ModConfig config = ConfigFile.config(); final ConfigBuilder builder = ConfigBuilder.create() .setParentScreen(parent) .transparentBackground() diff --git a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java index 6811efc..088ef6f 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java @@ -64,43 +64,6 @@ public void cycleAdjustMode() { else binding.adjustOffset = !binding.adjustOffset; } - // classic - public double getClassicX() { - return classic.cameraX * classic.scale; - } - - public double getClassicY() { - return classic.cameraY * classic.scale; - } - - public double getClassicZ() { - return classic.cameraZ * classic.scale; - } - - public double getCenterX() { - return classic.centerX * classic.scale; - } - - public double getCenterY() { - return classic.centerY * classic.scale; - } - - public double getCenterZ() { - return classic.centerZ * classic.scale; - } - - public float getClassicPitch() { - return classic.pitch; - } - - public float getClassicYaw() { - return classic.yaw; - } - - public float getClassicRoll() { - return classic.roll; - } - public void adjustOffsetX(int count) { if (isClassic) { switch (classic.adjustMode) { @@ -149,6 +112,43 @@ public void adjustOffsetZ(int count) { } } + // classic + public double getClassicX() { + return classic.cameraX * classic.scale; + } + + public double getClassicY() { + return classic.cameraY * classic.scale; + } + + public double getClassicZ() { + return classic.cameraZ * classic.scale; + } + + public double getCenterX() { + return classic.centerX * classic.scale; + } + + public double getCenterY() { + return classic.centerY * classic.scale; + } + + public double getCenterZ() { + return classic.centerZ * classic.scale; + } + + public float getClassicPitch() { + return classic.pitch; + } + + public float getClassicYaw() { + return classic.yaw; + } + + public float getClassicRoll() { + return classic.roll; + } + // binding public List getTargetList() { binding.clamp(); diff --git a/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java b/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java index 963ae4a..52e880e 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java @@ -55,7 +55,6 @@ private static void drawNormal(DrawContext context, Vec3d start, Vec3d normal, i public void initialize(int entitySize, int mouseX, int mouseY, int layers) { buildLastRecord(); - List sortByDepth = new ArrayList<>(); records.forEach(record -> { Vertex[][] vertices = record.vertices(); @@ -77,15 +76,11 @@ public void initialize(int entitySize, int mouseX, int mouseY, int layers) { focusedRecord = result.record; focusedIndex = result.index; } - target.scale *= entitySize; - try { - currentRecord = checkAndGetTarget(target, normal, position); - normal.rotateLocal((float) Math.toRadians(target.yaw()), normal.m10, normal.m11, normal.m12); - normal.rotateLocal((float) Math.toRadians(target.pitch()), normal.m00, normal.m01, normal.m02); - normal.rotateLocal((float) Math.toRadians(target.roll()), normal.m20, normal.m21, normal.m22); - } catch (Exception ignored) { - } + currentRecord = getTargetPosAndRot(target, normal, position); + normal.rotateLocal((float) Math.toRadians(target.yaw()), normal.m10, normal.m11, normal.m12); + normal.rotateLocal((float) Math.toRadians(target.pitch()), normal.m00, normal.m01, normal.m02); + normal.rotateLocal((float) Math.toRadians(target.roll()), normal.m20, normal.m21, normal.m22); } public String focusedTextureId() { @@ -164,5 +159,5 @@ private void drawPolyhedron(DrawContext context, int argb1, int argb2) { drawQuad(context, reversed, argb1, 1100); } - record Triple(double depth, BuiltRecord record, int index) { } + record Triple(double depth, BuiltRecord record, int index) {} } diff --git a/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java b/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java index d9f0926..13b842b 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java @@ -31,7 +31,7 @@ public class ModelViewScreen extends Screen { private static final String KEY_WIDGET = "screen.widget." + RealCamera.FULL_ID + ".modelView_"; private static final String KEY_TOOLTIP = "screen.tooltip." + RealCamera.FULL_ID + ".modelView_"; - protected int xSize = 420, ySize = 220, widgetWidth = (xSize - ySize) / 4 - 8, widgetHeight = 18; + protected int xSize = 406, ySize = 206, widgetWidth = (xSize - ySize) / 4 - 8, widgetHeight = 18; protected int x, y; private boolean initialized; private int entitySize = 80, layers = 0, category = 0, page = 0; @@ -146,7 +146,7 @@ private void initLeftWidgets(final int category) { adder.add(depthField, 1, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "depth"))); } adder.add(createButton(Text.translatable(KEY_WIDGET + "save"), widgetWidth, button -> { - ConfigFile.modConfig.putTarget(generateBindingTarget()); + ConfigFile.config().putTarget(generateBindingTarget()); ConfigFile.save(); initWidgets(category, page); })); @@ -161,8 +161,8 @@ private void initLeftWidgets(final int category) { } private void initRightWidgets(final int page) { - List targetList = ConfigFile.modConfig.getTargetList(); - final int widgetsPerPage = 6, pages = (targetList.size() - 1) / widgetsPerPage + 1; + List targetList = ConfigFile.config().getTargetList(); + final int widgetsPerPage = 9, pages = (targetList.size() - 1) / widgetsPerPage + 1; GridWidget gridWidget = new GridWidget(); gridWidget.getMainPositioner().margin(4, 2, 0, 0); Positioner smallPositioner = gridWidget.copyPositioner().margin(5, 3, 1, 1); @@ -178,7 +178,7 @@ private void initRightWidgets(final int page) { targetList.remove(target); ConfigFile.save(); initWidgets(category, page * widgetsPerPage >= targetList.size() && !targetList.isEmpty() ? page - 1 : page); - }), 1, smallPositioner); + }), 1, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "delete"))); } gridWidget.refreshPositions(); SimplePositioningWidget.setPos(gridWidget, x + (xSize + ySize) / 2 + 4, y + 22, x + xSize, y + ySize, 0, 0); diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java index da1c706..5b8fd95 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java @@ -36,7 +36,7 @@ public abstract class MixinCamera { @Inject(method = "update", at = @At("RETURN")) private void realcamera$updateCamera(BlockView area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickDelta, CallbackInfo cInfo) { if (!RealCameraCore.isActive()) return; - final ModConfig config = ConfigFile.modConfig; + final ModConfig config = ConfigFile.config(); Vec3d startVec = pos; Box box = focusedEntity.getBoundingBox(); if (config.isClassic()) { diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinClientPlayerEntity.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinClientPlayerEntity.java index 260db23..8be5a9d 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinClientPlayerEntity.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinClientPlayerEntity.java @@ -28,7 +28,7 @@ public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) { @Override public HitResult raycast(double maxDistance, float tickDelta, boolean includeFluids) { - if (!ConfigFile.modConfig.dynamicCrosshair() && RealCameraCore.isActive()) { + if (!ConfigFile.config().dynamicCrosshair() && RealCameraCore.isActive()) { RaycastUtil.update(this, maxDistance * maxDistance, tickDelta); return getWorld().raycast(RaycastUtil.getRaycastContext(RaycastContext.ShapeType.OUTLINE, includeFluids ? RaycastContext.FluidHandling.ANY : RaycastContext.FluidHandling.NONE, this)); diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java index 48aad04..71cd9fe 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java @@ -32,7 +32,7 @@ public abstract class MixinGameRenderer { @ModifyVariable(method = "updateTargetedEntity", at = @At("STORE"), ordinal = 0) private EntityHitResult realcamera$modifyEntityHitResult(EntityHitResult entityHitResult) { CrosshairUtil.capturedEntityHitResult = entityHitResult; - if (!ConfigFile.modConfig.dynamicCrosshair() && RealCameraCore.isActive()) { + if (!ConfigFile.config().dynamicCrosshair() && RealCameraCore.isActive()) { Vec3d startVec = RaycastUtil.getStartVec(); Vec3d endVec = RaycastUtil.getEndVec(); double sqDistance = (client.crosshairTarget != null ? client.crosshairTarget.getPos().squaredDistanceTo(startVec) : endVec.squaredDistanceTo(startVec)); @@ -47,7 +47,7 @@ public abstract class MixinGameRenderer { private void realcamera$onBeforeCameraUpdate(float tickDelta, long limitTime, MatrixStack matrices, CallbackInfo cInfo) { CompatibilityHelper.NEA_setDeltaTick(tickDelta); RealCameraCore.init(client); - if (RealCameraCore.isActive() && !ConfigFile.modConfig.isClassic()) { + if (RealCameraCore.isActive() && !ConfigFile.config().isClassic()) { RealCameraCore.updateModel(client, tickDelta); RealCameraCore.computeCamera(); } @@ -55,7 +55,7 @@ public abstract class MixinGameRenderer { @Inject(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;setupFrustum(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/math/Vec3d;Lorg/joml/Matrix4f;)V")) private void realcamera$onBeforeSetupFrustum(CallbackInfo cInfo) { - if (RealCameraCore.isActive() && !ConfigFile.modConfig.isClassic()) { + if (RealCameraCore.isActive() && !ConfigFile.config().isClassic()) { ((CameraAccessor) camera).invokeSetPos(RealCameraCore.getCameraPos(camera.getPos())); } } diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinInGameHud.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinInGameHud.java index 90104d6..7fde57f 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinInGameHud.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinInGameHud.java @@ -14,7 +14,7 @@ public abstract class MixinInGameHud { @Inject(method = "renderCrosshair(Lnet/minecraft/client/gui/DrawContext;)V", at = @At("HEAD")) private void realcamera$onRenderCrosshairHEAD(DrawContext context, CallbackInfo cInfo) { - if (ConfigFile.modConfig.dynamicCrosshair() && RealCameraCore.isActive()) { + if (ConfigFile.config().dynamicCrosshair() && RealCameraCore.isActive()) { context.getMatrices().push(); CrosshairUtil.translateMatrices(context.getMatrices()); } @@ -22,7 +22,7 @@ public abstract class MixinInGameHud { @Inject(method = "renderCrosshair(Lnet/minecraft/client/gui/DrawContext;)V", at = @At("RETURN")) private void realcamera$onRenderCrosshairRETURN(DrawContext context, CallbackInfo cInfo) { - if (ConfigFile.modConfig.dynamicCrosshair() && RealCameraCore.isActive()) { + if (ConfigFile.config().dynamicCrosshair() && RealCameraCore.isActive()) { context.getMatrices().pop(); } } diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinItem.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinItem.java index 436b325..9ea8391 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinItem.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinItem.java @@ -18,7 +18,7 @@ public abstract class MixinItem { @Inject(method = "raycast", at = @At("HEAD"), cancellable = true) private static void realcamera$coverRaycast(World world, PlayerEntity player, RaycastContext.FluidHandling fluidHandling, CallbackInfoReturnable cInfo) { - if (!ConfigFile.modConfig.dynamicCrosshair() && RealCameraCore.isActive()) { + if (!ConfigFile.config().dynamicCrosshair() && RealCameraCore.isActive()) { RaycastUtil.update(player, 25.0d, 1.0f); cInfo.setReturnValue(world.raycast(RaycastUtil.getRaycastContext(RaycastContext.ShapeType.OUTLINE, fluidHandling, player))); } diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinStuckObjectsFeatureRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinStuckObjectsFeatureRenderer.java index 6470486..27ddf29 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinStuckObjectsFeatureRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinStuckObjectsFeatureRenderer.java @@ -16,7 +16,7 @@ public abstract class MixinStuckObjectsFeatureRenderer { @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At("HEAD"), cancellable = true) private void realcamera$cancelRender(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, T livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo cInfo) { - if (livingEntity instanceof ClientPlayerEntity && RealCameraCore.isRendering() && !ConfigFile.modConfig.isClassic() && !ConfigFile.modConfig.renderStuckObjects()) { + if (livingEntity instanceof ClientPlayerEntity && RealCameraCore.isRendering() && !ConfigFile.config().isClassic() && !ConfigFile.config().renderStuckObjects()) { cInfo.cancel(); } } diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinWorldRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinWorldRenderer.java index 49859df..dee4a75 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinWorldRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinWorldRenderer.java @@ -25,7 +25,7 @@ public abstract class MixinWorldRenderer { if (!RealCameraCore.isRendering()) return; VertexConsumerProvider.Immediate immediate = this.bufferBuilders.getEntityVertexConsumers(); Vec3d cameraPos = camera.getPos(); - if (!ConfigFile.modConfig.isClassic()) RealCameraCore.renderCameraEntity(immediate); + if (!ConfigFile.config().isClassic()) RealCameraCore.renderCameraEntity(immediate); else renderEntity(camera.getFocusedEntity(), cameraPos.getX(), cameraPos.getY(), cameraPos.getZ(), tickDelta, matrices, immediate); } diff --git a/common/src/main/java/com/xtracr/realcamera/util/MathUtil.java b/common/src/main/java/com/xtracr/realcamera/util/MathUtil.java index f214313..dc07bfa 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/MathUtil.java +++ b/common/src/main/java/com/xtracr/realcamera/util/MathUtil.java @@ -10,10 +10,6 @@ public static double round(double d, int digits) { return Math.round(d * Math.pow(10, digits)) / Math.pow(10, digits); } - public static boolean isFinite(Vec3d vec3d) { - return Double.isFinite(vec3d.getX()) && Double.isFinite(vec3d.getY()) && Double.isFinite(vec3d.getZ()); - } - public static Vec3d getEulerAngleYXZ(Matrix3f normal) { if (normal.m21 <= -1.0) return new Vec3d(Math.PI / 2, Math.atan2(normal.m10, normal.m00), 0.0); else if (normal.m21 >= 1.0) return new Vec3d(-Math.PI / 2, -Math.atan2(normal.m10, normal.m00), 0.0); diff --git a/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java index e98e819..fea9cee 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java +++ b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java @@ -47,30 +47,7 @@ protected static Vertex[] getQuad(BuiltRecord record, float u, float v) { Polygon polygon = new Polygon(); for (Vertex vertex : quad) polygon.addPoint((int) (resolution * vertex.u), (int) (resolution * vertex.v)); return polygon.contains(resolution * u, resolution * v); - }).findAny().orElse(null); - } - - protected BuiltRecord checkAndGetTarget(BindingTarget target, Matrix3f normal, Vector3f position) throws NullPointerException, ArithmeticException { - Vertex[] forwardQuad = null, upwardQuad = null, positionQuad = null; - BuiltRecord retRecord = null; - for (BuiltRecord record : records) { - if (!record.renderLayer.toString().contains(target.textureId)) continue; - forwardQuad = getQuad(record, target.forwardU, target.forwardV); - upwardQuad = getQuad(record, target.upwardU, target.upwardV); - positionQuad = getQuad(record, target.posU, target.posV); - if (forwardQuad != null && upwardQuad != null && positionQuad != null) { - retRecord = record; - break; - } - } - if (forwardQuad == null || upwardQuad == null || positionQuad == null) throw new NullPointerException(); - Vec3d forward = forwardQuad[0].normal().normalize(); - Vec3d left = upwardQuad[0].normal().crossProduct(forward).normalize(); - Vec3d center = getPos(positionQuad, target.posU, target.posV); - if (!MathUtil.isFinite(forward) || !MathUtil.isFinite(left) || !MathUtil.isFinite(center)) throw new ArithmeticException(); - normal.set(left.toVector3f(), forward.crossProduct(left).toVector3f(), forward.toVector3f()); - position.set((float) target.offsetZ(), (float) target.offsetY(), (float) target.offsetX()).mul(normal).add(center.toVector3f()); - return retRecord; + }).findAny().orElse(new Vertex[]{new Vertex(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)}); } public void clear() { @@ -83,10 +60,19 @@ public void buildLastRecord() { lastRecord = null; } - public Vec3d getTargetPosAndRot(BindingTarget target, Matrix3f normal) throws NullPointerException, ArithmeticException { - Vector3f offset = new Vector3f(); - checkAndGetTarget(target, normal, offset); - return new Vec3d(offset); + public BuiltRecord getTargetPosAndRot(BindingTarget target, Matrix3f normal, Vector3f position) { + return records.stream().map(record -> { + if (!record.renderLayer.toString().contains(target.textureId)) return null; + Vec3d forward = getQuad(record, target.forwardU, target.forwardV)[0].normal().normalize(); + Vec3d left = getQuad(record, target.upwardU, target.upwardV)[0].normal().crossProduct(forward).normalize(); + Vertex[] positionQuad = getQuad(record, target.posU, target.posV); + if (positionQuad[0].normal().equals(Vec3d.ZERO) && forward.equals(Vec3d.ZERO) && left.equals(Vec3d.ZERO)) return null; + normal.set(left.toVector3f(), forward.crossProduct(left).toVector3f(), forward.toVector3f()); + Vec3d center = getPos(positionQuad, target.posU, target.posV); + if (!Double.isFinite(center.lengthSquared())) return null; + position.set((float) target.offsetZ(), (float) target.offsetY(), (float) target.offsetX()).mul(normal).add(center.toVector3f()); + return record; + }).filter(Objects::nonNull).findFirst().orElse(null); } public void drawByAnother(VertexConsumerProvider anotherProvider) { @@ -205,7 +191,7 @@ public void unfixColor() { } } - protected record BuiltRecord(RenderLayer renderLayer, Vertex[][] vertices, int quadCount, int additionalVertexCount) {} + public record BuiltRecord(RenderLayer renderLayer, Vertex[][] vertices, int quadCount, int additionalVertexCount) {} public record Vertex(double x, double y, double z, int argb, float u, float v, int overlay, int light, float normalX, float normalY, float normalZ) { public Vec3d pos() { diff --git a/common/src/main/resources/assets/realcamera/lang/en_us.json b/common/src/main/resources/assets/realcamera/lang/en_us.json index 9bda2e4..65a0778 100644 --- a/common/src/main/resources/assets/realcamera/lang/en_us.json +++ b/common/src/main/resources/assets/realcamera/lang/en_us.json @@ -71,5 +71,6 @@ "screen.tooltip.xtracr_realcamera.modelView_scale": "Scale, which controls the size of the offsets", "screen.tooltip.xtracr_realcamera.modelView_depth": "Planes where all vertex-to-screen distances are less than this value will not be rendered", "screen.tooltip.xtracr_realcamera.modelView_priority": "Priority when binding, the larger the value the higher the priority, and the higher the sorting on the right side", - "screen.tooltip.xtracr_realcamera.modelView_targetName": "Name of the config" + "screen.tooltip.xtracr_realcamera.modelView_targetName": "Name of the config", + "screen.tooltip.xtracr_realcamera.modelView_delete": "Delete" } \ No newline at end of file diff --git a/common/src/main/resources/assets/realcamera/lang/zh_cn.json b/common/src/main/resources/assets/realcamera/lang/zh_cn.json index cde9666..e589d2c 100644 --- a/common/src/main/resources/assets/realcamera/lang/zh_cn.json +++ b/common/src/main/resources/assets/realcamera/lang/zh_cn.json @@ -22,7 +22,7 @@ "config.tooltip.xtracr_realcamera.classicOffset": "摄像头相对旋转中心的偏移值", "config.tooltip.xtracr_realcamera.classicOffset_n": "注: 玩家的的前方、上方和左方分别为X、Y和Z轴", "config.tooltip.xtracr_realcamera.centerOffset": "旋转中心相对头部的偏移值", - "config.tooltip.xtracr_realcamera.cameraRotation": "额外的摄像头旋转,以度数为单位", + "config.tooltip.xtracr_realcamera.cameraRotation": "额外的摄像头旋转角度", "config.tooltip.xtracr_realcamera.cameraRotation_n": "注: 俯仰、偏航和翻滚分别是以左方、上方和前方为轴的旋转", "config.option.xtracr_realcamera.enabled": "开启功能", "config.option.xtracr_realcamera.isClassic": "经典模式", @@ -71,5 +71,6 @@ "screen.tooltip.xtracr_realcamera.modelView_scale": "缩放比例,控制偏移量的大小", "screen.tooltip.xtracr_realcamera.modelView_depth": "全部顶点到屏幕距离均小于该值的面不会被渲染", "screen.tooltip.xtracr_realcamera.modelView_priority": "绑定时的优先级,值越大优先级越高,并且在右侧排序越靠前", - "screen.tooltip.xtracr_realcamera.modelView_targetName": "配置的名称" + "screen.tooltip.xtracr_realcamera.modelView_targetName": "配置的名称", + "screen.tooltip.xtracr_realcamera.modelView_delete": "删除" } \ No newline at end of file diff --git a/common/src/main/resources/assets/realcamera/textures/gui/icon.png b/common/src/main/resources/assets/realcamera/textures/gui/icon.png index c921b5afe07cabf846b479baaa1d56854607cc28..50681e9391982363c57a3a8afd888b4ee5497b6b 100644 GIT binary patch delta 562 zcmdm{wN7h;Juk1Ru7OdAp^25Lk(H_8WFKAyG?7Z)N)_W2QzH{gb0b}oG_z#gG-H!Q zT?=z#Gu=c}gXE;NBuk4VL$l3deBYReQaRZ`Pz24AK*81ZX`yPL7#NtvJY5_^DsH{K zlik&9Akq-{eg96qMcf6fPrtb?6p=SnTkG3bAhF`d@d^1!XU_--GG9yC*^}=) zX?J5zn8`24=u`8dUMfK5fSZDJlyX)_`dAre^58)uF4B@ zhA`#}l?-dx92h2rGjIFU#K6H&!NO3($x*?}af5^91{V(pg95{W?aT$%kLF9d+>mUL z6+gayy?KWMgTqsXBW;{AObl;X6pYjgp0Fgy9KZS6?mQ>M6@CYwH$QmgEVUa}a`@D$ zF$9=11SW9K7oG5((|)^_0K*FLhBc}+2i-f4ABnG05db=knNyCDA)bjTj+x1fiE$ef zGZVv);)DbCER2i=!jlz6R3={#kp^NR76Arx#>pE+tbiPGW;DskuSHBI7l_Cs(T3s; Zzt#z)gxuU^&t1&`1fH&bF6*2UngE^cvpWC) delta 546 zcmZ3dwM}b-Juk13u910&p^=pd5E)PQ;Z;BrspPFxF-bE_wn$1f)-|v&NYph+F-g-+ zv`kIZHMKN1voNtVG)^>2+bqWSjfp6glMMt#&@2fQTwT9lwSyi51GAi`i(^Q|t+%%w zxegf!I9$B*zew&-@re~3-nUhJx1_~ARMfa@@@2BwMi&>xq9Q>D1_s88O8Kq#`?r-# zSXg8;oLYKh+9`%Ff7s?IGT81nJ;TQ%qr&Y_^Mgf<+aY9+v_Zv&1cq;UMdtQ8QVf@C zK5#rZ#(uit5rbJh(@hSRZA{Ee3>*v!3=IqnObk6yYU9WXRQMV8;Oy6W zMuz{a0t_F@6Ph{hG8PC