Skip to content

Commit

Permalink
Added 'Offset Model' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed Dec 13, 2023
1 parent 29a22e3 commit e98acf0
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Snapshots are [here](https://github.com/xTracr/RealCamera/actions/workflows/buil
* Customizable Player Models
* Compatible:
* most camera mods
* Player Animation Lib
* Not Enough Animations[^1]
* First Person Model
* Pehkui
Expand Down
1 change: 1 addition & 0 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* Customizable Player Models
* 兼容:
* 大多数摄像头模组
* Player Animation Lib
* Not Enough Animations[^1]
* First Person Model
* Pehkui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public static boolean isActive() {
}

public static void computeCamera(MinecraftClient client, float tickDelta) {
if (config.isClassic()) return;
modelOffset = Vec3d.ZERO;
if (config.isClassic()) return;

// GameRenderer.renderWorld
MatrixStack matrixStack = new MatrixStack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,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
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public boolean isAdjustingOffset() {
return binding.adjustOffset;
}

public boolean doOffsetModel() {
return binding.offsetModel;
}

public double getBindingX() {
return binding.cameraX;
}
Expand Down Expand Up @@ -300,6 +304,7 @@ private void clamp() {
public static class Binding {
public VanillaModelPart vanillaModelPart = VanillaModelPart.head;
public boolean adjustOffset = true;
public boolean offsetModel = false;
public double cameraX = 3.25D;
public double cameraY = 2.0D;
public double cameraZ = 0.0D;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ public abstract class MixinCamera {
Box box = focusedEntity.getBoundingBox();
double restrictedY = MathHelper.clamp(prevPos.getY(), box.minY + 0.1D, box.maxY - 0.1D);
startVec = new Vec3d(pos.getX(), restrictedY, pos.getZ());
setPos(prevPos);
realCamera$clipToSpace(startVec);
if (!config.doOffsetModel()) {
setPos(prevPos);
realCamera$clipToSpace(startVec);
}
RealCameraCore.setModelOffset(pos.subtract(prevPos));
setRotation(config.isYawingBound() ? RealCameraCore.getYaw() : yaw - config.getBindingYaw(),
config.isPitchingBound() ? RealCameraCore.getPitch() : pitch + config.getBindingPitch());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.xtracr.realcamera.mixins;

import com.xtracr.realcamera.RealCameraCore;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(EntityRenderDispatcher.class)
public abstract class MixinEntityRenderDispatcher {
@ModifyVariable(method = "render", at = @At("STORE"), ordinal = 0)
private <E extends Entity> Vec3d realCamera$modifyOffset(Vec3d vec, E entity, double x, double y, double z,
float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
if (entity instanceof ClientPlayerEntity && RealCameraCore.isActive()) {
vec = vec.add(RealCameraCore.getModelOffset());
}
return vec;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public abstract class MixinGameRenderer {

@Inject(method = "renderWorld", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/render/Camera;update(Lnet/minecraft/world/BlockView;Lnet/minecraft/entity/Entity;ZZF)V"))
private void realCamera$onBeforeCameraUpdate(float tickDelta, long limitTime, MatrixStack matrixStack, CallbackInfo cInfo) {
private void realCamera$onBeforeCameraUpdate(float tickDelta, long limitTime, MatrixStack matrices, CallbackInfo cInfo) {
if (RealCameraCore.isActive()) {
RealCameraCore.computeCamera(client, tickDelta);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.xtracr.realcamera.mixins;

import com.xtracr.realcamera.RealCameraCore;
import com.xtracr.realcamera.api.VirtualRenderer;
import com.xtracr.realcamera.utils.Flags;
import net.minecraft.client.network.AbstractClientPlayerEntity;
Expand All @@ -11,12 +10,10 @@
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.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerEntityRenderer.class)
public abstract class MixinPlayerEntityRenderer
Expand All @@ -38,14 +35,6 @@ public MixinPlayerEntityRenderer(Context ctx, PlayerEntityModel<AbstractClientPl
Flags.isRenderingClientPlayer = false;
}

@Inject(method = "getPositionOffset*", at = @At("RETURN"), cancellable = true)
private void realCamera$translateModel(AbstractClientPlayerEntity abstractClientPlayerEntity, float f, CallbackInfoReturnable<Vec3d> cInfo) {
if (RealCameraCore.isActive() && abstractClientPlayerEntity instanceof ClientPlayerEntity) {
Vec3d returnVec = cInfo.getReturnValue().add(RealCameraCore.getModelOffset());
cInfo.setReturnValue(returnVec);
}
}

@Inject(method = "setModelPose", at = @At("RETURN"))
private void realCamera$onSetModelPoseRETURN(AbstractClientPlayerEntity player, CallbackInfo cInfo) {
if (VirtualRenderer.shouldDisableRender("head")) model.head.visible = false;
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/resources/assets/realcamera/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

"config.option.xtracr_realcamera_vanillaModelPart": "Vanilla Model part",
"config.option.xtracr_realcamera_adjustOffset": "Adjust Camera Offset",
"config.option.xtracr_realcamera_offsetModel": "Offset Model",
"config.option.xtracr_realcamera_bindPitching": "Bind Pitching",
"config.option.xtracr_realcamera_bindYawing": "Bind Yawing",
"config.option.xtracr_realcamera_bindRolling": "Bind Rolling",
Expand All @@ -60,7 +61,6 @@
"config.option.xtracr_realcamera_useModModel": "Mod Model Compat",
"config.option.xtracr_realcamera_modelModID": "Model Mod ID",
"config.option.xtracr_realcamera_modModelPart": "Mod Model Part",
"config.option.xtracr_realcamera_doABarrelRoll": "Do A Barrel Roll",
"config.option.xtracr_realcamera_pehkui": "Pehkui",
"config.option.xtracr_realcamera_physicsMod": "Physics Mod",

Expand All @@ -87,6 +87,7 @@

"config.tooltip.xtracr_realcamera_vanillaModelPart": "Model part to bind camera to",
"config.tooltip.xtracr_realcamera_adjustOffset": "When pressing the adjustment key, adjust the offset or rotation of camera",
"config.tooltip.xtracr_realcamera_offsetModel": "Move the model to camera to keep the camera position constant. Compatibility with other mods may become better when turned on",

"config.tooltip.xtracr_realcamera_classicAdjustMode": "Determine which to adjust when pressing the adjustment key",

Expand Down
3 changes: 2 additions & 1 deletion common/src/main/resources/assets/realcamera/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

"config.option.xtracr_realcamera_vanillaModelPart": "原版模型部位",
"config.option.xtracr_realcamera_adjustOffset": "调整摄像头偏移",
"config.option.xtracr_realcamera_offsetModel": "偏移模型",
"config.option.xtracr_realcamera_bindPitching": "绑定俯仰",
"config.option.xtracr_realcamera_bindYawing": "绑定偏航",
"config.option.xtracr_realcamera_bindRolling": "绑定翻滚",
Expand All @@ -60,7 +61,6 @@
"config.option.xtracr_realcamera_useModModel": "模组模型兼容",
"config.option.xtracr_realcamera_modelModID": "模型模组ID",
"config.option.xtracr_realcamera_modModelPart": "模组模型部位",
"config.option.xtracr_realcamera_doABarrelRoll": "Do A Barrel Roll",
"config.option.xtracr_realcamera_pehkui": "Pehkui",
"config.option.xtracr_realcamera_physicsMod": "Physics Mod",

Expand All @@ -87,6 +87,7 @@

"config.tooltip.xtracr_realcamera_vanillaModelPart": "摄像头绑定的模型部位",
"config.tooltip.xtracr_realcamera_adjustOffset": "当前按下调整键时是调整摄像头的偏移还是旋转",
"config.tooltip.xtracr_realcamera_offsetModel": "使模型移动到摄像头上以保持摄像头位置不变,开启时与其它模组的兼容性可能会变好",

"config.tooltip.xtracr_realcamera_classicAdjustMode": "决定当前按下调整键时调整哪一个",

Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/realcamera-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"client": [
"MixinCamera",
"MixinClientPlayerEntity",
"MixinEntityRenderDispatcher",
"MixinEntityRenderer",
"MixinGameRenderer",
"MixinInGameHud",
Expand Down

0 comments on commit e98acf0

Please sign in to comment.