diff options
author | nea <nea@nea.moe> | 2023-10-28 04:07:47 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-10-28 04:07:47 +0200 |
commit | ad490f2ea7967cb6bb97cb797b33aa3554de46a5 (patch) | |
tree | c45cf7f4b8a6d60399fcc46f793c75bd8387211d /src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java | |
parent | 9e7da2829cdc949d211ef5021131b4a48ddc3054 (diff) | |
download | firmament-ad490f2ea7967cb6bb97cb797b33aa3554de46a5.tar.gz firmament-ad490f2ea7967cb6bb97cb797b33aa3554de46a5.tar.bz2 firmament-ad490f2ea7967cb6bb97cb797b33aa3554de46a5.zip |
Rename mixins after what they do, rather than where they do it
[no changelog]
Mixins are now named after what they do, and mixins for the same class that do different things should be in two
separate mixins now.
Diffstat (limited to 'src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java')
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java b/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java new file mode 100644 index 0000000..2da4176 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java @@ -0,0 +1,50 @@ +/* + * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.mixins; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.model.ModelLoader; +import net.minecraft.client.render.model.UnbakedModel; +import net.minecraft.client.texture.Sprite; +import net.minecraft.client.util.ModelIdentifier; +import net.minecraft.client.util.SpriteIdentifier; +import net.minecraft.resource.Resource; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Map; +import java.util.function.BiFunction; + +@Mixin(ModelLoader.class) +public abstract class CustomModelBakerPatch { + + @Shadow + protected abstract void addModel(ModelIdentifier modelId); + + @Shadow + @Final + private Map<Identifier, UnbakedModel> modelsToBake; + + @Shadow + public abstract UnbakedModel getOrLoadModel(Identifier id); + + @Inject(method = "bake", at = @At("HEAD")) + public void onBake(BiFunction<Identifier, SpriteIdentifier, Sprite> spriteLoader, CallbackInfo ci) { + Map<Identifier, Resource> resources = + MinecraftClient.getInstance().getResourceManager().findResources("models/item", it -> "firmskyblock".equals(it.getNamespace()) && it.getPath().endsWith(".json")); + for (Identifier identifier : resources.keySet()) { + ModelIdentifier modelId = new ModelIdentifier("firmskyblock", identifier.getPath().substring("models/item/".length(), identifier.getPath().length() - ".json".length()), "inventory"); + addModel(modelId); + } + modelsToBake.values().forEach(model -> model.setParents(this::getOrLoadModel)); + } +} |