From c352a58a0c016709c7a3e4ab6af62b48dca0e8d5 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:32:41 -0600 Subject: [PATCH] Fix PoseStack not empty crashes Fix Figura getting blamed for crashes when other mods failed to load --- .../figura/mixin/render/LevelRendererMixin.java | 7 ++++++- .../figura/mixin/render/PoseStackAccessor.java | 15 +++++++++++++++ .../figura/resources/FiguraRuntimeResources.java | 12 +++++++++--- .../src/main/resources/figura-common.mixins.json | 9 +++++---- 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 common/src/main/java/org/figuramc/figura/mixin/render/PoseStackAccessor.java diff --git a/common/src/main/java/org/figuramc/figura/mixin/render/LevelRendererMixin.java b/common/src/main/java/org/figuramc/figura/mixin/render/LevelRendererMixin.java index e8b1cc11b..9daf7c906 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/render/LevelRendererMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/render/LevelRendererMixin.java @@ -87,6 +87,8 @@ private void renderLevelFirstPerson(PoseStack stack, float tickDelta, long limit return; Avatar.firstPerson = true; + + int size = ((PoseStackAccessor)stack).getPoseStack().size(); stack.pushPose(); EntityRenderer entityRenderer = this.entityRenderDispatcher.getRenderer(livingEntity); @@ -102,7 +104,10 @@ private void renderLevelFirstPerson(PoseStack stack, float tickDelta, long limit float yaw = Mth.lerp(tickDelta, livingEntity.yRotO, livingEntity.getYRot()); entityRenderer.render(livingEntity, yaw, tickDelta, stack, bufferSource, LightTexture.FULL_BRIGHT); - stack.popPose(); + do { + stack.popPose(); + } while(((PoseStackAccessor)stack).getPoseStack().size() > size); + Avatar.firstPerson = false; } diff --git a/common/src/main/java/org/figuramc/figura/mixin/render/PoseStackAccessor.java b/common/src/main/java/org/figuramc/figura/mixin/render/PoseStackAccessor.java new file mode 100644 index 000000000..a1ce1f908 --- /dev/null +++ b/common/src/main/java/org/figuramc/figura/mixin/render/PoseStackAccessor.java @@ -0,0 +1,15 @@ +package org.figuramc.figura.mixin.render; + +import com.mojang.blaze3d.vertex.PoseStack; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Deque; + +@Mixin(PoseStack.class) +public interface PoseStackAccessor { + @Accessor("poseStack") + @Final + Deque getPoseStack(); +} diff --git a/common/src/main/java/org/figuramc/figura/resources/FiguraRuntimeResources.java b/common/src/main/java/org/figuramc/figura/resources/FiguraRuntimeResources.java index a03242dc3..1d28cb2c7 100644 --- a/common/src/main/java/org/figuramc/figura/resources/FiguraRuntimeResources.java +++ b/common/src/main/java/org/figuramc/figura/resources/FiguraRuntimeResources.java @@ -20,7 +20,7 @@ public class FiguraRuntimeResources { - public static final String ASSETS_VERSION = FiguraMod.METADATA.getCustomValueAsString("assets_version"); + private static String ASSETS_VERSION; public static final PathPackResources PACK = new PathPackResources(FiguraMod.MOD_NAME + " runtime resource pack", getRootDirectory(), true); public static Path getRootDirectory() { @@ -31,6 +31,12 @@ public static Path getAssetsDirectory() { return IOUtils.getOrCreateDir(getRootDirectory(), "assets/" + FiguraMod.MOD_ID); } + public static String getAssetsVersion() { + if (ASSETS_VERSION == null) + ASSETS_VERSION = FiguraMod.METADATA.getCustomValueAsString("assets_version"); + return ASSETS_VERSION; + } + private static CompletableFuture future; public static void clearCache() { @@ -52,7 +58,7 @@ public static CompletableFuture init() { } // get new hashes - try (InputStream stream = NetworkStuff.getResourcesHashes(ASSETS_VERSION)) { + try (InputStream stream = NetworkStuff.getResourcesHashes(getAssetsVersion())) { byte[] bytes = stream.readAllBytes(); String s = new String(bytes); hashes = JsonParser.parseString(s).getAsJsonObject(); @@ -107,7 +113,7 @@ private static void getAndSaveResource(String path) throws Exception { if (Configs.LOCAL_ASSETS.value) return; Path target = getAssetsDirectory().resolve(path); IOUtils.createDirIfNeeded(target.getParent()); - try (InputStream resource = NetworkStuff.getResource(ASSETS_VERSION, path); OutputStream fs = Files.newOutputStream(target)) { + try (InputStream resource = NetworkStuff.getResource(getAssetsVersion(), path); OutputStream fs = Files.newOutputStream(target)) { fs.write(resource.readAllBytes()); FiguraMod.debug("Downloaded resource \"" + path + "\""); } diff --git a/common/src/main/resources/figura-common.mixins.json b/common/src/main/resources/figura-common.mixins.json index 32a0df7e6..634555eb1 100644 --- a/common/src/main/resources/figura-common.mixins.json +++ b/common/src/main/resources/figura-common.mixins.json @@ -20,7 +20,10 @@ "MinecraftMixin", "ReloadableResourceManagerMixin", "SkullBlockEntityAccessor", + "SNIHelperMixin", "TextDisplayMixin", + "compat.GeckolibGeoArmorRendererMixin", + "compat.GeckolibGeoRendererMixin", "compat.SimpleVCMixin", "font.BakedGlyphMixin", "font.BitmapGlyphMixin", @@ -86,13 +89,11 @@ "render.renderers.SignRendererMixin", "render.renderers.SkullBlockRendererMixin", "render.renderers.TridentRendererMixin", + "render.PoseStackAccessor", "sound.ChannelHandleMixin", "sound.SoundEngineMixin", "sound.SoundManagerAccessor", - "sound.SubtitleOverlayMixin", - "compat.GeckolibGeoRendererMixin", - "compat.GeckolibGeoArmorRendererMixin", - "SNIHelperMixin" + "sound.SubtitleOverlayMixin" ], "server": [ ],