From 366f0df4a8587abdf92cf63a11a2cb78194767ad Mon Sep 17 00:00:00 2001 From: IMS212 Date: Mon, 25 Nov 2024 08:33:37 -0800 Subject: [PATCH] Update to Minecraft 1.21.4 --- buildSrc/src/main/kotlin/BuildConfig.kt | 10 +- common/build.gradle.kts | 2 - .../checks/SodiumResourcePackMetadata.java | 2 +- .../gui/options/control/ControlElement.java | 5 + .../client/gui/widgets/AbstractWidget.java | 3 + .../client/gui/widgets/FlatButtonWidget.java | 5 + .../model/color/DefaultColorProviders.java | 4 +- .../color/interop/ItemColorsExtension.java | 8 - .../sodium/client/model/quad/ModelQuad.java | 10 +- .../client/model/quad/ModelQuadView.java | 6 +- .../model/quad/ModelQuadViewMutable.java | 4 +- .../chunk/compile/pipeline/BlockRenderer.java | 11 +- .../client/render/frapi/SodiumRenderer.java | 10 +- .../render/frapi/helper/GeometryHelper.java | 5 +- .../frapi/material/MaterialFinderImpl.java | 13 +- .../frapi/material/MaterialViewImpl.java | 28 ++- .../render/frapi/mesh/EncodingFormat.java | 3 +- .../render/frapi/mesh/MeshBuilderImpl.java | 84 -------- .../client/render/frapi/mesh/MeshImpl.java | 45 +++- .../render/frapi/mesh/MutableMeshImpl.java | 93 ++++++++ .../frapi/mesh/MutableQuadViewImpl.java | 103 +++++++-- .../render/frapi/mesh/QuadViewImpl.java | 8 +- .../render/AbstractBlockRenderContext.java | 75 ++++--- .../frapi/render/AbstractRenderContext.java | 65 +----- .../frapi/render/ItemRenderContext.java | 199 ++++++++---------- .../render/NonTerrainBlockRenderContext.java | 11 +- .../render/immediate/CloudRenderer.java | 2 +- .../client/world/biome/BiomeColorMaps.java | 2 +- .../core/model/colors/ItemColorsMixin.java | 33 --- .../options/weather/LevelRendererMixin.java | 2 +- .../render/frapi/BakedModelMixin.java | 24 ++- .../render/frapi/ItemRendererAccessor.java | 9 +- .../render/frapi/ItemRendererMixin.java | 20 +- .../render/gui/font/BakedGlyphMixin.java | 55 ++++- .../render/model/item/ItemRendererMixin.java | 36 ++-- .../world/clouds/LevelRendererMixin.java | 2 +- .../render/world/sky/LevelRendererMixin.java | 2 +- .../tracking/SpriteContentsTickerMixin.java | 2 +- .../SpriteContentsInterpolationMixin.java | 4 +- .../main/resources/sodium-common.mixins.json | 1 - .../mods/sodium/fabric/SodiumFabricMod.java | 4 +- .../mixin/core/model/quad/BakedQuadMixin.java | 2 +- .../model/WeightedRandomListMixin.java | 2 + fabric/src/main/resources/fabric.mod.json | 2 +- neoforge/build.gradle.kts | 2 +- .../mixin/core/model/quad/BakedQuadMixin.java | 2 +- .../model/WeightedRandomListMixin.java | 2 + .../AbstractBlockRenderContextMixin.java | 29 ++- .../mods/sodium/neoforge/SodiumForgeMod.java | 4 +- 49 files changed, 552 insertions(+), 503 deletions(-) delete mode 100644 common/src/main/java/net/caffeinemc/mods/sodium/client/model/color/interop/ItemColorsExtension.java delete mode 100644 common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MeshBuilderImpl.java create mode 100644 common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableMeshImpl.java delete mode 100644 common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/colors/ItemColorsMixin.java diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index 62d770297f..5087153885 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -1,17 +1,17 @@ -import org.gradle.api.Project + import org.gradle.api.Project object BuildConfig { - val MINECRAFT_VERSION: String = "1.21.3" - val NEOFORGE_VERSION: String = "21.3.56" + val MINECRAFT_VERSION: String = "1.21.4" + val NEOFORGE_VERSION: String = "21.4.0-beta" val FABRIC_LOADER_VERSION: String = "0.16.9" - val FABRIC_API_VERSION: String = "0.110.0+1.21.3" + val FABRIC_API_VERSION: String = "0.110.5+1.21.4" // This value can be set to null to disable Parchment. // TODO: Re-add Parchment val PARCHMENT_VERSION: String? = null // https://semver.org/ - var MOD_VERSION: String = "0.6.1" + var MOD_VERSION: String = "0.6.2" fun createVersionString(project: Project): String { val builder = StringBuilder() diff --git a/common/build.gradle.kts b/common/build.gradle.kts index c56c417140..6595341f1e 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -65,8 +65,6 @@ dependencies { addDependentFabricModule("fabric-renderer-api-v1") addDependentFabricModule("fabric-rendering-data-attachment-v1") - modCompileOnly("net.fabricmc.fabric-api:fabric-renderer-api-v1:3.2.9+1172e897d7") - // We need to be careful during pre-launch that we don't touch any Minecraft classes, since other mods // will not yet have an opportunity to apply transformations. configurationPreLaunch("org.lwjgl:lwjgl:3.3.3") diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/checks/SodiumResourcePackMetadata.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/checks/SodiumResourcePackMetadata.java index 44898479b0..5a8a608588 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/checks/SodiumResourcePackMetadata.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/checks/SodiumResourcePackMetadata.java @@ -17,5 +17,5 @@ public record SodiumResourcePackMetadata(List ignoredShaders) { .apply(instance, SodiumResourcePackMetadata::new) ); public static final MetadataSectionType SERIALIZER = - MetadataSectionType.fromCodec("sodium", CODEC); + new MetadataSectionType<>("sodium", CODEC); } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/options/control/ControlElement.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/options/control/ControlElement.java index 7f39e02eb7..fbdb182130 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/options/control/ControlElement.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/options/control/ControlElement.java @@ -106,4 +106,9 @@ public Dim2i getDimensions() { public ScreenRectangle getRectangle() { return new ScreenRectangle(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height()); } + + @Override + public boolean isMouseOver(double x, double y) { + return this.dim.containsCursor(x, y); + } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/AbstractWidget.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/AbstractWidget.java index cf494b3e2c..30a3d5d3b2 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/AbstractWidget.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/AbstractWidget.java @@ -102,4 +102,7 @@ protected void drawBorder(GuiGraphics graphics, int x1, int y1, int x2, int y2, graphics.fill(x1, y1, x1 + 1, y2, color); graphics.fill(x2 - 1, y1, x2, y2, color); } + + @Override + public abstract boolean isMouseOver(double x, double y); } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget.java index 7d753555d1..4bdd04e73a 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget.java @@ -121,6 +121,11 @@ public Component getLabel() { return super.nextFocusPath(event); } + @Override + public boolean isMouseOver(double x, double y) { + return this.dim.containsCursor(x, y); + } + @Override public ScreenRectangle getRectangle() { return new ScreenRectangle(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height()); diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/color/DefaultColorProviders.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/color/DefaultColorProviders.java index 848896141b..c80d52022c 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/color/DefaultColorProviders.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/color/DefaultColorProviders.java @@ -7,7 +7,7 @@ import net.minecraft.client.renderer.BiomeColors; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.FluidState; + import java.util.Arrays; public class DefaultColorProviders { @@ -50,7 +50,7 @@ private VanillaAdapter(BlockColor color) { @Override public void getColors(LevelSlice slice, BlockPos pos, BlockPos.MutableBlockPos scratchPos, BlockState state, ModelQuadView quad, int[] output) { - Arrays.fill(output, 0xFF000000 | this.color.getColor(state, slice, pos, quad.getColorIndex())); + Arrays.fill(output, 0xFF000000 | this.color.getColor(state, slice, pos, quad.getTintIndex())); } } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/color/interop/ItemColorsExtension.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/color/interop/ItemColorsExtension.java deleted file mode 100644 index cee52b119f..0000000000 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/color/interop/ItemColorsExtension.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.caffeinemc.mods.sodium.client.model.color.interop; - -import net.minecraft.client.color.item.ItemColor; -import net.minecraft.world.item.ItemStack; - -public interface ItemColorsExtension { - ItemColor sodium$getColorProvider(ItemStack stack); -} diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuad.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuad.java index 49f2275082..54a01fd3bf 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuad.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuad.java @@ -15,7 +15,7 @@ public class ModelQuad implements ModelQuadViewMutable { private TextureAtlasSprite sprite; private Direction direction; - private int colorIdx; + private int tintIdx; private int faceNormal; @Override @@ -74,8 +74,8 @@ public void setSprite(TextureAtlasSprite sprite) { } @Override - public void setColorIndex(int index) { - this.colorIdx = index; + public void setTintIndex(int index) { + this.tintIdx = index; } @Override @@ -84,8 +84,8 @@ public void setLightFace(Direction direction) { } @Override - public int getColorIndex() { - return this.colorIdx; + public int getTintIndex() { + return this.tintIdx; } @Override diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadView.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadView.java index 373eadc27b..f04685e987 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadView.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadView.java @@ -60,9 +60,9 @@ public interface ModelQuadView { int getFlags(); /** - * @return The color index of this quad. + * @return The tint index of this quad. */ - int getColorIndex(); + int getTintIndex(); /** * @return The sprite texture used by this quad, or null if none is attached @@ -75,7 +75,7 @@ public interface ModelQuadView { Direction getLightFace(); default boolean hasColor() { - return this.getColorIndex() != -1; + return this.getTintIndex() != -1; } default int calculateNormal() { diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadViewMutable.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadViewMutable.java index 30753db6ca..02063e2cb3 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadViewMutable.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/quad/ModelQuadViewMutable.java @@ -69,7 +69,7 @@ public interface ModelQuadViewMutable extends ModelQuadView { void setLightFace(Direction direction); /** - * Sets the color index used by this quad + * Sets the tint index used by this quad */ - void setColorIndex(int index); + void setTintIndex(int index); } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer.java index ceacaabdda..e042e129d7 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer.java @@ -102,7 +102,7 @@ public void renderModel(BakedModel model, BlockState state, BlockPos pos, BlockP for (RenderType type : renderTypes) { this.type = type; - ((FabricBakedModel) model).emitBlockQuads(this.level, state, pos, this.randomSupplier, this); + ((FabricBakedModel) model).emitBlockQuads(getEmitter(), this.level, state, pos, this.randomSupplier, this::isFaceCulled); } type = null; @@ -115,7 +115,6 @@ public void renderModel(BakedModel model, BlockState state, BlockPos pos, BlockP @Override protected void processQuad(MutableQuadViewImpl quad) { final RenderMaterial mat = quad.material(); - final int colorIndex = mat.disableColorIndex() ? -1 : quad.colorIndex(); final TriState aoMode = mat.ambientOcclusion(); final ShadeMode shadeMode = mat.shadeMode(); final LightMode lightMode; @@ -135,13 +134,15 @@ protected void processQuad(MutableQuadViewImpl quad) { material = DefaultMaterials.forRenderLayer(blendMode.blockRenderLayer == null ? type : blendMode.blockRenderLayer); } - this.colorizeQuad(quad, colorIndex); + this.tintQuad(quad); this.shadeQuad(quad, lightMode, emissive, shadeMode); this.bufferQuad(quad, this.quadLightData.br, material); } - private void colorizeQuad(MutableQuadViewImpl quad, int colorIndex) { - if (colorIndex != -1) { + private void tintQuad(MutableQuadViewImpl quad) { + int tintIndex = quad.tintIndex(); + + if (tintIndex != -1) { ColorProvider colorProvider = this.colorProvider; if (colorProvider != null) { diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/SodiumRenderer.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/SodiumRenderer.java index 7b39a52063..1c6097574b 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/SodiumRenderer.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/SodiumRenderer.java @@ -18,11 +18,11 @@ import net.caffeinemc.mods.sodium.client.render.frapi.material.MaterialFinderImpl; import net.caffeinemc.mods.sodium.client.render.frapi.material.RenderMaterialImpl; -import net.caffeinemc.mods.sodium.client.render.frapi.mesh.MeshBuilderImpl; +import net.caffeinemc.mods.sodium.client.render.frapi.mesh.MutableMeshImpl; import net.fabricmc.fabric.api.renderer.v1.Renderer; import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder; import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; -import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder; +import net.fabricmc.fabric.api.renderer.v1.mesh.MutableMesh; import net.minecraft.resources.ResourceLocation; import java.util.HashMap; @@ -36,7 +36,7 @@ public class SodiumRenderer implements Renderer { public static final RenderMaterial STANDARD_MATERIAL = INSTANCE.materialFinder().find(); static { - INSTANCE.registerMaterial(RenderMaterial.MATERIAL_STANDARD, STANDARD_MATERIAL); + INSTANCE.registerMaterial(RenderMaterial.STANDARD_ID, STANDARD_MATERIAL); } private final HashMap materialMap = new HashMap<>(); @@ -44,8 +44,8 @@ public class SodiumRenderer implements Renderer { private SodiumRenderer() { } @Override - public MeshBuilder meshBuilder() { - return new MeshBuilderImpl(); + public MutableMesh mutableMesh() { + return new MutableMeshImpl(); } @Override diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/helper/GeometryHelper.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/helper/GeometryHelper.java index da25fe4eda..e1e0ef1f97 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/helper/GeometryHelper.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/helper/GeometryHelper.java @@ -21,6 +21,7 @@ import net.minecraft.core.Direction; import net.minecraft.util.Mth; import org.joml.Vector3f; +import org.joml.Vector3fc; /** * Static routines of general utility for renderer implementations. @@ -49,7 +50,7 @@ public static boolean isQuadParallelToFace(Direction face, QuadView quad) { *

Derived from the quad face normal and expects convex quads with all points co-planar. */ public static Direction lightFace(QuadView quad) { - final Vector3f normal = quad.faceNormal(); + final Vector3fc normal = quad.faceNormal(); return switch (GeometryHelper.longestAxis(normal)) { case X -> normal.x() > 0 ? Direction.EAST : Direction.WEST; case Y -> normal.y() > 0 ? Direction.UP : Direction.DOWN; @@ -63,7 +64,7 @@ public static Direction lightFace(QuadView quad) { /** * @see #longestAxis(float, float, float) */ - public static Direction.Axis longestAxis(Vector3f vec) { + public static Direction.Axis longestAxis(Vector3fc vec) { return longestAxis(vec.x(), vec.y(), vec.z()); } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/material/MaterialFinderImpl.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/material/MaterialFinderImpl.java index 44a5b97f83..105cd02a1c 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/material/MaterialFinderImpl.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/material/MaterialFinderImpl.java @@ -27,7 +27,6 @@ public class MaterialFinderImpl extends MaterialViewImpl implements MaterialFind static { MaterialFinderImpl finder = new MaterialFinderImpl(); finder.ambientOcclusion(TriState.DEFAULT); - finder.glint(TriState.DEFAULT); finder.shadeMode(ShadeMode.ENHANCED); defaultBits = finder.bits; @@ -48,12 +47,6 @@ public MaterialFinder blendMode(BlendMode blendMode) { return this; } - @Override - public MaterialFinder disableColorIndex(boolean disable) { - bits = disable ? (bits | COLOR_DISABLE_FLAG) : (bits & ~COLOR_DISABLE_FLAG); - return this; - } - @Override public MaterialFinder emissive(boolean isEmissive) { bits = isEmissive ? (bits | EMISSIVE_FLAG) : (bits & ~EMISSIVE_FLAG); @@ -75,10 +68,10 @@ public MaterialFinder ambientOcclusion(TriState mode) { } @Override - public MaterialFinder glint(TriState mode) { - Objects.requireNonNull(mode, "glint TriState may not be null"); + public MaterialFinder glintMode(GlintMode mode) { + Objects.requireNonNull(mode, "GlintMode may not be null"); - bits = (bits & ~GLINT_MASK) | (mode.ordinal() << GLINT_BIT_OFFSET); + bits = (bits & ~GLINT_MODE_MASK) | (mode.ordinal() << GLINT_MODE_BIT_OFFSET); return this; } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/material/MaterialViewImpl.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/material/MaterialViewImpl.java index e6a4ea1e2e..9bd55d47e2 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/material/MaterialViewImpl.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/material/MaterialViewImpl.java @@ -17,6 +17,7 @@ package net.caffeinemc.mods.sodium.client.render.frapi.material; import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; +import net.fabricmc.fabric.api.renderer.v1.material.GlintMode; import net.fabricmc.fabric.api.renderer.v1.material.MaterialView; import net.fabricmc.fabric.api.renderer.v1.material.ShadeMode; import net.fabricmc.fabric.api.util.TriState; @@ -33,32 +34,32 @@ public class MaterialViewImpl implements MaterialView { private static final int BLEND_MODE_COUNT = BLEND_MODES.length; private static final TriState[] TRI_STATES = TriState.values(); private static final int TRI_STATE_COUNT = TRI_STATES.length; + private static final GlintMode[] GLINT_MODES = GlintMode.values(); + private static final int GLINT_MODE_COUNT = GLINT_MODES.length; private static final ShadeMode[] SHADE_MODES = ShadeMode.values(); private static final int SHADE_MODE_COUNT = SHADE_MODES.length; protected static final int BLEND_MODE_BIT_LENGTH = Mth.ceillog2(BLEND_MODE_COUNT); - protected static final int COLOR_DISABLE_BIT_LENGTH = 1; protected static final int EMISSIVE_BIT_LENGTH = 1; protected static final int DIFFUSE_BIT_LENGTH = 1; protected static final int AO_BIT_LENGTH = Mth.ceillog2(TRI_STATE_COUNT); - protected static final int GLINT_BIT_LENGTH = Mth.ceillog2(TRI_STATE_COUNT); + protected static final int GLINT_MODE_BIT_LENGTH = Mth.ceillog2(GLINT_MODE_COUNT); protected static final int SHADE_MODE_BIT_LENGTH = Mth.ceillog2(SHADE_MODE_COUNT); protected static final int BLEND_MODE_BIT_OFFSET = 0; - protected static final int COLOR_DISABLE_BIT_OFFSET = BLEND_MODE_BIT_OFFSET + BLEND_MODE_BIT_LENGTH; - protected static final int EMISSIVE_BIT_OFFSET = COLOR_DISABLE_BIT_OFFSET + COLOR_DISABLE_BIT_LENGTH; + protected static final int EMISSIVE_BIT_OFFSET = BLEND_MODE_BIT_OFFSET + BLEND_MODE_BIT_LENGTH; protected static final int DIFFUSE_BIT_OFFSET = EMISSIVE_BIT_OFFSET + EMISSIVE_BIT_LENGTH; protected static final int AO_BIT_OFFSET = DIFFUSE_BIT_OFFSET + DIFFUSE_BIT_LENGTH; protected static final int GLINT_BIT_OFFSET = AO_BIT_OFFSET + AO_BIT_LENGTH; - protected static final int SHADE_MODE_BIT_OFFSET = GLINT_BIT_OFFSET + GLINT_BIT_LENGTH; + protected static final int GLINT_MODE_BIT_OFFSET = AO_BIT_OFFSET + AO_BIT_LENGTH; + protected static final int SHADE_MODE_BIT_OFFSET = GLINT_MODE_BIT_OFFSET + GLINT_MODE_BIT_LENGTH; protected static final int TOTAL_BIT_LENGTH = SHADE_MODE_BIT_OFFSET + SHADE_MODE_BIT_LENGTH; protected static final int BLEND_MODE_MASK = bitMask(BLEND_MODE_BIT_LENGTH, BLEND_MODE_BIT_OFFSET); - protected static final int COLOR_DISABLE_FLAG = bitMask(COLOR_DISABLE_BIT_LENGTH, COLOR_DISABLE_BIT_OFFSET); protected static final int EMISSIVE_FLAG = bitMask(EMISSIVE_BIT_LENGTH, EMISSIVE_BIT_OFFSET); protected static final int DIFFUSE_FLAG = bitMask(DIFFUSE_BIT_LENGTH, DIFFUSE_BIT_OFFSET); protected static final int AO_MASK = bitMask(AO_BIT_LENGTH, AO_BIT_OFFSET); - protected static final int GLINT_MASK = bitMask(GLINT_BIT_LENGTH, GLINT_BIT_OFFSET); + protected static final int GLINT_MODE_MASK = bitMask(GLINT_MODE_BIT_LENGTH, GLINT_MODE_BIT_OFFSET); protected static final int SHADE_MODE_MASK = bitMask(SHADE_MODE_BIT_LENGTH, SHADE_MODE_BIT_OFFSET); protected static int bitMask(int bitLength, int bitOffset) { @@ -68,12 +69,12 @@ protected static int bitMask(int bitLength, int bitOffset) { protected static boolean areBitsValid(int bits) { int blendMode = (bits & BLEND_MODE_MASK) >>> BLEND_MODE_BIT_OFFSET; int ao = (bits & AO_MASK) >>> AO_BIT_OFFSET; - int glint = (bits & GLINT_MASK) >>> GLINT_BIT_OFFSET; + int glintMode = (bits & GLINT_MODE_MASK) >>> GLINT_MODE_BIT_OFFSET; int shadeMode = (bits & SHADE_MODE_MASK) >>> SHADE_MODE_BIT_OFFSET; return blendMode < BLEND_MODE_COUNT && ao < TRI_STATE_COUNT - && glint < TRI_STATE_COUNT + && glintMode < GLINT_MODE_COUNT && shadeMode < SHADE_MODE_COUNT; } @@ -88,11 +89,6 @@ public BlendMode blendMode() { return BLEND_MODES[(bits & BLEND_MODE_MASK) >>> BLEND_MODE_BIT_OFFSET]; } - @Override - public boolean disableColorIndex() { - return (bits & COLOR_DISABLE_FLAG) != 0; - } - @Override public boolean emissive() { return (bits & EMISSIVE_FLAG) != 0; @@ -109,8 +105,8 @@ public TriState ambientOcclusion() { } @Override - public TriState glint() { - return TRI_STATES[(bits & GLINT_MASK) >>> GLINT_BIT_OFFSET]; + public GlintMode glintMode() { + return GLINT_MODES[(bits & GLINT_MODE_MASK) >>> GLINT_MODE_BIT_OFFSET]; } @Override diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/EncodingFormat.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/EncodingFormat.java index 583867ec87..3f40457ffe 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/EncodingFormat.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/EncodingFormat.java @@ -21,6 +21,7 @@ import com.mojang.blaze3d.vertex.VertexFormat; import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFacing; import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFlags; +import net.caffeinemc.mods.sodium.client.render.frapi.SodiumRenderer; import net.caffeinemc.mods.sodium.client.render.frapi.material.RenderMaterialImpl; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView; import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper; @@ -37,7 +38,7 @@ private EncodingFormat() { } static final int HEADER_BITS = 0; static final int HEADER_FACE_NORMAL = 1; - static final int HEADER_COLOR_INDEX = 2; + static final int HEADER_TINT_INDEX = 2; static final int HEADER_TAG = 3; public static final int HEADER_STRIDE = 4; diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MeshBuilderImpl.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MeshBuilderImpl.java deleted file mode 100644 index 34e69c8b1f..0000000000 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MeshBuilderImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2016, 2017, 2018, 2019 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.caffeinemc.mods.sodium.client.render.frapi.mesh; - -import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; -import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder; -import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; - -/** - * Our implementation of {@link MeshBuilder}, used for static mesh creation and baking. - * Not much to it - mainly it just needs to grow the int[] array as quads are appended - * and maintain/provide a properly-configured {@link net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView} instance. - * All the encoding and other work is handled in the quad base classes. - * The one interesting bit is in {@link Maker#emitDirectly()}. - */ -public class MeshBuilderImpl implements MeshBuilder { - private int[] data = new int[256]; - private int index = 0; - private int limit = data.length; - private final Maker maker = new Maker(); - - public MeshBuilderImpl() { - ensureCapacity(EncodingFormat.TOTAL_STRIDE); - maker.data = data; - maker.baseIndex = index; - maker.clear(); - } - - protected void ensureCapacity(int stride) { - if (stride > limit - index) { - limit *= 2; - final int[] bigger = new int[limit]; - System.arraycopy(data, 0, bigger, 0, index); - data = bigger; - maker.data = data; - } - } - - @Override - public QuadEmitter getEmitter() { - maker.clear(); - return maker; - } - - @Override - public Mesh build() { - final int[] packed = new int[index]; - System.arraycopy(data, 0, packed, 0, index); - index = 0; - maker.baseIndex = index; - maker.clear(); - return new MeshImpl(packed); - } - - /** - * Our base classes are used differently so we define final - * encoding steps in subtypes. This will be a static mesh used - * at render time so we want to capture all geometry now and - * apply non-location-dependent lighting. - */ - private class Maker extends MutableQuadViewImpl { - @Override - public void emitDirectly() { - computeGeometry(); - index += EncodingFormat.TOTAL_STRIDE; - ensureCapacity(EncodingFormat.TOTAL_STRIDE); - baseIndex = index; - } - } -} diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MeshImpl.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MeshImpl.java index 60fa624c90..051d27a709 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MeshImpl.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MeshImpl.java @@ -16,9 +16,11 @@ package net.caffeinemc.mods.sodium.client.render.frapi.mesh; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView; +import org.jetbrains.annotations.Range; import java.util.function.Consumer; @@ -28,17 +30,38 @@ */ public class MeshImpl implements Mesh { /** Used to satisfy external calls to {@link #forEach(Consumer)}. */ - private final ThreadLocal cursorPool = ThreadLocal.withInitial(QuadViewImpl::new); + private static final ThreadLocal> CURSOR_POOLS = ThreadLocal.withInitial(ObjectArrayList::new); - final int[] data; + int[] data; + int limit; MeshImpl(int[] data) { this.data = data; + limit = data.length; } + MeshImpl() {} + @Override - public void forEach(Consumer consumer) { - forEach(consumer, cursorPool.get()); + @Range(from = 0, to = Integer.MAX_VALUE) + public int size() { + return limit / EncodingFormat.TOTAL_STRIDE; + } + + @Override + public void forEach(Consumer action) { + ObjectArrayList pool = CURSOR_POOLS.get(); + QuadViewImpl cursor; + + if (pool.isEmpty()) { + cursor = new QuadViewImpl(); + } else { + cursor = pool.pop(); + } + + forEach(action, cursor); + + pool.push(cursor); } /** @@ -46,30 +69,34 @@ public void forEach(Consumer consumer) { * to avoid the performance hit of a thread-local lookup. * Also means renderer can hold final references to quad buffers. */ - void forEach(Consumer consumer, QuadViewImpl cursor) { - final int limit = data.length; + void forEach(Consumer action, C cursor) { + final int limit = this.limit; int index = 0; cursor.data = this.data; while (index < limit) { cursor.baseIndex = index; cursor.load(); - consumer.accept(cursor); + action.accept(cursor); index += EncodingFormat.TOTAL_STRIDE; } + + cursor.data = null; } + // TODO: This could be optimized by checking if the emitter is that of a MutableMeshImpl and if + // it has no transforms, in which case the entire data array can be copied in bulk. @Override public void outputTo(QuadEmitter emitter) { MutableQuadViewImpl e = (MutableQuadViewImpl) emitter; final int[] data = this.data; - final int limit = data.length; + final int limit = this.limit; int index = 0; while (index < limit) { System.arraycopy(data, index, e.data, e.baseIndex, EncodingFormat.TOTAL_STRIDE); e.load(); - e.emitDirectly(); + e.transformAndEmit(); index += EncodingFormat.TOTAL_STRIDE; } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableMeshImpl.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableMeshImpl.java new file mode 100644 index 0000000000..1f58afcb7d --- /dev/null +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableMeshImpl.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.caffeinemc.mods.sodium.client.render.frapi.mesh; + +import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; +import net.fabricmc.fabric.api.renderer.v1.mesh.MutableMesh; +import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; +import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; + +import java.util.function.Consumer; + +/** + * Our implementation of {@link MutableMesh}, used for static mesh creation and baking. + * Not much to it - mainly it just needs to grow the int[] array as quads are appended + * and maintain/provide a properly-configured {@link net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView} instance. + * All the encoding and other work is handled in the quad base classes. + * The one interesting bit is in {@link MutableQuadViewImpl#emitDirectly()}. + */ +public class MutableMeshImpl extends MeshImpl implements MutableMesh { + private final MutableQuadViewImpl emitter = new MutableQuadViewImpl() { + @Override + protected void emitDirectly() { + // Necessary because the validity of geometry is not encoded; reading mesh data always + // uses QuadViewImpl#load(), which assumes valid geometry. Built immutable meshes + // should also have valid geometry for better performance. + computeGeometry(); + limit += EncodingFormat.TOTAL_STRIDE; + ensureCapacity(EncodingFormat.TOTAL_STRIDE); + baseIndex = limit; + } +}; + + public MutableMeshImpl() { + data = new int[8 * EncodingFormat.TOTAL_STRIDE]; + limit = 0; + + ensureCapacity(EncodingFormat.TOTAL_STRIDE); + emitter.data = data; + emitter.baseIndex = limit; + emitter.clear(); + } + + private void ensureCapacity(int stride) { + if (stride > data.length - limit) { + final int[] bigger = new int[data.length * 2]; + System.arraycopy(data, 0, bigger, 0, limit); + data = bigger; + emitter.data = data; + } + } + + @Override + public QuadEmitter emitter() { + emitter.clear(); + return emitter; + } + + @Override + public void forEachMutable(Consumer action) { + // emitDirectly will not be called by forEach, so just reuse the main emitter. + forEach(action, emitter); + emitter.data = data; + emitter.baseIndex = limit; + } + + @Override + public Mesh immutableCopy() { + final int[] packed = new int[limit]; + System.arraycopy(data, 0, packed, 0, limit); + return new MeshImpl(packed); + } + + @Override + public void clear() { + limit = 0; + emitter.baseIndex = limit; + emitter.clear(); + } +} diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableQuadViewImpl.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableQuadViewImpl.java index 25e3e6a30b..fcde4314fa 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableQuadViewImpl.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableQuadViewImpl.java @@ -16,6 +16,7 @@ package net.caffeinemc.mods.sodium.client.render.frapi.mesh; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.caffeinemc.mods.sodium.api.util.NormI8; import net.caffeinemc.mods.sodium.client.model.quad.BakedQuadView; import net.caffeinemc.mods.sodium.client.render.frapi.SodiumRenderer; @@ -24,6 +25,7 @@ import net.caffeinemc.mods.sodium.client.render.frapi.material.RenderMaterialImpl; 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.mesh.QuadTransform; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView; import net.fabricmc.fabric.api.renderer.v1.model.SpriteFinder; import net.minecraft.client.renderer.LightTexture; @@ -49,6 +51,42 @@ public abstract class MutableQuadViewImpl extends QuadViewImpl implements QuadEm @Nullable private TextureAtlasSprite cachedSprite; + protected static final QuadTransform NO_TRANSFORM = q -> true; + + protected QuadTransform activeTransform = NO_TRANSFORM; + private final ObjectArrayList transformStack = new ObjectArrayList<>(); + private final QuadTransform stackTransform = q -> { + int i = transformStack.size() - 1; + + while (i >= 0) { + if (!transformStack.get(i--).transform(q)) { + return false; + } + } + + return true; + }; + + /** Used for quick clearing of quad buffers. Implicitly has invalid geometry. */ + static final int[] DEFAULT = EMPTY.clone(); + + static { + MutableQuadViewImpl quad = new MutableQuadViewImpl() { + @Override + protected void emitDirectly() { + // This quad won't be emitted. It's only used to configure the default quad data. + } + }; + + // Start with all zeroes + quad.data = DEFAULT; + // Apply non-zero defaults + quad.color(-1, -1, -1, -1); + quad.cullFace(null); + quad.material(SodiumRenderer.STANDARD_MATERIAL); + quad.tintIndex(-1); + } + @Nullable public TextureAtlasSprite cachedSprite() { return cachedSprite; @@ -69,14 +107,9 @@ public TextureAtlasSprite sprite(SpriteFinder finder) { } public void clear() { - System.arraycopy(EMPTY, 0, data, baseIndex, EncodingFormat.TOTAL_STRIDE); + System.arraycopy(DEFAULT, 0, data, baseIndex, EncodingFormat.TOTAL_STRIDE); isGeometryInvalid = true; nominalFace = null; - normalFlags(0); - tag(0); - colorIndex(-1); - cullFace(null); - material(SodiumRenderer.STANDARD_MATERIAL); cachedSprite(null); } @@ -135,6 +168,32 @@ public MutableQuadViewImpl normal(int vertexIndex, float x, float y, float z) { return this; } + @Override + public void pushTransform(QuadTransform transform) { + if (transform == null) { + throw new NullPointerException("QuadTransform cannot be null!"); + } + + transformStack.push(transform); + + if (transformStack.size() == 1) { + activeTransform = transform; + } else if (transformStack.size() == 2) { + activeTransform = stackTransform; + } + } + + @Override + public void popTransform() { + transformStack.pop(); + + if (transformStack.isEmpty()) { + activeTransform = NO_TRANSFORM; + } else if (transformStack.size() == 1) { + activeTransform = transformStack.getFirst(); + } + } + /** * Internal helper method. Copies face normals to vertex normals lacking one. */ @@ -169,17 +228,13 @@ public final MutableQuadViewImpl nominalFace(@Nullable Direction face) { @Override public final MutableQuadViewImpl material(RenderMaterial material) { - if (material == null) { - material = SodiumRenderer.STANDARD_MATERIAL; - } - data[baseIndex + HEADER_BITS] = EncodingFormat.material(data[baseIndex + HEADER_BITS], (RenderMaterialImpl) material); return this; } @Override - public final MutableQuadViewImpl colorIndex(int colorIndex) { - data[baseIndex + HEADER_COLOR_INDEX] = colorIndex; + public final MutableQuadViewImpl tintIndex(int tintIndex) { + data[baseIndex + HEADER_TINT_INDEX] = tintIndex; return this; } @@ -192,12 +247,15 @@ public final MutableQuadViewImpl tag(int tag) { @Override public MutableQuadViewImpl copyFrom(QuadView quad) { final QuadViewImpl q = (QuadViewImpl) quad; - q.computeGeometry(); System.arraycopy(q.data, q.baseIndex, data, baseIndex, EncodingFormat.TOTAL_STRIDE); - faceNormal.set(q.faceNormal); nominalFace = q.nominalFace; - isGeometryInvalid = false; + + isGeometryInvalid = q.isGeometryInvalid; + + if (!isGeometryInvalid) { + faceNormal.set(q.faceNormal); + } if (quad instanceof MutableQuadViewImpl mutableQuad) { cachedSprite(mutableQuad.cachedSprite()); @@ -237,7 +295,7 @@ public final MutableQuadViewImpl fromVanilla(BakedQuad quad, RenderMaterial mate fromVanillaInternal(quad.getVertices(), 0); data[baseIndex + HEADER_BITS] = EncodingFormat.cullFace(0, cullFace); nominalFace(quad.getDirection()); - colorIndex(quad.getTintIndex()); + tintIndex(quad.getTintIndex()); // TODO: Is this the same as hasShade? if (!((BakedQuadView) quad).hasShade()) { @@ -276,11 +334,20 @@ public final MutableQuadViewImpl fromVanilla(BakedQuad quad, RenderMaterial mate * Emit the quad without clearing the underlying data. * Geometry is not guaranteed to be valid when called, but can be computed by calling {@link #computeGeometry()}. */ - public abstract void emitDirectly(); + protected abstract void emitDirectly(); + + /** + * Apply transforms and then if transforms return true, emit the quad without clearing the underlying data. + */ + public final void transformAndEmit() { + if (activeTransform.transform(this)) { + emitDirectly(); + } + } @Override public final MutableQuadViewImpl emit() { - emitDirectly(); + transformAndEmit(); clear(); return this; } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/QuadViewImpl.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/QuadViewImpl.java index 5e87722527..4610108382 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/QuadViewImpl.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/mesh/QuadViewImpl.java @@ -256,8 +256,8 @@ public final RenderMaterialImpl material() { } @Override - public final int colorIndex() { - return data[baseIndex + HEADER_COLOR_INDEX]; + public final int tintIndex() { + return data[baseIndex + HEADER_TINT_INDEX]; } @Override @@ -328,8 +328,8 @@ public int getLight(int idx) { } @Override - public int getColorIndex() { - return material().disableColorIndex() ? -1 : colorIndex(); + public int getTintIndex() { + return tintIndex(); } @Override diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractBlockRenderContext.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractBlockRenderContext.java index df370b5697..84e20f5f0b 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractBlockRenderContext.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractBlockRenderContext.java @@ -33,6 +33,7 @@ import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.function.Predicate; import java.util.function.Supplier; /** @@ -58,12 +59,17 @@ public abstract class AbstractBlockRenderContext extends AbstractRenderContext { STANDARD_MATERIALS[i] = SodiumRenderer.INSTANCE.materialFinder().ambientOcclusion(state).find(); } } - private final MutableQuadViewImpl editorQuad = new MutableQuadViewImpl() { + + public class BlockEmitter extends MutableQuadViewImpl { { data = new int[EncodingFormat.TOTAL_STRIDE]; clear(); } + public void bufferDefaultModel(BakedModel model, BlockState state, Predicate cullTest) { + AbstractBlockRenderContext.this.bufferDefaultModel(model, state, cullTest); + } + @Override public void emitDirectly() { if (type == null) { @@ -71,7 +77,11 @@ public void emitDirectly() { } renderQuad(this); } - }; + } + + + + private final MutableQuadViewImpl editorQuad = new BlockEmitter(); /** * The world which the block is being rendered in. @@ -128,7 +138,6 @@ public QuadEmitter getEmitter() { return this.editorQuad; } - @Override public boolean isFaceCulled(@Nullable Direction face) { if (face == null || !this.enableCulling) { return false; @@ -150,19 +159,10 @@ public boolean isFaceCulled(@Nullable Direction face) { } } - @Override - public ItemDisplayContext itemTransformationMode() { - throw new UnsupportedOperationException("itemTransformationMode can only be called on an item render context."); - } - /** * Pipeline entrypoint - handles transform and culling checks. */ private void renderQuad(MutableQuadViewImpl quad) { - if (!this.transform(quad)) { - return; - } - if (this.isFaceCulled(quad.cullFace())) { return; } @@ -207,47 +207,44 @@ protected void shadeQuad(MutableQuadViewImpl quad, LightMode lightMode, boolean } /* Handling of vanilla models - this is the hot path for non-modded models */ - public void bufferDefaultModel(BakedModel model, @Nullable BlockState state) { + public void bufferDefaultModel(BakedModel model, @Nullable BlockState state, Predicate cullTest) { MutableQuadViewImpl editorQuad = this.editorQuad; // If there is no transform, we can check the culling face once for all the quads, // and we don't need to check for transforms per-quad. - boolean noTransform = !this.hasTransform(); for (int i = 0; i <= ModelHelper.NULL_FACE_ID; i++) { final Direction cullFace = ModelHelper.faceFromIndex(i); + if (cullTest.test(cullFace)) { + continue; + } + RandomSource random = this.randomSupplier.get(); AmbientOcclusionMode ao = PlatformBlockAccess.getInstance().usesAmbientOcclusion(model, state, modelData, type, slice, pos); - if (noTransform) { - if (!this.isFaceCulled(cullFace)) { - final List quads = PlatformModelAccess.getInstance().getQuads(level, pos, model, state, cullFace, random, type, modelData); - final int count = quads.size(); - - for (int j = 0; j < count; j++) { - final BakedQuad q = quads.get(j); - editorQuad.fromVanilla(q, (type == RenderType.tripwire() || type == RenderType.translucent()) ? TRANSLUCENT_MATERIAL : STANDARD_MATERIALS[ao.ordinal()], cullFace); - // Call processQuad instead of emit for efficiency - // (avoid unnecessarily clearing data, trying to apply transforms, and performing cull check again) - - this.processQuad(editorQuad); - } - } - } else { - final List quads = PlatformModelAccess.getInstance().getQuads(level, pos, model, state, cullFace, random, type, modelData); - final int count = quads.size(); - - for (int j = 0; j < count; j++) { - final BakedQuad q = quads.get(j); - editorQuad.fromVanilla(q, (type == RenderType.tripwire() || type == RenderType.translucent()) ? TRANSLUCENT_MATERIAL : STANDARD_MATERIALS[ao.ordinal()], cullFace); - // Call renderQuad instead of emit for efficiency - // (avoid unnecessarily clearing data) - this.renderQuad(editorQuad); - } + + final List quads = PlatformModelAccess.getInstance().getQuads(level, pos, model, state, cullFace, random, type, modelData); + final int count = quads.size(); + + for (int j = 0; j < count; j++) { + final BakedQuad q = quads.get(j); + editorQuad.fromVanilla(q, (type == RenderType.tripwire() || type == RenderType.translucent()) ? TRANSLUCENT_MATERIAL : STANDARD_MATERIALS[ao.ordinal()], cullFace); + // Call processQuad instead of emit for efficiency + // (avoid unnecessarily clearing data, trying to apply transforms, and performing cull check again) + + this.processQuad(editorQuad); } } editorQuad.clear(); } + + public SodiumModelData getModelData() { + return modelData; + } + + public RenderType getRenderType() { + return type; + } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractRenderContext.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractRenderContext.java index 6074c497cf..0f033a2c25 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractRenderContext.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractRenderContext.java @@ -19,69 +19,10 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; -import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; +import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; import java.util.function.Consumer; -public abstract class AbstractRenderContext implements RenderContext { - private static final QuadTransform NO_TRANSFORM = q -> true; - - private QuadTransform activeTransform = NO_TRANSFORM; - private final ObjectArrayList transformStack = new ObjectArrayList<>(); - private final QuadTransform stackTransform = q -> { - int i = transformStack.size() - 1; - - while (i >= 0) { - if (!transformStack.get(i--).transform(q)) { - return false; - } - } - - return true; - }; - - @Deprecated - private final Consumer meshConsumer = mesh -> mesh.outputTo(getEmitter()); - - protected final boolean transform(MutableQuadView q) { - return activeTransform.transform(q); - } - - @Override - public boolean hasTransform() { - return activeTransform != NO_TRANSFORM; - } - - @Override - public void pushTransform(QuadTransform transform) { - if (transform == null) { - throw new NullPointerException("Renderer received null QuadTransform."); - } - - transformStack.push(transform); - - if (transformStack.size() == 1) { - activeTransform = transform; - } else if (transformStack.size() == 2) { - activeTransform = stackTransform; - } - } - - @Override - public void popTransform() { - transformStack.pop(); - - if (transformStack.isEmpty()) { - activeTransform = NO_TRANSFORM; - } else if (transformStack.size() == 1) { - activeTransform = transformStack.get(0); - } - } - - // Overridden to prevent allocating a lambda every time this method is called. - @Deprecated - @Override - public Consumer meshConsumer() { - return meshConsumer; - } +public abstract class AbstractRenderContext { + abstract QuadEmitter getEmitter(); } 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 b80277d2ff..d08d1d414f 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 @@ -27,25 +27,24 @@ 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.GlintMode; 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.FabricBakedModel; -import net.fabricmc.fabric.api.util.TriState; import net.fabricmc.fabric.impl.renderer.VanillaModelEncoder; -import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.renderer.item.ItemStackRenderState; import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; import net.minecraft.world.item.ItemDisplayContext; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.SingleThreadedRandomSource; import org.jetbrains.annotations.Nullable; import org.joml.Matrix3f; import org.joml.Matrix4f; +import java.util.Arrays; import java.util.function.Supplier; /** @@ -54,29 +53,43 @@ public class ItemRenderContext extends AbstractRenderContext { /** Value vanilla uses for item rendering. The only sensible choice, of course. */ private static final long ITEM_RANDOM_SEED = 42L; + private static final int GLINT_COUNT = ItemStackRenderState.FoilType.values().length; - private final MutableQuadViewImpl editorQuad = new MutableQuadViewImpl() { + public class ItemEmitter extends MutableQuadViewImpl { { data = new int[EncodingFormat.TOTAL_STRIDE]; clear(); } + public void bufferDefaultModel(BakedModel model) { + ItemRenderContext.this.bufferDefaultModel(this, model, null); + } + + @Override public void emitDirectly() { renderQuad(this); } - }; - private final ItemColors colorMap; + public boolean hasTransforms() { + return activeTransform != NO_TRANSFORM; + } + } + + private final MutableQuadViewImpl editorQuad = new ItemEmitter(); + private final VanillaModelBufferer vanillaBufferer; + public ItemRenderContext(VanillaModelBufferer vanillaBufferer) { + this.vanillaBufferer = vanillaBufferer; + } + private final RandomSource random = new SingleThreadedRandomSource(ITEM_RANDOM_SEED); private final Supplier randomSupplier = () -> { random.setSeed(ITEM_RANDOM_SEED); return random; }; - private ItemStack itemStack; private ItemDisplayContext transformMode; private PoseStack poseStack; private Matrix4f matPosition; @@ -85,22 +98,13 @@ public void emitDirectly() { private MultiBufferSource bufferSource; private int lightmap; private int overlay; + private int[] colors; - private boolean isDefaultTranslucent; - private boolean isDefaultGlint; - private boolean isGlintDynamicDisplay; + private RenderType defaultLayer; + private ItemStackRenderState.FoilType defaultGlint; - private PoseStack.Pose dynamicDisplayGlintEntry; - private VertexConsumer translucentVertexConsumer; - private VertexConsumer cutoutVertexConsumer; - private VertexConsumer translucentGlintVertexConsumer; - private VertexConsumer cutoutGlintVertexConsumer; - private VertexConsumer defaultVertexConsumer; - - public ItemRenderContext(ItemColors colorMap, VanillaModelBufferer vanillaBufferer) { - this.colorMap = colorMap; - this.vanillaBufferer = vanillaBufferer; - } + private PoseStack.Pose specialGlintEntry; + private final VertexConsumer[] vertexConsumerCache = new VertexConsumer[3 * GLINT_COUNT]; @Override public QuadEmitter getEmitter() { @@ -108,18 +112,7 @@ public QuadEmitter getEmitter() { return editorQuad; } - @Override - public boolean isFaceCulled(@Nullable Direction face) { - throw new UnsupportedOperationException("isFaceCulled can only be called on a block render context."); - } - - @Override - public ItemDisplayContext itemTransformationMode() { - return transformMode; - } - - public void renderModel(ItemStack itemStack, ItemDisplayContext transformMode, boolean invert, PoseStack poseStack, MultiBufferSource bufferSource, int lightmap, int overlay, BakedModel model) { - this.itemStack = itemStack; + public void renderModel(ItemDisplayContext transformMode, PoseStack poseStack, MultiBufferSource bufferSource, int lightmap, int overlay, BakedModel model, int[] colors, RenderType layer, ItemStackRenderState.FoilType glint) { this.transformMode = transformMode; this.poseStack = poseStack; matPosition = poseStack.last().pose(); @@ -128,51 +121,39 @@ public void renderModel(ItemStack itemStack, ItemDisplayContext transformMode, b this.bufferSource = bufferSource; this.lightmap = lightmap; this.overlay = overlay; - computeOutputInfo(); + this.colors = colors; + + defaultLayer = layer; + defaultGlint = glint; - ((FabricBakedModel) model).emitItemQuads(itemStack, randomSupplier, this); + ((FabricBakedModel) model).emitItemQuads(getEmitter(), randomSupplier); - this.itemStack = null; this.poseStack = null; this.bufferSource = null; + this.colors = null; - dynamicDisplayGlintEntry = null; - translucentVertexConsumer = null; - cutoutVertexConsumer = null; - translucentGlintVertexConsumer = null; - cutoutGlintVertexConsumer = null; - defaultVertexConsumer = null; - } - - private void computeOutputInfo() { - isDefaultTranslucent = ItemBlockRenderTypes.getRenderType(this.itemStack) == Sheets.translucentItemSheet(); - isDefaultGlint = itemStack.hasFoil(); - isGlintDynamicDisplay = ItemRendererAccessor.sodium$hasAnimatedTexture(itemStack); - - defaultVertexConsumer = getVertexConsumer(BlendMode.DEFAULT, TriState.DEFAULT); + this.specialGlintEntry = null; + Arrays.fill(vertexConsumerCache, null); } private void renderQuad(MutableQuadViewImpl quad) { - if (!transform(quad)) { - return; - } - final RenderMaterial mat = quad.material(); - final int colorIndex = mat.disableColorIndex() ? -1 : quad.colorIndex(); final boolean emissive = mat.emissive(); - final VertexConsumer vertexConsumer = getVertexConsumer(mat.blendMode(), mat.glint()); + final VertexConsumer vertexConsumer = getVertexConsumer(mat.blendMode(), mat.glintMode()); - colorizeQuad(quad, colorIndex); + tintQuad(quad); shadeQuad(quad, emissive); bufferQuad(quad, vertexConsumer); } - private void colorizeQuad(MutableQuadViewImpl quad, int colorIndex) { - if (colorIndex != -1) { - final int itemColor = colorMap.getColor(itemStack, colorIndex); + private void tintQuad(MutableQuadViewImpl quad) { + final int tintIndex = quad.tintIndex(); + + if (tintIndex != -1 && tintIndex < colors.length) { + final int color = colors[tintIndex]; for (int i = 0; i < 4; i++) { - quad.color(i, ColorMixer.mulComponentWise(itemColor, quad.color(i))); + quad.color(i, ColorMixer.mulComponentWise(color, quad.color(i))); } } } @@ -201,82 +182,86 @@ private void bufferQuad(MutableQuadViewImpl quad, VertexConsumer vertexConsumer) * in {@code RenderLayers.getEntityBlockLayer}. Layers other than * translucent are mapped to cutout. */ - private VertexConsumer getVertexConsumer(BlendMode blendMode, TriState glintMode) { - boolean translucent; - boolean glint; + private VertexConsumer getVertexConsumer(BlendMode blendMode, GlintMode glintMode) { + RenderType type; + ItemStackRenderState.FoilType glint; if (blendMode == BlendMode.DEFAULT) { - translucent = isDefaultTranslucent; + type = defaultLayer; } else { - translucent = blendMode == BlendMode.TRANSLUCENT; + type = blendMode == BlendMode.TRANSLUCENT ? Sheets.translucentItemSheet() : Sheets.cutoutBlockSheet(); } - if (glintMode == TriState.DEFAULT) { - glint = isDefaultGlint; + if (glintMode == GlintMode.DEFAULT) { + glint = defaultGlint; } else { - glint = glintMode == TriState.TRUE; + glint = glintMode.glint; } - if (translucent) { - if (glint) { - if (translucentGlintVertexConsumer == null) { - translucentGlintVertexConsumer = createVertexConsumer(Sheets.translucentItemSheet(), true); - } + int cacheIndex; - return translucentGlintVertexConsumer; - } else { - if (translucentVertexConsumer == null) { - translucentVertexConsumer = createVertexConsumer(Sheets.translucentItemSheet(), false); - } - - return translucentVertexConsumer; - } + if (type == Sheets.translucentItemSheet()) { + cacheIndex = 0; + } else if (type == Sheets.cutoutBlockSheet()) { + cacheIndex = GLINT_COUNT; } else { - if (glint) { - if (cutoutGlintVertexConsumer == null) { - cutoutGlintVertexConsumer = createVertexConsumer(Sheets.cutoutBlockSheet(), true); - } + cacheIndex = 2 * GLINT_COUNT; + } - return cutoutGlintVertexConsumer; - } else { - if (cutoutVertexConsumer == null) { - cutoutVertexConsumer = createVertexConsumer(Sheets.cutoutBlockSheet(), false); - } + cacheIndex += glint.ordinal(); + VertexConsumer vertexConsumer = vertexConsumerCache[cacheIndex]; - return cutoutVertexConsumer; - } + if (vertexConsumer == null) { + vertexConsumer = createVertexConsumer(type, glint); + vertexConsumerCache[cacheIndex] = vertexConsumer; } + + return vertexConsumer; } - private VertexConsumer createVertexConsumer(RenderType renderType, boolean glint) { - if (isGlintDynamicDisplay && glint) { - if (dynamicDisplayGlintEntry == null) { - dynamicDisplayGlintEntry = poseStack.last().copy(); + private VertexConsumer createVertexConsumer(RenderType type, ItemStackRenderState.FoilType glint) { + if (glint == ItemStackRenderState.FoilType.SPECIAL) { + if (specialGlintEntry == null) { + specialGlintEntry = poseStack.last().copy(); if (transformMode == ItemDisplayContext.GUI) { - MatrixUtil.mulComponentWise(dynamicDisplayGlintEntry.pose(), 0.5F); + MatrixUtil.mulComponentWise(specialGlintEntry.pose(), 0.5F); } else if (transformMode.firstPerson()) { - MatrixUtil.mulComponentWise(dynamicDisplayGlintEntry.pose(), 0.75F); + MatrixUtil.mulComponentWise(specialGlintEntry.pose(), 0.75F); } } - return ItemRenderer.getCompassFoilBuffer(bufferSource, renderType, dynamicDisplayGlintEntry); + return ItemRendererAccessor.sodium$getCompassFoilBuffer(bufferSource, type, specialGlintEntry); } - return ItemRenderer.getFoilBuffer(bufferSource, renderType, true, glint); + return ItemRenderer.getFoilBuffer(bufferSource, type, true, glint != ItemStackRenderState.FoilType.NONE); } - public void bufferDefaultModel(BakedModel model, @Nullable BlockState state) { - if (hasTransform() || vanillaBufferer == null) { - VanillaModelEncoder.emitItemQuads(model, state, randomSupplier, ItemRenderContext.this); + public void bufferDefaultModel(QuadEmitter quadEmitter, BakedModel model, @Nullable BlockState state) { + if (vanillaBufferer == null) { + VanillaModelEncoder.emitItemQuads(quadEmitter, model, null, randomSupplier); } else { - vanillaBufferer.accept(model, itemStack, lightmap, overlay, poseStack, defaultVertexConsumer); + VertexConsumer vertexConsumer; + if (defaultGlint == ItemStackRenderState.FoilType.SPECIAL) { + PoseStack.Pose pose = poseStack.last().copy(); + if (transformMode == ItemDisplayContext.GUI) { + MatrixUtil.mulComponentWise(pose.pose(), 0.5F); + } else if (transformMode.firstPerson()) { + MatrixUtil.mulComponentWise(pose.pose(), 0.75F); + } + + vertexConsumer = ItemRendererAccessor.sodium$getCompassFoilBuffer(bufferSource, defaultLayer, pose); + } else { + vertexConsumer = ItemRenderer.getFoilBuffer(bufferSource, defaultLayer, true, defaultGlint != ItemStackRenderState.FoilType.NONE); + } + + vanillaBufferer.accept(model, colors, lightmap, overlay, poseStack, vertexConsumer); } } /** used to accept a method reference from the ItemRenderer. */ @FunctionalInterface public interface VanillaModelBufferer { - void accept(BakedModel model, ItemStack stack, int color, int overlay, PoseStack matrixStack, VertexConsumer buffer); + void accept(BakedModel model, int[] colirs, int color, int overlay, PoseStack matrixStack, VertexConsumer buffer); } } 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 a0220a8776..7c0a26cf11 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 @@ -76,7 +76,7 @@ public void renderModel(BlockAndTintGetter blockView, BakedModel model, BlockSta this.prepareCulling(cull); this.prepareAoInfo(model.useAmbientOcclusion()); - ((FabricBakedModel) model).emitBlockQuads(blockView, state, pos, this.randomSupplier, this); + ((FabricBakedModel) model).emitBlockQuads(getEmitter(), blockView, state, pos, this.randomSupplier, this::isFaceCulled); this.level = null; this.type = null; @@ -89,7 +89,6 @@ public void renderModel(BlockAndTintGetter blockView, BakedModel model, BlockSta @Override protected void processQuad(MutableQuadViewImpl quad) { final RenderMaterial mat = quad.material(); - final int colorIndex = mat.disableColorIndex() ? -1 : quad.colorIndex(); final TriState aoMode = mat.ambientOcclusion(); final ShadeMode shadeMode = mat.shadeMode(); final LightMode lightMode; @@ -100,14 +99,14 @@ protected void processQuad(MutableQuadViewImpl quad) { } final boolean emissive = mat.emissive(); - colorizeQuad(quad, colorIndex); + tintQuad(quad); shadeQuad(quad, lightMode, emissive, shadeMode); bufferQuad(quad); } - private void colorizeQuad(MutableQuadViewImpl quad, int colorIndex) { - if (colorIndex != -1) { - final int blockColor = 0xFF000000 | this.colorMap.getColor(this.state, this.level, this.pos, colorIndex); + private void tintQuad(MutableQuadViewImpl quad) { + if (quad.tintIndex() != -1) { + final int blockColor = 0xFF000000 | this.colorMap.getColor(this.state, this.level, this.pos, quad.tintIndex()); for (int i = 0; i < 4; i++) { quad.color(i, ColorMixer.mulComponentWise(blockColor, quad.color(i))); diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer.java index b6630a65c5..16cf9cf093 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer.java @@ -153,7 +153,7 @@ public void render(Camera camera, FogParameters fogParameters = FogRenderer.setupFog(camera, FogRenderer.FogMode.FOG_TERRAIN, new Vector4f(prevFogParameters.red(), prevFogParameters.green(), prevFogParameters.blue(), prevFogParameters.alpha()), renderDistance * 8, shouldUseWorldFog(level, cameraPos), tickDelta); - RenderSystem.setShaderColor(ARGB.from8BitChannel(ARGB.red(color)), ARGB.from8BitChannel(ARGB.green(color)), ARGB.from8BitChannel(ARGB.blue(color)), 0.8F); + RenderSystem.setShaderColor(ARGB.redFloat(color), ARGB.greenFloat(color), ARGB.blueFloat(color), 0.8F); RenderSystem.setShaderFog(fogParameters); RenderTarget renderTarget = Minecraft.getInstance().levelRenderer.getCloudsTarget(); diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/world/biome/BiomeColorMaps.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/world/biome/BiomeColorMaps.java index a06dab7bd1..87ea7b5599 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/world/biome/BiomeColorMaps.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/world/biome/BiomeColorMaps.java @@ -19,7 +19,7 @@ public static int getGrassColor(int index) { public static int getFoliageColor(int index) { if (index == INVALID_INDEX || index >= FoliageColor.pixels.length) { - return FoliageColor.getDefaultColor(); + return FoliageColor.FOLIAGE_DEFAULT; } return FoliageColor.pixels[index]; diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/colors/ItemColorsMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/colors/ItemColorsMixin.java deleted file mode 100644 index 9fc9f999ff..0000000000 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/colors/ItemColorsMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.caffeinemc.mods.sodium.mixin.core.model.colors; - -import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap; -import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; -import net.caffeinemc.mods.sodium.client.model.color.interop.ItemColorsExtension; -import net.minecraft.client.color.item.ItemColor; -import net.minecraft.client.color.item.ItemColors; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ItemColors.class) -public class ItemColorsMixin implements ItemColorsExtension { - @Unique - private final Reference2ReferenceMap itemsToColor = - new Reference2ReferenceOpenHashMap<>(); - - @Inject(method = "register", at = @At("TAIL")) - private void preRegisterColor(ItemColor provider, ItemLike[] items, CallbackInfo ci) { - for (ItemLike convertible : items) { - this.itemsToColor.put(convertible.asItem(), provider); - } - } - - @Override - public ItemColor sodium$getColorProvider(ItemStack stack) { - return this.itemsToColor.get(stack.getItem()); - } -} diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/options/weather/LevelRendererMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/options/weather/LevelRendererMixin.java index b8405ebb86..207b9c4509 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/options/weather/LevelRendererMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/options/weather/LevelRendererMixin.java @@ -10,7 +10,7 @@ @Mixin(WeatherEffectRenderer.class) public class LevelRendererMixin { - @Redirect(method = "render(Lnet/minecraft/world/level/Level;Lnet/minecraft/client/renderer/LightTexture;IFLnet/minecraft/world/phys/Vec3;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;useFancyGraphics()Z")) + @Redirect(method = "render(Lnet/minecraft/world/level/Level;Lnet/minecraft/client/renderer/MultiBufferSource;IFLnet/minecraft/world/phys/Vec3;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;useFancyGraphics()Z")) private boolean redirectGetFancyWeather() { return SodiumClientMod.options().quality.weatherQuality.isFancy(Minecraft.getInstance().options.graphicsMode().get()); } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/BakedModelMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/BakedModelMixin.java index 55d863a21f..1c71d14e8e 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/BakedModelMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/BakedModelMixin.java @@ -2,28 +2,40 @@ import net.caffeinemc.mods.sodium.client.render.frapi.render.AbstractBlockRenderContext; import net.caffeinemc.mods.sodium.client.render.frapi.render.ItemRenderContext; +import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; -import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; +import java.util.function.Predicate; import java.util.function.Supplier; @Mixin(BakedModel.class) public interface BakedModelMixin extends FabricBakedModel { @Override - default void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { - ((AbstractBlockRenderContext) context).bufferDefaultModel((BakedModel) this, state); + default void emitItemQuads(QuadEmitter emitter, Supplier randomSupplier) { + if (emitter instanceof ItemRenderContext.ItemEmitter itemE && !itemE.hasTransforms()) { + itemE.bufferDefaultModel((BakedModel) this); + } else { + FabricBakedModel.super.emitItemQuads(emitter, randomSupplier); + } } - // Override the default implementation to redirect to the fast ItemRenderer#renderBakedItemModel method when no transforms are applied. @Override - default void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { - ((ItemRenderContext) context).bufferDefaultModel((BakedModel) this, null); + default void emitBlockQuads(QuadEmitter emitter, BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier randomSupplier, Predicate<@Nullable Direction> cullTest) { + if (emitter instanceof AbstractBlockRenderContext.BlockEmitter) { + ((AbstractBlockRenderContext.BlockEmitter) emitter).bufferDefaultModel((BakedModel) this, state, cullTest); + } else if (emitter instanceof ItemRenderContext.ItemEmitter itemE && !itemE.hasTransforms()) { + itemE.bufferDefaultModel((BakedModel) this); + } else { + FabricBakedModel.super.emitBlockQuads(emitter, blockView, state, pos, randomSupplier, cullTest); + } } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/ItemRendererAccessor.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/ItemRendererAccessor.java index 0cd683bcf1..4ea1b211b9 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/ItemRendererAccessor.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/ItemRendererAccessor.java @@ -16,15 +16,18 @@ package net.caffeinemc.mods.sodium.mixin.features.render.frapi; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.ItemRenderer; -import net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(ItemRenderer.class) public interface ItemRendererAccessor { - @Invoker("hasAnimatedTexture") - static boolean sodium$hasAnimatedTexture(ItemStack stack) { + @Invoker("getCompassFoilBuffer") + static VertexConsumer sodium$getCompassFoilBuffer(MultiBufferSource provider, RenderType layer, PoseStack.Pose entry) { throw new AssertionError(); } } \ No newline at end of file diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/ItemRendererMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/ItemRendererMixin.java index 73aa73b669..a4e9a7a463 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/ItemRendererMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/frapi/ItemRendererMixin.java @@ -20,9 +20,10 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import net.caffeinemc.mods.sodium.client.render.frapi.render.ItemRenderContext; import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; -import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.renderer.item.ItemStackRenderState; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; @@ -39,23 +40,20 @@ */ @Mixin(ItemRenderer.class) public abstract class ItemRendererMixin { - @Final @Shadow - private ItemColors itemColors; - - @Shadow - protected abstract void renderModelLists(BakedModel bakedModel, ItemStack itemStack, int i, int j, PoseStack poseStack, VertexConsumer vertexConsumer); + private static void renderModelLists(BakedModel bakedModel, int[] is, int i, int j, PoseStack poseStack, VertexConsumer vertexConsumer) { + } @Unique - private final ItemRenderContext.VanillaModelBufferer vanillaBufferer = this::renderModelLists; + private static final ItemRenderContext.VanillaModelBufferer vanillaBufferer = ItemRendererMixin::renderModelLists; @Unique - private final ThreadLocal contexts = ThreadLocal.withInitial(() -> new ItemRenderContext(itemColors, vanillaBufferer)); + private static final ThreadLocal contexts = ThreadLocal.withInitial(() -> new ItemRenderContext(vanillaBufferer)); - @Inject(method = "renderItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/BakedModel;isCustomRenderer()Z"), cancellable = true) - private void beforeRenderItem(ItemStack stack, ItemDisplayContext transformMode, PoseStack matrixStack, MultiBufferSource vertexConsumerProvider, int light, int overlay, BakedModel model, boolean invert, CallbackInfo ci) { + @Inject(method = "renderItem", at = @At(value = "HEAD"), cancellable = true) + private static void beforeRenderItem(ItemDisplayContext itemDisplayContext, PoseStack poseStack, MultiBufferSource multiBufferSource, int light, int overlay, int[] colors, BakedModel model, RenderType renderType, ItemStackRenderState.FoilType foilType, CallbackInfo ci) { if (!((FabricBakedModel) model).isVanillaAdapter()) { - contexts.get().renderModel(stack, transformMode, invert, matrixStack, vertexConsumerProvider, light, overlay, model); + contexts.get().renderModel(itemDisplayContext, poseStack, multiBufferSource, light, overlay, model, colors, renderType, foilType); ci.cancel(); } } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/gui/font/BakedGlyphMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/gui/font/BakedGlyphMixin.java index d2196af0f8..5ddb0fe18d 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/gui/font/BakedGlyphMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/gui/font/BakedGlyphMixin.java @@ -52,8 +52,8 @@ public class BakedGlyphMixin { * @reason Use intrinsics * @author JellySquid */ - @Inject(method = "render", at = @At("HEAD"), cancellable = true) - private void drawFast(boolean italic, float x, float y, Matrix4f matrix, VertexConsumer vertexConsumer, int c, int light, CallbackInfo ci) { + @Inject(method = "render(ZFFFLorg/joml/Matrix4f;Lcom/mojang/blaze3d/vertex/VertexConsumer;IZI)V", at = @At("HEAD"), cancellable = true) + private void drawFast(boolean italic, float x, float y, float z, Matrix4f matrix, VertexConsumer vertexConsumer, int c, boolean bl2, int light, CallbackInfo ci) { var writer = VertexConsumerUtils.convertOrLog(vertexConsumer); if (writer == null) { @@ -68,6 +68,7 @@ private void drawFast(boolean italic, float x, float y, Matrix4f matrix, VertexC float h2 = y + this.down; float w1 = italic ? 1.0F - 0.25F * this.up : 0.0F; float w2 = italic ? 1.0F - 0.25F * this.down : 0.0F; + float offset = bl2 ? 0.1F : 0.0F; int color = ColorARGB.toABGR(c); @@ -75,16 +76,58 @@ private void drawFast(boolean italic, float x, float y, Matrix4f matrix, VertexC long buffer = stack.nmalloc(4 * GlyphVertex.STRIDE); long ptr = buffer; - write(ptr, matrix, x1 + w1, h1, 0.0F, color, this.u0, this.v0, light); + write(ptr, matrix, x1 + w1 - offset, h1 - offset, z, color, this.u0, this.v0, light); ptr += GlyphVertex.STRIDE; - write(ptr, matrix, x1 + w2, h2, 0.0F, color, this.u0, this.v1, light); + write(ptr, matrix, x1 + w2 - offset, h2 + offset, z, color, this.u0, this.v1, light); ptr += GlyphVertex.STRIDE; - write(ptr, matrix, x2 + w2, h2, 0.0F, color, this.u1, this.v1, light); + write(ptr, matrix, x2 + w2 + offset, h2 + offset, z, color, this.u1, this.v1, light); ptr += GlyphVertex.STRIDE; - write(ptr, matrix, x2 + w1, h1, 0.0F, color, this.u1, this.v0, light); + write(ptr, matrix, x2 + w1 + offset, h1 - offset, z, color, this.u1, this.v0, light); + ptr += GlyphVertex.STRIDE; + + writer.push(stack, buffer, 4, GlyphVertex.FORMAT); + } + } + + /** + * @reason Use intrinsics + * @author JellySquid + */ + @Inject(method = "buildEffect", at = @At("HEAD"), cancellable = true) + private void drawEffectFast(BakedGlyph.Effect effect, float offset, float depthOffset, int c, VertexConsumer vertexConsumer, int light, Matrix4f matrix, CallbackInfo ci) { + var writer = VertexConsumerUtils.convertOrLog(vertexConsumer); + + if (writer == null) { + return; + } + + ci.cancel(); + + float x1 = effect.x0(); + float x2 = effect.x1(); + float h1 = effect.y0(); + float h2 = effect.y1(); + float z = effect.depth() + depthOffset; + + int color = ColorARGB.toABGR(c); + + try (MemoryStack stack = MemoryStack.stackPush()) { + long buffer = stack.nmalloc(4 * GlyphVertex.STRIDE); + long ptr = buffer; + + write(ptr, matrix, x1 + offset, h1 + offset, z, color, this.u0, this.v0, light); + ptr += GlyphVertex.STRIDE; + + write(ptr, matrix, x1 + offset, h2 + offset, z, color, this.u0, this.v1, light); + ptr += GlyphVertex.STRIDE; + + write(ptr, matrix, x2 + offset, h2 + offset, z, color, this.u1, this.v1, light); + ptr += GlyphVertex.STRIDE; + + write(ptr, matrix, x2 + offset, h1 + offset, z, color, this.u1, this.v0, light); ptr += GlyphVertex.STRIDE; writer.push(stack, buffer, 4, GlyphVertex.FORMAT); 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 a3b15c4252..12ca36097e 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 @@ -4,12 +4,9 @@ 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; import net.caffeinemc.mods.sodium.api.util.ColorARGB; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; -import net.minecraft.client.color.item.ItemColor; -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.resources.model.BakedModel; @@ -26,20 +23,21 @@ import java.util.List; @Mixin(ItemRenderer.class) -public class ItemRendererMixin { +public abstract class ItemRendererMixin { @Unique - private final RandomSource random = new SingleThreadedRandomSource(42L); + private static final ThreadLocal random = ThreadLocal.withInitial(() -> new SingleThreadedRandomSource(42L)); @Shadow - @Final - private ItemColors itemColors; + private static int getLayerColorSafe(int[] is, int i) { + throw new AssertionError("Not shadowed"); + } /** * @reason Avoid allocations * @author JellySquid */ @Inject(method = "renderModelLists", at = @At("HEAD"), cancellable = true) - private void renderModelFast(BakedModel model, ItemStack itemStack, int light, int overlay, PoseStack matrixStack, VertexConsumer vertexConsumer, CallbackInfo ci) { + private static void renderModelFast(BakedModel model, int[] colors, int light, int overlay, PoseStack poseStack, VertexConsumer vertexConsumer, CallbackInfo ci) { var writer = VertexConsumerUtils.convertOrLog(vertexConsumer); if (writer == null) { @@ -48,21 +46,17 @@ private void renderModelFast(BakedModel model, ItemStack itemStack, int light, i ci.cancel(); - RandomSource random = this.random; - PoseStack.Pose matrices = matrixStack.last(); - - ItemColor colorProvider = null; + RandomSource random = ItemRendererMixin.random.get(); + long seed = 42L; - if (!itemStack.isEmpty()) { - colorProvider = ((ItemColorsExtension) this.itemColors).sodium$getColorProvider(itemStack); - } + PoseStack.Pose matrices = poseStack.last(); for (Direction direction : DirectionUtil.ALL_DIRECTIONS) { random.setSeed(42L); List quads = model.getQuads(null, direction, random); if (!quads.isEmpty()) { - this.renderBakedItemQuads(matrices, writer, quads, itemStack, colorProvider, light, overlay); + renderBakedItemQuads(matrices, writer, quads, colors, light, overlay); } } @@ -70,13 +64,13 @@ private void renderModelFast(BakedModel model, ItemStack itemStack, int light, i List quads = model.getQuads(null, null, random); if (!quads.isEmpty()) { - this.renderBakedItemQuads(matrices, writer, quads, itemStack, colorProvider, light, overlay); + renderBakedItemQuads(matrices, writer, quads, colors, light, overlay); } } @Unique @SuppressWarnings("ForLoopReplaceableByForEach") - private void renderBakedItemQuads(PoseStack.Pose matrices, VertexBufferWriter writer, List quads, ItemStack itemStack, ItemColor colorProvider, int light, int overlay) { + private static void renderBakedItemQuads(PoseStack.Pose matrices, VertexBufferWriter writer, List quads, int[] colors, int light, int overlay) { for (int i = 0; i < quads.size(); i++) { BakedQuad bakedQuad = quads.get(i); @@ -88,10 +82,10 @@ private void renderBakedItemQuads(PoseStack.Pose matrices, VertexBufferWriter wr int color = 0xFFFFFFFF; - if (colorProvider != null && quad.hasColor()) { - color = ColorARGB.toABGR((colorProvider.getColor(itemStack, quad.getColorIndex()))); + if (bakedQuad.isTinted()) { + color = ColorARGB.toABGR(getLayerColorSafe(colors, bakedQuad.getTintIndex())); } - + BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay, BakedModelEncoder.shouldMultiplyAlpha()); SpriteUtil.markSpriteActive(quad.getSprite()); diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/clouds/LevelRendererMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/clouds/LevelRendererMixin.java index 7bd7e6c87a..41952c70ef 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/clouds/LevelRendererMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/clouds/LevelRendererMixin.java @@ -58,7 +58,7 @@ public void renderCloudsFabric(ResourceHandle resourceHandle, int @Group(name = "sodium$cloudsOverride", min = 1, max = 1) @Dynamic - @Inject(method = { "lambda$addCloudsPass$6" }, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/CloudRenderer;render(ILnet/minecraft/client/CloudStatus;FLorg/joml/Matrix4f;Lorg/joml/Matrix4f;Lnet/minecraft/world/phys/Vec3;F)V"), cancellable = true, require = 0) // Inject after Forge checks dimension support + @Inject(method = { "lambda$addCloudsPass$4" }, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/CloudRenderer;render(ILnet/minecraft/client/CloudStatus;FLorg/joml/Matrix4f;Lorg/joml/Matrix4f;Lnet/minecraft/world/phys/Vec3;F)V"), cancellable = true, require = 0) // Inject after Forge checks dimension support public void renderCloudsNeo(ResourceHandle resourcehandle, float p_365209_, Vec3 p_362985_, Matrix4f modelView, Matrix4f projectionMatrix, int color, CloudStatus p_364196_, float p_362337_, CallbackInfo ci) { ci.cancel(); diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/sky/LevelRendererMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/sky/LevelRendererMixin.java index aeef59294b..9b37260485 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/sky/LevelRendererMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/sky/LevelRendererMixin.java @@ -33,7 +33,7 @@ public abstract class LevelRendererMixin { *

When updating Sodium to new releases of the game, please check for new * ways the fog can be reduced in {@link FogRenderer#setupFog(Camera, FogRenderer.FogMode, org.joml.Vector4f, float, boolean, float)} ()}.

*/ - @Inject(method = { "method_62215", "lambda$addSkyPass$12" }, require = 1, at = @At("HEAD"), cancellable = true) + @Inject(method = { "method_62215", "lambda$addSkyPass$10" }, require = 1, at = @At("HEAD"), cancellable = true) private void preRenderSky(CallbackInfo ci) { // Cancels sky rendering when the camera is submersed underwater. // This prevents the sky from being visible through chunks culled by Sodium's fog occlusion. diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/SpriteContentsTickerMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/SpriteContentsTickerMixin.java index b00d32e827..29b3b24ecf 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/SpriteContentsTickerMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/tracking/SpriteContentsTickerMixin.java @@ -44,7 +44,7 @@ private void preTick(CallbackInfo ci) { if (onDemand && !parent.sodium$isActive()) { this.subFrame++; List frames = ((AnimatedTextureAccessor)this.animationInfo).getFrames(); - if (this.subFrame >= ((SpriteContentsFrameInfoAccessor)frames.get(this.frame)).getTime()) { + if (this.subFrame >= ((SpriteContentsFrameInfoAccessor) (Object) frames.get(this.frame)).getTime()) { this.frame = (this.frame + 1) % frames.size(); this.subFrame = 0; } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/upload/SpriteContentsInterpolationMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/upload/SpriteContentsInterpolationMixin.java index 23eaf24ffc..9812fb7eb2 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/upload/SpriteContentsInterpolationMixin.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/textures/animations/upload/SpriteContentsInterpolationMixin.java @@ -43,10 +43,10 @@ void uploadInterpolatedFrame(int x, int y, SpriteContents.Ticker arg) { SpriteContentsAnimatedTextureAccessor animation2 = (SpriteContentsAnimatedTextureAccessor) ((SpriteContentsTickerAccessor) arg).getAnimationInfo(); List frames = ((SpriteContentsAnimatedTextureAccessor) animation).getFrames(); SpriteContentsTickerAccessor accessor = (SpriteContentsTickerAccessor) arg; - SpriteContentsFrameInfoAccessor animationFrame = (SpriteContentsFrameInfoAccessor) frames.get(accessor.getFrameIndex()); + SpriteContentsFrameInfoAccessor animationFrame = (SpriteContentsFrameInfoAccessor) (Object) frames.get(accessor.getFrameIndex()); int curIndex = animationFrame.getIndex(); - int nextIndex = ((SpriteContentsFrameInfoAccessor) animation2.getFrames().get((accessor.getFrameIndex() + 1) % frames.size())).getIndex(); + int nextIndex = ((SpriteContentsFrameInfoAccessor) (Object) animation2.getFrames().get((accessor.getFrameIndex() + 1) % frames.size())).getIndex(); if (curIndex == nextIndex) { return; diff --git a/common/src/main/resources/sodium-common.mixins.json b/common/src/main/resources/sodium-common.mixins.json index 9cce3b84b6..59d85915e3 100644 --- a/common/src/main/resources/sodium-common.mixins.json +++ b/common/src/main/resources/sodium-common.mixins.json @@ -14,7 +14,6 @@ "core.WindowMixin", "core.gui.LevelLoadStatusManagerMixin", "core.model.colors.BlockColorsMixin", - "core.model.colors.ItemColorsMixin", "core.model.TextureAtlasSpriteMixin", "core.render.BlockEntityTypeMixin", "core.render.TextureAtlasMixin", diff --git a/fabric/src/main/java/net/caffeinemc/mods/sodium/fabric/SodiumFabricMod.java b/fabric/src/main/java/net/caffeinemc/mods/sodium/fabric/SodiumFabricMod.java index 9aa1881b56..a2ede200f0 100644 --- a/fabric/src/main/java/net/caffeinemc/mods/sodium/fabric/SodiumFabricMod.java +++ b/fabric/src/main/java/net/caffeinemc/mods/sodium/fabric/SodiumFabricMod.java @@ -4,7 +4,7 @@ import net.caffeinemc.mods.sodium.client.render.frapi.SodiumRenderer; import net.caffeinemc.mods.sodium.client.util.FlawlessFrames; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.renderer.v1.RendererAccess; +import net.fabricmc.fabric.api.renderer.v1.Renderer; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; import java.util.function.Consumer; @@ -23,6 +23,6 @@ public void onInitializeClient() { .getEntrypoints("frex_flawless_frames", Consumer.class) .forEach(api -> api.accept(FlawlessFrames.getProvider())); - RendererAccess.INSTANCE.registerRenderer(SodiumRenderer.INSTANCE); + Renderer.register(SodiumRenderer.INSTANCE); } } diff --git a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/quad/BakedQuadMixin.java b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/quad/BakedQuadMixin.java index 55166c64b9..38d70ac214 100644 --- a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/quad/BakedQuadMixin.java +++ b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/quad/BakedQuadMixin.java @@ -109,7 +109,7 @@ public int getFlags() { } @Override - public int getColorIndex() { + public int getTintIndex() { return this.tintIndex; } diff --git a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/features/model/WeightedRandomListMixin.java b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/features/model/WeightedRandomListMixin.java index d73d05f7d2..9bb5b70266 100644 --- a/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/features/model/WeightedRandomListMixin.java +++ b/fabric/src/main/java/net/caffeinemc/mods/sodium/mixin/features/model/WeightedRandomListMixin.java @@ -21,6 +21,8 @@ public class WeightedRandomListMixin implements Weighte @Override public E sodium$getQuick(RandomSource random) { + if (this.totalWeight == 0) return null; + int randomValue = Math.abs((int) random.nextLong()) % this.totalWeight; int i = 0; diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 73d15b64b0..981d74eca4 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -71,7 +71,7 @@ "sodium-fabric.mixins.json" ], "depends" : { - "minecraft": ["1.21.2", "1.21.3"], + "minecraft": ["1.21.4"], "fabricloader" : ">=0.16.0", "fabric-block-view-api-v2" : "*", "fabric-renderer-api-v1" : "*", diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts index 45f43c0d9d..4c23904cea 100644 --- a/neoforge/build.gradle.kts +++ b/neoforge/build.gradle.kts @@ -54,7 +54,7 @@ dependencies { } addEmbeddedFabricModule("org.sinytra.forgified-fabric-api:fabric-api-base:0.4.42+d1308ded19") - addEmbeddedFabricModule("org.sinytra.forgified-fabric-api:fabric-renderer-api-v1:4.0.3+63dbf70448") + addEmbeddedFabricModule("org.sinytra.forgified-fabric-api:fabric-renderer-api-v1:5.0.0+babc52e504") addEmbeddedFabricModule("org.sinytra.forgified-fabric-api:fabric-rendering-data-attachment-v1:0.3.48+73761d2e19") addEmbeddedFabricModule("org.sinytra.forgified-fabric-api:fabric-block-view-api-v2:1.0.10+9afaaf8c19") diff --git a/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/quad/BakedQuadMixin.java b/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/quad/BakedQuadMixin.java index f7a2d4b661..6f09fa3591 100644 --- a/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/quad/BakedQuadMixin.java +++ b/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/quad/BakedQuadMixin.java @@ -111,7 +111,7 @@ public int getFlags() { } @Override - public int getColorIndex() { + public int getTintIndex() { return this.tintIndex; } diff --git a/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/features/model/WeightedRandomListMixin.java b/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/features/model/WeightedRandomListMixin.java index d73d05f7d2..9bb5b70266 100644 --- a/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/features/model/WeightedRandomListMixin.java +++ b/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/features/model/WeightedRandomListMixin.java @@ -21,6 +21,8 @@ public class WeightedRandomListMixin implements Weighte @Override public E sodium$getQuick(RandomSource random) { + if (this.totalWeight == 0) return null; + int randomValue = Math.abs((int) random.nextLong()) % this.totalWeight; int i = 0; diff --git a/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/platform/neoforge/AbstractBlockRenderContextMixin.java b/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/platform/neoforge/AbstractBlockRenderContextMixin.java index ed7d5a42ac..6338d1f1fc 100644 --- a/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/platform/neoforge/AbstractBlockRenderContextMixin.java +++ b/neoforge/src/main/java/net/caffeinemc/mods/sodium/mixin/platform/neoforge/AbstractBlockRenderContextMixin.java @@ -2,27 +2,36 @@ import net.caffeinemc.mods.sodium.client.render.frapi.render.AbstractBlockRenderContext; import net.caffeinemc.mods.sodium.client.services.SodiumModelData; -import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; +import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; import net.minecraft.client.renderer.RenderType; import net.neoforged.neoforge.client.model.data.ModelData; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(AbstractBlockRenderContext.class) -public abstract class AbstractBlockRenderContextMixin implements RenderContext { - @Shadow - protected RenderType type; +@Mixin(AbstractBlockRenderContext.BlockEmitter.class) +public abstract class AbstractBlockRenderContextMixin implements QuadEmitter { + @Unique + private AbstractBlockRenderContext parent; - @Shadow - protected SodiumModelData modelData; + /** + * @author IMS + * @reason Access parent + */ + @Inject(method = "", at = @At("RETURN")) + public void assignParent(AbstractBlockRenderContext parent, CallbackInfo ci) { + this.parent = parent; + } @Override public ModelData getModelData() { - return (ModelData) (Object) this.modelData; + return (ModelData) (Object) this.parent.getModelData(); } @Override public RenderType getRenderType() { - return type; + return this.parent.getRenderType(); } } diff --git a/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/SodiumForgeMod.java b/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/SodiumForgeMod.java index d6bebd24c0..fe561559f5 100644 --- a/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/SodiumForgeMod.java +++ b/neoforge/src/main/java/net/caffeinemc/mods/sodium/neoforge/SodiumForgeMod.java @@ -3,7 +3,7 @@ import net.caffeinemc.mods.sodium.client.gui.SodiumOptionsGUI; import net.caffeinemc.mods.sodium.client.render.frapi.SodiumRenderer; import net.caffeinemc.mods.sodium.client.util.FlawlessFrames; -import net.fabricmc.fabric.api.renderer.v1.RendererAccess; +import net.fabricmc.fabric.api.renderer.v1.Renderer; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModContainer; @@ -20,7 +20,7 @@ public class SodiumForgeMod { public SodiumForgeMod(IEventBus bus, ModContainer modContainer) { modContainer.registerExtensionPoint(IConfigScreenFactory.class, (minecraft, screen) -> SodiumOptionsGUI.createScreen(screen)); - RendererAccess.INSTANCE.registerRenderer(SodiumRenderer.INSTANCE); + Renderer.register(SodiumRenderer.INSTANCE); MethodHandles.Lookup lookup = MethodHandles.lookup();