diff --git a/build.gradle b/build.gradle index 43e2299..7957577 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,10 @@ allprojects { apply plugin: "architectury-plugin" apply plugin: "maven-publish" - archivesBaseName = rootProject.archives_base_name + base { + archivesName = rootProject.archives_base_name + } + version = rootProject.mod_version group = rootProject.maven_group diff --git a/changelog.md b/changelog.md index 5fedc66..d3344f9 100644 --- a/changelog.md +++ b/changelog.md @@ -22,6 +22,7 @@ * 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: * 0.4.0-alpha: * Fixed an issue where the camera would not follow the model action when the player started/ended sneaking @@ -99,6 +100,7 @@ * 0.5.4-beta: * 添加了功能#15, 修复#35 * 修改了clip to space的方式来避免#23和#32 + * 0.5.5-beta: * 0.4.0-alpha: * 修复了玩家开始/结束潜行时摄像头未跟上模型动作的问题 diff --git a/common/build.gradle b/common/build.gradle index 4380b14..8d97d3e 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -8,7 +8,7 @@ loom { dependencies { - modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" + modCompileOnly "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" // Cloth Config modCompileOnly("me.shedaniel.cloth:cloth-config:${rootProject.cloth_config_version}") { diff --git a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java index 76c48c6..118031e 100644 --- a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java +++ b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java @@ -18,10 +18,7 @@ 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.RotationAxis; -import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.*; import net.minecraft.world.RaycastContext; import org.joml.Matrix3f; import org.joml.Vector4f; @@ -31,6 +28,7 @@ public class RealCameraCore { private static String status = "Successful"; private static float cameraRoll = 0.0F; + private static Vec3d modelOffset = Vec3d.ZERO; public static String getStatus() { return status; @@ -40,6 +38,10 @@ public static float getRoll() { return cameraRoll; } + public static Vec3d getModelOffset() { + return modelOffset; + } + public static boolean isActive() { MinecraftClient client = MinecraftClient.getInstance(); return config.isEnabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null @@ -48,6 +50,7 @@ public static boolean isActive() { public static void updateCamera(Camera camera, MinecraftClient client, float tickDelta) { cameraRoll = 0.0F; + modelOffset = Vec3d.ZERO; if (config.isRendering() && !config.disableRenderingWhen(client)) { ((CameraAccessor) camera).setThirdPerson(true); @@ -125,7 +128,12 @@ private static void bindingModeUpdate(Camera camera, MinecraftClient client, flo Vec3d referVec = camera.getPos(); ((CameraAccessor) camera).invokeMoveBy(-offset.z(), offset.y(), -offset.x()); + Vec3d prevPos = camera.getPos(); + Box box = player.getBoundingBox(); + double restrictedY = MathHelper.clamp(camera.getPos().getY(), box.minY + 0.1D, box.maxY - 0.1D); + referVec = new Vec3d(referVec.getX(), restrictedY, referVec.getZ()); clipCameraToSpace(camera, referVec); + modelOffset = camera.getPos().subtract(prevPos); Matrix3f normal = matrixStack.peek().getNormalMatrix().scale(1.0F, -1.0F, -1.0F); normal.rotateLocal((float) Math.toRadians(config.getBindingYaw()), normal.m10, normal.m11, normal.m12); @@ -142,8 +150,7 @@ private static void bindingModeUpdate(Camera camera, MinecraftClient client, flo 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; + final float depth = 0.08F; for (int i = 0; i < 8; ++i) { float f = depth * ((i & 1) * 2 - 1); float g = depth * ((i >> 1 & 1) * 2 - 1); @@ -155,10 +162,8 @@ private static void clipCameraToSpace(Camera camera, Vec3d referVec) { 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, diff --git a/common/src/main/java/com/xtracr/realcamera/api/VirtualRenderer.java b/common/src/main/java/com/xtracr/realcamera/api/VirtualRenderer.java index 5360758..aab777c 100644 --- a/common/src/main/java/com/xtracr/realcamera/api/VirtualRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/api/VirtualRenderer.java @@ -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.shouldDisableRender(modelPartName) && RealCameraCore.isActive(); } public static boolean virtualRender(float tickDelta, MatrixStack matrixStack) { 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 4a4a40e..3e53be8 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java @@ -149,10 +149,6 @@ public void adjustBindingZ(boolean add) { } // classic - public Classic.AdjustMode getClassicAdjustMode() { - return classic.adjustMode; - } - public double getClassicX() { return classic.cameraX; } @@ -375,8 +371,8 @@ public static class Compats { } public static class Disable { - public static final Set optionalParts = new HashSet<>(Set.of("head", "hat", "helmet")); - protected static final List defaultParts = Arrays.asList("head", "hat", "helmet"); + public static final Set optionalParts = new HashSet<>(Set.of("head", "hat", "slot_head")); + protected static final List defaultParts = Arrays.asList("head", "hat", "slot_head"); protected static final Triple, List> defaultTriple = new Triple<> ("holding", List.of("new item id"), List.of("new action")); protected static final List, List>> defaultConditions = Arrays.asList( diff --git a/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerEntity.java b/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerEntity.java index bc4a98f..fd32088 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerEntity.java +++ b/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerEntity.java @@ -1,7 +1,6 @@ package com.xtracr.realcamera.mixins; import com.xtracr.realcamera.api.VirtualRenderer; -import com.xtracr.realcamera.utils.Flags; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -14,7 +13,6 @@ public class MixinPlayerEntity { @Inject(method = "getEquippedStack", at = @At("HEAD"), cancellable = true) private void realCamera$onGetEquippedStackHEAD(EquipmentSlot slot, CallbackInfoReturnable cInfo) { - if (!Flags.isRenderingClientPlayer) return; if (VirtualRenderer.shouldDisableRender("slot_head") && slot == EquipmentSlot.HEAD || VirtualRenderer.shouldDisableRender("slot_chest") && slot == EquipmentSlot.CHEST || VirtualRenderer.shouldDisableRender("slot_legs") && slot == EquipmentSlot.LEGS || diff --git a/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerEntityRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerEntityRenderer.java index 56b698f..eee3c69 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerEntityRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerEntityRenderer.java @@ -1,5 +1,6 @@ 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; @@ -10,10 +11,12 @@ 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 @@ -35,9 +38,16 @@ public MixinPlayerEntityRenderer(Context ctx, PlayerEntityModel 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 (!Flags.isRenderingClientPlayer) return; if (VirtualRenderer.shouldDisableRender("head")) model.head.visible = false; if (VirtualRenderer.shouldDisableRender("hat")) model.hat.visible = false; if (VirtualRenderer.shouldDisableRender("body")) model.body.visible = false; diff --git a/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerHeldItemFeatureRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerHeldItemFeatureRenderer.java index 9357d1d..a54fc65 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerHeldItemFeatureRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixins/MixinPlayerHeldItemFeatureRenderer.java @@ -1,7 +1,6 @@ package com.xtracr.realcamera.mixins; import com.xtracr.realcamera.api.VirtualRenderer; -import com.xtracr.realcamera.utils.Flags; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.feature.PlayerHeldItemFeatureRenderer; import net.minecraft.client.render.model.json.ModelTransformationMode; @@ -19,7 +18,6 @@ public abstract class MixinPlayerHeldItemFeatureRenderer { @Inject(method = "renderItem", at = @At("HEAD"), cancellable = true) private void realCamera$onRenderItemHEAD(LivingEntity entity, ItemStack stack, ModelTransformationMode transformationMode, Arm arm, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo cInfo) { - if (!Flags.isRenderingClientPlayer) return; if (VirtualRenderer.shouldDisableRender("heldItem")) cInfo.cancel(); } } diff --git a/common/src/main/java/com/xtracr/realcamera/utils/Flags.java b/common/src/main/java/com/xtracr/realcamera/utils/Flags.java index 79a5626..9bc7f13 100644 --- a/common/src/main/java/com/xtracr/realcamera/utils/Flags.java +++ b/common/src/main/java/com/xtracr/realcamera/utils/Flags.java @@ -1,6 +1,5 @@ package com.xtracr.realcamera.utils; public class Flags { - public static boolean isRenderingWorld = false; public static boolean isRenderingClientPlayer = false; } diff --git a/fabric/build.gradle b/fabric/build.gradle index 2edae72..8b2fa12 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -2,7 +2,7 @@ plugins { id "com.github.johnrengelman.shadow" version "7.1.2" } -archivesBaseName = rootProject.archivesBaseName + "-fabric" +archivesBaseName = rootProject.archives_base_name + "-" + rootProject.minecraft_version + "-fabric" architectury { platformSetupLoomIde() @@ -48,18 +48,13 @@ shadowJar { exclude "architectury.common.json" configurations = [project.configurations.shadowCommon] - archiveClassifier.set("dev-shadow") + archiveClassifier = "dev-shadow" } remapJar { injectAccessWidener = true inputFile.set shadowJar.archiveFile dependsOn shadowJar - archiveClassifier.set(null) -} - -jar { - archiveClassifier.set("dev") } sourcesJar { diff --git a/fabric/src/main/java/com/xtracr/realcamera/EventHandler.java b/fabric/src/main/java/com/xtracr/realcamera/EventHandler.java index b03ebd4..4adb8c2 100644 --- a/fabric/src/main/java/com/xtracr/realcamera/EventHandler.java +++ b/fabric/src/main/java/com/xtracr/realcamera/EventHandler.java @@ -8,7 +8,6 @@ public class EventHandler { public static void onWorldRenderStart(WorldRenderContext context) { - Flags.isRenderingWorld = true; if (ConfigFile.modConfig.isCrosshairDynamic() && RealCameraCore.isActive()) { CrosshairUtils.update(MinecraftClient.getInstance(), context.camera(), context.matrixStack().peek().getPositionMatrix(), context.projectionMatrix()); diff --git a/fabric/src/main/java/com/xtracr/realcamera/RealCameraFabric.java b/fabric/src/main/java/com/xtracr/realcamera/RealCameraFabric.java index 71a91ef..25326b4 100644 --- a/fabric/src/main/java/com/xtracr/realcamera/RealCameraFabric.java +++ b/fabric/src/main/java/com/xtracr/realcamera/RealCameraFabric.java @@ -1,6 +1,5 @@ package com.xtracr.realcamera; -import com.xtracr.realcamera.utils.Flags; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -16,7 +15,6 @@ public void onInitializeClient() { ClientTickEvents.END_CLIENT_TICK.register(KeyBindings::handle); WorldRenderEvents.START.register(EventHandler::onWorldRenderStart); - WorldRenderEvents.END.register(context -> Flags.isRenderingWorld = false); KeyBindingHelper.registerKeyBinding(KeyBindings.TOGGLE_PERSPECTIVE); KeyBindingHelper.registerKeyBinding(KeyBindings.TOGGLE_ADJUST_MODE); diff --git a/forge/build.gradle b/forge/build.gradle index 2f03ca2..ea52fda 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -2,7 +2,7 @@ plugins { id "com.github.johnrengelman.shadow" version "7.1.2" } -archivesBaseName = rootProject.archivesBaseName + "-forge" +archivesBaseName = rootProject.archives_base_name + "-" + rootProject.minecraft_version + "-forge" architectury { platformSetupLoomIde() @@ -36,7 +36,7 @@ dependencies { modRuntimeOnly "me.shedaniel.cloth:cloth-config-forge:${rootProject.cloth_config_version}" // Epic Fight - modCompileOnly "curse.maven:epic-fight-mod-405076:4902504" + //modCompileOnly "curse.maven:epic-fight-mod-405076:4902504" common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false } @@ -55,17 +55,12 @@ shadowJar { exclude "architectury.common.json" configurations = [project.configurations.shadowCommon] - archiveClassifier.set("dev-shadow") + archiveClassifier = "dev-shadow" } remapJar { inputFile.set shadowJar.archiveFile dependsOn shadowJar - archiveClassifier.set(null) -} - -jar { - archiveClassifier.set("dev") } sourcesJar { diff --git a/forge/src/main/java/com/xtracr/realcamera/EventHandler.java b/forge/src/main/java/com/xtracr/realcamera/EventHandler.java index 4b823f3..3506f60 100644 --- a/forge/src/main/java/com/xtracr/realcamera/EventHandler.java +++ b/forge/src/main/java/com/xtracr/realcamera/EventHandler.java @@ -30,13 +30,10 @@ public static void onCameraUpdate(ComputeCameraAngles event) { @SubscribeEvent public static void onRenderWorldStage(RenderLevelStageEvent event) { if (RenderLevelStageEvent.Stage.AFTER_SKY.equals(event.getStage())) { - Flags.isRenderingWorld = true; if (ConfigFile.modConfig.isCrosshairDynamic() && RealCameraCore.isActive()) { CrosshairUtils.update(MinecraftClient.getInstance(), event.getCamera(), event.getPoseStack().peek().getPositionMatrix(), event.getProjectionMatrix()); } - } else if (RenderLevelStageEvent.Stage.AFTER_WEATHER.equals(event.getStage())) { - Flags.isRenderingWorld = false; } } } diff --git a/gradle.properties b/gradle.properties index f8f7968..68ee1b8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,17 +2,16 @@ org.gradle.jvmargs=-Xmx4G org.gradle.parallel=true # Loader Properties -minecraft_version=1.20.2 +minecraft_version=1.20.4 enabled_platforms=fabric,forge -forge_version=1.20.2-48.0.49 -fabric_loader_version=0.15.0 -yarn_mappings=1.20.2+build.4 +forge_version=1.20.4-49.0.3 +fabric_loader_version=0.15.1 +yarn_mappings=1.20.4+build.1 # Mod Properties -modid=realcamera -mod_version=0.5.4-beta +mod_version=0.5.5-beta maven_group=com.xtracr.realcamera -archives_base_name=realcamera-1.20.2 +archives_base_name=realcamera # Dependencies -fabric_api_version=0.91.1+1.20.2 -cloth_config_version=12.0.111 -modmenu_version=8.0.0-beta.2 +fabric_api_version=0.91.2+1.20.4 +cloth_config_version=13.0.114 +modmenu_version=9.0.0-pre.1 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index c1962a7..7f93135 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c30b486..1af9e09 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index aeb74cb..0adc8e1 100644 --- a/gradlew +++ b/gradlew @@ -83,7 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -130,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. diff --git a/settings.gradle b/settings.gradle index 1da0001..9ab4c78 100644 --- a/settings.gradle +++ b/settings.gradle @@ -9,6 +9,6 @@ pluginManagement { include("common") include("fabric") -include("forge") +//include("forge") rootProject.name = "RealCamera"