diff options
author | Linnea Gräf <nea@nea.moe> | 2024-05-11 03:28:05 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-05-14 18:45:59 +0200 |
commit | 7682534f6fd139b75f24c79b76098fe05f0fa0fe (patch) | |
tree | 34d94c8fd7b531da128ff0130bf463393e2560e0 /src/main/java | |
parent | 53dc0c3b0a758ce2afff2637a5a5f22aa1733c56 (diff) | |
download | firmament-7682534f6fd139b75f24c79b76098fe05f0fa0fe.tar.gz firmament-7682534f6fd139b75f24c79b76098fe05f0fa0fe.tar.bz2 firmament-7682534f6fd139b75f24c79b76098fe05f0fa0fe.zip |
Add custom global textures
Diffstat (limited to 'src/main/java')
4 files changed, 98 insertions, 6 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java b/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java index 2da4176..6bd9ba1 100644 --- a/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java +++ b/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java @@ -1,11 +1,13 @@ /* * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> * * SPDX-License-Identifier: GPL-3.0-or-later */ package moe.nea.firmament.mixins; +import moe.nea.firmament.events.BakeExtraModelsEvent; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.model.ModelLoader; import net.minecraft.client.render.model.UnbakedModel; @@ -39,12 +41,7 @@ public abstract class CustomModelBakerPatch { @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); - } + BakeExtraModelsEvent.Companion.publish(new BakeExtraModelsEvent(this::addModel)); modelsToBake.values().forEach(model -> model.setParents(this::getOrLoadModel)); } } diff --git a/src/main/java/moe/nea/firmament/mixins/EarlyResourceReloadPatch.java b/src/main/java/moe/nea/firmament/mixins/EarlyResourceReloadPatch.java new file mode 100644 index 0000000..144eda1 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/EarlyResourceReloadPatch.java @@ -0,0 +1,30 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.mixins; + +import moe.nea.firmament.events.EarlyResourceReloadEvent; +import net.minecraft.resource.ReloadableResourceManagerImpl; +import net.minecraft.resource.ResourceManager; +import net.minecraft.resource.ResourcePack; +import net.minecraft.resource.ResourceReload; +import net.minecraft.util.Unit; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; + +@Mixin(ReloadableResourceManagerImpl.class) +public abstract class EarlyResourceReloadPatch implements ResourceManager { + @Inject(method = "reload", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/SimpleResourceReload;start(Lnet/minecraft/resource/ResourceManager;Ljava/util/List;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Z)Lnet/minecraft/resource/ResourceReload;", shift = At.Shift.BEFORE)) + public void onResourceReload(Executor prepareExecutor, Executor applyExecutor, CompletableFuture<Unit> initialStage, List<ResourcePack> packs, CallbackInfoReturnable<ResourceReload> cir) { + EarlyResourceReloadEvent.Companion.publish(new EarlyResourceReloadEvent(this, prepareExecutor)); + } +} diff --git a/src/main/java/moe/nea/firmament/mixins/ResourceReloaderRegistrationPatch.java b/src/main/java/moe/nea/firmament/mixins/ResourceReloaderRegistrationPatch.java new file mode 100644 index 0000000..bf0b925 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/ResourceReloaderRegistrationPatch.java @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.mixins; + +import moe.nea.firmament.events.FinalizeResourceManagerEvent; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.RunArgs; +import net.minecraft.resource.ReloadableResourceManagerImpl; +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; + +@Mixin(MinecraftClient.class) +public class ResourceReloaderRegistrationPatch { + @Shadow + @Final + private ReloadableResourceManagerImpl resourceManager; + + @Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ResourcePackManager;createResourcePacks()Ljava/util/List;", shift = At.Shift.BEFORE)) + private void onBeforeResourcePackCreation(RunArgs args, CallbackInfo ci) { + FinalizeResourceManagerEvent.Companion.publish(new FinalizeResourceManagerEvent(this.resourceManager)); + } +} + diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java b/src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java new file mode 100644 index 0000000..ec1d09c --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java @@ -0,0 +1,34 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.mixins.custommodels; + +import moe.nea.firmament.features.texturepack.CustomGlobalTextures; +import net.minecraft.client.render.item.ItemModels; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +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(ItemRenderer.class) +public abstract class GlobalModelOverridePatch { + + @Shadow + public abstract ItemModels getModels(); + + @Inject(method = "getModel", at = @At("HEAD"), cancellable = true) + private void overrideGlobalModel( + ItemStack stack, World world, LivingEntity entity, + int seed, CallbackInfoReturnable<BakedModel> cir) { + CustomGlobalTextures.replaceGlobalModel(this.getModels(), stack, cir); + } +} |