Skip to content

Commit

Permalink
Update to 0.5.5-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed Dec 19, 2023
1 parent eb005c6 commit 6f09695
Show file tree
Hide file tree
Showing 22 changed files with 231 additions and 234 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
* 0.5.4-beta:
* Added feature #15, fixed #35
* Changed the way of clipping to space to avoid #23 and #32
* 0.5.5-beta:
* Changed the way of clipping to space to avoid #37
* Deleted the option of disabling "clip to space"
* Separate the part that modifies camera from the part that computes it

* 0.4.0-alpha:
* Fixed an issue where the camera would not follow the model action when the player started/ended sneaking
Expand Down Expand Up @@ -99,6 +103,10 @@
* 0.5.4-beta:
* 添加了功能#15, 修复#35
* 修改了clip to space的方式来避免#23#32
* 0.5.5-beta:
* 修改了clip to space的方式来避免#37
* 删除了禁用"clip to space"的选项
* 将修改摄像头的部分与计算它的部分分离开来

* 0.4.0-alpha:
* 修复了玩家开始/结束潜行时摄像头未跟上模型动作的问题
Expand Down
155 changes: 52 additions & 103 deletions common/src/main/java/com/xtracr/realcamera/RealCameraCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,95 @@
import com.xtracr.realcamera.compat.PhysicsModCompat;
import com.xtracr.realcamera.config.ConfigFile;
import com.xtracr.realcamera.config.ModConfig;
import com.xtracr.realcamera.mixins.CameraAccessor;
import com.xtracr.realcamera.mixins.PlayerEntityRendererAccessor;
import com.xtracr.realcamera.utils.MathUtils;
import com.xtracr.realcamera.utils.Matrix3fc;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.entity.PlayerEntityRenderer;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3f;
import net.minecraft.util.math.Vector4f;
import net.minecraft.world.RaycastContext;

