From 4bf53dcaf18dcc1fb7b064f482b2e8922d9d326f Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 14 Mar 2024 18:58:22 +0100 Subject: Bandaid fix resources not being loade for june [no changelog] --- .minecraft | 1 + .../firmament/mixins/BandAidResourcePackPatch.java | 30 ++++++++++++++++++++++ .../moe/nea/firmament/repo/RepoModResourcePack.kt | 23 +++++++++++++++++ src/main/resources/firmament.accesswidener | 1 + 4 files changed, 55 insertions(+) create mode 120000 .minecraft create mode 100644 src/main/java/moe/nea/firmament/mixins/BandAidResourcePackPatch.java diff --git a/.minecraft b/.minecraft new file mode 120000 index 0000000..06714e7 --- /dev/null +++ b/.minecraft @@ -0,0 +1 @@ +/home/nea/.local/share/PrismLauncher/instances/livid fucking dies/.minecraft/ \ No newline at end of file diff --git a/src/main/java/moe/nea/firmament/mixins/BandAidResourcePackPatch.java b/src/main/java/moe/nea/firmament/mixins/BandAidResourcePackPatch.java new file mode 100644 index 0000000..3100dbe --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/BandAidResourcePackPatch.java @@ -0,0 +1,30 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.mixins; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.sugar.Local; +import moe.nea.firmament.repo.RepoModResourcePack; +import net.minecraft.resource.ReloadableResourceManagerImpl; +import net.minecraft.resource.Resource; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import java.util.Optional; + +@Mixin(ReloadableResourceManagerImpl.class) +public class BandAidResourcePackPatch { + + @ModifyReturnValue( + method = "getResource", + at = @At("RETURN") + ) + private Optional injectOurCustomResourcesInCaseExistingMethodsFailed(Optional original, @Local Identifier identifier) { + return original.or(() -> RepoModResourcePack.Companion.createResourceDirectly(identifier)); + } +} diff --git a/src/main/kotlin/moe/nea/firmament/repo/RepoModResourcePack.kt b/src/main/kotlin/moe/nea/firmament/repo/RepoModResourcePack.kt index c511c90..810e2a4 100644 --- a/src/main/kotlin/moe/nea/firmament/repo/RepoModResourcePack.kt +++ b/src/main/kotlin/moe/nea/firmament/repo/RepoModResourcePack.kt @@ -9,6 +9,7 @@ package moe.nea.firmament.repo import java.io.InputStream import java.nio.file.Files import java.nio.file.Path +import java.util.* import net.fabricmc.fabric.api.resource.ModResourcePack import net.fabricmc.loader.api.FabricLoader import net.fabricmc.loader.api.metadata.ModMetadata @@ -18,17 +19,39 @@ import kotlin.io.path.relativeTo import kotlin.streams.asSequence import net.minecraft.resource.AbstractFileResourcePack import net.minecraft.resource.InputSupplier +import net.minecraft.resource.NamespaceResourceManager +import net.minecraft.resource.Resource import net.minecraft.resource.ResourcePack import net.minecraft.resource.ResourceType +import net.minecraft.resource.metadata.ResourceMetadata import net.minecraft.resource.metadata.ResourceMetadataReader import net.minecraft.util.Identifier import net.minecraft.util.PathUtil +import moe.nea.firmament.Firmament class RepoModResourcePack(val basePath: Path) : ModResourcePack { companion object { fun append(packs: MutableList) { + Firmament.logger.info("Registering mod resource pack") packs.add(RepoModResourcePack(RepoDownloadManager.repoSavedLocation)) } + + fun createResourceDirectly(identifier: Identifier): Optional { + val pack = RepoModResourcePack(RepoDownloadManager.repoSavedLocation) + return Optional.of( + Resource( + pack, + pack.open(ResourceType.CLIENT_RESOURCES, identifier) ?: return Optional.empty() + ) { + val base = + pack.open(ResourceType.CLIENT_RESOURCES, identifier.withPath(identifier.path + ".mcmeta")) + if (base == null) + ResourceMetadata.NONE + else + NamespaceResourceManager.loadMetadata(base) + } + ) + } } override fun close() { diff --git a/src/main/resources/firmament.accesswidener b/src/main/resources/firmament.accesswidener index 541b152..56d2c36 100644 --- a/src/main/resources/firmament.accesswidener +++ b/src/main/resources/firmament.accesswidener @@ -14,3 +14,4 @@ accessible method net/minecraft/entity/decoration/ArmorStandEntity setSmall (Z)V accessible field net/minecraft/entity/passive/AbstractHorseEntity items Lnet/minecraft/inventory/SimpleInventory; accessible field net/minecraft/entity/passive/AbstractHorseEntity SADDLED_FLAG I accessible field net/minecraft/entity/passive/AbstractHorseEntity HORSE_FLAGS Lnet/minecraft/entity/data/TrackedData; +accessible method net/minecraft/resource/NamespaceResourceManager loadMetadata (Lnet/minecraft/resource/InputSupplier;)Lnet/minecraft/resource/metadata/ResourceMetadata; -- cgit