Skip to content

Commit

Permalink
Improved default configs and reformatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed Mar 1, 2024
1 parent b146c62 commit 1220a5a
Show file tree
Hide file tree
Showing 28 changed files with 465 additions and 547 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##

Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

## 特性 ##

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
101 changes: 29 additions & 72 deletions common/src/main/java/com/xtracr/realcamera/config/BindingTarget.java
Original file line number Diff line number Diff line change
@@ -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<BindingTarget> 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;
Expand All @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())));
Expand Down Expand Up @@ -299,7 +299,6 @@ private void clamp() {
}

public static class Binding {
protected static final List<BindingTarget> defaultTargets = List.of(BindingTarget.MINECRAFT_HEAD, BindingTarget.MINECRAFT_HEAD_2);
public VanillaModelPart vanillaModelPart = VanillaModelPart.head;
public boolean experimental = false;
public boolean adjustOffset = true;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
52 changes: 27 additions & 25 deletions common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@
public class ModelAnalyser extends VertexRecorder {
private BuiltRecord focusedRecord;

private static boolean intersects(Vertex[] quad, List<Vertex[]> 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);
Expand Down Expand Up @@ -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<Vertex[]> 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();
}
}
Loading

0 comments on commit 1220a5a

Please sign in to comment.