Skip to content

Commit

Permalink
fix: Sync animated textures when not animating visible textures
Browse files Browse the repository at this point in the history
Fixes CaffeineMC#1479

`SpriteContents.Interpolation#apply` only applies the image. Time tracking is still done in `SpriteContents.AnimatorImpl#tick`; interpolation gets that information from the animator implementation.
  • Loading branch information
FlashyReese committed Jul 10, 2023
1 parent bcf022e commit 68b0e0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.render.texture.SpriteContentsExtended;
import net.minecraft.client.texture.SpriteContents;
import org.spongepowered.asm.mixin.Final;
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(SpriteContents.AnimatorImpl.class)
public class MixinSpriteContentsAnimatorImpl {
@Shadow
int currentTime;
@Shadow
@Final
SpriteContents.Animation animation;
@Shadow
int frame;
@Unique
private SpriteContents parent;

Expand All @@ -30,6 +39,12 @@ private void preTick(CallbackInfo ci) {
boolean onDemand = SodiumClientMod.options().performance.animateOnlyVisibleTextures;

if (onDemand && !parent.isActive()) {
this.currentTime++;
if (this.currentTime >= this.animation.frames.get(this.frame).time) {
this.frame = (this.frame + 1) % this.animation.frames.size();
this.currentTime = 0;
}

ci.cancel();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/sodium.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ accessible class net/minecraft/client/texture/TextureStitcher$Holder

accessible method net/minecraft/client/render/Frustum isVisible (DDDDDD)Z
accessible method net/minecraft/client/texture/SpriteContents upload (IIII[Lnet/minecraft/client/texture/NativeImage;)V
accessible field net/minecraft/client/texture/SpriteContents$Animation frames Ljava/util/List;
accessible field net/minecraft/client/texture/SpriteContents$AnimationFrame time I
accessible method net/minecraft/client/render/BackgroundRenderer getFogModifier (Lnet/minecraft/entity/Entity;F)Lnet/minecraft/client/render/BackgroundRenderer$StatusEffectFogModifier;

accessible field net/minecraft/client/texture/NativeImage pointer J
Expand Down

0 comments on commit 68b0e0d

Please sign in to comment.