Skip to content

Commit

Permalink
Do not apply optimizations to sprites with special tickers
Browse files Browse the repository at this point in the history
  • Loading branch information
jellysquid3 committed Jan 1, 2025
1 parent ffb8cba commit 07ce020
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,23 @@ private boolean validateQuadUVs(TextureAtlasSprite atlasSprite) {
}

private static TerrainRenderPass getDowngradedPass(TextureAtlasSprite sprite, TerrainRenderPass pass) {
if (sprite.contents() instanceof SpriteContentsExtension contents) {
if (pass == DefaultTerrainRenderPasses.TRANSLUCENT && !contents.sodium$hasTranslucentPixels()) {
pass = DefaultTerrainRenderPasses.CUTOUT;
if (sprite instanceof TextureAtlasSpriteExtension spriteExt) {
// Some mods may use a custom ticker which we cannot look into. To avoid problems with these mods,
// do not attempt to downgrade the render pass.
if (spriteExt.sodium$hasUnknownImageContents()) {
return pass;
}
if (pass == DefaultTerrainRenderPasses.CUTOUT && !contents.sodium$hasTransparentPixels()) {
pass = DefaultTerrainRenderPasses.SOLID;

if (sprite.contents() instanceof SpriteContentsExtension contentsExt) {
if (pass == DefaultTerrainRenderPasses.TRANSLUCENT && !contentsExt.sodium$hasTranslucentPixels()) {
pass = DefaultTerrainRenderPasses.CUTOUT;
}
if (pass == DefaultTerrainRenderPasses.CUTOUT && !contentsExt.sodium$hasTransparentPixels()) {
pass = DefaultTerrainRenderPasses.SOLID;
}
}
}

return pass;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline;

public interface TextureAtlasSpriteExtension {
boolean sodium$hasUnknownImageContents();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.caffeinemc.mods.sodium.mixin.features.textures.scan;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.TextureAtlasSpriteExtension;
import net.minecraft.client.renderer.texture.SpriteContents;
import net.minecraft.client.renderer.texture.SpriteTicker;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(TextureAtlasSprite.class)
public class TextureAtlasSpriteMixin implements TextureAtlasSpriteExtension {
@Unique
private boolean hasUnknownImageContents;

@WrapOperation(method = "createTicker", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/SpriteContents;createTicker()Lnet/minecraft/client/renderer/texture/SpriteTicker;"))
private SpriteTicker hookTickerInstantiation(SpriteContents instance, Operation<SpriteTicker> original) {
var ticker = original.call(instance);

if (ticker != null && !(ticker instanceof SpriteContents.Ticker)) {
this.hasUnknownImageContents = true;
}

return ticker;
}

@Override
public boolean sodium$hasUnknownImageContents() {
return this.hasUnknownImageContents;
}
}
1 change: 1 addition & 0 deletions common/src/main/resources/sodium-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"features.textures.mipmaps.MipmapGeneratorMixin",
"features.textures.mipmaps.SpriteContentsMixin",
"features.textures.scan.SpriteContentsMixin",
"features.textures.scan.TextureAtlasSpriteMixin",
"workarounds.context_creation.WindowMixin",
"workarounds.event_loop.RenderSystemMixin"
]
Expand Down

0 comments on commit 07ce020

Please sign in to comment.