Skip to content

Commit

Permalink
Fixed #21, updated localization and added message on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed Apr 28, 2024
1 parent 1fd2cdb commit 8543d13
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class KeyBindings {
boolean enabled = config().enabled();
ConfigFile.load();
config().setEnabled(!enabled);
RealCameraCore.readyToSendMessage();
});
createKeyBinding("toggleAdjustMode", client -> config().cycleAdjustMode());
createKeyBinding("toggleCameraMode", client -> config().setClassic(!config().isClassic()));
Expand Down
19 changes: 14 additions & 5 deletions common/src/main/java/com/xtracr/realcamera/RealCameraCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
Expand All @@ -24,7 +25,7 @@ public class RealCameraCore {
private static final VertexRecorder recorder = new VertexRecorder();
public static BindingTarget currentTarget = new BindingTarget();
private static Vec3d pos = Vec3d.ZERO, cameraPos = Vec3d.ZERO, offset = Vec3d.ZERO;
private static boolean active = false, rendering = false;
private static boolean active = false, rendering = false, readyToSendMessage = true;
private static float pitch, yaw, roll;

public static float getPitch(float f) {
Expand Down Expand Up @@ -57,16 +58,20 @@ public static void setCameraPos(Vec3d vec3d) {

public static void init(MinecraftClient client) {
Entity entity = client.getCameraEntity();
active = config().enabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null && entity != null && !DisableHelper.check("disableMod", entity);
rendering = config().renderModel() && entity != null && !DisableHelper.check("disableRender", entity);
active = config().enabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null && entity != null && !DisableHelper.isDisabled("mainFeature", entity);
rendering = active && config().renderModel() && !DisableHelper.isDisabled("renderModel", entity);
}

public static void readyToSendMessage() {
readyToSendMessage = config().enabled();
}

public static boolean isActive() {
return active;
}

public static boolean isRendering() {
return active && rendering;
return rendering;
}

public static void updateModel(MinecraftClient client, float tickDelta) {
Expand Down Expand Up @@ -117,7 +122,11 @@ public static void computeCamera() {
} catch (Exception ignored) {
}
}
if (currentTarget.isEmpty()) active = false;
if (currentTarget.isEmpty()) {
Entity player = MinecraftClient.getInstance().player;
if (readyToSendMessage && player != null) player.sendMessage(Text.translatable("message." + RealCamera.FULL_ID + ".bindingFailed"));
active = readyToSendMessage = false;
} else readyToSendMessage = true;
normal.rotateLocal((float) Math.toRadians(currentTarget.yaw()), normal.m10, normal.m11, normal.m12);
normal.rotateLocal((float) Math.toRadians(currentTarget.pitch()), normal.m00, normal.m01, normal.m02);
normal.rotateLocal((float) Math.toRadians(currentTarget.roll()), normal.m20, normal.m21, normal.m22);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ public final class DisableHelper {
private static final Map<String, Predicate<LivingEntity>> predicates = new HashMap<>();

public static void initialize() {
registerOr("disableMod", LivingEntity::isSleeping);
registerOr("disableRender", entity -> entity instanceof PlayerEntity player && player.isUsingSpyglass());
registerOr("disableRender", entity -> config().getDisableRenderItems().contains(Registries.ITEM.getId(entity.getMainHandStack().getItem()).toString()));
registerOr("disableRender", entity -> config().getDisableRenderItems().contains(Registries.ITEM.getId(entity.getOffHandStack().getItem()).toString()));
registerOr("mainFeature", LivingEntity::isSleeping);
registerOr("renderModel", entity -> entity instanceof PlayerEntity player && player.isUsingSpyglass());
registerOr("renderModel", entity -> config().getDisableRenderItems().contains(Registries.ITEM.getId(entity.getMainHandStack().getItem()).toString()));
registerOr("renderModel", entity -> config().getDisableRenderItems().contains(Registries.ITEM.getId(entity.getOffHandStack().getItem()).toString()));
}

public static void registerOr(String type, Predicate<LivingEntity> predicate) {
predicates.compute(type, (key, oldPredicate) -> oldPredicate != null ? predicate.or(oldPredicate) : predicate);
predicates.merge(type, predicate, Predicate::or);
}

public static boolean check(String type, Entity cameraEntity) {
public static boolean isDisabled(String type, Entity cameraEntity) {
Predicate<LivingEntity> predicate = predicates.get(type);
if (config().isClassic() || predicate == null) return false;
return cameraEntity instanceof LivingEntity entity && predicate.test(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ 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 + "renderStuckObjects"), config.renderModel)
.setDefaultValue(true)
.setTooltip(Text.translatable(TOOLTIP + "renderStuckObjects"))
.setSaveConsumer(b -> config.renderModel = b)
.build());
binding.addEntry(entryBuilder.startStrList(Text.translatable(OPTION + "disableRenderItems"), config.binding.disableRenderItems)
.setDefaultValue(ModConfig.Binding.defaultDisableRenderItems)
.setTooltip(Text.translatable(TOOLTIP + "disableRenderItems"))
.setSaveConsumer(l -> config.binding.disableRenderItems = l)
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ public List<BindingTarget> getTargetList() {
return binding.targetList;
}

public boolean renderStuckObjects() {
return binding.renderStuckObjects;
}

public List<String> getDisableRenderItems() {
return binding.disableRenderItems;
}
Expand Down Expand Up @@ -209,6 +213,7 @@ public AdjustMode cycle() {
public static class Binding {
protected static final List<String> defaultDisableRenderItems = List.of("minecraft:filled_map");
public boolean adjustOffset = true;
public boolean renderStuckObjects = true;
public List<String> disableRenderItems = new ArrayList<>(defaultDisableRenderItems);
public List<BindingTarget> targetList = new ArrayList<>(BindingTarget.defaultTargets);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ private void initLeftWidgets(final int category) {
upwardVField = createFloatField(widgetWidth, 0, upwardVField);
posUField = createFloatField(widgetWidth, 0, posUField);
posVField = createFloatField(widgetWidth, 0, posVField);
textureIdField = createTextField(widgetWidth * 2 + 4, textureIdField);
String textureId = textureIdField != null ? textureIdField.getText() : "";
textureIdField = createTextField(widgetWidth * 2 + 4, null);
textureIdField.setMaxLength(1024);
textureIdField.setText(textureId);
scaleField = createFloatField(widgetWidth, 1.0f, scaleField).setMax(64.0f);
depthField = createFloatField(widgetWidth, 0.2f, depthField).setMax(16.0f);
if (category == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.xtracr.realcamera.mixin;

import com.xtracr.realcamera.RealCameraCore;
import com.xtracr.realcamera.config.ConfigFile;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.StuckObjectsFeatureRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
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;

@Mixin(StuckObjectsFeatureRenderer.class)
public abstract class MixinStuckObjectsFeatureRenderer<T extends LivingEntity> {
@Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At("HEAD"), cancellable = true)
private void realcamera$cancelRender(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, T livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo cInfo) {
if (livingEntity instanceof ClientPlayerEntity && RealCameraCore.isRendering() && !ConfigFile.modConfig.isClassic() && !ConfigFile.modConfig.renderStuckObjects()) {
cInfo.cancel();
}
}
}
5 changes: 5 additions & 0 deletions common/src/main/resources/assets/realcamera/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@
"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.renderStuckObjects": "Render Stuck Objects",
"config.option.xtracr_realcamera.disableRenderItems": "Disable rendering when holding",
"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.renderStuckObjects": "Arrows, bee stings and other objects that can be stuck in the player's body",

"message.xtracr_realcamera.bindingFailed": "[Real Camera]: Binding failed, please go to the Model View screen and configure manually",

"screen.xtracr_realcamera.modelView_title": "Model View",
"screen.widget.xtracr_realcamera.modelView_selectMode": "Selecting",
Expand Down
5 changes: 5 additions & 0 deletions common/src/main/resources/assets/realcamera/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@
"config.option.xtracr_realcamera.roll": "翻滚角",
"config.option.xtracr_realcamera.toModelViewGui": "详细设置请前往%s界面(需设置快捷键来打开它)",
"config.option.xtracr_realcamera.adjustOffset": "调整摄像头偏移",
"config.option.xtracr_realcamera.renderStuckObjects": "渲染卡在身上的物体",
"config.option.xtracr_realcamera.disableRenderItems": "在手持...时禁用渲染",
"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.renderStuckObjects": "箭,蜂刺和其它会卡在玩家身体里的物体",

"message.xtracr_realcamera.bindingFailed": "[Real Camera]: 绑定失败,请前往模型视图界面手动设置",

"screen.xtracr_realcamera.modelView_title": "模型视图",
"screen.widget.xtracr_realcamera.modelView_selectMode": "选择",
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 @@ -13,6 +13,7 @@
"MixinHeldItemRenderer",
"MixinInGameHud",
"MixinItem",
"MixinStuckObjectsFeatureRenderer",
"MixinWorldRenderer"
],
"server": [
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ forge_version=1.20.1-47.2.30
fabric_loader_version=0.15.10
yarn_mappings=1.20.1+build.10
# Mod Properties
mod_version=0.6.1-alpha.1
mod_version=0.6.1-alpha.2
maven_group=com.xtracr.realcamera
archives_base_name=realcamera
# Dependencies
Expand Down

0 comments on commit 8543d13

Please sign in to comment.