From b4fe00a3148dc8485e19890bcdbc09614be67bba Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Tue, 7 Dec 2021 23:53:13 -0800 Subject: [PATCH] Fix potential nullpointer rendering breaking overlay - Should backport for #52 --- .../java/com/jozufozu/flywheel/core/atlas/AtlasInfo.java | 7 ++++++- .../jozufozu/flywheel/core/crumbling/CrumblingGroup.java | 5 ++--- .../com/jozufozu/flywheel/mixin/RenderTexturesMixin.java | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/core/atlas/AtlasInfo.java b/src/main/java/com/jozufozu/flywheel/core/atlas/AtlasInfo.java index 01388512b..6b915c3a9 100644 --- a/src/main/java/com/jozufozu/flywheel/core/atlas/AtlasInfo.java +++ b/src/main/java/com/jozufozu/flywheel/core/atlas/AtlasInfo.java @@ -3,6 +3,8 @@ package com.jozufozu.flywheel.core.atlas; import java.util.HashMap; import java.util.Map; +import javax.annotation.Nullable; + import com.jozufozu.flywheel.mixin.atlas.SheetDataAccessor; import net.minecraft.client.Minecraft; @@ -24,15 +26,18 @@ public class AtlasInfo { return null; } + @Nullable public static SheetData getAtlasData(TextureAtlasSprite texture) { return getAtlasData(texture.atlas()); } + @Nullable public static SheetData getAtlasData(TextureAtlas atlas) { return getAtlasData(atlas.location()); } - public static SheetData getAtlasData(ResourceLocation loc) { + @Nullable + public static SheetData getAtlasData(@Nullable ResourceLocation loc) { return sheetData.get(loc); } diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java index 0250bf51d..c53db3b8a 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java @@ -48,11 +48,10 @@ public class CrumblingGroup

extends InstancedMateria } private void updateAtlasSize() { - ResourceLocation texture = RenderTextures.getShaderTexture(0); - if (texture != null) { - SheetData atlasData = AtlasInfo.getAtlasData(texture); + SheetData atlasData = AtlasInfo.getAtlasData(RenderTextures.getShaderTexture(0)); + if (atlasData != null) { width = atlasData.width; height = atlasData.height; } else { diff --git a/src/main/java/com/jozufozu/flywheel/mixin/RenderTexturesMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/RenderTexturesMixin.java index ac2b09450..5e38c5ea1 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/RenderTexturesMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/RenderTexturesMixin.java @@ -13,7 +13,7 @@ import net.minecraft.resources.ResourceLocation; @Mixin(RenderSystem.class) public class RenderTexturesMixin { - @Inject(method = "_setShaderTexture(ILnet/minecraft/resources/ResourceLocation;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/TextureManager;getTexture(Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/renderer/texture/AbstractTexture;")) + @Inject(method = "_setShaderTexture(ILnet/minecraft/resources/ResourceLocation;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/AbstractTexture;getId()I")) private static void storeTextureLoc(int pShaderTexture, ResourceLocation pTextureId, CallbackInfo ci) { RenderTextures._setShaderTexture(pShaderTexture, pTextureId); }