From ddf2fc5a7413e3015a0c0dba3f81ac7778dc7eec Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Tue, 23 May 2023 19:29:24 -0400 Subject: [PATCH] Provide more useful information if the image used in DynamicTexture is null --- .../mixin/safety/DynamicTextureMixin.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/safety/DynamicTextureMixin.java diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/safety/DynamicTextureMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/safety/DynamicTextureMixin.java new file mode 100644 index 00000000..388cc1eb --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/safety/DynamicTextureMixin.java @@ -0,0 +1,24 @@ +package org.embeddedt.modernfix.common.mixin.safety; + +import com.mojang.blaze3d.platform.NativeImage; +import net.minecraft.client.renderer.texture.DynamicTexture; +import org.embeddedt.modernfix.ModernFix; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(DynamicTexture.class) +public class DynamicTextureMixin { + @Shadow @Nullable private NativeImage pixels; + + @Redirect(method = "(Lcom/mojang/blaze3d/platform/NativeImage;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/texture/DynamicTexture;pixels:Lcom/mojang/blaze3d/platform/NativeImage;", ordinal = 0)) + private void putNewPixel(DynamicTexture texture, NativeImage pixels) { + if(pixels == null) { + ModernFix.LOGGER.error("Null image provided to DynamicTexture", new Exception()); + pixels = new NativeImage(4, 4, false); + } + this.pixels = pixels; + } +}