diff --git a/common/src/main/java/com/xtracr/realcamera/KeyBindings.java b/common/src/main/java/com/xtracr/realcamera/KeyBindings.java index bb691bc..6b99f8f 100644 --- a/common/src/main/java/com/xtracr/realcamera/KeyBindings.java +++ b/common/src/main/java/com/xtracr/realcamera/KeyBindings.java @@ -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())); diff --git a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java index 3931bb2..1ddc7ba 100644 --- a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java +++ b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java @@ -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; @@ -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) { @@ -57,8 +58,12 @@ 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() { @@ -66,7 +71,7 @@ public static boolean isActive() { } public static boolean isRendering() { - return active && rendering; + return rendering; } public static void updateModel(MinecraftClient client, float tickDelta) { @@ -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); diff --git a/common/src/main/java/com/xtracr/realcamera/compat/DisableHelper.java b/common/src/main/java/com/xtracr/realcamera/compat/DisableHelper.java index 0fd0c0e..3d38ac5 100644 --- a/common/src/main/java/com/xtracr/realcamera/compat/DisableHelper.java +++ b/common/src/main/java/com/xtracr/realcamera/compat/DisableHelper.java @@ -15,17 +15,17 @@ public final class DisableHelper { private static final Map> 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 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 predicate = predicates.get(type); if (config().isClassic() || predicate == null) return false; return cameraEntity instanceof LivingEntity entity && predicate.test(entity); diff --git a/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java b/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java index fc3edd4..2c380f1 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java @@ -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()); diff --git a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java index 0d84e38..6811efc 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java @@ -155,6 +155,10 @@ public List getTargetList() { return binding.targetList; } + public boolean renderStuckObjects() { + return binding.renderStuckObjects; + } + public List getDisableRenderItems() { return binding.disableRenderItems; } @@ -209,6 +213,7 @@ public AdjustMode cycle() { public static class Binding { protected static final List defaultDisableRenderItems = List.of("minecraft:filled_map"); public boolean adjustOffset = true; + public boolean renderStuckObjects = true; public List disableRenderItems = new ArrayList<>(defaultDisableRenderItems); public List targetList = new ArrayList<>(BindingTarget.defaultTargets); diff --git a/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java b/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java index cb43a83..d9f0926 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java @@ -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) { diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinStuckObjectsFeatureRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinStuckObjectsFeatureRenderer.java new file mode 100644 index 0000000..6470486 --- /dev/null +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinStuckObjectsFeatureRenderer.java @@ -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 { + @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(); + } + } +} diff --git a/common/src/main/resources/assets/realcamera/lang/en_us.json b/common/src/main/resources/assets/realcamera/lang/en_us.json index 94d7531..9bda2e4 100644 --- a/common/src/main/resources/assets/realcamera/lang/en_us.json +++ b/common/src/main/resources/assets/realcamera/lang/en_us.json @@ -38,6 +38,8 @@ "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", @@ -45,6 +47,9 @@ "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", diff --git a/common/src/main/resources/assets/realcamera/lang/zh_cn.json b/common/src/main/resources/assets/realcamera/lang/zh_cn.json index 71a0d50..cde9666 100644 --- a/common/src/main/resources/assets/realcamera/lang/zh_cn.json +++ b/common/src/main/resources/assets/realcamera/lang/zh_cn.json @@ -38,6 +38,8 @@ "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": "在第一人称视角下渲染玩家模型", @@ -45,6 +47,9 @@ "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": "选择", diff --git a/common/src/main/resources/realcamera-common.mixins.json b/common/src/main/resources/realcamera-common.mixins.json index 2954af4..f73975b 100644 --- a/common/src/main/resources/realcamera-common.mixins.json +++ b/common/src/main/resources/realcamera-common.mixins.json @@ -13,6 +13,7 @@ "MixinHeldItemRenderer", "MixinInGameHud", "MixinItem", + "MixinStuckObjectsFeatureRenderer", "MixinWorldRenderer" ], "server": [ diff --git a/gradle.properties b/gradle.properties index 287a100..57fec17 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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