diff options
author | nea <nea@nea.moe> | 2023-07-25 17:34:07 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-07-25 17:34:07 +0200 |
commit | 0aacb6b965852647fde85045882b6aa6cf58c287 (patch) | |
tree | 4be786b2a3765ffac8f9d50fc1d311a6b11c8d69 /src/main/java/moe/nea | |
parent | 1a07394887e546a3381cc7548b9be287671d243d (diff) | |
download | Firmament-0aacb6b965852647fde85045882b6aa6cf58c287.tar.gz Firmament-0aacb6b965852647fde85045882b6aa6cf58c287.tar.bz2 Firmament-0aacb6b965852647fde85045882b6aa6cf58c287.zip |
Add custom texture pack support
Diffstat (limited to 'src/main/java/moe/nea')
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/MixinItemModels.java | 27 | ||||
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/MixinModelLoader.java | 44 |
2 files changed, 71 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/MixinItemModels.java b/src/main/java/moe/nea/firmament/mixins/MixinItemModels.java new file mode 100644 index 0000000..2c2cc31 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/MixinItemModels.java @@ -0,0 +1,27 @@ +package moe.nea.firmament.mixins; + +import moe.nea.firmament.events.CustomItemModelEvent; +import net.minecraft.client.render.item.ItemModels; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.render.model.BakedModelManager; +import net.minecraft.item.ItemStack; +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.CallbackInfoReturnable; + +@Mixin(ItemModels.class) +public class MixinItemModels { + @Shadow + @Final + private BakedModelManager modelManager; + + @Inject(method = "getModel(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/client/render/model/BakedModel;", at = @At("HEAD"), cancellable = true) + public void onGetModel(ItemStack stack, CallbackInfoReturnable<BakedModel> cir) { + var model = CustomItemModelEvent.getModel(stack, modelManager); + if (model != null) + cir.setReturnValue(model); + } +} diff --git a/src/main/java/moe/nea/firmament/mixins/MixinModelLoader.java b/src/main/java/moe/nea/firmament/mixins/MixinModelLoader.java new file mode 100644 index 0000000..8d43083 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/MixinModelLoader.java @@ -0,0 +1,44 @@ +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 MixinModelLoader { + + @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)); + } +} |