From 5af11b4a207a70f4c61aadf3317077ec0a401a1e Mon Sep 17 00:00:00 2001 From: xTracr Date: Sun, 3 Mar 2024 14:05:14 +0800 Subject: [PATCH] Optimized some codes (1) --- .github/workflows/publish.yml | 4 +- changelog.md | 142 ++++++++++-------- .../com/xtracr/realcamera/RealCameraCore.java | 17 +-- .../realcamera/config/ConfigScreen.java | 2 +- .../xtracr/realcamera/config/ModConfig.java | 6 +- .../xtracr/realcamera/gui/ModelAnalyser.java | 3 +- .../realcamera/gui/ModelViewScreen.java | 8 +- .../realcamera/gui/NumberFieldWidget.java | 4 +- .../mixin/MixinClientPlayerEntity.java | 13 +- .../realcamera/mixin/MixinGameRenderer.java | 7 +- .../mixin/MixinHeldItemRenderer.java | 11 +- .../com/xtracr/realcamera/util/MathUtil.java | 10 +- .../realcamera/util/VertexRecorder.java | 8 +- .../assets/realcamera/lang/en_us.json | 2 +- .../assets/realcamera/lang/zh_cn.json | 2 +- 15 files changed, 125 insertions(+), 114 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index edf8996..f297d1c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,12 +18,12 @@ jobs: run: env - name: Checkout Repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: true - name: Setup JDK - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: "temurin" java-version: 17 diff --git a/changelog.md b/changelog.md index ad2f22b..6bf521a 100644 --- a/changelog.md +++ b/changelog.md @@ -6,11 +6,11 @@ ### Test Versions ### -* 0.6.0-beta: - * 0.6.0-alpha.1: +* 0.6: +* 0.6.0-alpha.1: * Added model view screen * Allowed to select the model part you want to bind directly in the screen - * 0.6.0-alpha.2: +* 0.6.0-alpha.2: * Fixed #41, #46 and #48 * Fix minor grammar errors (#44) * Optimized the GUI display and changed logic of selection button @@ -18,7 +18,7 @@ * Added pause button and show cube button * Allowed to disable rendering vertices based on depth relative to screen * Added 'AutoBind' feature - * 0.6.0-alpha.3: +* 0.6.0-alpha.3: * Changed to bind based on UV coordinates and improved GUI * Fixed #54 * Improved Gui and Fixed a bug that would cause crash @@ -29,81 +29,92 @@ * Added 'preview' feature * Removed commands * Improved default configs and reformatted code +* 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: + * 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: +* 0.5.2-beta: * Fixed #7, #8 and clipping issue - * 0.5.3-beta: +* 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: +* 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: +* 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: + * 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: +* 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: +* 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: +* 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: + * 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: +* 0.3.2-alpha: * Added more binding mode configurations * Attempted to bind camera direction to the model part - * 0.3.3-alpha: +* 0.3.3-alpha: * Allowed camera direction to be bound to the model part - * 0.3.4-alpha: +* 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: +* 0.3.5-alpha: * Optimized code logic * Allowed to disable in specfic conditions - * 0.3.6-alpha: +* 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 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 functionality to move camera and its rotation center + * Added feature to move camera and its rotation center ## 中文 ## @@ -111,11 +122,11 @@ ### 测试版 ### -* 0.6.0-beta: - * 0.6.0-alpha.1: +* 0.6: +* 0.6.0-alpha.1: * 添加了模型视图界面 * 允许在界面中选择想要绑定的模型部位 - * 0.6.0-alpha.2: +* 0.6.0-alpha.2: * 修复了#41、#46和#48 * 修复了一些语法问题(#44) * 优化了GUI显示效果以及修改了选择按钮的逻辑 @@ -123,7 +134,7 @@ * 添加了暂停按钮和显示立方体按钮 * 允许根据相对于屏幕的距离禁用渲染部分顶点 * 添加了'自动绑定'功能 - * 0.6.0-alpha.3: +* 0.6.0-alpha.3: * 改为基于UV坐标绑定并且改进了GUI * 修复了#54 * 改进了GUI,修复了一个会导致崩溃的问题 @@ -134,78 +145,89 @@ * 添加了'预览'功能 * 移除了命令 * 改进了默认配置,重新格式化代码 +* 0.6.0-beta: + * 优化了部分代码 + +* 0.5: * 0.5.0-beta: -* 重新设计了配置屏幕 -* 删除了命令,因为它不再有用 -* 允许禁用渲染部分模型 - * 0.5.1-beta: + * 重新设计了配置屏幕 + * 删除了命令,因为它不再有用 + * 允许禁用渲染部分模型 +* 0.5.1-beta: * 把`绑定旋转`选项分为了三个选项 - * 0.5.2-beta: +* 0.5.2-beta: * 修复了#7, #8以及clip的问题 - * 0.5.3-beta: +* 0.5.3-beta: * 兼容Physics Mod的海洋物理 (#6) * 允许在手持特定物品时禁用 * 添加了对1.19.2的支持 * 更新至1.20 - * 0.5.4-beta: +* 0.5.4-beta: * 添加了功能#15, 修复#35 * 修改了clip to space的方式来避免#23和#32 - * 0.5.5-beta: +* 0.5.5-beta: * 修改了clip to space的方式来避免#37 * 删除了禁用"clip to space"的选项 * 将修改摄像头的部分与计算它的部分分离开来 + +* 0.4: * 0.4.0-alpha: -* 修复了玩家开始/结束潜行时摄像头未跟上模型动作的问题 -* 兼容Pehkui -* 用于兼容的API - * 0.4.1-alpha: + * 修复了玩家开始/结束潜行时摄像头未跟上模型动作的问题 + * 兼容Pehkui + * 用于兼容的API +* 0.4.1-alpha: * 兼容EpicFight * 新增用于调试的命令 - * 0.4.2-alpha: +* 0.4.2-alpha: * 修复了额外的摄像头旋转在特定情况下无法正确应用的问题 * 允许用按键调整摄像头旋转 - * 0.4.3-alpha: +* 0.4.3-alpha: * 允许调整经典模式下的摄像头旋转 * 改进了准心命中结果的计算 * Bug修复: * 鞘翅飞行时模型有时不渲染 * 缰绳位置不正确 - * 0.4.4-alpha: +* 0.4.4-alpha: * 添加了动态十字准心功能 * 添加了防止摄像头进入方块内部(Clip to space)的功能 + +* 0.3: * 0.3.0-alpha: -* 使玩家十字准心的命中结果与十字准心的实际位置相匹配 -* 尝试实现绑定模式的效果 - * 0.3.1-alpha: + * 使玩家十字准心的命中结果与十字准心的实际位置相匹配 + * 尝试实现绑定模式的效果 +* 0.3.1-alpha: * 添加了对其余动作的摄像头位置修正 * 初步完善了绑定模式 - * 0.3.2-alpha: +* 0.3.2-alpha: * 添加了更多绑定模式的配置 * 尝试将摄像头方向绑定在模型上 - * 0.3.3-alpha: +* 0.3.3-alpha: * 允许将摄像头方向绑定在模型上 - * 0.3.4-alpha: +* 0.3.4-alpha: * 允许让十字准心的方向跟随摄像头 * 修改了MOD名字 * 修复了两个绑定模式下的问题: * 摄像头与模型动画不完全同步 * 开启物品栏时摄像头跟随物品栏内人物模型转动 - * 0.3.5-alpha: +* 0.3.5-alpha: * 代码逻辑优化 * 允许在特定情况下禁用mod部分功能 - * 0.3.6-alpha: +* 0.3.6-alpha: * 代码逻辑优化 * 更新至1.19.4 * 支持Fabric + +* 0.2: * 0.2.0-alpha: -* 添加了玩家模型渲染模式 - * 0.2.1-alpha: + * 添加了玩家模型渲染模式 +* 0.2.1-alpha: * 添加了对潜行动作的摄像头位置的修正 * 可以在玩家模型渲染模式下渲染十字准心 + * 0.1.0-alpha: -* 添加了移动摄像头及其旋转中心的功能 + * 添加了移动摄像头及其旋转中心的功能 diff --git a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java index 10c32d8..ca60305 100644 --- a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java +++ b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java @@ -95,13 +95,11 @@ public static boolean isActive() { } public static void renderPlayer(VertexConsumerProvider vertexConsumers) { - MatrixStack matrixStack = new MatrixStack(); - matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(roll)); - matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(pitch)); - matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(yaw + 180.0f)); - Matrix3f normalMatrix = matrixStack.peek().getNormalMatrix().transpose().invert(); - Matrix4f positionMatrix = matrixStack.peek().getPositionMatrix().transpose().invertAffine() - .translate((float) -pos.getX(), (float) -pos.getY(), (float) -pos.getZ()); + Matrix3f normalMatrix = new Matrix3f().rotate(RotationAxis.POSITIVE_Z.rotationDegrees(roll)) + .rotate(RotationAxis.POSITIVE_X.rotationDegrees(pitch)) + .rotate(RotationAxis.POSITIVE_Y.rotationDegrees(yaw + 180.0f)) + .transpose().invert(); + Matrix4f positionMatrix = new Matrix4f(normalMatrix).translate((float) -pos.getX(), (float) -pos.getY(), (float) -pos.getZ()); BiFunction function = (renderLayer, vertices) -> { double depth = currentTarget.disablingDepth(), centerZ = 0; int count = vertices.length; @@ -134,14 +132,13 @@ public static void computeCamera(MinecraftClient client, float tickDelta) { pos = new Vec3d(offset.x(), offset.y(), offset.z()); Matrix3f normal = matrixStack.peek().getNormalMatrix().scale(1.0f, -1.0f, -1.0f); if (config().binding.experimental) { - List targetList = new ArrayList<>(); + List targetList = new ArrayList<>(List.of(config().getTarget())); if (config().binding.autoBind) { List targets = config().binding.targetList; recorder.setCurrent(renderLayer -> targets.stream().anyMatch(t -> renderLayer.toString().contains(t.textureId()))); String textureId = recorder.currentTextureId(); if (textureId != null) targetList.addAll(targets.stream().filter(t -> textureId.contains(t.textureId())).toList()); } - targetList.add(config().getTarget(config().binding.targetName)); for (BindingTarget target : targetList) { try { recorder.setCurrent(renderLayer -> renderLayer.toString().contains(target.textureId())); @@ -156,7 +153,7 @@ public static void computeCamera(MinecraftClient client, float tickDelta) { normal.rotateLocal((float) Math.toRadians(currentTarget.yaw()), normal.m10, normal.m11, normal.m12); normal.rotateLocal((float) Math.toRadians(currentTarget.pitch()), normal.m00, normal.m01, normal.m02); normal.rotateLocal((float) Math.toRadians(currentTarget.roll()), normal.m20, normal.m21, normal.m22); - Vec3d eulerAngle = MathUtil.getEulerAngleYXZ(normal).multiply(180.0d / Math.PI); + Vec3d eulerAngle = MathUtil.getEulerAngleYXZ(normal).multiply(Math.toDegrees(1)); pitch = (float) eulerAngle.getX(); yaw = (float) -eulerAngle.getY(); roll = (float) eulerAngle.getZ(); 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 4d60110..150e2c7 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java @@ -314,7 +314,7 @@ public static Screen create(Screen parent) { disable.addEntry(disableModWhen.build()); experimental.addEntry(entryBuilder.startBooleanToggle(Text.literal("Enabled"), config.binding.experimental) - .setDefaultValue(true) + .setDefaultValue(false) .setSaveConsumer(b -> config.binding.experimental = b) .build()); experimental.addEntry(entryBuilder.startBooleanToggle(Text.literal("Auto Bind"), config.binding.autoBind) 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 599d706..229c7ed 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java @@ -81,8 +81,8 @@ public boolean isAdjustingOffset() { return binding.adjustOffset; } - public BindingTarget getTarget(String name) { - return binding.targetList.stream().filter(target -> target.name().equals(name)).findAny().orElse(null); + public BindingTarget getTarget() { + return binding.targetList.stream().filter(t -> t.name().equals(binding.targetName)).findAny().orElse(null); } public boolean isXBound() { @@ -306,7 +306,7 @@ private void clamp() { public static class Binding { public List targetList = new ArrayList<>(BindingTarget.defaultTargets); public VanillaModelPart vanillaModelPart = VanillaModelPart.head; - public boolean experimental = true; + public boolean experimental = false; public boolean adjustOffset = true; public boolean autoBind = true; public String targetName = "minecraft_head"; 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 ea668d3..49255a0 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java @@ -66,10 +66,11 @@ public int getFocusedIndex(int mouseX, int mouseY, int layers) { Polygon polygon = new Polygon(); Vertex[] quad = vertices[i]; for (Vertex vertex : quad) polygon.addPoint((int) vertex.x(), (int) vertex.y()); + if (!polygon.contains(mouseX, mouseY)) continue; Vertex point = quad[0]; double deltaZ = 0; if (point.normalZ() != 0) deltaZ = (point.normalX() * (mouseX - point.x()) + point.normalY() * (mouseY - point.y())) / point.normalZ(); - if (polygon.contains(mouseX, mouseY)) sortByDepth.add(new Triple(point.z() + deltaZ, record, i)); + sortByDepth.add(new Triple(point.z() + deltaZ, record, i)); } }); if (sortByDepth.isEmpty()) return -1; 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 0219b2f..14d1056 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java @@ -334,12 +334,12 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { if (mouseInViewArea(mouseX, mouseY)) { if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && !InputUtil.isKeyPressed(client.getWindow().getHandle(), GLFW.GLFW_KEY_LEFT_ALT)) { - xRot = MathHelper.wrapDegrees(xRot + (float) deltaY / 90f); - yRot = MathHelper.wrapDegrees(yRot - (float) deltaX / 90f); + xRot += (float) (Math.PI * deltaY / ySize); + yRot -= (float) (Math.PI * deltaX / ySize); return true; } else if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) { - entityX = entityX + deltaX / entitySize; - entityY = entityY + deltaY / entitySize; + entityX += deltaX / entitySize; + entityY += deltaY / entitySize; return true; } } diff --git a/common/src/main/java/com/xtracr/realcamera/gui/NumberFieldWidget.java b/common/src/main/java/com/xtracr/realcamera/gui/NumberFieldWidget.java index 4b7cb90..99a6606 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/NumberFieldWidget.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/NumberFieldWidget.java @@ -58,8 +58,8 @@ protected void checkText() { setRenderTextProvider((string, firstCharacterIndex) -> OrderedText.styledForwardsVisitedString(string, Style.EMPTY)); try { T value = getValueInternal(); - if (value.compareTo(minimum) < 0) throw new Exception("<" + minimum); - if (value.compareTo(maximum) > 0) throw new Exception(">" + maximum); + if (value.compareTo(minimum) < 0) throw new Exception("< " + minimum); + if (value.compareTo(maximum) > 0) throw new Exception("> " + maximum); } catch (Exception exception) { super.setTooltip(Tooltip.of(Text.literal("Invalid number: " + exception.getMessage()).styled(s -> s.withColor(Formatting.RED)))); setRenderTextProvider((string, firstCharacterIndex) -> OrderedText.styledForwardsVisitedString(string, Style.EMPTY.withColor(Formatting.RED))); 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 15fa7b9..140cc05 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinClientPlayerEntity.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinClientPlayerEntity.java @@ -6,13 +6,14 @@ import com.xtracr.realcamera.util.RaycastUtil; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.option.Perspective; import net.minecraft.client.world.ClientWorld; import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.RaycastContext; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ClientPlayerEntity.class) public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity { @@ -20,11 +21,9 @@ public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) { super(world, profile); } - @Redirect(method = "getLeashPos", at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/option/Perspective;isFirstPerson()Z")) - private boolean realCamera$returnFalse(Perspective perspective) { - if (ConfigFile.modConfig.isRendering() && RealCameraCore.isActive()) return false; - return perspective.isFirstPerson(); + @Inject(method = "getLeashPos", at = @At("HEAD"), cancellable = true) + private void realcamera$onGetLeashPosHEAD(float delta, CallbackInfoReturnable cInfo) { + if (ConfigFile.modConfig.isRendering() && RealCameraCore.isActive()) cInfo.setReturnValue(super.getLeashPos(delta)); } @Override 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 1ccc4ca..7be6b40 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java @@ -25,7 +25,6 @@ public abstract class MixinGameRenderer { @Shadow @Final MinecraftClient client; - @Shadow @Final private Camera camera; @@ -35,11 +34,9 @@ public abstract class MixinGameRenderer { if (!ConfigFile.modConfig.isCrosshairDynamic() && RealCameraCore.isActive()) { Vec3d startVec = RaycastUtil.getStartVec(); Vec3d endVec = RaycastUtil.getEndVec(); - double sqDistance = (client.crosshairTarget != null ? - client.crosshairTarget.getPos().squaredDistanceTo(startVec) : endVec.squaredDistanceTo(startVec)); + double sqDistance = (client.crosshairTarget != null ? client.crosshairTarget.getPos().squaredDistanceTo(startVec) : endVec.squaredDistanceTo(startVec)); Entity cameraEntity = client.getCameraEntity(); - Box box = cameraEntity.getBoundingBox().stretch(cameraEntity.getRotationVec(client.getTickDelta()) - .multiply(client.interactionManager.getReachDistance())).expand(1.0, 1.0, 1.0); + Box box = cameraEntity.getBoundingBox().stretch(cameraEntity.getRotationVec(client.getTickDelta()).multiply(client.interactionManager.getReachDistance())).expand(1.0, 1.0, 1.0); CrosshairUtil.capturedEntityHitResult = ProjectileUtil.raycast(cameraEntity, startVec, endVec, box, entity -> !entity.isSpectator() && entity.canHit(), sqDistance); } return CrosshairUtil.capturedEntityHitResult; diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinHeldItemRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinHeldItemRenderer.java index e770ab1..8c4df8f 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinHeldItemRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinHeldItemRenderer.java @@ -4,13 +4,10 @@ import com.xtracr.realcamera.config.ConfigFile; import com.xtracr.realcamera.config.ModConfig; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.item.HeldItemRenderer; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Hand; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -23,12 +20,10 @@ public abstract class MixinHeldItemRenderer { @Shadow @Final private MinecraftClient client; - @Inject(method = "renderFirstPersonItem", at = @At("HEAD"), cancellable = true) - private void realcamera$cancelRendering(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, - ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo cInfo) { + @Inject(method = "renderItem(FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/network/ClientPlayerEntity;I)V", at = @At("HEAD"), cancellable = true) + private void realcamera$cancelRendering(float tickDelta, MatrixStack matrices, VertexConsumerProvider.Immediate vertexConsumers, ClientPlayerEntity player, int light, CallbackInfo cInfo) { ModConfig config = ConfigFile.modConfig; - if (player instanceof ClientPlayerEntity && RealCameraCore.isActive() && config.isRendering() && - !config.shouldDisableRendering(client) && !config.allowRenderingHand(client)) { + if (player instanceof ClientPlayerEntity && RealCameraCore.isActive() && config.isRendering() && !config.shouldDisableRendering(client) && !config.allowRenderingHand(client)) { cInfo.cancel(); } } 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 6adf59d..6662ef3 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/MathUtil.java +++ b/common/src/main/java/com/xtracr/realcamera/util/MathUtil.java @@ -15,10 +15,10 @@ public static boolean isFinite(Vec3d vec3d) { } public static Vec3d getEulerAngleYXZ(Matrix3f normal) { - if (normal.m21 <= -1.0d) { - return new Vec3d(Math.PI / 2, Math.atan2(normal.m10, normal.m00), 0.0d); - } else if (normal.m21 >= 1.0d) { - return new Vec3d(-Math.PI / 2, -Math.atan2(normal.m10, normal.m00), 0.0d); + 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); } double xRot = Math.asin(-normal.m21); double yRot = Math.atan2(normal.m20, normal.m22); @@ -34,7 +34,7 @@ public static Vec3d getIntersectionPoint(Vec3d planePoint, Vec3d planeNormal, Ve public static Vec3d projectToVec2d(Vec3d vec3d, Matrix4f... projectionMatrices) { Vector4f vector4f = new Vector4f((float) vec3d.getX(), (float) vec3d.getY(), (float) vec3d.getZ(), 1.0f); for (Matrix4f matrix4f : projectionMatrices) vector4f.mul(matrix4f); - if (vector4f.w() == 0.0d) return Vec3d.ZERO; + if (vector4f.w() == 0.0) return Vec3d.ZERO; return new Vec3d(vector4f.x(), vector4f.y(), 0).multiply(1 / (double) vector4f.w()); } } 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 c5bda6c..4607dae 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java +++ b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java @@ -68,11 +68,11 @@ public void setCurrent(Predicate predicate) { } public Vec3d getTargetPosAndRot(BindingTarget target, Matrix3f normal) throws NullPointerException, ArithmeticException { - Vec3d front = Objects.requireNonNull(getQuad(currentRecord, target.forwardU(), target.forwardV()))[0].normal(); - Vec3d up = Objects.requireNonNull(getQuad(currentRecord, target.upwardU(), target.upwardV()))[0].normal(); + Vec3d forward = Objects.requireNonNull(getQuad(currentRecord, target.forwardU(), target.forwardV()))[0].normal().normalize(); + Vec3d left = Objects.requireNonNull(getQuad(currentRecord, target.upwardU(), target.upwardV()))[0].normal().crossProduct(forward).normalize(); Vec3d center = getPos(Objects.requireNonNull(getQuad(currentRecord, target.posU(), target.posV())), target.posU(), target.posV()); - if (!MathUtil.isFinite(front) || !MathUtil.isFinite(up) || !MathUtil.isFinite(center)) throw new ArithmeticException(); - normal.set(up.crossProduct(front).toVector3f(), up.toVector3f(), front.toVector3f()); + if (!MathUtil.isFinite(forward) || !MathUtil.isFinite(left) || !MathUtil.isFinite(center)) throw new ArithmeticException(); + normal.set(left.toVector3f(), forward.crossProduct(left).toVector3f(), forward.toVector3f()); Vector3f offset = new Vector3f((float) target.offsetZ(), (float) target.offsetY(), (float) target.offsetX()).mul(normal); return center.add(offset.x(), offset.y(), offset.z()); } 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 d631da9..89c6a04 100644 --- a/common/src/main/resources/assets/realcamera/lang/en_us.json +++ b/common/src/main/resources/assets/realcamera/lang/en_us.json @@ -104,6 +104,6 @@ "screen.tooltip.xtracr_realcamera.modelView_bindButtons": "When disabled, the camera's relative relationship to the model will not change, but the camera's corresponding attributes will not be modified by this mod", "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_bind": "Displayed in green on the right is the currently bound one. Will be ignored if '%s' is enabled", + "screen.tooltip.xtracr_realcamera.modelView_bind": "Prioritized when binding, and displayed in green on the right side", "screen.tooltip.xtracr_realcamera.modelView_listName": "Name of the config" } \ 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 2d4f465..a1b0064 100644 --- a/common/src/main/resources/assets/realcamera/lang/zh_cn.json +++ b/common/src/main/resources/assets/realcamera/lang/zh_cn.json @@ -104,6 +104,6 @@ "screen.tooltip.xtracr_realcamera.modelView_bindButtons": "当禁用时,摄像头与模型的相对关系不会变化,但摄像头的对应属性不会被本模组修改", "screen.tooltip.xtracr_realcamera.modelView_scale": "缩放比例,控制偏移量的大小", "screen.tooltip.xtracr_realcamera.modelView_depth": "全部顶点到屏幕距离均小于该值的面不会被渲染", - "screen.tooltip.xtracr_realcamera.modelView_bind": "在右侧显示为绿色的是当前所绑定的,在'%s'启用时会被忽略", + "screen.tooltip.xtracr_realcamera.modelView_bind": "绑定时优先考虑,在右侧显示为绿色", "screen.tooltip.xtracr_realcamera.modelView_listName": "配置的名称" } \ No newline at end of file