Skip to content

Commit

Permalink
Fixed #59 and removed 'UMA' option
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed Mar 8, 2024
1 parent 6d7a9a2 commit 43f495f
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 24 deletions.
4 changes: 3 additions & 1 deletion common/src/main/java/com/xtracr/realcamera/RealCamera.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xtracr.realcamera;

import com.xtracr.realcamera.compat.CompatibilityHelper;
import com.xtracr.realcamera.config.ConfigFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -9,7 +10,8 @@ public class RealCamera {
public static final String FULL_ID = "xtracr_" + MODID;
public static final Logger LOGGER = LoggerFactory.getLogger(MODID);

public static void setup() {
public static void initialize() {
ConfigFile.load();
CompatibilityHelper.initialize();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.xtracr.realcamera.compat;

import com.xtracr.realcamera.RealCameraCore;
import com.xtracr.realcamera.config.ConfigFile;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.function.Supplier;

public class CompatibilityHelper {
private static Class<?> NEA_NEAnimationsLoader = null;
private static Method NEA_playerTransformer_setDeltaTick = null;

@SuppressWarnings("unchecked")
public static void initialize() {
if (isClassLoaded("net.bettercombat.BetterCombat")) try {
Class<?> BetterCombat_CompatibilityFlags = Class.forName("net.bettercombat.compatibility.CompatibilityFlags");
Field firstPersonRenderField = BetterCombat_CompatibilityFlags.getField("firstPersonRender");
Supplier<Boolean> firstPersonRender = (Supplier<Boolean>) firstPersonRenderField.get(null);
Supplier<Boolean> newFirstPersonRender = () -> firstPersonRender.get() && !(RealCameraCore.isActive() && ConfigFile.modConfig.isRendering());
firstPersonRenderField.set(null, newFirstPersonRender);
} catch (Exception ignored) {
}
if (isClassLoaded("dev.tr7zw.notenoughanimations.versionless.NEABaseMod")) try {
NEA_NEAnimationsLoader = Class.forName("dev.tr7zw.notenoughanimations.NEAnimationsLoader");
Class<?> NEA_PlayerTransformer = Class.forName("dev.tr7zw.notenoughanimations.logic.PlayerTransformer");
NEA_playerTransformer_setDeltaTick = NEA_PlayerTransformer.getDeclaredMethod("setDeltaTick", float.class);
} catch (Exception ignored) {
}
}

public static void NEA_setDeltaTick(float tickDelta) {
if (NEA_NEAnimationsLoader != null) try {
Object NEA_NEAnimationsLoader_INSTANCE = NEA_NEAnimationsLoader.getDeclaredField("INSTANCE").get(null);
Object NEA_playerTransformer = NEA_NEAnimationsLoader.getDeclaredField("playerTransformer").get(NEA_NEAnimationsLoader_INSTANCE);
NEA_playerTransformer_setDeltaTick.invoke(NEA_playerTransformer, tickDelta);
} catch (Exception ignored) {
}
}

public static boolean isClassLoaded(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException exception) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ 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 + "updateModel"), config.binding.updateModel)
.setDefaultValue(true)
.setTooltip(Text.translatable(TOOLTIP + "updateModel"))
.setSaveConsumer(b -> config.binding.updateModel = b)
.build());

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ public void adjustOffsetZ(int count) {
}

// binding
public boolean updateModelAgain() {
return binding.updateModel;
}

public List<BindingTarget> getTargetList() {
binding.clamp();
return binding.targetList;
Expand Down Expand Up @@ -208,7 +204,6 @@ public AdjustMode cycle() {

public static class Binding {
public boolean adjustOffset = true;
public boolean updateModel = true;
public List<BindingTarget> targetList = new ArrayList<>(BindingTarget.defaultTargets);

private void clamp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.xtracr.realcamera.mixin;

import com.xtracr.realcamera.RealCameraCore;
import com.xtracr.realcamera.compat.CompatibilityHelper;
import com.xtracr.realcamera.config.ConfigFile;
import com.xtracr.realcamera.util.CrosshairUtil;
import com.xtracr.realcamera.util.RaycastUtil;
Expand Down Expand Up @@ -44,6 +45,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 matrices, CallbackInfo cInfo) {
CompatibilityHelper.NEA_setDeltaTick(tickDelta);
RealCameraCore.init(client);
if (RealCameraCore.isActive() && !ConfigFile.modConfig.isClassic()) {
RealCameraCore.updateModel(client, tickDelta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.xtracr.realcamera.RealCameraCore;
import com.xtracr.realcamera.config.ConfigFile;
import com.xtracr.realcamera.config.ModConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
Expand All @@ -19,8 +18,6 @@

@Mixin(WorldRenderer.class)
public abstract class MixinWorldRenderer {
@Shadow
@Final private MinecraftClient client;
@Shadow
@Final private BufferBuilderStorage bufferBuilders;

Expand All @@ -31,10 +28,7 @@ public abstract class MixinWorldRenderer {
if (!RealCameraCore.isActive() || !config.isRendering() || (camera.getFocusedEntity() instanceof PlayerEntity player && player.isUsingSpyglass())) return;
VertexConsumerProvider.Immediate immediate = this.bufferBuilders.getEntityVertexConsumers();
Vec3d cameraPos = camera.getPos();
if (!config.isClassic()) {
if (config.updateModelAgain()) RealCameraCore.updateModel(client, tickDelta);
RealCameraCore.renderCameraEntity(immediate);
}
if (!config.isClassic()) RealCameraCore.renderCameraEntity(immediate);
else renderEntity(camera.getFocusedEntity(), cameraPos.getX(), cameraPos.getY(), cameraPos.getZ(), tickDelta, matrices, immediate);
}

Expand Down
2 changes: 0 additions & 2 deletions common/src/main/resources/assets/realcamera/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@
"config.option.xtracr_realcamera.roll": "Roll",
"config.option.xtracr_realcamera.toModelViewGui": "For detailed settings, please go to the %s screen (key bind need to be set to open it)",
"config.option.xtracr_realcamera.adjustOffset": "Adjust Camera Offset",
"config.option.xtracr_realcamera.updateModel": "Update Model State Again Before Rendering",
"config.tooltip.xtracr_realcamera.isClassic": "Classic mode only makes simple changes to the position and rotation of camera",
"config.tooltip.xtracr_realcamera.dynamicCrosshair": "When enabled, the crosshair will follow the player's view, ensuring consistent hit result\nRecommended to enable when Jade, WTHIT or similar mods are installed",
"config.tooltip.xtracr_realcamera.renderModel": "Render player model in first-person perspective",
"config.tooltip.xtracr_realcamera.adjustStep": "Length or 1/100 of the angle of the adjustment per step",
"config.tooltip.xtracr_realcamera.classicAdjustMode": "Determine which to adjust when pressing the adjustment key",
"config.tooltip.xtracr_realcamera.scale": "Control the size of the offsets",
"config.tooltip.xtracr_realcamera.adjustOffset": "When pressing the adjustment key, adjust the offset or rotation of camera",
"config.tooltip.xtracr_realcamera.updateModel": "Have some impact on performance, recommended to turn off, if no visible difference after turned off\nCode running order: update player model (advanced here by RealCamera) -> update camera -> some mods may be initialized here -> (update player model again) -> render player model",

"screen.xtracr_realcamera.modelView_title": "Model View",
"screen.widget.xtracr_realcamera.modelView_selectMode": "Selecting",
Expand Down
2 changes: 0 additions & 2 deletions common/src/main/resources/assets/realcamera/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@
"config.option.xtracr_realcamera.roll": "翻滚角",
"config.option.xtracr_realcamera.toModelViewGui": "详细设置请前往%s界面(需设置快捷键来打开它)",
"config.option.xtracr_realcamera.adjustOffset": "调整摄像头偏移",
"config.option.xtracr_realcamera.updateModel": "在渲染前再次更新模型状态",
"config.tooltip.xtracr_realcamera.isClassic": "经典模式只对摄像头的位置和旋转做简单的修改",
"config.tooltip.xtracr_realcamera.dynamicCrosshair": "在开启状态下,十字准心会随着玩家的视线移动,确保命中结果不受影响\n在安装了Jade、WTHIT或类似模组时建议启用",
"config.tooltip.xtracr_realcamera.renderModel": "在第一人称视角下渲染玩家模型",
"config.tooltip.xtracr_realcamera.adjustStep": "每步调整的角度的1/100或长度",
"config.tooltip.xtracr_realcamera.classicAdjustMode": "决定当前按下调整键时调整哪一个",
"config.tooltip.xtracr_realcamera.scale": "控制偏移量的大小",
"config.tooltip.xtracr_realcamera.adjustOffset": "当前按下调整键时是调整摄像头的偏移还是旋转",
"config.tooltip.xtracr_realcamera.updateModel": "会对性能产生一定影响,建议关闭,如果关闭后没有可见的区别\n代码运行顺序:更新玩家模型(被RealCamera提前至此)->更新摄像头->部分模组可能在此处初始化->(再次更新玩家模型)->渲染玩家模型",

"screen.xtracr_realcamera.modelView_title": "模型视图",
"screen.widget.xtracr_realcamera.modelView_selectMode": "选择",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class RealCameraFabric implements ClientModInitializer {
@Override
public void onInitializeClient() {
RealCamera.setup();
RealCamera.initialize();
KeyBindings.register(KeyBindingHelper::registerKeyBinding);

ClientTickEvents.END_CLIENT_TICK.register(KeyBindings::handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public RealCameraForge() {

@SubscribeEvent
public void clientSetup(FMLClientSetupEvent event) {
RealCamera.setup();
RealCamera.initialize();

MinecraftForge.EVENT_BUS.addListener(EventHandler::onKeyInput);
MinecraftForge.EVENT_BUS.addListener(EventPriority.LOWEST, EventHandler::onCameraUpdate);
Expand Down

0 comments on commit 43f495f

Please sign in to comment.