aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java
blob: 740fbc743caaaed06fabdd9851a2d2b563875076 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

package moe.nea.firmament.mixins.custommodels;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import moe.nea.firmament.features.texturepack.BakedOverrideData;
import moe.nea.firmament.features.texturepack.CustomSkyBlockTextures;
import moe.nea.firmament.features.texturepack.FirmamentModelPredicate;
import moe.nea.firmament.features.texturepack.ModelOverrideData;
import net.minecraft.client.render.model.json.ModelOverride;
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Mixin(ModelOverrideList.class)
public class TestForFirmamentOverridePredicatesPatch {

    @ModifyArg(method = "<init>(Lnet/minecraft/client/render/model/Baker;Lnet/minecraft/client/render/model/json/JsonUnbakedModel;Ljava/util/List;)V",
        at = @At(
            value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"
        ))
    public Object onInit(
        Object element,
        @Local ModelOverride modelOverride
    ) {
        var bakedOverride = (ModelOverrideList.BakedOverride) element;
        ((BakedOverrideData) bakedOverride)
            .setFirmamentOverrides(((ModelOverrideData) modelOverride).getFirmamentOverrides());
        return element;
    }

    @ModifyExpressionValue(method = "apply", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/json/ModelOverrideList$BakedOverride;test([F)Z"))
    public boolean testFirmamentOverrides(boolean originalValue,
                                          @Local ModelOverrideList.BakedOverride bakedOverride,
                                          @Local(argsOnly = true) ItemStack stack) {
        if (!originalValue) return false;
        var overrideData = (BakedOverrideData) bakedOverride;
        var overrides = overrideData.getFirmamentOverrides();
        if (overrides == null) return true;
        if (!CustomSkyBlockTextures.TConfig.INSTANCE.getEnableModelOverrides()) return false;
        for (FirmamentModelPredicate firmamentOverride : overrides) {
            if (!firmamentOverride.test(stack))
                return false;
        }
        return true;
    }
}