public class RealCameraCore {
private static final ModConfig config = ConfigFile.modConfig;

private static String status = "Successful";
private static float cameraRoll = 0.0F;
private static float pitch = 0.0F;
private static float yaw = 0.0F;
private static float roll = 0.0F;
private static Vec3d pos = Vec3d.ZERO;
private static Vec3d modelOffset = Vec3d.ZERO;

public static String getStatus() {
return status;
}

public static float getPitch() {
return pitch;
}

public static float getYaw() {
return yaw;
}

public static float getRoll() {
return cameraRoll;
return roll;
}

public static boolean isActive() {
MinecraftClient client = MinecraftClient.getInstance();
return config.isEnabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null
&& client.player != null && !config.disableModWhen(client);
public static Vec3d getPos() {
return pos;
}

public static void updateCamera(Camera camera, MinecraftClient client, float tickDelta) {
cameraRoll = 0.0F;
public static Vec3d getModelOffset() {
return modelOffset;
}

if (config.isRendering() && !config.disableRenderingWhen(client)) {
((CameraAccessor) camera).setThirdPerson(true);
}
public static void setModelOffset(Vec3d vec3d) {
modelOffset = vec3d;
}

if (config.isClassic()) {
classicModeUpdate(camera, client, tickDelta);
} else {
// GameRenderer.render
bindingModeUpdate(camera, client, tickDelta, new MatrixStack());
}
public static boolean isActive() {
MinecraftClient client = MinecraftClient.getInstance();
return config.isEnabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null
&& client.player != null && !config.shouldDisableMod(client);
}

private static void classicModeUpdate(Camera camera, MinecraftClient client, float tickDelta) {
ClientPlayerEntity player = client.player;
public static void computeCamera(MinecraftClient client, float tickDelta) {
modelOffset = Vec3d.ZERO;
roll = config.getClassicRoll();
if (config.isClassic()) return;

float centerYaw = camera.getYaw();
float pitch = camera.getPitch() + config.getClassicPitch();
float yaw = centerYaw - config.getClassicYaw();
cameraRoll = config.getClassicRoll();
Vec3d offset = new Vec3d(config.getClassicX(), config.getClassicY(), config.getClassicZ()).multiply(config.getScale());
Vec3d center = new Vec3d(config.getCenterX(), config.getCenterY(), config.getCenterZ()).multiply(config.getScale());
// GameRenderer.renderWorld
MatrixStack matrixStack = new MatrixStack();
virtualRender(client, tickDelta, matrixStack);

if (player.isSneaking()) {
center = center.add(0.0D, -0.021875D, 0.0D);
}
if (config.compatPehkui()) {
offset = PehkuiCompat.scaleVec3d(offset, player, tickDelta);
center = PehkuiCompat.scaleVec3d(center, player, tickDelta);
}
// ModelPart$Cuboid.renderCuboid
Vector4f offset = new Vector4f((float)(config.getBindingZ() * config.getScale()),
-(float)(config.getBindingY() * config.getScale()),
-(float)(config.getBindingX() * config.getScale()), 1.0F);
offset.transform(matrixStack.peek().getPositionMatrix());
pos = new Vec3d(offset.getX(), offset.getY(), offset.getZ());

((CameraAccessor) camera).invokeSetRotation(centerYaw, 0.0F);
((CameraAccessor) camera).invokeMoveBy(center.getX(), center.getY(), center.getZ());
((CameraAccessor) camera).invokeSetRotation(yaw, pitch);
Vec3d referVec = camera.getPos();
((CameraAccessor) camera).invokeMoveBy(offset.getX(), offset.getY(), offset.getZ());
clipCameraToSpace(camera, referVec);
Matrix3fc normal = new Matrix3fc(matrixStack.peek().getNormalMatrix()).scale(1.0F, -1.0F, -1.0F);
normal.rotateLocal((float) Math.toRadians(config.getBindingYaw()), normal.m10, normal.m11, normal.m12);
normal.rotateLocal((float) Math.toRadians(config.getBindingPitch()), normal.m00, normal.m01, normal.m02);
normal.rotateLocal((float) Math.toRadians(config.getBindingRoll()), normal.m20, normal.m21, normal.m22);
Vec3d eulerAngle = MathUtils.getEulerAngleYXZ(normal).multiply(180.0D / Math.PI);
pitch = (float) eulerAngle.getX();
yaw = (float) -eulerAngle.getY();
roll = config.isRollingBound() ? (float) eulerAngle.getZ() : config.getBindingRoll();
}

private static void bindingModeUpdate(Camera camera, MinecraftClient client, float tickDelta, MatrixStack matrixStack) {

// GameRenderer.renderWorld
matrixStack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(camera.getPitch()));
matrixStack.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(camera.getYaw() + 180.0F));
matrixStack.peek().getNormalMatrix().loadIdentity();
// WorldRenderer.render
private static void virtualRender(MinecraftClient client, float tickDelta, MatrixStack matrixStack) {
ClientPlayerEntity player = client.player;
// WorldRenderer.render
if (player.age == 0) {
player.lastRenderX = player.getX();
player.lastRenderY = player.getY();
Expand All @@ -103,68 +102,18 @@ private static void bindingModeUpdate(Camera camera, MinecraftClient client, flo
// WorldRenderer.renderEntity
Vec3d renderOffset = new Vec3d(MathHelper.lerp(tickDelta, player.lastRenderX, player.getX()),
MathHelper.lerp(tickDelta, player.lastRenderY, player.getY()),
MathHelper.lerp(tickDelta, player.lastRenderZ, player.getZ()))
.subtract(camera.getPos());
MathHelper.lerp(tickDelta, player.lastRenderZ, player.getZ()));
// EntityRenderDispatcher.render
if (config.compatPhysicsMod())
PhysicsModCompat.renderStart(client.getEntityRenderDispatcher(), player, renderOffset.getX(),
renderOffset.getY(), renderOffset.getZ(), MathHelper.lerp(tickDelta, player.prevYaw, player.getYaw()), tickDelta, matrixStack);
PhysicsModCompat.renderStart(client.getEntityRenderDispatcher(), player, renderOffset.getX(), renderOffset.getY(),
renderOffset.getZ(), MathHelper.lerp(tickDelta, player.prevYaw, player.getYaw()), tickDelta, matrixStack);

PlayerEntityRenderer playerRenderer = (PlayerEntityRenderer) client.getEntityRenderDispatcher().getRenderer(player);
renderOffset = renderOffset.add(playerRenderer.getPositionOffset(player, tickDelta));
matrixStack.translate(renderOffset.getX(), renderOffset.getY(), renderOffset.getZ());

if (config.compatPehkui()) PehkuiCompat.scaleMatrices(matrixStack, player, tickDelta);

virtualRender(player, playerRenderer, tickDelta, matrixStack);

// ModelPart$Cuboid.renderCuboid
Vector4f offset = new Vector4f((float)(config.getBindingZ() * config.getScale()),
-(float)(config.getBindingY() * config.getScale()),
-(float)(config.getBindingX() * config.getScale()), 1.0F);
offset.transform(matrixStack.peek().getPositionMatrix());

Vec3d referVec = camera.getPos();
((CameraAccessor) camera).invokeMoveBy(-offset.getZ(), offset.getY(), -offset.getX());
clipCameraToSpace(camera, referVec);

Matrix3fc normal = new Matrix3fc(matrixStack.peek().getNormalMatrix()).scale(1.0F, -1.0F, -1.0F);
normal.rotateLocal((float) Math.toRadians(config.getBindingYaw()), normal.m10, normal.m11, normal.m12);
normal.rotateLocal((float) Math.toRadians(config.getBindingPitch()), normal.m00, normal.m01, normal.m02);
normal.rotateLocal((float) Math.toRadians(config.getBindingRoll()), normal.m20, normal.m21, normal.m22);
Vec3d eulerAngle = MathUtils.getEulerAngleYXZ(normal).multiply(180.0D / Math.PI);

float pitch = config.isPitchingBound() ? (float) eulerAngle.getX() : camera.getPitch() + config.getBindingPitch();
float yaw = config.isYawingBound() ? (float) eulerAngle.getY() : -camera.getYaw() + config.getBindingYaw();
cameraRoll = config.isRollingBound() ? (float) eulerAngle.getZ() : config.getBindingRoll();
((CameraAccessor) camera).invokeSetRotation(-yaw, pitch);
}

private static void clipCameraToSpace(Camera camera, Vec3d referVec) {
if (!config.doClipToSpace()) return;
Vec3d offset = camera.getPos().subtract(referVec);
boolean hitted = false;
final float depth = 0.1F;
for (int i = 0; i < 8; ++i) {
float f = depth * ((i & 1) * 2 - 1);
float g = depth * ((i >> 1 & 1) * 2 - 1);
float h = depth * ((i >> 2 & 1) * 2 - 1);
Vec3d start = referVec.add(f, g, h);
Vec3d end = referVec.add(offset).add(f, g, h);
HitResult hitResult = ((CameraAccessor) camera).getArea().raycast(new RaycastContext(start, end,
RaycastContext.ShapeType.VISUAL, RaycastContext.FluidHandling.NONE, camera.getFocusedEntity()));
double l = hitResult.getPos().distanceTo(start);
if (hitResult.getType() == HitResult.Type.MISS || l >= offset.length()) continue;
offset = offset.multiply(l / offset.length());
hitted = true;
}
((CameraAccessor) camera).invokeSetPos(referVec.add(offset));
if (hitted && offset.length() <= 0.8F) ((CameraAccessor) camera).setThirdPerson(false);
}

private static void virtualRender(AbstractClientPlayerEntity player, PlayerEntityRenderer playerRenderer,
float tickDelta, MatrixStack matrixStack) {

if (config.isUsingModModel()) {
status = "Successful";
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static String getModelPartName() {
*/
public static boolean shouldDisableRender(String modelPartName) {
ModConfig.Disable.optionalParts.add(modelPartName);
return Flags.isRenderingWorld && config.shouldDisableRender(modelPartName) && RealCameraCore.isActive();
return Flags.isRenderingClientPlayer && config.shouldDisableModelPart(modelPartName) && RealCameraCore.isActive();
}

public static boolean virtualRender(float tickDelta, MatrixStack matrixStack) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.xtracr.realcamera.RealCamera;
import com.xtracr.realcamera.RealCameraCore;
import com.xtracr.realcamera.api.VirtualRenderer;
import com.xtracr.realcamera.compat.DoABarrelRollCompat;
import com.xtracr.realcamera.compat.PehkuiCompat;
import com.xtracr.realcamera.compat.PhysicsModCompat;
import com.xtracr.realcamera.utils.Triple;
Expand Down Expand Up @@ -53,11 +52,6 @@ public static Screen create(Screen parent) {
.setTooltip(Text.translatable(TOOLTIP + "classic"))
.setSaveConsumer(b -> config.general.classic = b)
.build());
general.addEntry(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "clipToSpace"), config.general.clipToSpace)
.setDefaultValue(true)
.setTooltip(Text.translatable(TOOLTIP + "clipToSpace"))
.setSaveConsumer(b -> config.general.clipToSpace = b)
.build());
general.addEntry(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "dynamicCrosshair"), config.general.dynamicCrosshair)
.setDefaultValue(false)
.setTooltip(Text.translatable(TOOLTIP + "dynamicCrosshair"))
Expand Down Expand Up @@ -93,6 +87,11 @@ public static Screen create(Screen parent) {
.setTooltip(Text.translatable(TOOLTIP + "adjustOffset"))
.setSaveConsumer(b -> config.binding.adjustOffset = b)
.build());
binding.addEntry(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "offsetModel"), config.binding.offsetModel)
.setDefaultValue(false)
.setTooltip(Text.translatable(TOOLTIP + "offsetModel"))
.setSaveConsumer(b -> config.binding.offsetModel = b)
.build());
SubCategoryBuilder bindingCameraOffset = entryBuilder.startSubCategory(Text.translatable(CATEGORY + "cameraOffset"))
.setTooltip(Text.translatable(TOOLTIP + "bindingOffset"), Text.translatable(TOOLTIP + "bindingOffset_n"));
bindingCameraOffset.add(entryBuilder.startDoubleField(Text.translatable(OPTION + "cameraOffset", "X"), config.binding.cameraX)
Expand Down Expand Up @@ -239,11 +238,6 @@ public static Screen create(Screen parent) {
.build());
SubCategoryBuilder compatSwitches = entryBuilder.startSubCategory(Text.translatable(CATEGORY + "compatSwitches"))
.setTooltip(Text.translatable(TOOLTIP + "compatSwitches"));
if (DoABarrelRollCompat.loaded)
compatSwitches.add(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "doABarrelRoll"), config.compats.doABarrelRoll)
.setDefaultValue(true)
.setSaveConsumer(b -> config.compats.doABarrelRoll = b)
.build());
if (PehkuiCompat.loaded)
compatSwitches.add(entryBuilder.startBooleanToggle(Text.translatable(OPTION + "pehkui"), config.compats.pehkui)
.setDefaultValue(true)
Expand Down
Loading

0 comments on commit 6f09695

Please sign in to comment.