From 31d08b0ecef8bb0a00d031c80b29d5ba78015615 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Fri, 13 Sep 2024 12:26:18 -0700 Subject: [PATCH] Overwrite TextureAtlasSprite#uvShrinkRatio (#2746) Mods, especially on Fabric, typically don't use FaceBakery to create custom quads outside of baked models, but they may still use uvShrinkRatio to manually shrink the UVs. --- .../mixin/core/model/FaceBakeryMixin.java | 18 ------------------ .../core/model/TextureAtlasSpriteMixin.java | 17 +++++++++++++++++ common/src/main/resources/sodium.mixins.json | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) delete mode 100644 common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/FaceBakeryMixin.java create mode 100644 common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/TextureAtlasSpriteMixin.java diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/FaceBakeryMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/FaceBakeryMixin.java deleted file mode 100644 index bbcdaf56e2..0000000000 --- a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/FaceBakeryMixin.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.caffeinemc.mods.sodium.mixin.core.model; - -import net.minecraft.client.renderer.block.model.FaceBakery; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(FaceBakery.class) -public class FaceBakeryMixin { - @Redirect(method = "bakeQuad", at = @At(value = "INVOKE", target = - "Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;uvShrinkRatio()F")) - private float alterUvShrinkRatio(TextureAtlasSprite sprite) { - // Vanilla tries to apply a bias to texture coordinates to avoid texture bleeding. This is counterproductive - // with Sodium's terrain rendering, since the bias is applied in the shader instead. - return 0.0f; - } -} diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/TextureAtlasSpriteMixin.java b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/TextureAtlasSpriteMixin.java new file mode 100644 index 0000000000..88b3bd316c --- /dev/null +++ b/common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/model/TextureAtlasSpriteMixin.java @@ -0,0 +1,17 @@ +package net.caffeinemc.mods.sodium.mixin.core.model; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(TextureAtlasSprite.class) +public class TextureAtlasSpriteMixin { + @Overwrite + public float uvShrinkRatio() { + // Vanilla tries to apply a bias to texture coordinates to avoid texture bleeding (see FaceBakery#bakeQuad). + // This is counterproductive with Sodium's terrain rendering, since the bias is applied in the shader instead. + // Overwrite this method instead of adjusting its return value in FaceBakery as other mods may use it to + // manually apply the bias. + return 0.0f; + } +} diff --git a/common/src/main/resources/sodium.mixins.json b/common/src/main/resources/sodium.mixins.json index ade970e0c0..a41962e84e 100644 --- a/common/src/main/resources/sodium.mixins.json +++ b/common/src/main/resources/sodium.mixins.json @@ -15,7 +15,7 @@ "core.gui.LevelLoadStatusManagerMixin", "core.model.colors.BlockColorsMixin", "core.model.colors.ItemColorsMixin", - "core.model.FaceBakeryMixin", + "core.model.TextureAtlasSpriteMixin", "core.render.BlockEntityTypeMixin", "core.render.TextureAtlasMixin", "core.render.VertexFormatMixin",