Fix potential nullpointer rendering breaking overlay

- Should backport for #52
This commit is contained in:
Jozufozu 2021-12-07 23:53:13 -08:00
parent ef5de609a2
commit b4fe00a314
3 changed files with 9 additions and 5 deletions

View file

@ -3,6 +3,8 @@ package com.jozufozu.flywheel.core.atlas;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable;
import com.jozufozu.flywheel.mixin.atlas.SheetDataAccessor; import com.jozufozu.flywheel.mixin.atlas.SheetDataAccessor;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -24,15 +26,18 @@ public class AtlasInfo {
return null; return null;
} }
@Nullable
public static SheetData getAtlasData(TextureAtlasSprite texture) { public static SheetData getAtlasData(TextureAtlasSprite texture) {
return getAtlasData(texture.atlas()); return getAtlasData(texture.atlas());
} }
@Nullable
public static SheetData getAtlasData(TextureAtlas atlas) { public static SheetData getAtlasData(TextureAtlas atlas) {
return getAtlasData(atlas.location()); return getAtlasData(atlas.location());
} }
public static SheetData getAtlasData(ResourceLocation loc) { @Nullable
public static SheetData getAtlasData(@Nullable ResourceLocation loc) {
return sheetData.get(loc); return sheetData.get(loc);
} }

View file

@ -48,11 +48,10 @@ public class CrumblingGroup<P extends CrumblingProgram> extends InstancedMateria
} }
private void updateAtlasSize() { private void updateAtlasSize() {
ResourceLocation texture = RenderTextures.getShaderTexture(0);
if (texture != null) { SheetData atlasData = AtlasInfo.getAtlasData(RenderTextures.getShaderTexture(0));
SheetData atlasData = AtlasInfo.getAtlasData(texture);
if (atlasData != null) {
width = atlasData.width; width = atlasData.width;
height = atlasData.height; height = atlasData.height;
} else { } else {

View file

@ -13,7 +13,7 @@ import net.minecraft.resources.ResourceLocation;
@Mixin(RenderSystem.class) @Mixin(RenderSystem.class)
public class RenderTexturesMixin { 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) { private static void storeTextureLoc(int pShaderTexture, ResourceLocation pTextureId, CallbackInfo ci) {
RenderTextures._setShaderTexture(pShaderTexture, pTextureId); RenderTextures._setShaderTexture(pShaderTexture, pTextureId);
} }