Skip to content

Commit 85e0613

Browse files
committed
Fixed #88, #89 and #90
1 parent 1aac5fc commit 85e0613

13 files changed

+100
-46
lines changed

README.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@ Snapshots are [here](https://github.com/xTracr/RealCamera/actions/workflows/buil
1414
* Render player model in first-person perspective.
1515
* Use F6 to toggle the feature on or off and other hotkeys to adjust the camera.
1616
* Configure these features in the config screen (Cloth Config required).
17+
18+
### Configuration (0.6+) ###
19+
1720
* Theoretically, most mod models are supported, but need to be configured manually:
18-
* First, set the key binding for `Open Model View Screen`.
19-
* Open the model view gui and left click with left Alt held to select the corresponding face of the model, scroll with left Alt held to switch between the different layers of the model.
20-
* By clicking the `Selecting` button on the left, switch between the three to select the `Forward Vector`, `Upward Vector`, and `Target Plane`.
21-
* Enter the `Preview` section, where you can see the relative relationship between the camera and the model and make certain adjustments (you can also adjust through key bindings).
22-
* Enter a name and save (if needed, other settings such as priority can be changed).
21+
* First, set the key binding for `Open Model View Screen`.
22+
* ![model view screen](https://cdn.modrinth.com/data/fYYSAh4R/images/cc484d54238992077ab3632c274a2631efeca35f.png)
23+
* Open the model view screen and left click with left Alt held to select the corresponding face of the model, scroll with left Alt held to switch between the different layers of the model.
24+
* By clicking the `Selecting` button on the left, switch between the three to select the `Forward Vector`, `Upward Vector`, and `Target Plane`.
25+
* Enter the `Preview` section, where you can see the relative relationship between the camera and the model and make certain adjustments (you can also adjust through key bindings).
26+
* ![preview](https://cdn.modrinth.com/data/fYYSAh4R/images/22cfcf444bbf2d3c0d0280e470a29f01b9308617.png)
27+
* Enter a name and save (if needed, other settings such as priority can be changed).
2328

24-
### Dependencies ###
29+
## Dependencies ##
2530

2631
* Fabric:
2732
* [Fabric API](https://modrinth.com/mod/fabric-api)
28-
* 所有平台:
33+
* Both:
2934
* (Optional but recommended) [Cloth Config API](https://modrinth.com/mod/cloth-config)
3035

3136
## FAQ ##

README_ZH.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@
1414
* 在第一人称视角下渲染玩家模型
1515
* 按下F6来开关,另外一些键来调整摄像头
1616
* 在配置界面配置以上特性(需Cloth Config)
17+
18+
### 配置 ###
19+
1720
* 理论上支持大多数模组模型,但需要手动进行配置:
18-
* 首先设置`打开模型视图界面`的按键绑定
19-
* 打开模型视图界面,左Alt+左键选择模型的对应的面,左Alt+滚轮可以在模型的不同层间切换
20-
* 通过点击左侧的`选择`按钮,在三者间切换,选好`向前矢量``向上矢量``目标平面`
21-
* 进入`预览`部分,在这里可以看到摄像头与模型的相对关系并进行一定的调整(也可以通过按键绑定调整)
22-
* 输入名称并保存(如果需要,还有其他设置如优先级可以更改)
21+
* 首先设置`打开模型视图界面`的按键绑定
22+
* ![model view screen](https://cdn.modrinth.com/data/fYYSAh4R/images/cc484d54238992077ab3632c274a2631efeca35f.png)
23+
* 打开模型视图界面,左Alt+左键选择模型的对应的面,左Alt+滚轮可以在模型的不同层间切换
24+
* 通过点击左侧的`选择`按钮,在三者间切换,选好`向前矢量``向上矢量``目标平面`
25+
* 进入`预览`部分,在这里可以看到摄像头与模型的相对关系并进行一定的调整(也可以通过按键绑定调整)
26+
* ![preview](https://cdn.modrinth.com/data/fYYSAh4R/images/22cfcf444bbf2d3c0d0280e470a29f01b9308617.png)
27+
* 输入名称并保存(如果需要,还有其他设置如优先级可以更改)
2328

24-
### 依赖项目 ###
29+
## 依赖项目 ##
2530

2631
* Fabric:
2732
* [Fabric API](https://modrinth.com/mod/fabric-api)
28-
* Both:
33+
* 所有平台:
2934
* (可选但建议)[Cloth Config API](https://modrinth.com/mod/cloth-config)
3035

3136
## 常见问题 ##

common/src/main/java/com/xtracr/realcamera/RealCameraCore.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ public static void renderCameraEntity(MultiBufferSource bufferSource, Matrix4f p
105105
final double depth = currentTarget.disablingDepth;
106106
for (VertexRecorder.Vertex[] primitive : record.primitives()) {
107107
for (VertexRecorder.Vertex vertex : primitive) {
108-
if (Math.fma(m02, vertex.x(), Math.fma(m12, vertex.y(), Math.fma(m22, vertex.z(), m32))) < -depth) {
109-
VertexRecorder.renderVertices(primitive, buffer, positionMatrix, normalMatrix);
110-
break;
111-
}
108+
if (Math.fma(m02, vertex.x(), Math.fma(m12, vertex.y(), Math.fma(m22, vertex.z(), m32))) > -depth) continue;
109+
VertexRecorder.renderVertices(primitive, buffer, positionMatrix, normalMatrix);
110+
break;
112111
}
113112
}
114113
});

common/src/main/java/com/xtracr/realcamera/compat/CompatibilityHelper.java

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.xtracr.realcamera.compat;
22

33
import com.xtracr.realcamera.RealCameraCore;
4+
import net.minecraft.world.item.ItemStack;
45

56
import java.lang.reflect.Field;
67
import java.lang.reflect.Method;
@@ -9,6 +10,7 @@
910
public class CompatibilityHelper {
1011
private static Class<?> NEA_NEAnimationsLoader = null;
1112
private static Method NEA_playerTransformer_setDeltaTick = null;
13+
protected static Method Exposure_CameraItem_isActive = null;
1214

1315
@SuppressWarnings("unchecked")
1416
public static void initialize() {
@@ -26,6 +28,11 @@ public static void initialize() {
2628
NEA_playerTransformer_setDeltaTick = NEA_PlayerTransformer.getDeclaredMethod("setDeltaTick", float.class);
2729
} catch (Exception ignored) {
2830
}
31+
if (isClassLoaded("io.github.mortuusars.exposure.Exposure")) try {
32+
Class<?> Exposure_CameraItem = Class.forName("io.github.mortuusars.exposure.item.CameraItem");
33+
Exposure_CameraItem_isActive = Exposure_CameraItem.getDeclaredMethod("isActive", ItemStack.class);
34+
} catch (Exception ignored) {
35+
}
2936
}
3037

3138
public static void NEA_setDeltaTick(float tickDelta) {

common/src/main/java/com/xtracr/realcamera/compat/DisableHelper.java

+14
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,33 @@
55
import net.minecraft.world.entity.Entity;
66
import net.minecraft.world.entity.LivingEntity;
77
import net.minecraft.world.entity.player.Player;
8+
import net.minecraft.world.item.ItemStack;
89

910
import java.util.HashMap;
1011
import java.util.Map;
1112
import java.util.function.Predicate;
1213

1314
public class DisableHelper {
1415
private static final Map<String, Predicate<LivingEntity>> predicates = new HashMap<>();
16+
private static final String EXPOSURE_CAMERA = "exposure:camera";
1517

1618
public static void initialize() {
1719
registerOr("mainFeature", LivingEntity::isSleeping);
1820
registerOr("renderModel", entity -> entity instanceof Player player && player.isScoping());
1921
registerOr("renderModel", entity -> ConfigFile.config().getDisableRenderItems().contains(BuiltInRegistries.ITEM.getKey(entity.getMainHandItem().getItem()).toString()));
2022
registerOr("renderModel", entity -> ConfigFile.config().getDisableRenderItems().contains(BuiltInRegistries.ITEM.getKey(entity.getOffhandItem().getItem()).toString()));
23+
registerOr("renderModel", entity -> {
24+
if (CompatibilityHelper.Exposure_CameraItem_isActive == null) return false;
25+
final ItemStack itemStack;
26+
if (EXPOSURE_CAMERA.equals(BuiltInRegistries.ITEM.getKey(entity.getMainHandItem().getItem()).toString())) itemStack = entity.getMainHandItem();
27+
else if (EXPOSURE_CAMERA.equals(BuiltInRegistries.ITEM.getKey(entity.getOffhandItem().getItem()).toString())) itemStack = entity.getOffhandItem();
28+
else return false;
29+
try {
30+
return (boolean) CompatibilityHelper.Exposure_CameraItem_isActive.invoke(itemStack.getItem(), itemStack);
31+
} catch (Exception ignored) {
32+
return false;
33+
}
34+
});
2135
}
2236

2337
public static void registerOr(String type, Predicate<LivingEntity> predicate) {

common/src/main/java/com/xtracr/realcamera/config/BindingTarget.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import java.util.List;
66

77
public class BindingTarget {
8-
protected static final List<BindingTarget> defaultTargets = List.of(createDefaultTarget("minecraft_head", "minecraft:textures/entity/player/", 5, false),
9-
createDefaultTarget("skin_head", "minecraft:skins/", 5, false),
10-
createDefaultTarget("minecraft_head_2", "minecraft:textures/entity/player/", 0, true),
11-
createDefaultTarget("skin_head_2", "minecraft:skins/", 0, true));
8+
protected static final List<BindingTarget> defaultTargets = List.of(vanillaTarget("minecraft_head", 5, false).offsetX(-0.1),
9+
vanillaTarget("skin_head", 5, false).offsetX(-0.1),
10+
vanillaTarget("minecraft_head_2", 1, true).offsetX(-0.1),
11+
vanillaTarget("skin_head_2", 1, true).offsetX(-0.1),
12+
vanillaTarget("minecraft_head_3", 0, true).offsetX(-0.06).offsetY(-0.08).disablingDepth(0.08f),
13+
vanillaTarget("skin_head_3", 0, true).offsetX(-0.06).offsetY(-0.08).disablingDepth(0.08f));
1214
public final String name, textureId;
1315
public int priority = 0;
1416
public float forwardU = 0, forwardV = 0, upwardU = 0, upwardV = 0, posU = 0, posV = 0, disablingDepth = 0.2f;
@@ -26,13 +28,12 @@ public BindingTarget(String name, String textureId) {
2628
this.textureId = textureId;
2729
}
2830

29-
private static BindingTarget createDefaultTarget(String name, String textureId, int priority, boolean shouldBind) {
30-
return new BindingTarget(name, textureId).priority(priority)
31+
private static BindingTarget vanillaTarget(String name, int priority, boolean shouldBind) {
32+
return new BindingTarget(name, name.contains("skin") ? "minecraft:skins/" : "minecraft:textures/entity/player/").priority(priority)
3133
.forwardU(0.1875f).forwardV(0.2f)
3234
.upwardU(0.1875f).upwardV(0.075f)
3335
.posU(0.1875f).posV(0.2f)
3436
.bindX(shouldBind).bindZ(shouldBind).bindRotation(shouldBind)
35-
.offsetX(-0.1)
3637
.disabledTextureIds(List.of("minecraft:textures/entity/enderdragon/dragon.png"));
3738
}
3839

common/src/main/java/com/xtracr/realcamera/config/ModConfig.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ public static class Binding {
214214
protected static final List<String> defaultDisableRenderItems = List.of("minecraft:filled_map");
215215
public boolean adjustOffset = true;
216216
public boolean renderStuckObjects = true;
217-
public List<String> disableRenderItems = new ArrayList<>(defaultDisableRenderItems);
217+
public List<String> disableRenderItems = defaultDisableRenderItems;
218218
public List<BindingTarget> targetList = new ArrayList<>(BindingTarget.defaultTargets);
219219

220220
private void clamp() {
221-
if (disableRenderItems == null) disableRenderItems = new ArrayList<>();
221+
if (disableRenderItems == null) disableRenderItems = List.of();
222222
if (targetList == null || targetList.isEmpty()) targetList = new ArrayList<>(BindingTarget.defaultTargets);
223223
}
224224
}

common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private void initRightWidgets(final int category, final int page) {
227227
@Override
228228
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
229229
super.render(graphics, mouseX, mouseY, delta);
230-
drawEntity(graphics, x + (xSize - ySize) / 2, y, x + (xSize + ySize) / 2, y + ySize, mouseX, mouseY, minecraft.player);
230+
renderEntityInViewArea(graphics, x + (xSize - ySize) / 2, y, x + (xSize + ySize) / 2, y + ySize, mouseX, mouseY, minecraft.player);
231231
}
232232

233233
@Override
@@ -238,7 +238,7 @@ public void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, float
238238
graphics.fill(x + (xSize + ySize) / 2 + 4, y, x + xSize, y + ySize, 0xFF444444);
239239
}
240240

241-
protected void drawEntity(GuiGraphics graphics, int x1, int y1, int x2, int y2, int mouseX, int mouseY, LivingEntity entity) {
241+
protected void renderEntityInViewArea(GuiGraphics graphics, int x1, int y1, int x2, int y2, int mouseX, int mouseY, LivingEntity entity) {
242242
float centerX = (float) (x1 + x2) / 2.0f;
243243
float centerY = (float) (y1 + y2) / 2.0f;
244244
graphics.enableScissor(x1, y1, x2, y2);
@@ -254,7 +254,7 @@ protected void drawEntity(GuiGraphics graphics, int x1, int y1, int x2, int y2,
254254
entity.yHeadRot = entity.getYRot();
255255
entity.yHeadRotO = entity.getYRot();
256256
Vector3f vector3f = new Vector3f((float) entityX, (float) entityY, -2.0f);
257-
drawEntity(graphics, centerX, centerY, mouseX, mouseY, vector3f, quaternionf, entity);
257+
renderEntityWithAnalyser(graphics, centerX, centerY, mouseX, mouseY, vector3f, quaternionf, entity);
258258
entity.yBodyRot = entityBodyYaw;
259259
entity.setYRot(entityYaw);
260260
entity.setXRot(entityPitch);
@@ -263,7 +263,7 @@ protected void drawEntity(GuiGraphics graphics, int x1, int y1, int x2, int y2,
263263
graphics.disableScissor();
264264
}
265265

266-
protected void drawEntity(GuiGraphics graphics, float x, float y, int mouseX, int mouseY, Vector3f offset, Quaternionf quaternionf, LivingEntity entity) {
266+
protected void renderEntityWithAnalyser(GuiGraphics graphics, float x, float y, int mouseX, int mouseY, Vector3f offset, Quaternionf quaternionf, LivingEntity entity) {
267267
graphics.pose().pushPose();
268268
graphics.pose().translate(x, y, 0);
269269
graphics.pose().mulPose(new Matrix4f().scaling(entitySize, entitySize, -entitySize));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.xtracr.realcamera.mixin;
2+
3+
import net.minecraft.client.renderer.GameRenderer;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.gen.Accessor;
6+
7+
@Mixin(GameRenderer.class)
8+
public interface GameRendererAccessor {
9+
@Accessor
10+
float getFov();
11+
12+
@Accessor
13+
float getOldFov();
14+
}

common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.xtracr.realcamera.config.ConfigFile;
55
import com.xtracr.realcamera.config.ModConfig;
66
import net.minecraft.client.Camera;
7+
import net.minecraft.client.Minecraft;
78
import net.minecraft.util.Mth;
89
import net.minecraft.world.entity.Entity;
910
import net.minecraft.world.entity.LivingEntity;
@@ -55,14 +56,14 @@ public abstract class MixinCamera {
5556
setPosition(prevPos);
5657
setRotation(RealCameraCore.getYaw(yRot), RealCameraCore.getPitch(xRot));
5758
}
58-
realcamera$clipToSpace(startVec);
59+
realcamera$clipToSpace(startVec, realcamera$getFov(tickDelta));
5960
RealCameraCore.setCameraPos(position);
6061
}
6162

6263
@Unique
63-
private void realcamera$clipToSpace(Vec3 startVec) {
64+
private void realcamera$clipToSpace(Vec3 startVec, double fov) {
6465
Vec3 offset = position.subtract(startVec);
65-
final float depth = 0.085f;
66+
final float depth = 0.05f + (float) (fov * (0.0001 + 0.000005 * fov));
6667
for (int i = 0; i < 8; ++i) {
6768
float f = depth * ((i & 1) * 2 - 1);
6869
float g = depth * ((i >> 1 & 1) * 2 - 1);
@@ -77,6 +78,13 @@ public abstract class MixinCamera {
7778
setPosition(startVec.add(offset));
7879
}
7980

81+
@Unique
82+
private static float realcamera$getFov(float tickDelta) {
83+
Minecraft client = Minecraft.getInstance();
84+
float multiplier = Mth.lerp(tickDelta, ((GameRendererAccessor) client.gameRenderer).getOldFov(), ((GameRendererAccessor) client.gameRenderer).getFov());
85+
return client.options.fov().get() * multiplier;
86+
}
87+
8088
@Shadow
8189
protected abstract void move(float x, float y, float z);
8290

common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public void buildRecords() {
6060
public BuiltRecord getTargetPosAndRot(BindingTarget target, Matrix3f normal, Vector3f position, boolean mirrored) {
6161
return records.stream().map(record -> {
6262
if (!record.textureId().contains(target.textureId)) return null;
63-
Vec3 forward = getPrimitive(record, target.forwardU, target.forwardV)[0].normal().normalize();
64-
Vec3 left = getPrimitive(record, target.upwardU, target.upwardV)[0].normal().cross(forward).normalize();
63+
Vec3 forward = getPrimitive(record, target.forwardU, target.forwardV)[0].normal();
64+
Vec3 left = getPrimitive(record, target.upwardU, target.upwardV)[0].normal().cross(forward);
6565
Vertex[] face = getPrimitive(record, target.posU, target.posV);
6666
if (face[0].normal().equals(Vec3.ZERO) && forward.equals(Vec3.ZERO) && left.equals(Vec3.ZERO)) return null;
6767
normal.set(left.scale(mirrored ? -1 : 1).toVector3f(), forward.cross(left).toVector3f(), forward.toVector3f());
@@ -194,7 +194,7 @@ public Vec3 pos() {
194194
}
195195

196196
public Vec3 normal() {
197-
return new Vec3(normalX, normalY, normalZ);
197+
return new Vec3(normalX, normalY, normalZ).normalize();
198198
}
199199

200200
public void render(VertexConsumer buffer, Matrix4f positionMatrix, Matrix3f normalMatrix) {

common/src/main/resources/realcamera-common.mixins.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
],
88
"client": [
99
"CameraAccessor",
10+
"GameRendererAccessor",
1011
"MixinCamera",
11-
"MixinLocalPlayer",
1212
"MixinGameRenderer",
13-
"MixinItemInHandRenderer",
1413
"MixinGui",
1514
"MixinItem",
16-
"MixinStuckInBodyLater",
17-
"MixinLevelRenderer"
15+
"MixinItemInHandRenderer",
16+
"MixinLevelRenderer",
17+
"MixinLocalPlayer",
18+
"MixinStuckInBodyLater"
1819
],
1920
"server": [
2021
],

gradle.properties

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ org.gradle.parallel=true
55
minecraft_version=1.21
66
enabled_platforms=fabric,neoforge
77
fabric_loader_version=0.15.11
8-
neoforge_version=21.0.1-beta
9-
#yarn_mappings=1.21+build.1
8+
neoforge_version=21.0.83-beta
9+
#yarn_mappings=1.21+build.7
1010
# Mod Properties
11-
mod_version=0.6.1-beta
11+
mod_version=0.6.2-beta.1
1212
maven_group=com.xtracr.realcamera
1313
archives_base_name=realcamera
1414
# Dependencies
15-
fabric_api_version=0.100.1+1.21
15+
fabric_api_version=0.100.6+1.21
1616
cloth_config_version=15.0.127
17-
modmenu_version=11.0.0-beta.1
17+
modmenu_version=11.0.1

0 commit comments

Comments
 (0)