Skip to content

Commit

Permalink
Fix PoseStack not empty crashes
Browse files Browse the repository at this point in the history
Fix Figura getting blamed for crashes when other mods failed to load
  • Loading branch information
UnlikePaladin committed Feb 26, 2024
1 parent 44390bc commit c352a58
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
Expand Up @@ -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<? super LivingEntity> entityRenderer = this.entityRenderDispatcher.getRenderer(livingEntity);
Expand All @@ -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;
}

Expand Down
@@ -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<PoseStack.Pose> getPoseStack();
}
Expand Up @@ -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() {
Expand All @@ -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<Void> future;

public static void clearCache() {
Expand All @@ -52,7 +58,7 @@ public static CompletableFuture<Void> 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();
Expand Down Expand Up @@ -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 + "\"");
}
Expand Down
9 changes: 5 additions & 4 deletions common/src/main/resources/figura-common.mixins.json
Expand Up @@ -20,7 +20,10 @@
"MinecraftMixin",
"ReloadableResourceManagerMixin",
"SkullBlockEntityAccessor",
"SNIHelperMixin",
"TextDisplayMixin",
"compat.GeckolibGeoArmorRendererMixin",
"compat.GeckolibGeoRendererMixin",
"compat.SimpleVCMixin",
"font.BakedGlyphMixin",
"font.BitmapGlyphMixin",
Expand Down Expand Up @@ -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": [
],
Expand Down

0 comments on commit c352a58

Please sign in to comment.