From 61a874afd1211c4c9e4e0e6bb80d6612fbcb2bda Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 13 Sep 2024 16:35:12 -0400 Subject: [PATCH 1/5] Convert spriteUtil into a api --- .../mods/sodium/api/texture/SpriteUtil.java | 26 +++++++++++++++++++ .../render/chunk/RenderSectionManager.java | 4 +-- .../render/chunk/data/BuiltSectionInfo.java | 4 +-- .../frapi/render/ItemRenderContext.java | 4 +-- .../render/NonTerrainBlockRenderContext.java | 4 +-- .../{SpriteUtil.java => SpriteUtilImpl.java} | 9 ++++--- .../intrinsics/BufferBuilderMixin.java | 10 +++---- .../render/model/item/ItemRendererMixin.java | 4 +-- .../animations/tracking/GuiGraphicsMixin.java | 6 ++--- .../tracking/ModelBlockRendererMixin.java | 4 +-- .../tracking/TextureAtlasMixin.java | 4 +-- .../tracking/TextureSheetParticleMixin.java | 6 ++--- .../model/block/ModelBlockRendererMixin.java | 4 +-- .../model/block/ModelBlockRendererMixin.java | 4 +-- 14 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java rename common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/{SpriteUtil.java => SpriteUtilImpl.java} (68%) diff --git a/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java b/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java new file mode 100644 index 0000000000..712f27d9ea --- /dev/null +++ b/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java @@ -0,0 +1,26 @@ +package net.caffeinemc.mods.sodium.api.texture; + +import net.caffeinemc.mods.sodium.api.internal.DependencyInjection; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +@ApiStatus.AvailableSince("0.6.0") +public interface SpriteUtil { + SpriteUtil INSTANCE = DependencyInjection.load(SpriteUtil.class, + "net.caffeinemc.mods.sodium.client.render.texture.SpriteUtilImpl"); + + /** + * Marks a provided sprite as active + * @param sprite The sprite you want to mark as active + */ + void markSpriteActive(@Nullable TextureAtlasSprite sprite); + + /** + * Checks if the provided sprite has an animation + * + * @param sprite The sprite you want to check + * @return true if the provided sprite has an animation, false if it doesn't + */ + boolean hasAnimation(TextureAtlasSprite sprite); +} diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java index 21aae7a7e1..b05d80e6ca 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java @@ -8,6 +8,7 @@ import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import it.unimi.dsi.fastutil.objects.ReferenceSet; import it.unimi.dsi.fastutil.objects.ReferenceSets; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.SodiumClientMod; import net.caffeinemc.mods.sodium.client.gl.device.CommandList; import net.caffeinemc.mods.sodium.client.gl.device.RenderDevice; @@ -37,7 +38,6 @@ import net.caffeinemc.mods.sodium.client.render.chunk.translucent_sorting.trigger.CameraMovement; import net.caffeinemc.mods.sodium.client.render.chunk.translucent_sorting.trigger.SortTriggering; import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkMeshFormats; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.render.util.RenderAsserts; import net.caffeinemc.mods.sodium.client.render.viewport.CameraTransform; import net.caffeinemc.mods.sodium.client.render.viewport.Viewport; @@ -274,7 +274,7 @@ public void tickVisibleRenders() { } for (TextureAtlasSprite sprite : sprites) { - SpriteUtil.markSpriteActive(sprite); + SpriteUtil.INSTANCE.markSpriteActive(sprite); } } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/data/BuiltSectionInfo.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/data/BuiltSectionInfo.java index 25bf883a4d..a747eb042f 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/data/BuiltSectionInfo.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/data/BuiltSectionInfo.java @@ -1,10 +1,10 @@ package net.caffeinemc.mods.sodium.client.render.chunk.data; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionFlags; import net.caffeinemc.mods.sodium.client.render.chunk.occlusion.VisibilityEncoding; import net.caffeinemc.mods.sodium.client.render.chunk.terrain.TerrainRenderPass; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; import net.minecraft.client.renderer.chunk.VisibilitySet; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.Direction; @@ -79,7 +79,7 @@ public void setOcclusionData(VisibilitySet data) { * @param sprite The sprite */ public void addSprite(TextureAtlasSprite sprite) { - if (SpriteUtil.hasAnimation(sprite)) { + if (SpriteUtil.INSTANCE.hasAnimation(sprite)) { this.animatedSprites.add(sprite); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/ItemRenderContext.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/ItemRenderContext.java index 62dfae8cad..dda4614bfe 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/ItemRenderContext.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/ItemRenderContext.java @@ -19,11 +19,11 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.MatrixUtil; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.render.frapi.helper.ColorHelper; import net.caffeinemc.mods.sodium.client.render.frapi.mesh.EncodingFormat; import net.caffeinemc.mods.sodium.client.render.frapi.mesh.MutableQuadViewImpl; import net.caffeinemc.mods.sodium.client.render.texture.SpriteFinderCache; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; import net.caffeinemc.mods.sodium.mixin.features.render.frapi.ItemRendererAccessor; import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; @@ -223,7 +223,7 @@ private void shadeQuad(MutableQuadViewImpl quad, boolean emissive) { private void bufferQuad(MutableQuadViewImpl quad, VertexConsumer vertexConsumer) { QuadEncoder.writeQuadVertices(quad, vertexConsumer, overlay, matPosition, trustedNormals, matNormal); - SpriteUtil.markSpriteActive(quad.sprite(SpriteFinderCache.forBlockAtlas())); + SpriteUtil.INSTANCE.markSpriteActive(quad.sprite(SpriteFinderCache.forBlockAtlas())); } /** diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/NonTerrainBlockRenderContext.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/NonTerrainBlockRenderContext.java index 130d240b2e..22fa0f5a74 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/NonTerrainBlockRenderContext.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/NonTerrainBlockRenderContext.java @@ -18,13 +18,13 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.model.light.LightMode; import net.caffeinemc.mods.sodium.client.model.light.LightPipelineProvider; import net.caffeinemc.mods.sodium.client.model.light.data.SingleBlockLightDataCache; import net.caffeinemc.mods.sodium.client.render.frapi.helper.ColorHelper; import net.caffeinemc.mods.sodium.client.render.frapi.mesh.MutableQuadViewImpl; import net.caffeinemc.mods.sodium.client.render.texture.SpriteFinderCache; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.services.SodiumModelData; import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; import net.fabricmc.fabric.api.renderer.v1.material.ShadeMode; @@ -127,6 +127,6 @@ protected void shadeQuad(MutableQuadViewImpl quad, LightMode lightMode, boolean private void bufferQuad(MutableQuadViewImpl quad) { QuadEncoder.writeQuadVertices(quad, vertexConsumer, overlay, matPosition, trustedNormals, matNormal); - SpriteUtil.markSpriteActive(quad.sprite(SpriteFinderCache.forBlockAtlas())); + SpriteUtil.INSTANCE.markSpriteActive(quad.sprite(SpriteFinderCache.forBlockAtlas())); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtil.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java similarity index 68% rename from common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtil.java rename to common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java index 084acc18b5..d65121732b 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtil.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java @@ -1,10 +1,12 @@ package net.caffeinemc.mods.sodium.client.render.texture; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import org.jetbrains.annotations.Nullable; -public class SpriteUtil { - public static void markSpriteActive(@Nullable TextureAtlasSprite sprite) { +public class SpriteUtilImpl implements SpriteUtil { + @Override + public void markSpriteActive(@Nullable TextureAtlasSprite sprite) { if (sprite == null) { // Can happen in some cases, for example if a mod passes a BakedQuad with a null sprite // to a VertexConsumer that does not have a texture element. @@ -14,7 +16,8 @@ public static void markSpriteActive(@Nullable TextureAtlasSprite sprite) { ((SpriteContentsExtension) sprite.contents()).sodium$setActive(true); } - public static boolean hasAnimation(TextureAtlasSprite sprite) { + @Override + public boolean hasAnimation(TextureAtlasSprite sprite) { return ((SpriteContentsExtension) sprite.contents()).sodium$hasAnimation(); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java index 28b0af3412..5da7c772e8 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java @@ -3,9 +3,9 @@ import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.model.quad.ModelQuadView; import net.caffeinemc.mods.sodium.client.render.immediate.model.BakedModelEncoder; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; import net.caffeinemc.mods.sodium.api.util.ColorABGR; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.minecraft.client.renderer.block.model.BakedQuad; @@ -25,7 +25,7 @@ public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float r, f if (!this.fastFormat) { VertexConsumer.super.putBulkData(matrices, bakedQuad, r, g, b, a, light, overlay); - SpriteUtil.markSpriteActive(bakedQuad.getSprite()); + SpriteUtil.INSTANCE.markSpriteActive(bakedQuad.getSprite()); return; } @@ -41,7 +41,7 @@ public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float r, f int color = ColorABGR.pack(r, g, b, a); BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - SpriteUtil.markSpriteActive(quad.getSprite()); + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } @Override @@ -49,7 +49,7 @@ public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float[] br if (!this.fastFormat) { VertexConsumer.super.putBulkData(matrices, bakedQuad, brightnessTable, r, g, b, a, light, overlay, colorize); - SpriteUtil.markSpriteActive(bakedQuad.getSprite()); + SpriteUtil.INSTANCE.markSpriteActive(bakedQuad.getSprite()); return; } @@ -64,6 +64,6 @@ public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float[] br BakedModelEncoder.writeQuadVertices(writer, matrices, quad, r, g, b, a, brightnessTable, colorize, light, overlay); - SpriteUtil.markSpriteActive(quad.getSprite()); + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java index dc521d3bba..819bee42e0 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java @@ -1,8 +1,8 @@ package net.caffeinemc.mods.sodium.mixin.features.render.model.item; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.model.quad.BakedQuadView; import net.caffeinemc.mods.sodium.client.render.immediate.model.BakedModelEncoder; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.render.vertex.VertexConsumerUtils; import net.caffeinemc.mods.sodium.client.model.color.interop.ItemColorsExtension; import net.caffeinemc.mods.sodium.client.util.DirectionUtil; @@ -94,7 +94,7 @@ private void renderBakedItemQuads(PoseStack.Pose matrices, VertexBufferWriter wr BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - SpriteUtil.markSpriteActive(quad.getSprite()); + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/GuiGraphicsMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/GuiGraphicsMixin.java index 49d71efb44..fed72a54e8 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/GuiGraphicsMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/GuiGraphicsMixin.java @@ -1,6 +1,6 @@ package net.caffeinemc.mods.sodium.mixin.features.textures.animations.tracking; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import org.spongepowered.asm.mixin.Mixin; @@ -16,7 +16,7 @@ private void preDrawSprite(int x, int y, int z, TextureAtlasSprite sprite, CallbackInfo ci) { - SpriteUtil.markSpriteActive(sprite); + SpriteUtil.INSTANCE.markSpriteActive(sprite); } @Inject(method = "blit(IIIIILnet/minecraft/client/renderer/texture/TextureAtlasSprite;FFFF)V", at = @At("HEAD")) @@ -26,6 +26,6 @@ private void preDrawSprite(int x, int y, int z, float red, float green, float blue, float alpha, CallbackInfo ci) { - SpriteUtil.markSpriteActive(sprite); + SpriteUtil.INSTANCE.markSpriteActive(sprite); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/ModelBlockRendererMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/ModelBlockRendererMixin.java index 020ee3cb27..21b5c4d1d4 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/ModelBlockRendererMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/ModelBlockRendererMixin.java @@ -2,7 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.minecraft.client.renderer.block.ModelBlockRenderer; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.core.BlockPos; @@ -22,6 +22,6 @@ public class ModelBlockRendererMixin { */ @Inject(method = "putQuadData", at = @At("HEAD")) private void preRenderQuad(BlockAndTintGetter level, BlockState state, BlockPos pos, VertexConsumer vertexConsumer, PoseStack.Pose matrices, BakedQuad quad, float brightness0, float brightness1, float brightness2, float brightness3, int light0, int light1, int light2, int light3, int overlay, CallbackInfo ci) { - SpriteUtil.markSpriteActive(quad.getSprite()); + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/TextureAtlasMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/TextureAtlasMixin.java index d60038f2c4..f23ca8fe4f 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/TextureAtlasMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/TextureAtlasMixin.java @@ -1,6 +1,6 @@ package net.caffeinemc.mods.sodium.mixin.features.textures.animations.tracking; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import org.spongepowered.asm.mixin.Mixin; @@ -15,7 +15,7 @@ private void preReturnSprite(CallbackInfoReturnable cir) { TextureAtlasSprite sprite = cir.getReturnValue(); if (sprite != null) { - SpriteUtil.markSpriteActive(sprite); + SpriteUtil.INSTANCE.markSpriteActive(sprite); } } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/TextureSheetParticleMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/TextureSheetParticleMixin.java index 6773925be4..a4f162ab15 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/TextureSheetParticleMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/TextureSheetParticleMixin.java @@ -1,7 +1,7 @@ package net.caffeinemc.mods.sodium.mixin.features.textures.animations.tracking; import com.mojang.blaze3d.vertex.VertexConsumer; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.particle.SingleQuadParticle; @@ -28,13 +28,13 @@ protected TextureSheetParticleMixin(ClientLevel level, double x, double y, doubl @Inject(method = "setSprite(Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;)V", at = @At("RETURN")) private void afterSetSprite(TextureAtlasSprite sprite, CallbackInfo ci) { - this.shouldTickSprite = sprite != null && SpriteUtil.hasAnimation(sprite); + this.shouldTickSprite = sprite != null && SpriteUtil.INSTANCE.hasAnimation(sprite); } @Override public void render(VertexConsumer vertexConsumer, Camera camera, float tickDelta) { if (this.shouldTickSprite) { - SpriteUtil.markSpriteActive(this.sprite); + SpriteUtil.INSTANCE.markSpriteActive(this.sprite); } super.render(vertexConsumer, camera, tickDelta); diff --git a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java index 59240cbb4b..18776f342c 100644 --- a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java +++ b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java @@ -2,11 +2,11 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.caffeinemc.mods.sodium.api.util.ColorABGR; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.caffeinemc.mods.sodium.client.model.quad.BakedQuadView; import net.caffeinemc.mods.sodium.client.render.immediate.model.BakedModelEncoder; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.render.vertex.VertexConsumerUtils; import net.caffeinemc.mods.sodium.client.util.DirectionUtil; import net.minecraft.client.renderer.block.ModelBlockRenderer; @@ -46,7 +46,7 @@ private static void renderQuads(PoseStack.Pose matrices, VertexBufferWriter writ BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - SpriteUtil.markSpriteActive(quad.getSprite()); + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } } diff --git a/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java b/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java index 7feb74b4d2..814604cbef 100644 --- a/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java +++ b/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java @@ -2,11 +2,11 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.caffeinemc.mods.sodium.api.util.ColorABGR; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.caffeinemc.mods.sodium.client.model.quad.BakedQuadView; import net.caffeinemc.mods.sodium.client.render.immediate.model.BakedModelEncoder; -import net.caffeinemc.mods.sodium.client.render.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.render.vertex.VertexConsumerUtils; import net.caffeinemc.mods.sodium.client.util.DirectionUtil; import net.minecraft.client.renderer.RenderType; @@ -48,7 +48,7 @@ private static void renderQuads(PoseStack.Pose matrices, VertexBufferWriter writ BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - SpriteUtil.markSpriteActive(quad.getSprite()); + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } } From 10d2295b8e635f6c4b304d535d163728541a2582 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 15 Sep 2024 11:08:35 -0400 Subject: [PATCH 2/5] Make it experimental --- .../java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java b/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java index 712f27d9ea..ff48852983 100644 --- a/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java +++ b/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java @@ -5,6 +5,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +@ApiStatus.Experimental @ApiStatus.AvailableSince("0.6.0") public interface SpriteUtil { SpriteUtil INSTANCE = DependencyInjection.load(SpriteUtil.class, From dbb5bb5b99ef3af64a6de1132c84331ba12a1447 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 15 Sep 2024 11:19:06 -0400 Subject: [PATCH 3/5] Require NotNull --- .../mods/sodium/api/texture/SpriteUtil.java | 4 ++-- .../sodium/client/render/texture/SpriteUtilImpl.java | 12 +++++------- .../intrinsics/BufferBuilderMixin.java | 10 ++++++---- .../render/model/item/ItemRendererMixin.java | 3 ++- .../render/model/block/ModelBlockRendererMixin.java | 3 ++- .../render/model/block/ModelBlockRendererMixin.java | 3 ++- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java b/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java index ff48852983..ec3b2e861f 100644 --- a/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java +++ b/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java @@ -3,7 +3,7 @@ import net.caffeinemc.mods.sodium.api.internal.DependencyInjection; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; @ApiStatus.Experimental @ApiStatus.AvailableSince("0.6.0") @@ -15,7 +15,7 @@ public interface SpriteUtil { * Marks a provided sprite as active * @param sprite The sprite you want to mark as active */ - void markSpriteActive(@Nullable TextureAtlasSprite sprite); + void markSpriteActive(@NotNull TextureAtlasSprite sprite); /** * Checks if the provided sprite has an animation diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java index d65121732b..92f8c7d049 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java @@ -2,16 +2,14 @@ import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; public class SpriteUtilImpl implements SpriteUtil { @Override - public void markSpriteActive(@Nullable TextureAtlasSprite sprite) { - if (sprite == null) { - // Can happen in some cases, for example if a mod passes a BakedQuad with a null sprite - // to a VertexConsumer that does not have a texture element. - return; - } + public void markSpriteActive(@NotNull TextureAtlasSprite sprite) { + Objects.requireNonNull(sprite); ((SpriteContentsExtension) sprite.contents()).sodium$setActive(true); } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java index 5da7c772e8..ac232b77c9 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java @@ -24,7 +24,7 @@ public abstract class BufferBuilderMixin implements VertexConsumer { public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float r, float g, float b, float a, int light, int overlay) { if (!this.fastFormat) { VertexConsumer.super.putBulkData(matrices, bakedQuad, r, g, b, a, light, overlay); - + SpriteUtil.INSTANCE.markSpriteActive(bakedQuad.getSprite()); return; @@ -41,14 +41,15 @@ public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float r, f int color = ColorABGR.pack(r, g, b, a); BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + if (quad.getSprite() != null) + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } @Override public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float[] brightnessTable, float r, float g, float b, float a, int[] light, int overlay, boolean colorize) { if (!this.fastFormat) { VertexConsumer.super.putBulkData(matrices, bakedQuad, brightnessTable, r, g, b, a, light, overlay, colorize); - + SpriteUtil.INSTANCE.markSpriteActive(bakedQuad.getSprite()); return; @@ -64,6 +65,7 @@ public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float[] br BakedModelEncoder.writeQuadVertices(writer, matrices, quad, r, g, b, a, brightnessTable, colorize, light, overlay); - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + if (quad.getSprite() != null) + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java index 819bee42e0..411f4195b4 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java @@ -94,7 +94,8 @@ private void renderBakedItemQuads(PoseStack.Pose matrices, VertexBufferWriter wr BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + if (quad.getSprite() != null) + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } } } diff --git a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java index 18776f342c..b598bb5f72 100644 --- a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java +++ b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java @@ -46,7 +46,8 @@ private static void renderQuads(PoseStack.Pose matrices, VertexBufferWriter writ BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + if (quad.getSprite() != null) + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } } diff --git a/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java b/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java index 814604cbef..97dbbb3392 100644 --- a/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java +++ b/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java @@ -48,7 +48,8 @@ private static void renderQuads(PoseStack.Pose matrices, VertexBufferWriter writ BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + if (quad.getSprite() != null) + SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); } } From db3c90160f112a3c16243d6b6c5729ec5b5c89d7 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 15 Sep 2024 13:15:44 -0400 Subject: [PATCH 4/5] address reviews --- .../mods/sodium/api/texture/SpriteUtil.java | 2 +- .../frapi/render/ItemRenderContext.java | 6 +++- .../render/NonTerrainBlockRenderContext.java | 6 +++- .../client/render/texture/SpriteUtilImpl.java | 2 +- .../intrinsics/BufferBuilderMixin.java | 33 ++++++++++++++----- .../render/model/item/ItemRendererMixin.java | 8 +++-- .../tracking/ModelBlockRendererMixin.java | 8 ++++- .../model/block/ModelBlockRendererMixin.java | 7 ++-- .../model/block/ModelBlockRendererMixin.java | 7 ++-- 9 files changed, 60 insertions(+), 19 deletions(-) diff --git a/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java b/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java index ec3b2e861f..f21eb45e10 100644 --- a/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java +++ b/common/src/api/java/net/caffeinemc/mods/sodium/api/texture/SpriteUtil.java @@ -23,5 +23,5 @@ public interface SpriteUtil { * @param sprite The sprite you want to check * @return true if the provided sprite has an animation, false if it doesn't */ - boolean hasAnimation(TextureAtlasSprite sprite); + boolean hasAnimation(@NotNull TextureAtlasSprite sprite); } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/ItemRenderContext.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/ItemRenderContext.java index dda4614bfe..f28c9c7216 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/ItemRenderContext.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/ItemRenderContext.java @@ -35,6 +35,7 @@ import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; @@ -223,7 +224,10 @@ private void shadeQuad(MutableQuadViewImpl quad, boolean emissive) { private void bufferQuad(MutableQuadViewImpl quad, VertexConsumer vertexConsumer) { QuadEncoder.writeQuadVertices(quad, vertexConsumer, overlay, matPosition, trustedNormals, matNormal); - SpriteUtil.INSTANCE.markSpriteActive(quad.sprite(SpriteFinderCache.forBlockAtlas())); + TextureAtlasSprite sprite = quad.sprite(SpriteFinderCache.forBlockAtlas()); + if (sprite != null) { + SpriteUtil.INSTANCE.markSpriteActive(sprite); + } } /** diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/NonTerrainBlockRenderContext.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/NonTerrainBlockRenderContext.java index 22fa0f5a74..1ef82b6069 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/NonTerrainBlockRenderContext.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/NonTerrainBlockRenderContext.java @@ -32,6 +32,7 @@ import net.fabricmc.fabric.api.util.TriState; import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.renderer.ItemBlockRenderTypes; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; import net.minecraft.util.RandomSource; @@ -127,6 +128,9 @@ protected void shadeQuad(MutableQuadViewImpl quad, LightMode lightMode, boolean private void bufferQuad(MutableQuadViewImpl quad) { QuadEncoder.writeQuadVertices(quad, vertexConsumer, overlay, matPosition, trustedNormals, matNormal); - SpriteUtil.INSTANCE.markSpriteActive(quad.sprite(SpriteFinderCache.forBlockAtlas())); + TextureAtlasSprite sprite = quad.sprite(SpriteFinderCache.forBlockAtlas()); + if (sprite != null) { + SpriteUtil.INSTANCE.markSpriteActive(sprite); + } } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java index 92f8c7d049..28739686d1 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteUtilImpl.java @@ -15,7 +15,7 @@ public void markSpriteActive(@NotNull TextureAtlasSprite sprite) { } @Override - public boolean hasAnimation(TextureAtlasSprite sprite) { + public boolean hasAnimation(@NotNull TextureAtlasSprite sprite) { return ((SpriteContentsExtension) sprite.contents()).sodium$hasAnimation(); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java index ac232b77c9..f5ab93d978 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java @@ -9,6 +9,9 @@ import net.caffeinemc.mods.sodium.api.util.ColorABGR; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import org.checkerframework.common.returnsreceiver.qual.This; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,8 +27,13 @@ public abstract class BufferBuilderMixin implements VertexConsumer { public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float r, float g, float b, float a, int light, int overlay) { if (!this.fastFormat) { VertexConsumer.super.putBulkData(matrices, bakedQuad, r, g, b, a, light, overlay); - - SpriteUtil.INSTANCE.markSpriteActive(bakedQuad.getSprite()); + + TextureAtlasSprite sprite = bakedQuad.getSprite(); + // This can be null + //noinspection ConstantValue + if (sprite != null) { + SpriteUtil.INSTANCE.markSpriteActive(sprite); + } return; } @@ -41,16 +49,23 @@ public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float r, f int color = ColorABGR.pack(r, g, b, a); BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - if (quad.getSprite() != null) - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + TextureAtlasSprite sprite = quad.getSprite(); + if (sprite != null) { + SpriteUtil.INSTANCE.markSpriteActive(sprite); + } } @Override public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float[] brightnessTable, float r, float g, float b, float a, int[] light, int overlay, boolean colorize) { if (!this.fastFormat) { VertexConsumer.super.putBulkData(matrices, bakedQuad, brightnessTable, r, g, b, a, light, overlay, colorize); - - SpriteUtil.INSTANCE.markSpriteActive(bakedQuad.getSprite()); + + TextureAtlasSprite sprite = bakedQuad.getSprite(); + // This can be null + //noinspection ConstantValue + if (sprite != null) { + SpriteUtil.INSTANCE.markSpriteActive(sprite); + } return; } @@ -65,7 +80,9 @@ public void putBulkData(PoseStack.Pose matrices, BakedQuad bakedQuad, float[] br BakedModelEncoder.writeQuadVertices(writer, matrices, quad, r, g, b, a, brightnessTable, colorize, light, overlay); - if (quad.getSprite() != null) - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + TextureAtlasSprite sprite = quad.getSprite(); + if (sprite != null) { + SpriteUtil.INSTANCE.markSpriteActive(sprite); + } } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java index 411f4195b4..76ba590135 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/model/item/ItemRendererMixin.java @@ -3,6 +3,7 @@ import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.caffeinemc.mods.sodium.client.model.quad.BakedQuadView; import net.caffeinemc.mods.sodium.client.render.immediate.model.BakedModelEncoder; +import net.caffeinemc.mods.sodium.client.render.texture.SpriteFinderCache; import net.caffeinemc.mods.sodium.client.render.vertex.VertexConsumerUtils; import net.caffeinemc.mods.sodium.client.model.color.interop.ItemColorsExtension; import net.caffeinemc.mods.sodium.client.util.DirectionUtil; @@ -12,6 +13,7 @@ import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; @@ -94,8 +96,10 @@ private void renderBakedItemQuads(PoseStack.Pose matrices, VertexBufferWriter wr BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - if (quad.getSprite() != null) - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + TextureAtlasSprite sprite = quad.getSprite(); + if (sprite != null) { + SpriteUtil.INSTANCE.markSpriteActive(sprite); + } } } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/ModelBlockRendererMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/ModelBlockRendererMixin.java index 21b5c4d1d4..cb666fa6aa 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/ModelBlockRendererMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/ModelBlockRendererMixin.java @@ -5,6 +5,7 @@ import net.caffeinemc.mods.sodium.api.texture.SpriteUtil; import net.minecraft.client.renderer.block.ModelBlockRenderer; import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; @@ -22,6 +23,11 @@ public class ModelBlockRendererMixin { */ @Inject(method = "putQuadData", at = @At("HEAD")) private void preRenderQuad(BlockAndTintGetter level, BlockState state, BlockPos pos, VertexConsumer vertexConsumer, PoseStack.Pose matrices, BakedQuad quad, float brightness0, float brightness1, float brightness2, float brightness3, int light0, int light1, int light2, int light3, int overlay, CallbackInfo ci) { - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + TextureAtlasSprite sprite = quad.getSprite(); + // This can be null + //noinspection ConstantValue + if (sprite != null) { + SpriteUtil.INSTANCE.markSpriteActive(sprite); + } } } diff --git a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java index b598bb5f72..35da440eed 100644 --- a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java +++ b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/fabric/features/render/model/block/ModelBlockRendererMixin.java @@ -11,6 +11,7 @@ import net.caffeinemc.mods.sodium.client.util.DirectionUtil; import net.minecraft.client.renderer.block.ModelBlockRenderer; import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; import net.minecraft.util.Mth; @@ -46,8 +47,10 @@ private static void renderQuads(PoseStack.Pose matrices, VertexBufferWriter writ BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - if (quad.getSprite() != null) - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + TextureAtlasSprite sprite = quad.getSprite(); + if (sprite != null) { + SpriteUtil.INSTANCE.markSpriteActive(sprite); + } } } diff --git a/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java b/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java index 97dbbb3392..33f255a124 100644 --- a/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java +++ b/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/mixin/features/render/model/block/ModelBlockRendererMixin.java @@ -12,6 +12,7 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.ModelBlockRenderer; import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; import net.minecraft.util.Mth; @@ -48,8 +49,10 @@ private static void renderQuads(PoseStack.Pose matrices, VertexBufferWriter writ BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay); - if (quad.getSprite() != null) - SpriteUtil.INSTANCE.markSpriteActive(quad.getSprite()); + TextureAtlasSprite sprite = quad.getSprite(); + if (sprite != null) { + SpriteUtil.INSTANCE.markSpriteActive(sprite); + } } } From 5574827aaa5373a4734b8f36ea4130e7dd0a82f4 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 15 Sep 2024 13:17:52 -0400 Subject: [PATCH 5/5] Fix imports --- .../immediate/buffer_builder/intrinsics/BufferBuilderMixin.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java index f5ab93d978..ae1c0399ee 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/immediate/buffer_builder/intrinsics/BufferBuilderMixin.java @@ -10,8 +10,6 @@ import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import org.checkerframework.common.returnsreceiver.qual.This; -import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow;