From c360314a7361c74ceb2ba957cef68aaed8f5030d Mon Sep 17 00:00:00 2001 From: tr7zw Date: Fri, 14 Jun 2024 18:38:21 +0200 Subject: [PATCH] Update to 1.21 --- .github/workflows/tag.yml | 56 +++++++++++++++++++ settings.json | 5 +- .../dev/tr7zw/firstperson/LogicHandler.java | 35 +++++++----- .../config/ConfigScreenProvider.java | 3 +- .../mixins/FeatureRendererMixin.java | 22 ++++++-- .../mixins/HeldItemRendererMixin.java | 3 +- .../tr7zw/firstperson/mixins/PlayerMixin.java | 5 +- .../mixins/PlayerRendererMixin.java | 6 +- .../mixins/RenderDispatcherMixin.java | 16 ++++-- .../mixins/WorldRendererMixin.java | 22 ++++++-- .../modsupport/PlayerAnimatorSupport.java | 2 +- versions/mainProject | 2 +- 12 files changed, 138 insertions(+), 39 deletions(-) diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 58ebb614..9486362e 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -447,3 +447,59 @@ jobs: name: ${{github.ref_name}}-1.20.6 - Fabric files: 'versions/1.20.6-fabric/build/libs/!(*-@(dev|sources|javadoc|all)).jar' game-versions: 1.20.6 + - name: Publish-1.21-forge-Curseforge + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + curseforge-id: 333287 + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + loaders: forge + name: ${{github.ref_name}}-1.21 - Forge + version-type: beta + files: 'versions/1.21-forge/build/libs/!(*-@(dev|sources|javadoc|all)).jar' + game-versions: 1.21 + - name: Publish-1.21-forge-Modrinth + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + modrinth-id: H5XMjpHi + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + loaders: forge + name: ${{github.ref_name}}-1.21 - Forge + files: 'versions/1.21-forge/build/libs/!(*-@(dev|sources|javadoc|all)).jar' + game-versions: 1.21 + - name: Publish-1.21-neoforge-Curseforge + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + curseforge-id: 333287 + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + loaders: neoforge + name: ${{github.ref_name}}-1.21 - NeoForge + version-type: beta + files: 'versions/1.21-neoforge/build/libs/!(*-@(dev|sources|javadoc|all)).jar' + game-versions: 1.21 + - name: Publish-1.21-neoforge-Modrinth + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + modrinth-id: H5XMjpHi + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + loaders: neoforge + name: ${{github.ref_name}}-1.21 - NeoForge + files: 'versions/1.21-neoforge/build/libs/!(*-@(dev|sources|javadoc|all)).jar' + game-versions: 1.21 + - name: Publish-1.21-fabric-Curseforge + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + curseforge-id: 333287 + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + loaders: fabric + name: ${{github.ref_name}}-1.21 - Fabric + files: 'versions/1.21-fabric/build/libs/!(*-@(dev|sources|javadoc|all)).jar' + game-versions: 1.21 + - name: Publish-1.21-fabric-Modrinth + uses: Kir-Antipov/mc-publish@v3.3.0 + with: + modrinth-id: H5XMjpHi + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + loaders: fabric + name: ${{github.ref_name}}-1.21 - Fabric + files: 'versions/1.21-fabric/build/libs/!(*-@(dev|sources|javadoc|all)).jar' + game-versions: 1.21 diff --git a/settings.json b/settings.json index f483c2a6..33a76d0c 100644 --- a/settings.json +++ b/settings.json @@ -22,6 +22,9 @@ "1.20.4-fabric", "1.20.6-forge", "1.20.6-neoforge", - "1.20.6-fabric" + "1.20.6-fabric", + "1.21-forge", + "1.21-neoforge", + "1.21-fabric" ] } diff --git a/src/main/java/dev/tr7zw/firstperson/LogicHandler.java b/src/main/java/dev/tr7zw/firstperson/LogicHandler.java index c48862e3..104efa52 100644 --- a/src/main/java/dev/tr7zw/firstperson/LogicHandler.java +++ b/src/main/java/dev/tr7zw/firstperson/LogicHandler.java @@ -15,7 +15,6 @@ import net.minecraft.client.CameraType; import net.minecraft.client.Minecraft; import net.minecraft.client.player.AbstractClientPlayer; -import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; @@ -88,8 +87,9 @@ public boolean shouldApplyThirdPerson(boolean thirdPerson) { * * @param entity * @param defValue + * @param delta */ - public void updatePositionOffset(Entity entity, Vec3 defValue) { + public void updatePositionOffset(Entity entity, Vec3 defValue, float delta) { offset = defValue; // handle sleeping if (entity == client.getCameraEntity() && client.player.isSleeping()) { @@ -105,7 +105,7 @@ public void updatePositionOffset(Entity entity, Vec3 defValue) { return; } player = (AbstractClientPlayer) entity; - realYaw = Mth.rotLerp(client.getFrameTime(), player.yBodyRotO, player.yBodyRot); + realYaw = Mth.rotLerp(delta, player.yBodyRotO, player.yBodyRot); if (!player.isLocalPlayer() || client.getCameraEntity() == player) { float bodyOffset; if (isCrawlingOrSwimming(client.player)) { @@ -120,9 +120,10 @@ public void updatePositionOffset(Entity entity, Vec3 defValue) { bodyOffset = Constants.SNEAK_BODY_OFFSET + fpm.getConfig().sneakXOffset / 100f; } else if (player.isPassenger()) { if (player.getVehicle() instanceof Boat || player.getVehicle() instanceof Minecart) { - realYaw = Mth.rotLerp(client.getFrameTime(), player.yBodyRotO, player.yBodyRot); + realYaw = Mth.rotLerp(delta, player.yBodyRotO, player.yBodyRot); } else if (player.getVehicle() instanceof LivingEntity living) { - realYaw = calculateBodyRot(Mth.rotLerp(client.getFrameTime(), living.yBodyRotO, living.yBodyRot), NMSHelper.getYRot(player)); + realYaw = calculateBodyRot(Mth.rotLerp(delta, living.yBodyRotO, living.yBodyRot), + NMSHelper.getYRot(player)); } else { // Non living entities don't use any custom rotation // realYaw = Mth.rotLerp(client.getFrameTime(), player.getVehicle().yRotO, @@ -145,23 +146,23 @@ public void updatePositionOffset(Entity entity, Vec3 defValue) { } offset = new Vec3(x, y, z); } - + private static float calculateBodyRot(float entityBodyRot, float riderHeadRot) { // Wrap the head rotation to the range [-180, 180] float wrappedHeadRot = Mth.wrapDegrees(riderHeadRot); - + // Calculate the difference between the head and body rotation float rotDiff = Mth.wrapDegrees(wrappedHeadRot - entityBodyRot); - + // If the difference is more than 50 degrees, adjust the body rotation if (Mth.abs(rotDiff) > 50.0F) { // Pull the body along with the head entityBodyRot = wrappedHeadRot - 50.0F * Math.signum(rotDiff); } - + // Ensure the body rotation is wrapped to [-180, 180] entityBodyRot = Mth.wrapDegrees(entityBodyRot); - + return entityBodyRot; } @@ -234,7 +235,8 @@ public boolean hideArmsAndItems(LivingEntity livingEntity) { * @return */ public boolean hideArmsAndItems(LivingEntity livingEntity, ItemStack mainhand, ItemStack offhand) { - if (FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming && livingEntity instanceof Player player && isSwimming(player)) { + if (FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming && livingEntity instanceof Player player + && isSwimming(player)) { return false; } if (lookingDown()) { @@ -265,7 +267,8 @@ public boolean dynamicHandsEnabled(LivingEntity livingEntity) { * @return */ public boolean dynamicHandsEnabled(LivingEntity livingEntity, ItemStack mainhand, ItemStack offhand) { - if (FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming && livingEntity instanceof Player player && isSwimming(player)) { + if (FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming && livingEntity instanceof Player player + && isSwimming(player)) { return false; } return fpm.getConfig().dynamicMode && fpm.getConfig().vanillaHandsMode != VanillaHands.OFF @@ -295,10 +298,11 @@ public void addAutoDisableItem(Item item) { public void reloadAutoVanillaHandsSettings() { autoVanillaHandItems.clear(); autoDisableItems.clear(); - Item invalid = NMSHelper.getItem(new ResourceLocation("minecraft", "air")); + Item invalid = NMSHelper.getItem(NMSHelper.getResourceLocation("minecraft", "air")); for (String itemId : fpm.getConfig().autoVanillaHands) { try { - Item item = NMSHelper.getItem(new ResourceLocation(itemId.split(":")[0], itemId.split(":")[1])); + Item item = NMSHelper + .getItem(NMSHelper.getResourceLocation(itemId.split(":")[0], itemId.split(":")[1])); if (invalid != item) { addAutoVanillaHandsItem(item); } @@ -309,7 +313,8 @@ public void reloadAutoVanillaHandsSettings() { FirstPersonBase.LOGGER.info("Loaded Vanilla Hands items: {}", autoVanillaHandItems); for (String itemId : fpm.getConfig().autoToggleModItems) { try { - Item item = NMSHelper.getItem(new ResourceLocation(itemId.split(":")[0], itemId.split(":")[1])); + Item item = NMSHelper + .getItem(NMSHelper.getResourceLocation(itemId.split(":")[0], itemId.split(":")[1])); if (invalid != item) { addAutoDisableItem(item); } diff --git a/src/main/java/dev/tr7zw/firstperson/config/ConfigScreenProvider.java b/src/main/java/dev/tr7zw/firstperson/config/ConfigScreenProvider.java index 8328ddca..13c0179a 100644 --- a/src/main/java/dev/tr7zw/firstperson/config/ConfigScreenProvider.java +++ b/src/main/java/dev/tr7zw/firstperson/config/ConfigScreenProvider.java @@ -42,7 +42,8 @@ public void initialize() { options.add(getOnOffOption("text.firstperson.option.firstperson.dynamicMode", () -> fpm.getConfig().dynamicMode, b -> fpm.getConfig().dynamicMode = b)); options.add(getOnOffOption("text.firstperson.option.firstperson.vanillaHandsSkipSwimming", - () -> fpm.getConfig().vanillaHandsSkipSwimming, b -> fpm.getConfig().vanillaHandsSkipSwimming = b)); + () -> fpm.getConfig().vanillaHandsSkipSwimming, + b -> fpm.getConfig().vanillaHandsSkipSwimming = b)); // spotless:off //#if MC >= 11900 diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/FeatureRendererMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/FeatureRendererMixin.java index b6ac00e5..7a55e18d 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/FeatureRendererMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/FeatureRendererMixin.java @@ -23,9 +23,16 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public abstract class FeatureRendererMixin { @Inject(method = "renderColoredCutoutModel", at = @At("HEAD"), cancellable = true) + // spotless:off + //#if MC >= 12100 private static void removeHead(EntityModel model, ResourceLocation texture, - PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float red, float green, - float blue, CallbackInfo ci) { + PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, int color, CallbackInfo ci) { + //#else + //$$private static void removeHead(EntityModel model, ResourceLocation texture, + //$$ PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float red, float green, + //$$ float blue, CallbackInfo ci) { + //#endif + //spotless:on if (FirstPersonModelCore.instance.isRenderingPlayer()) { if (!(model instanceof HeadedModel)) { ci.cancel(); @@ -39,9 +46,16 @@ private static void removeHead(EntityModel model, Re } @Inject(method = "renderColoredCutoutModel", at = @At("RETURN"), cancellable = true) + // spotless:off + //#if MC >= 12100 private static void removeReturn(EntityModel model, ResourceLocation texture, - PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float red, float green, - float blue, CallbackInfo ci) { + PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, int color, CallbackInfo ci) { + //#else + //$$private static void removeReturn(EntityModel model, ResourceLocation texture, + //$$ PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float red, float green, + //$$ float blue, CallbackInfo ci) { + //#endif + //spotless:on if (model instanceof HeadedModel) { ((ModelPartBase) (Object) ((HeadedModel) model).getHead()).showAgain(); if (model instanceof VillagerHeadModel villager) { diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/HeldItemRendererMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/HeldItemRendererMixin.java index e12a7cde..72f0cf10 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/HeldItemRendererMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/HeldItemRendererMixin.java @@ -52,7 +52,8 @@ public void renderFirstPersonItem(AbstractClientPlayer player, float tickDelta, info.cancel(); return; } - if(FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming && FirstPersonModelCore.instance.getLogicHandler().isSwimming(player)) { + if (FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming + && FirstPersonModelCore.instance.getLogicHandler().isSwimming(player)) { // while actively swimming, dont show the offhand item info.cancel(); return; diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/PlayerMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/PlayerMixin.java index a361979d..915810c5 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/PlayerMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/PlayerMixin.java @@ -29,8 +29,9 @@ public void getItemBySlot(EquipmentSlot slot, CallbackInfoReturnable ci.setReturnValue(ItemStack.EMPTY); return; } - if ((slot == EquipmentSlot.MAINHAND || slot == EquipmentSlot.OFFHAND) && FirstPersonModelCore.instance - .getLogicHandler().hideArmsAndItems(Minecraft.getInstance().player, this.inventory.getSelected(), this.inventory.offhand.get(0))) { + if ((slot == EquipmentSlot.MAINHAND || slot == EquipmentSlot.OFFHAND) + && FirstPersonModelCore.instance.getLogicHandler().hideArmsAndItems(Minecraft.getInstance().player, + this.inventory.getSelected(), this.inventory.offhand.get(0))) { ci.setReturnValue(ItemStack.EMPTY); return; } diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/PlayerRendererMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/PlayerRendererMixin.java index b477a052..e104a3df 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/PlayerRendererMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/PlayerRendererMixin.java @@ -25,14 +25,14 @@ public class PlayerRendererMixin { private static Minecraft fpmMcInstance = Minecraft.getInstance(); @Inject(method = "getRenderOffset", at = @At("RETURN"), cancellable = true) - public void getRenderOffset(AbstractClientPlayer entity, float f, CallbackInfoReturnable ci) { + public void getRenderOffset(AbstractClientPlayer entity, float delta, CallbackInfoReturnable ci) { if (entity == fpmMcInstance.cameraEntity && FirstPersonModelCore.instance.isRenderingPlayer()) { - FirstPersonModelCore.instance.getLogicHandler().updatePositionOffset(entity, Vec3.ZERO); + FirstPersonModelCore.instance.getLogicHandler().updatePositionOffset(entity, Vec3.ZERO, delta); Vec3 offset = ci.getReturnValue().add(FirstPersonModelCore.instance.getLogicHandler().getOffset()); for (PlayerOffsetHandler handler : FirstPersonAPI.getPlayerOffsetHandlers()) { - offset = handler.applyOffset(entity, f, ci.getReturnValue(), offset); + offset = handler.applyOffset(entity, delta, ci.getReturnValue(), offset); } ci.setReturnValue(offset); diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/RenderDispatcherMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/RenderDispatcherMixin.java index 69545144..4dcf44af 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/RenderDispatcherMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/RenderDispatcherMixin.java @@ -62,13 +62,17 @@ private static void shadowMove(PoseStack matrices, MultiBufferSource vertexConsu @Inject(method = "renderHitbox", at = @At(value = "HEAD"), cancellable = true) // spotless:off - //#if MC >= 11700 + //#if MC < 11700 + //$$ private void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f, CallbackInfo ci) { + //#elseif MC < 12100 + //$$ private static void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f, + //$$ CallbackInfo ci) { + //#else private static void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f, - CallbackInfo ci) { - //#else - //$$ private void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f, CallbackInfo ci) { - //#endif - //spotless:on + float g, float h, float i, + CallbackInfo ci) { + //#endif + //spotless:on if (entity == fpmMcInstance.cameraEntity && fpmMcInstance.options.getCameraType() == CameraType.FIRST_PERSON) { ci.cancel(); } diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/WorldRendererMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/WorldRendererMixin.java index 149bba59..5ade5485 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/WorldRendererMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/WorldRendererMixin.java @@ -18,6 +18,9 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.phys.Vec3; // spotless:off +//#if MC >= 12100 +import net.minecraft.client.DeltaTracker; +//#endif //#if MC >= 11903 import org.joml.Matrix4f; //#else @@ -40,10 +43,15 @@ public class WorldRendererMixin { //$$ @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;checkPoseStack(Lcom/mojang/blaze3d/vertex/PoseStack;)V", ordinal = 0)) //$$ public void render(PoseStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, //$$ GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f matrix4f, CallbackInfo info) { + //#elseif MC < 12100 + //$$ @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;checkPoseStack(Lcom/mojang/blaze3d/vertex/PoseStack;)V", ordinal = 0)) + //$$ public void render(float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, + //$$ GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo info) { + //$$ PoseStack matrices = new PoseStack(); //#else - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;checkPoseStack(Lcom/mojang/blaze3d/vertex/PoseStack;)V", ordinal = 0)) - public void render(float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, - GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo info) { + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;checkPoseStack(Lcom/mojang/blaze3d/vertex/PoseStack;)V", ordinal = 0)) + public void render(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, + LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo info) { PoseStack matrices = new PoseStack(); //#endif //spotless:on @@ -53,7 +61,13 @@ public void render(float tickDelta, long limitTime, boolean renderBlockOutline, Vec3 vec3d = camera.getPosition(); MultiBufferSource.BufferSource immediate = renderBuffers.bufferSource(); FirstPersonModelCore.instance.setRenderingPlayer(true); - renderEntity(camera.getEntity(), vec3d.x(), vec3d.y(), vec3d.z(), tickDelta, matrices, immediate); + // spotless:off + //#if MC < 12100 + //$$ renderEntity(camera.getEntity(), vec3d.x(), vec3d.y(), vec3d.z(), tickDelta, matrices, immediate); + //#else + renderEntity(camera.getEntity(), vec3d.x(), vec3d.y(), vec3d.z(), deltaTracker.getGameTimeDeltaPartialTick(false), matrices, immediate); + //#endif + //spotless:on FirstPersonModelCore.instance.setRenderingPlayer(false); } diff --git a/src/main/java/dev/tr7zw/firstperson/modsupport/PlayerAnimatorSupport.java b/src/main/java/dev/tr7zw/firstperson/modsupport/PlayerAnimatorSupport.java index 9f38c147..3df75600 100644 --- a/src/main/java/dev/tr7zw/firstperson/modsupport/PlayerAnimatorSupport.java +++ b/src/main/java/dev/tr7zw/firstperson/modsupport/PlayerAnimatorSupport.java @@ -59,7 +59,7 @@ public Vec3 applyOffset(AbstractClientPlayer entity, float delta, Vec3 original, relativeTranslation.translate(0, bodyOffset, 0); // Roll back the first [0,1,0] translation. // calculate the actual rotations and - float realYaw = Mth.rotLerp(minecraft.getFrameTime(), entity.yBodyRotO, entity.yBodyRot); + float realYaw = Mth.rotLerp(delta, entity.yBodyRotO, entity.yBodyRot); Matrix4f matrix = new Matrix4f(); // To multiply from LEFT, I have to create a new instance?! matrix.mul(new Matrix4f().scale(-1, 1, 1)); // What is going on with this?! diff --git a/versions/mainProject b/versions/mainProject index 304eaace..dfdd5113 100644 --- a/versions/mainProject +++ b/versions/mainProject @@ -1 +1 @@ -1.20.6-fabric \ No newline at end of file +1.21-fabric \ No newline at end of file