Skip to content

Commit

Permalink
Animate sprites again
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Jun 27, 2023
1 parent 9658831 commit 86c56aa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import me.jellysquid.mods.sodium.client.frapi.helper.NormalHelper;
import me.jellysquid.mods.sodium.client.frapi.helper.TextureHelper;
import me.jellysquid.mods.sodium.client.frapi.material.RenderMaterialImpl;
import net.fabricmc.fabric.api.renderer.v1.model.SpriteFinder;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.texture.Sprite;
import net.minecraft.util.math.Direction;
Expand All @@ -43,6 +44,9 @@
* numbers. It also allows for a consistent interface for those transformations.
*/
public abstract class MutableQuadViewImpl extends QuadViewImpl implements QuadEmitter {
@Nullable
private Sprite cachedSprite;

public void clear() {
System.arraycopy(EMPTY, 0, data, baseIndex, EncodingFormat.TOTAL_STRIDE);
isGeometryInvalid = true;
Expand All @@ -52,6 +56,7 @@ public void clear() {
colorIndex(-1);
cullFace(null);
material(SodiumRenderer.MATERIAL_STANDARD);
cachedSprite = null;
}

@Override
Expand All @@ -75,6 +80,7 @@ public MutableQuadViewImpl uv(int vertexIndex, float u, float v) {
final int i = baseIndex + vertexIndex * VERTEX_STRIDE + VERTEX_U;
data[i] = Float.floatToRawIntBits(u);
data[i + 1] = Float.floatToRawIntBits(v);
cachedSprite = null;
return this;
}

Expand Down Expand Up @@ -170,6 +176,7 @@ public MutableQuadViewImpl copyFrom(QuadView quad) {
@Override
public final MutableQuadViewImpl fromVanilla(int[] quadData, int startIndex) {
isGeometryInvalid = true;
cachedSprite = null;
fromVanillaInternal(quadData, startIndex);

return this;
Expand Down Expand Up @@ -213,6 +220,8 @@ public final MutableQuadViewImpl fromVanilla(BakedQuad quad, RenderMaterial mate
data[baseIndex + HEADER_BITS] = EncodingFormat.geometryFlags(data[baseIndex + HEADER_BITS], view.getFlags());
isGeometryInvalid = false;

cachedSprite = quad.getSprite();

return this;
}

Expand All @@ -228,4 +237,15 @@ public final MutableQuadViewImpl emit() {
clear();
return this;
}

public final Sprite getSprite(SpriteFinder finder) {
@Nullable
Sprite ret = cachedSprite;

if (ret == null) {
cachedSprite = ret = finder.find(this);
}

return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@
import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadFacing;
import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadOrientation;
import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers;
import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuilder;
import me.jellysquid.mods.sodium.client.render.chunk.data.ChunkRenderBounds;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.DefaultMaterials;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material;
import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder;
import me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache;
import me.jellysquid.mods.sodium.client.render.texture.SpriteUtil;
import me.jellysquid.mods.sodium.client.util.ModelQuadUtil;
import me.jellysquid.mods.sodium.client.world.biome.BlockColorsExtended;
import net.caffeinemc.mods.sodium.api.util.ColorABGR;
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode;
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
import net.fabricmc.fabric.api.renderer.v1.model.SpriteFinder;
import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.LocalRandom;
Expand All @@ -54,6 +58,8 @@ public class BlockRendererFRAPI implements IBlockRenderer {

private final boolean useAmbientOcclusion;

private final SpriteFinder spriteFinder;

// Holders for state used in FRAPI as we can't pass them via parameters
private BlockRenderContext ctx;
private ChunkBuildBuffers buffers;
Expand Down Expand Up @@ -81,6 +87,7 @@ public BlockRendererFRAPI(MinecraftClient client, LightPipelineProviderFRAPI lig

this.occlusionCache = new BlockOcclusionCache();
this.useAmbientOcclusion = MinecraftClient.isAmbientOcclusionEnabled();
this.spriteFinder = SpriteFinder.get(MinecraftClient.getInstance().getBakedModelManager().getAtlas(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE));
}

public void renderModel(BlockRenderContext ctx, ChunkBuildBuffers buffers, ChunkRenderBounds.Builder bounds) {
Expand Down Expand Up @@ -223,8 +230,12 @@ private void bufferQuad(BlockRenderContext ctx, MutableQuadViewImpl quad, float[
bounds.add(out.x, out.y, out.z, normalFace);
}

var vertexBuffer = buffers.get(material).getVertexBuffer(normalFace);
ChunkModelBuilder modelBuilder = buffers.get(material);

var vertexBuffer = modelBuilder.getVertexBuffer(normalFace);
vertexBuffer.push(vertices, material);

modelBuilder.addSprite(quad.getSprite(this.spriteFinder));
}

private class Context extends AbstractRenderContext {
Expand Down

0 comments on commit 86c56aa

Please sign in to comment.