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.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);
}

View File

@ -48,11 +48,10 @@ public class CrumblingGroup<P extends CrumblingProgram> 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 {

View File

@ -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);
}