Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SpriteUtil to API package #2747

Open
wants to merge 6 commits into
base: 1.21.1/stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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")
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
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);
IThundxr marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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);
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -274,7 +274,7 @@ public void tickVisibleRenders() {
}

for (TextureAtlasSprite sprite : sprites) {
SpriteUtil.markSpriteActive(sprite);
SpriteUtil.INSTANCE.markSpriteActive(sprite);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
IThundxr marked this conversation as resolved.
Show resolved Hide resolved

return;
}
Expand All @@ -41,15 +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.markSpriteActive(quad.getSprite());
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.markSpriteActive(bakedQuad.getSprite());
SpriteUtil.INSTANCE.markSpriteActive(bakedQuad.getSprite());
IThundxr marked this conversation as resolved.
Show resolved Hide resolved

return;
}
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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"))
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +15,7 @@ private void preReturnSprite(CallbackInfoReturnable<TextureAtlasSprite> cir) {
TextureAtlasSprite sprite = cir.getReturnValue();

if (sprite != null) {
SpriteUtil.markSpriteActive(sprite);
SpriteUtil.INSTANCE.markSpriteActive(sprite);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand Down