From 1220a5a344c18a0a4d80145048e0bfe6f6f9404a Mon Sep 17 00:00:00 2001 From: xTracr Date: Fri, 1 Mar 2024 21:40:02 +0800 Subject: [PATCH] Improved default configs and reformatted code --- README.md | 9 +- README_ZH.md | 5 +- .../com/xtracr/realcamera/KeyBindings.java | 2 +- .../com/xtracr/realcamera/RealCameraCore.java | 2 +- .../realcamera/config/BindingTarget.java | 101 +++----- .../xtracr/realcamera/config/ModConfig.java | 7 +- .../realcamera/gui/CyclingTexturedButton.java | 2 +- .../xtracr/realcamera/gui/ModelAnalyser.java | 52 ++-- .../realcamera/gui/ModelViewScreen.java | 34 +-- .../realcamera/gui/NumberFieldWidget.java | 2 +- .../xtracr/realcamera/gui/TexturedButton.java | 9 +- .../xtracr/realcamera/mixin/MixinCamera.java | 4 +- .../realcamera/mixin/MixinEntityRenderer.java | 2 +- .../realcamera/mixin/MixinGameRenderer.java | 3 +- .../mixin/MixinHeldItemRenderer.java | 2 +- .../xtracr/realcamera/mixin/MixinItem.java | 2 +- .../mixin/MixinPlayerEntityRenderer.java | 2 +- .../MixinPlayerHeldItemFeatureRenderer.java | 2 +- .../realcamera/mixin/MixinWorldRenderer.java | 4 +- .../mixin/PlayerEntityRendererAccessor.java | 2 +- .../realcamera/util/VertexRecorder.java | 52 ++-- .../assets/realcamera/lang/en_us.json | 223 +++++++++--------- .../assets/realcamera/lang/fr_fr.json | 178 +++++++------- .../assets/realcamera/lang/zh_cn.json | 223 +++++++++--------- fabric/src/main/resources/fabric.mod.json | 4 - .../realcamera/compat/EpicFightCompat.java | 2 +- forge/src/main/resources/META-INF/mods.toml | 70 +++--- forge/src/main/resources/pack.mcmeta | 12 +- 28 files changed, 465 insertions(+), 547 deletions(-) diff --git a/README.md b/README.md index 4c9f087..e814324 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,10 @@ Make the camera more realistic in the first-person view. Supported versions: 1.18-1.20 Forge & Fabric. -Download the mod from [Releases](https://github.com/xTracr/RealCamera/releases), [Modrinth](https://modrinth.com/mod/real-camera) or [CurseForge](https://curseforge.com/minecraft/mc-mods/real-camera) -Snapshots are [here](https://github.com/xTracr/RealCamera/actions/workflows/build.yml) +Download the mod +from [Releases](https://github.com/xTracr/RealCamera/releases), [Modrinth](https://modrinth.com/mod/real-camera) +or [CurseForge](https://curseforge.com/minecraft/mc-mods/real-camera) +Snapshots are [here](https://github.com/xTracr/RealCamera/actions/workflows/build.yml) ## Features ## @@ -14,7 +16,8 @@ Snapshots are [here](https://github.com/xTracr/RealCamera/actions/workflows/buil * Render player model in first-person perspective. * Use F6 to toggle the feature on or off and other hotkeys to adjust the camera. * Configure these features in the config screen (Cloth Config required). -* Support most mod models in theory with the upcoming feature in 0.6+ (You can discuss it [here](https://github.com/xTracr/RealCamera/discussions)) +* Support most mod models in theory with the upcoming feature in 0.6+ (You can discuss + it [here](https://github.com/xTracr/RealCamera/discussions)) > Learn more about [Configuration](https://github.com/xTracr/RealCamera/wiki/Configuration) diff --git a/README_ZH.md b/README_ZH.md index 7aa5b4f..1a46b9f 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -4,8 +4,9 @@ 使第一人称视角下的摄像头更加真实。 支持的版本: 1.18-1.20 Forge & Fabric -从[Releases](https://github.com/xTracr/RealCamera/releases)、[Modrinth](https://modrinth.com/mod/real-camera)或[CurseForge](https://curseforge.com/minecraft/mc-mods/real-camera)下载 -快照版在[这里](https://github.com/xTracr/RealCamera/actions/workflows/build.yml) +从[Releases](https://github.com/xTracr/RealCamera/releases)、[Modrinth](https://modrinth.com/mod/real-camera) +或[CurseForge](https://curseforge.com/minecraft/mc-mods/real-camera)下载 +快照版在[这里](https://github.com/xTracr/RealCamera/actions/workflows/build.yml) ## 特性 ## diff --git a/common/src/main/java/com/xtracr/realcamera/KeyBindings.java b/common/src/main/java/com/xtracr/realcamera/KeyBindings.java index 0f7332e..5c19644 100644 --- a/common/src/main/java/com/xtracr/realcamera/KeyBindings.java +++ b/common/src/main/java/com/xtracr/realcamera/KeyBindings.java @@ -25,7 +25,7 @@ public final class KeyBindings { private static final KeyBinding ADJUST_BACK = createKeyBinding("adjustBACK"); private static final KeyBinding ADJUST_LEFT = createKeyBinding("adjustLEFT"); private static final KeyBinding ADJUST_RIGHT = createKeyBinding("adjustRIGHT"); - + public static KeyBinding createKeyBinding(String id) { return createKeyBinding(id, GLFW.GLFW_KEY_UNKNOWN); } diff --git a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java index f60ab2c..ba29205 100644 --- a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java +++ b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java @@ -35,12 +35,12 @@ public class RealCameraCore { private static final VertexRecorder recorder = new VertexRecorder(); + public static BindingTarget currentTarget = new BindingTarget(); private static String status = "Successful"; private static boolean renderingPlayer = false; private static boolean active = false; private static float pitch, yaw, roll; private static Vec3d pos = Vec3d.ZERO, cameraPos = Vec3d.ZERO; - public static BindingTarget currentTarget = new BindingTarget(); public static String getStatus() { return status; diff --git a/common/src/main/java/com/xtracr/realcamera/config/BindingTarget.java b/common/src/main/java/com/xtracr/realcamera/config/BindingTarget.java index 5055f7f..2ecfb24 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/BindingTarget.java +++ b/common/src/main/java/com/xtracr/realcamera/config/BindingTarget.java @@ -1,19 +1,24 @@ package com.xtracr.realcamera.config; +import java.util.List; + public class BindingTarget { - public static final BindingTarget MINECRAFT_HEAD = new BindingTarget("minecraft_head", "minecraft:textures/entity/player/", 0.1875f, 0.2f, 0.1875f, 0.075f, 0.1875f, 0.2f, false, true, false, false, 1, -0.15f, 0, 0, 0, 0, 0, 0.2f); - public static final BindingTarget MINECRAFT_HEAD_2 = new BindingTarget("minecraft_head_2", "minecraft:textures/entity/player/", 0.1875f, 0.2f, 0.1875f, 0.075f, 0.1875f, 0.2f, true, true, true, true, 1, -0.15f, 0, 0, 0, 0, 0, 0.2f); - String name, textureId; - float forwardU, forwardV, upwardU, upwardV, posU, posV; - boolean bindX, bindY, bindZ, bindRotation; - double scale, offsetX, offsetY, offsetZ; - float pitch, yaw, roll, disablingDepth; + protected static final List defaultTargets = List.of(createDefaultTarget("minecraft_head", "minecraft:textures/entity/player/", false), + createDefaultTarget("minecraft_head_2", "minecraft:textures/entity/player/", true), + createDefaultTarget("skin_head", "minecraft:skins/", false), + createDefaultTarget("skin_head_2", "minecraft:skins/", true)); + private final String name, textureId; + private final float forwardU, forwardV, upwardU, upwardV, posU, posV, disablingDepth; + private final boolean bindX, bindY, bindZ, bindRotation; + private final double scale; + private double offsetX, offsetY, offsetZ; + private float pitch, yaw, roll; public BindingTarget() { - this(null, null, 0, 0, 0, 0, 0, 0, true, true, true, true, 1, 0, 0, 0, 0, 0, 0, 0); + this(null, null, 0, 0, 0, 0, 0, 0, 0.2f, false, true, false, false, 1, 0, 0, 0, 0, 0, 0); } - public BindingTarget(String name, String textureId, float forwardU, float forwardV, float upwardU, float upwardV, float posU, float posV, boolean bindX, boolean bindY, boolean bindZ, boolean bindRotation, double scale, double offsetX, double offsetY, double offsetZ, float pitch, float yaw, float roll, float disablingDepth) { + public BindingTarget(String name, String textureId, float forwardU, float forwardV, float upwardU, float upwardV, float posU, float posV, float disablingDepth, boolean bindX, boolean bindY, boolean bindZ, boolean bindRotation, double scale, double offsetX, double offsetY, double offsetZ, float pitch, float yaw, float roll) { this.name = name; this.textureId = textureId; this.forwardU = forwardU; @@ -22,6 +27,7 @@ public BindingTarget(String name, String textureId, float forwardU, float forwar this.upwardV = upwardV; this.posU = posU; this.posV = posV; + this.disablingDepth = disablingDepth; this.bindX = bindX; this.bindY = bindY; this.bindZ = bindZ; @@ -33,113 +39,76 @@ public BindingTarget(String name, String textureId, float forwardU, float forwar this.pitch = pitch; this.yaw = yaw; this.roll = roll; - this.disablingDepth = disablingDepth; } - public String name() { - return name; + private static ModConfig config() { + return ConfigFile.modConfig; } - public void setName(String name) { - this.name = name; + private static BindingTarget createDefaultTarget(String name, String textureId, boolean shouldBind) { + return new BindingTarget(name, textureId, 0.1875f, 0.2f, 0.1875f, 0.075f, 0.1875f, 0.2f, 0.2f, shouldBind, true, shouldBind, shouldBind, 1, -0.12, 0, 0, 0, 0, 0); } - public String textureId() { - return textureId; + public boolean isEmpty() { + return name == null; } - public void setTextureId(String textureId) { - this.textureId = textureId; + public String name() { + return name; } - public float forwardU() { - return forwardU; + public String textureId() { + return textureId; } - public void setForwardU(float forwardU) { - this.forwardU = forwardU; + public float forwardU() { + return forwardU; } public float forwardV() { return forwardV; } - public void setForwardV(float forwardV) { - this.forwardV = forwardV; - } - public float upwardU() { return upwardU; } - public void setUpwardU(float upwardU) { - this.upwardU = upwardU; - } - public float upwardV() { return upwardV; } - public void setUpwardV(float upwardV) { - this.upwardV = upwardV; - } - public float posU() { return posU; } - public void setPosU(float posU) { - this.posU = posU; - } - public float posV() { return posV; } - public void setPosV(float posV) { - this.posV = posV; + public float disablingDepth() { + return disablingDepth; } public boolean bindX() { return isExperimental() ? bindX : config().isXBound(); } - public void setBindX(boolean bindX) { - this.bindX = bindX; - } - public boolean bindY() { return isExperimental() ? bindY : config().isYBound(); } - public void setBindY(boolean bindY) { - this.bindY = bindY; - } - public boolean bindZ() { return isExperimental() ? bindZ : config().isZBound(); } - public void setBindZ(boolean bindZ) { - this.bindZ = bindZ; - } - public boolean bindRotation() { return isExperimental() ? bindRotation : config().isRotationBound(); } - public void setBindRotation(boolean bindRotation) { - this.bindRotation = bindRotation; - } - public double scale() { return isExperimental() ? scale : config().getScale(); } - public void setScale(double scale) { - this.scale = scale; - } - public double offsetX() { return isExperimental() ? offsetX * scale : config().getBindingX() * config().getScale(); } @@ -188,19 +157,7 @@ public void setRoll(float roll) { this.roll = roll; } - public float disablingDepth() { - return disablingDepth; - } - - public void setDisablingDepth(float disablingDepth) { - this.disablingDepth = disablingDepth; - } - private boolean isExperimental() { return config().binding.experimental && textureId != null; } - - private static ModConfig config() { - return ConfigFile.modConfig; - } } 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 fca077e..522eb3e 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java @@ -129,7 +129,7 @@ public void setAdjustOffset(boolean value) { } public void putTarget(BindingTarget target) { - if (target.name() != null) binding.targetMap.put(target.name(), target); + if (!target.isEmpty()) binding.targetMap.put(target.name(), target); } public void adjustBindingX(boolean add) { @@ -249,7 +249,7 @@ private boolean shouldDisable(MinecraftClient client, String action) { if (!triple.getRight().contains(action)) continue; String behavior = triple.getLeft(); b = b || (client.player.isHolding(stack -> - triple.getMiddle().contains(Registries.ITEM.getId(stack.getItem()).toString())) && + triple.getMiddle().contains(Registries.ITEM.getId(stack.getItem()).toString())) && (behavior.equals("holding") || (behavior.equals("attacking") && client.options.attackKey.isPressed()) || (behavior.equals("using") && client.options.useKey.isPressed()))); @@ -299,7 +299,6 @@ private void clamp() { } public static class Binding { - protected static final List defaultTargets = List.of(BindingTarget.MINECRAFT_HEAD, BindingTarget.MINECRAFT_HEAD_2); public VanillaModelPart vanillaModelPart = VanillaModelPart.head; public boolean experimental = false; public boolean adjustOffset = true; @@ -321,7 +320,7 @@ private void clamp() { if (vanillaModelPart == null) vanillaModelPart = VanillaModelPart.head; if (targetMap == null || targetMap.isEmpty()) { targetMap = new LinkedHashMap<>(); - defaultTargets.forEach(target -> targetMap.put(target.name(), target)); + BindingTarget.defaultTargets.forEach(target -> targetMap.put(target.name(), target)); } cameraX = MathHelper.clamp(cameraX, MIN_DOUBLE, MAX_DOUBLE); cameraY = MathHelper.clamp(cameraY, MIN_DOUBLE, MAX_DOUBLE); diff --git a/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java b/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java index b5ce393..d4b85fa 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java @@ -21,7 +21,7 @@ public CyclingTexturedButton(int u, int v, int maximum) { } public CyclingTexturedButton(int x, int y, int width, int height, int u, int v, int maximum) { - this(x, y, width, height, u, v, height, maximum, ICON_TEXTURE, 256, 256, Text.empty()); + this(x, y, width, height, u, v, height, maximum, ICON_TEXTURE, 256, 256, Text.empty()); } public CyclingTexturedButton(int x, int y, int width, int height, int u, int v, int vOffset, int maximum, Identifier texture, int textureWidth, int textureHeight, Text message) { 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 7dfd249..b1156fc 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java @@ -18,6 +18,32 @@ public class ModelAnalyser extends VertexRecorder { private BuiltRecord focusedRecord; + private static boolean intersects(Vertex[] quad, List quads) { + final float precision = 0.00001f; + for (Vertex[] q : quads) + for (Vertex v1 : quad) + for (Vertex v2 : q) if (v1.pos().squaredDistanceTo(v2.pos()) < precision) return true; + return false; + } + + private static void drawQuad(DrawContext context, Vertex[] quad, int argb, int offset) { + VertexConsumer vertexConsumer = context.getVertexConsumers().getBuffer(RenderLayer.getGui()); + for (Vertex vertex : quad) + vertexConsumer.vertex(vertex.x(), vertex.y(), vertex.z() + offset).color(argb).next(); + if (quad.length == 3) vertexConsumer.vertex(quad[2].x(), quad[2].y(), quad[2].z() + offset).color(argb).next(); + context.draw(); + } + + private static void drawNormal(DrawContext context, Vec3d start, Vec3d normal, int length, int argb) { + Vec3d end = normal.multiply(length).add(start); + VertexConsumer vertexConsumer = context.getVertexConsumers().getBuffer(RenderLayer.getLineStrip()); + vertexConsumer.vertex(start.getX(), start.getY(), start.getZ() + 1200f).color(argb) + .normal((float) normal.getX(), (float) normal.getY(), (float) normal.getZ()).next(); + vertexConsumer.vertex(end.getX(), end.getY(), end.getZ() + 1200f).color(argb) + .normal((float) normal.getX(), (float) normal.getY(), (float) normal.getZ()).next(); + context.draw(); + } + public String focusedTextureId() { if (focusedRecord == null) return null; return getTextureId(focusedRecord); @@ -120,33 +146,9 @@ public void drawPolyhedron(DrawContext context, int quadIndex, int argb1, int ar drawQuad(context, reversed, argb1, 1100); } - public void drawNormal(DrawContext context, float u, float v, int length, int argb) { + public void drawNormal(DrawContext context, float u, float v, int length, int argb) { Vertex[] quad; if (currentRecord == null || (quad = getQuad(currentRecord, u, v)) == null) return; drawNormal(context, getPos(quad, u, v), quad[0].normal(), length, argb); } - - private static boolean intersects(Vertex[] quad, List quads) { - final float precision = 0.00001f; - for (Vertex[] q : quads) for (Vertex v1 : quad) - for (Vertex v2 : q) if (v1.pos().squaredDistanceTo(v2.pos()) < precision) return true; - return false; - } - - private static void drawQuad(DrawContext context, Vertex[] quad, int argb, int offset) { - VertexConsumer vertexConsumer = context.getVertexConsumers().getBuffer(RenderLayer.getGui()); - for (Vertex vertex : quad) vertexConsumer.vertex(vertex.x(), vertex.y(), vertex.z() + offset).color(argb).next(); - if (quad.length == 3) vertexConsumer.vertex(quad[2].x(), quad[2].y(), quad[2].z() + offset).color(argb).next(); - context.draw(); - } - - private static void drawNormal(DrawContext context, Vec3d start, Vec3d normal, int length, int argb) { - Vec3d end = normal.multiply(length).add(start); - VertexConsumer vertexConsumer = context.getVertexConsumers().getBuffer(RenderLayer.getLineStrip()); - vertexConsumer.vertex(start.getX(), start.getY(), start.getZ() + 1200f).color(argb) - .normal((float) normal.getX(), (float) normal.getY(), (float) normal.getZ()).next(); - vertexConsumer.vertex(end.getX(), end.getY(), end.getZ() + 1200f).color(argb) - .normal((float) normal.getX(), (float) normal.getY(), (float) normal.getZ()).next(); - context.draw(); - } } 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 36ed7c6..43ec766 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java @@ -38,12 +38,12 @@ public class ModelViewScreen extends Screen { private float xRot, yRot; private String focusedTextureId; private Vec2f focusedUV; - private NumberFieldWidget forwardUField, forwardVField, upwardUField, upwardVField, posUField, posVField, scaleField, depthField; private TextFieldWidget textureIdField, nameField; + private NumberFieldWidget forwardUField, forwardVField, upwardUField, upwardVField, posUField, posVField, scaleField, depthField; private final CyclingButtonWidget selectingButton = createCyclingButton(Map.of( - 0, Text.translatable(KEY_WIDGET + "forwardMode").styled(s -> s.withColor(Formatting.GREEN)), - 1, Text.translatable(KEY_WIDGET + "upwardMode").styled(s -> s.withColor(Formatting.RED)), - 2, Text.translatable(KEY_WIDGET + "posMode").styled(s -> s.withColor(Formatting.BLUE))), + 0, Text.translatable(KEY_WIDGET + "forwardMode").styled(s -> s.withColor(Formatting.GREEN)), + 1, Text.translatable(KEY_WIDGET + "upwardMode").styled(s -> s.withColor(Formatting.RED)), + 2, Text.translatable(KEY_WIDGET + "posMode").styled(s -> s.withColor(Formatting.BLUE))), widgetWidth * 2 + 4, Text.translatable(KEY_WIDGET + "selectMode")); private final CyclingTexturedButton pauseButton = new CyclingTexturedButton(0, 0, 2); private final CyclingTexturedButton bindXButton = new CyclingTexturedButton(16, 0, 2); @@ -117,7 +117,7 @@ private void initLeftWidgets(final int category) { adder.add(upwardVField, 1, smallPositioner); adder.add(posUField, 1, smallPositioner); adder.add(posVField, 1, smallPositioner); - adder.add(textureIdField,2, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "textureId"))); + adder.add(textureIdField, 2, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "textureId"))); } else if (category == 1) { Positioner sliderPositioner = gridWidget.copyPositioner().margin(-20, 2, 0, 0); adder.add(bindXButton, 1, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "bindButtons"))); @@ -128,8 +128,8 @@ private void initLeftWidgets(final int category) { adder.add(offsetZSlider, 1, sliderPositioner); adder.add(bindRotButton, 1, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "bindButtons"))); adder.add(pitchSlider, 1, sliderPositioner); - adder.add(yawSlider,2, gridWidget.copyPositioner().margin(26, 2, 0, 0)); - adder.add(rollSlider,2, gridWidget.copyPositioner().margin(26, 2, 0, 0)); + adder.add(yawSlider, 2, gridWidget.copyPositioner().margin(26, 2, 0, 0)); + adder.add(rollSlider, 2, gridWidget.copyPositioner().margin(26, 2, 0, 0)); adder.add(scaleField, 1, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "scale"))); adder.add(depthField, 1, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "depth"))); } @@ -143,7 +143,7 @@ private void initLeftWidgets(final int category) { ConfigFile.save(); initWidgets(category, page); })).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "bind", "Auto Bind"))); - adder.add(nameField = createTextField(widgetWidth * 2 + 4, nameField),2, smallPositioner) + adder.add(nameField = createTextField(widgetWidth * 2 + 4, nameField), 2, smallPositioner) .setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "listName"))); nameField.setMaxLength(20); gridWidget.refreshPositions(); @@ -194,10 +194,10 @@ public void renderBackground(DrawContext context) { } protected void drawEntity(DrawContext context, int x1, int y1, int x2, int y2, int mouseX, int mouseY, LivingEntity entity) { - float centerX = (float)(x1 + x2) / 2.0f; - float centerY = (float)(y1 + y2) / 2.0f; + float centerX = (float) (x1 + x2) / 2.0f; + float centerY = (float) (y1 + y2) / 2.0f; context.enableScissor(x1, y1, x2, y2); - Quaternionf quaternionf = new Quaternionf().rotateX((float) Math.PI/6 + xRot).rotateY((float) Math.PI/6 + yRot).rotateZ((float) Math.PI); + Quaternionf quaternionf = new Quaternionf().rotateX((float) Math.PI / 6 + xRot).rotateY((float) Math.PI / 6 + yRot).rotateZ((float) Math.PI); float entityBodyYaw = entity.bodyYaw; float entityYaw = entity.getYaw(); float entityPitch = entity.getPitch(); @@ -248,15 +248,15 @@ protected void drawEntity(DrawContext context, float x, float y, int mouseX, int } protected BindingTarget generateBindingTarget() { - return new BindingTarget(nameField.getText(), textureIdField.getText(), forwardUField.getValue(), - forwardVField.getValue(), upwardUField.getValue(), upwardVField.getValue(), posUField.getValue(), posVField.getValue(), + return new BindingTarget(nameField.getText(), textureIdField.getText(), forwardUField.getValue(), forwardVField.getValue(), upwardUField.getValue(), + upwardVField.getValue(), posUField.getValue(), posVField.getValue(), depthField.getValue(), bindXButton.getValue() == 0, bindYButton.getValue() == 0, bindZButton.getValue() == 0, bindRotButton.getValue() == 0, scaleField.getValue(), offsetXSlider.getValue(), offsetYSlider.getValue(), offsetZSlider.getValue(), - (float) pitchSlider.getValue(), (float) yawSlider.getValue(), (float) rollSlider.getValue(), depthField.getValue()); + (float) pitchSlider.getValue(), (float) yawSlider.getValue(), (float) rollSlider.getValue()); } protected void loadBindingTarget(BindingTarget target) { - if (target.name() == null) return; + if (target.isEmpty()) return; nameField.setText(target.name()); textureIdField.setText(target.textureId()); forwardUField.setValue(target.forwardU()); @@ -265,6 +265,7 @@ protected void loadBindingTarget(BindingTarget target) { upwardVField.setValue(target.upwardV()); posUField.setValue(target.posU()); posVField.setValue(target.posV()); + depthField.setValue(target.disablingDepth()); scaleField.setValue((float) target.scale()); bindXButton.setValue(target.bindX() ? 0 : 1); offsetXSlider.setValue(target.offsetX()); @@ -276,7 +277,6 @@ protected void loadBindingTarget(BindingTarget target) { pitchSlider.setValue(target.pitch()); yawSlider.setValue(target.yaw()); rollSlider.setValue(target.roll()); - depthField.setValue(target.disablingDepth()); } private ButtonWidget createButton(Text message, int width, ButtonWidget.PressAction onPress) { @@ -356,4 +356,6 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) { public boolean shouldPause() { return pauseButton.getValue() == 1; } + + } 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 42654f2..4b7cb90 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/NumberFieldWidget.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/NumberFieldWidget.java @@ -12,8 +12,8 @@ public abstract class NumberFieldWidget> extends TextFieldWidget { private final T defaultValue; - private Tooltip tooltip; protected T maximum, minimum; + private Tooltip tooltip; NumberFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, T defaultValue, T maximum, T minimum, @Nullable NumberFieldWidget copyFrom, Text text) { super(textRenderer, x, y, width, height, text); diff --git a/common/src/main/java/com/xtracr/realcamera/gui/TexturedButton.java b/common/src/main/java/com/xtracr/realcamera/gui/TexturedButton.java index 3b18c31..ee4b4d7 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/TexturedButton.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/TexturedButton.java @@ -11,9 +11,9 @@ public class TexturedButton extends PressableWidget { private static final Identifier ICON_TEXTURE = new Identifier(RealCamera.MODID, "textures/gui/icon.png"); - private final Consumer onPress; protected final Identifier texture; protected final int textureWidth, textureHeight; + private final Consumer onPress; protected int u, v; public TexturedButton(int u, int v, Consumer onPress) { @@ -25,7 +25,7 @@ public TexturedButton(int x, int y, int width, int height, int u, int v, Consume } public TexturedButton(int x, int y, int width, int height, int u, int v, Identifier texture, - int textureWidth, int textureHeight, Consumer onPress, Text message) { + int textureWidth, int textureHeight, Consumer onPress, Text message) { super(x, y, width, height, message); this.textureWidth = textureWidth; this.textureHeight = textureHeight; @@ -35,11 +35,6 @@ public TexturedButton(int x, int y, int width, int height, int u, int v, Identif this.texture = texture; } - public void setUV(int u, int v) { - this.u = u; - this.v = v; - } - @Override public void onPress() { onPress.accept(this); 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 ae00dca..210f9ee 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java @@ -35,7 +35,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) { + float tickDelta, CallbackInfo cInfo) { if (!RealCameraCore.isActive()) return; final ModConfig config = ConfigFile.modConfig; Vec3d startVec = pos; @@ -80,7 +80,7 @@ public abstract class MixinCamera { } setPos(startVec.add(offset)); } - + @Shadow protected abstract void moveBy(double x, double y, double z); diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinEntityRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinEntityRenderer.java index abd3799..50f52bf 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinEntityRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinEntityRenderer.java @@ -15,7 +15,7 @@ public abstract class MixinEntityRenderer { @Inject(method = "shouldRender", at = @At("HEAD"), cancellable = true) private void realCamera$onShouldRenderHEAD(T entity, Frustum frustum, double x, double y, double z, - CallbackInfoReturnable cInfo) { + CallbackInfoReturnable cInfo) { if (ConfigFile.modConfig.isRendering() && RealCameraCore.isActive() && entity instanceof ClientPlayerEntity) { cInfo.setReturnValue(true); } 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 0cbd5ec..1ccc4ca 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java @@ -26,7 +26,8 @@ public abstract class MixinGameRenderer { @Shadow @Final MinecraftClient client; - @Shadow @Final private Camera camera; + @Shadow + @Final private Camera camera; @ModifyVariable(method = "updateTargetedEntity", at = @At("STORE"), ordinal = 0) private EntityHitResult realCamera$modifyEntityHitResult(EntityHitResult entityHitResult) { 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 255a299..e770ab1 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinHeldItemRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinHeldItemRenderer.java @@ -25,7 +25,7 @@ public abstract class MixinHeldItemRenderer { @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) { + ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo cInfo) { ModConfig config = ConfigFile.modConfig; if (player instanceof ClientPlayerEntity && RealCameraCore.isActive() && config.isRendering() && !config.shouldDisableRendering(client) && !config.allowRenderingHand(client)) { 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 6be6705..bd2cdfe 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinItem.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinItem.java @@ -17,7 +17,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) { + CallbackInfoReturnable cInfo) { if (!ConfigFile.modConfig.isCrosshairDynamic() && 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/MixinPlayerEntityRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinPlayerEntityRenderer.java index f899415..8d63f84 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinPlayerEntityRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinPlayerEntityRenderer.java @@ -15,7 +15,7 @@ public abstract class MixinPlayerEntityRenderer extends LivingEntityRenderer> { public MixinPlayerEntityRenderer(Context ctx, PlayerEntityModel model, - float shadowRadius) { + float shadowRadius) { super(ctx, model, shadowRadius); } diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinPlayerHeldItemFeatureRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinPlayerHeldItemFeatureRenderer.java index 91316fc..636a1e6 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinPlayerHeldItemFeatureRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinPlayerHeldItemFeatureRenderer.java @@ -17,7 +17,7 @@ public abstract class MixinPlayerHeldItemFeatureRenderer { @Inject(method = "renderItem", at = @At("HEAD"), cancellable = true) private void realCamera$onRenderItemHEAD(LivingEntity entity, ItemStack stack, ModelTransformationMode transformationMode, - Arm arm, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo cInfo) { + Arm arm, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo cInfo) { if (VirtualRenderer.shouldDisableRender("heldItem")) 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 0681e67..7781378 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinWorldRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinWorldRenderer.java @@ -24,9 +24,9 @@ public abstract class MixinWorldRenderer { @Final private BufferBuilderStorage bufferBuilders; @Inject(method = "render", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;drawCurrentLayer()V", ordinal = 0)) + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;drawCurrentLayer()V", ordinal = 0)) private void realcamera$renderClientPlayer(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, - Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f projectionMatrix, CallbackInfo cInfo) { + Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f projectionMatrix, CallbackInfo cInfo) { ModConfig config = ConfigFile.modConfig; if (camera.isThirdPerson() || !RealCameraCore.isActive() || !config.isRendering() || config.shouldDisableRendering(this.client)) return; VertexConsumerProvider.Immediate immediate = this.bufferBuilders.getEntityVertexConsumers(); diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/PlayerEntityRendererAccessor.java b/common/src/main/java/com/xtracr/realcamera/mixin/PlayerEntityRendererAccessor.java index 04ce47d..7bb78ca 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/PlayerEntityRendererAccessor.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/PlayerEntityRendererAccessor.java @@ -16,5 +16,5 @@ public interface PlayerEntityRendererAccessor { @Invoker void invokeSetupTransforms(AbstractClientPlayerEntity abstractClientPlayerEntity, MatrixStack matrixStack, - float f, float bodyYaw, float tickDelta); + float f, float bodyYaw, float tickDelta); } 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 e958844..e0ea53c 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java +++ b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java @@ -24,6 +24,32 @@ public class VertexRecorder implements VertexConsumerProvider { protected BuiltRecord currentRecord; private VertexRecord lastRecord; + protected static Vertex[] getQuad(BuiltRecord record, float u, float v) { + final int resolution = 1000000; + for (Vertex[] quad : record.vertices) { + Polygon polygon = new Polygon(); + for (Vertex vertex : quad) polygon.addPoint((int) (resolution * vertex.u), (int) (resolution * vertex.v)); + if (polygon.contains(resolution * u, resolution * v)) return quad; + } + return null; + } + + protected static Vec3d getPos(Vertex[] quad, float u, float v) { + if (quad.length < 3) return quad[0].pos(); + float u0 = quad[0].u, v0 = quad[0].v, u1 = quad[1].u, v1 = quad[1].v, u2 = quad[2].u, v2 = quad[2].v; + float alpha = ((u - u1) * (v1 - v2) - (v - v1) * (u1 - u2)) / ((u0 - u1) * (v1 - v2) - (v0 - v1) * (u1 - u2)), + beta = ((u - u2) * (v2 - v0) - (v - v2) * (u2 - u0)) / ((u1 - u2) * (v2 - v0) - (v1 - v2) * (u2 - u0)); + return quad[0].pos().multiply(alpha).add(quad[1].pos().multiply(beta)).add(quad[2].pos().multiply(1 - alpha - beta)); + } + + protected static String getTextureId(BuiltRecord record) { + String name = record.renderLayer.toString(); + Pattern pattern = Pattern.compile("texture\\[Optional\\[(.*?)]"); + Matcher matcher = pattern.matcher(name); + if (matcher.find()) return matcher.group(1); + return name; + } + public void clear() { records.clear(); currentRecord = null; @@ -94,32 +120,6 @@ public void drawByAnother(VertexConsumerProvider anotherProvider, Predicate