|
| 1 | +/* |
| 2 | + * This file is part of FalseTweaks. |
| 3 | + * |
| 4 | + * Copyright (C) 2022-2025 FalsePattern |
| 5 | + * All Rights Reserved |
| 6 | + * |
| 7 | + * The above copyright notice and this permission notice shall be included |
| 8 | + * in all copies or substantial portions of the Software. |
| 9 | + * |
| 10 | + * FalseTweaks is free software: you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU Lesser General Public License as published by |
| 12 | + * the Free Software Foundation, only version 3 of the License. |
| 13 | + * |
| 14 | + * FalseTweaks is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU Lesser General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU Lesser General Public License |
| 20 | + * along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>. |
| 21 | + */ |
| 22 | + |
| 23 | +package com.falsepattern.falsetweaks.mixin.mixins.client.animfix.swansong; |
| 24 | + |
| 25 | +import com.falsepattern.falsetweaks.api.animfix.IAnimationUpdateBatcher; |
| 26 | +import com.falsepattern.falsetweaks.modules.animfix.AnimationUpdateBatcherRegistry; |
| 27 | +import com.falsepattern.falsetweaks.modules.animfix.interfaces.ITextureMapMixin; |
| 28 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 29 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 30 | +import com.llamalad7.mixinextras.sugar.Local; |
| 31 | +import com.llamalad7.mixinextras.sugar.Share; |
| 32 | +import com.llamalad7.mixinextras.sugar.ref.LocalRef; |
| 33 | +import com.ventooth.swansong.mixin.interfaces.PBRTextureHolder; |
| 34 | +import com.ventooth.swansong.pbr.PBRTextureEngine; |
| 35 | +import it.unimi.dsi.fastutil.objects.ObjectList; |
| 36 | +import lombok.val; |
| 37 | +import org.spongepowered.asm.mixin.Mixin; |
| 38 | +import org.spongepowered.asm.mixin.injection.At; |
| 39 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 40 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 41 | + |
| 42 | +import net.minecraft.client.renderer.texture.TextureAtlasSprite; |
| 43 | +import net.minecraft.client.renderer.texture.TextureMap; |
| 44 | + |
| 45 | +@Mixin(value = PBRTextureEngine.class, |
| 46 | + remap = false) |
| 47 | +public abstract class PBRTextureEngineMixin { |
| 48 | + @WrapOperation(method = "uploadAtlasSpritesAll", |
| 49 | + at = @At(value = "INVOKE", |
| 50 | + target = "Lcom/ventooth/swansong/pbr/PBRTextureEngine;uploadAtlasSpriteLayer(ILit/unimi/dsi/fastutil/objects/ObjectList;IIII)V", |
| 51 | + ordinal = 0), |
| 52 | + require = 1) |
| 53 | + private static void uploadNorm(int glName, |
| 54 | + ObjectList<TextureAtlasSprite> sprites, |
| 55 | + int width, |
| 56 | + int height, |
| 57 | + int mipLevels, |
| 58 | + int defaultCol, |
| 59 | + Operation<Void> original, |
| 60 | + @Local(argsOnly = true) PBRTextureHolder map) { |
| 61 | + AnimationUpdateBatcherRegistry.batcher = ((ITextureMapMixin)map).ft$getBatcherNorm(); |
| 62 | + original.call(glName, sprites, width, height, mipLevels, defaultCol); |
| 63 | + AnimationUpdateBatcherRegistry.batcher = null; |
| 64 | + } |
| 65 | + |
| 66 | + @WrapOperation(method = "uploadAtlasSpritesAll", |
| 67 | + at = @At(value = "INVOKE", |
| 68 | + target = "Lcom/ventooth/swansong/pbr/PBRTextureEngine;uploadAtlasSpriteLayer(ILit/unimi/dsi/fastutil/objects/ObjectList;IIII)V", |
| 69 | + ordinal = 1), |
| 70 | + require = 1) |
| 71 | + private static void uploadSpec(int glName, |
| 72 | + ObjectList<TextureAtlasSprite> sprites, |
| 73 | + int width, |
| 74 | + int height, |
| 75 | + int mipLevels, |
| 76 | + int defaultCol, |
| 77 | + Operation<Void> original, |
| 78 | + @Local(argsOnly = true) PBRTextureHolder map) { |
| 79 | + AnimationUpdateBatcherRegistry.batcher = ((ITextureMapMixin)map).ft$getBatcherSpec(); |
| 80 | + original.call(glName, sprites, width, height, mipLevels, defaultCol); |
| 81 | + AnimationUpdateBatcherRegistry.batcher = null; |
| 82 | + } |
| 83 | + |
| 84 | + @WrapOperation(method = "uploadAtlasSpritesAll", |
| 85 | + at = @At(value = "INVOKE", |
| 86 | + target = "Lcom/ventooth/swansong/pbr/PBRTextureEngine;uploadAtlasSpriteLayer(ILit/unimi/dsi/fastutil/objects/ObjectList;IIII)V", |
| 87 | + ordinal = 2), |
| 88 | + require = 1) |
| 89 | + private static void uploadBase(int glName, |
| 90 | + ObjectList<TextureAtlasSprite> sprites, |
| 91 | + int width, |
| 92 | + int height, |
| 93 | + int mipLevels, |
| 94 | + int defaultCol, |
| 95 | + Operation<Void> original, |
| 96 | + @Local(argsOnly = true) PBRTextureHolder map) { |
| 97 | + AnimationUpdateBatcherRegistry.batcher = ((ITextureMapMixin)map).getBatcher(); |
| 98 | + original.call(glName, sprites, width, height, mipLevels, defaultCol); |
| 99 | + AnimationUpdateBatcherRegistry.batcher = null; |
| 100 | + } |
| 101 | + |
| 102 | + @Inject(method = "uploadAtlasSpriteLayer", |
| 103 | + at = @At(value = "INVOKE", |
| 104 | + target = "Ljava/lang/Math;min(II)I"), |
| 105 | + require = 1) |
| 106 | + private static void uploadAnimated(CallbackInfo ci, |
| 107 | + @Local TextureAtlasSprite sprite) { |
| 108 | + if (AnimationUpdateBatcherRegistry.batcher != null && sprite.hasAnimationMetadata()) { |
| 109 | + AnimationUpdateBatcherRegistry.batcher.scheduleUpload(sprite.getFrameTextureData(0), |
| 110 | + sprite.getIconWidth(), |
| 111 | + sprite.getIconHeight(), |
| 112 | + sprite.getOriginX(), |
| 113 | + sprite.getOriginY()); |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + @WrapOperation(method = "uploadAtlasSpriteLayer", |
| 118 | + at = @At(value = "INVOKE", |
| 119 | + target = "Lnet/minecraft/client/renderer/texture/TextureUtil;uploadTextureMipmap([[IIIIIZZ)V", |
| 120 | + remap = true), |
| 121 | + require = 1) |
| 122 | + private static void dontScheduleNonAnimated(int[][] texture, |
| 123 | + int width, |
| 124 | + int height, |
| 125 | + int xOffset, |
| 126 | + int yOffset, |
| 127 | + boolean a, |
| 128 | + boolean b, |
| 129 | + Operation<Void> original) { |
| 130 | + val batch = AnimationUpdateBatcherRegistry.batcher; |
| 131 | + AnimationUpdateBatcherRegistry.batcher = null; |
| 132 | + original.call(texture, width, height, xOffset, yOffset, a, b); |
| 133 | + AnimationUpdateBatcherRegistry.batcher = batch; |
| 134 | + } |
| 135 | + |
| 136 | + @Inject(method = "updateAnimations", |
| 137 | + at = @At("HEAD"), |
| 138 | + require = 1) |
| 139 | + private static void preUpdateAnimations(CallbackInfo ci, |
| 140 | + @Local(argsOnly = true) TextureMap map, |
| 141 | + @Share("baseBatcher")LocalRef<IAnimationUpdateBatcher> baseBatcher) { |
| 142 | + baseBatcher.set(AnimationUpdateBatcherRegistry.batcher); |
| 143 | + AnimationUpdateBatcherRegistry.batcher = null; |
| 144 | + } |
| 145 | + |
| 146 | + @Inject(method = "updateAnimations", |
| 147 | + at = @At(value = "INVOKE", |
| 148 | + target = "Lcom/ventooth/swansong/sufrace/PBRTexture2D;bind()V", |
| 149 | + ordinal = 0), |
| 150 | + require = 1) |
| 151 | + private static void preUpdateNorm(CallbackInfo ci, |
| 152 | + @Local(argsOnly = true) TextureMap map) { |
| 153 | + AnimationUpdateBatcherRegistry.batcher = ((ITextureMapMixin)map).ft$getBatcherNorm(); |
| 154 | + } |
| 155 | + |
| 156 | + @Inject(method = "updateAnimations", |
| 157 | + at = @At(value = "INVOKE", |
| 158 | + target = "Lcom/ventooth/swansong/sufrace/PBRTexture2D;bind()V", |
| 159 | + ordinal = 1), |
| 160 | + require = 1) |
| 161 | + private static void preUpdateSpec(CallbackInfo ci, |
| 162 | + @Local(argsOnly = true) TextureMap map) { |
| 163 | + val b = AnimationUpdateBatcherRegistry.batcher; |
| 164 | + if (b != null) { |
| 165 | + b.upload(); |
| 166 | + } |
| 167 | + AnimationUpdateBatcherRegistry.batcher = ((ITextureMapMixin)map).ft$getBatcherSpec(); |
| 168 | + } |
| 169 | + |
| 170 | + @Inject(method = "updateAnimations", |
| 171 | + at = @At(value = "INVOKE", |
| 172 | + target = "Lnet/minecraft/client/renderer/texture/TextureUtil;bindTexture(I)V", |
| 173 | + remap = true), |
| 174 | + require = 1) |
| 175 | + private static void preUpdateResetTex(CallbackInfo ci) { |
| 176 | + val b = AnimationUpdateBatcherRegistry.batcher; |
| 177 | + if (b != null) { |
| 178 | + b.upload(); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + @Inject(method = "updateAnimations", |
| 183 | + at = @At("RETURN"), |
| 184 | + require = 1) |
| 185 | + private static void postUpdateAnimations(CallbackInfo ci, |
| 186 | + @Share("baseBatcher")LocalRef<IAnimationUpdateBatcher> baseBatcher) { |
| 187 | + AnimationUpdateBatcherRegistry.batcher = baseBatcher.get(); |
| 188 | + } |
| 189 | +} |
0 commit comments