From 620411811ea8e2f742073c556e5fa1cdfe4ee530 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sat, 11 Nov 2023 18:41:00 -0600 Subject: [PATCH] Prevent a possible crash --- .../pfm/PaladinFurnitureModUpdateChecker.java | 4 ++-- .../pfm/client/PathPackRPWrapper.java | 18 +++++++++++++----- .../pfm/fabric/PaladinFurnitureModFabric.java | 1 - .../PFMReloadableResourceManagerImplMixin.java | 1 + .../PFMReloadableResourceManagerImplMixin.java | 1 + .../registry/forge/RecipeRegistryForge.java | 1 - 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureModUpdateChecker.java b/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureModUpdateChecker.java index df4bb007a..eeb7bf37e 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureModUpdateChecker.java +++ b/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureModUpdateChecker.java @@ -187,10 +187,10 @@ public Optional getUpdateMessageServer() { if (textParts.length > 1) { MutableText component1 = new LiteralText(textParts[0]); MutableText component2 = new LiteralText(textParts[1]); - MutableText link = new LiteralText(info.modHost).styled(arg -> arg.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, info.modDownload)).withUnderline(true)); + MutableText link = new LiteralText(info.modHost).styled(arg -> arg.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, info.modDownload))); return Optional.of(component1.append(link).append(component2)); } else { - MutableText link = new LiteralText(info.modHost).styled(arg -> arg.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, info.modDownload)).withUnderline(true)); + MutableText link = new LiteralText(info.modHost).styled(arg -> arg.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, info.modDownload))); return Optional.of(new LiteralText(textParts[0]).append(link)); } } else { diff --git a/common/src/main/java/com/unlikepaladin/pfm/client/PathPackRPWrapper.java b/common/src/main/java/com/unlikepaladin/pfm/client/PathPackRPWrapper.java index caef7fc9a..598a18ebf 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/client/PathPackRPWrapper.java +++ b/common/src/main/java/com/unlikepaladin/pfm/client/PathPackRPWrapper.java @@ -1,5 +1,6 @@ package com.unlikepaladin.pfm.client; +import com.unlikepaladin.pfm.runtime.PFMRuntimeResources; import net.minecraft.resource.ResourcePack; import net.minecraft.resource.ResourceType; import net.minecraft.resource.metadata.PackResourceMetadata; @@ -26,7 +27,7 @@ public PathPackRPWrapper(Supplier delegate, PackResourceMetadata p @Nullable @Override public InputStream openRoot(String fileName) throws IOException { - if (fileName.equals("pack.png")) { + if (PFMRuntimeResources.ready && fileName.equals("pack.png")) { return delegate.get().openRoot(fileName); } return null; @@ -34,17 +35,23 @@ public InputStream openRoot(String fileName) throws IOException { @Override public InputStream open(ResourceType type, Identifier id) throws IOException { - return delegate.get().open(type, id); + if (PFMRuntimeResources.ready) + return delegate.get().open(type, id); + return null; } @Override public Collection findResources(ResourceType type, String namespace, String prefix, int maxDepth, Predicate pathFilter) { - return delegate.get().findResources(type, namespace, prefix, maxDepth, pathFilter); + if (PFMRuntimeResources.ready) + return delegate.get().findResources(type, namespace, prefix, maxDepth, pathFilter); + return null; } @Override public boolean contains(ResourceType type, Identifier id) { - return delegate.get().contains(type, id); + if (PFMRuntimeResources.ready) + return delegate.get().contains(type, id); + return false; } @Override @@ -68,6 +75,7 @@ public String getName() { @Override public void close() { - delegate.get().close(); + if (PFMRuntimeResources.ready) + delegate.get().close(); } } diff --git a/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java b/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java index 1d93575ed..7c717a2ba 100644 --- a/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java +++ b/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java @@ -92,7 +92,6 @@ public void onInitialize() { BlockItemRegistryFabric.registerItems(); BlockItemRegistryFabric.registerBlocks(); //PFMRuntimeResources.prepareAsyncResourceGen(); No async gen because Forge won't behave, blame it. - PFMRuntimeResources.ready = true; StatisticsRegistryFabric.registerStatistics(); SoundRegistryFabric.registerSounds(); NetworkRegistryFabric.registerPackets(); diff --git a/fabric/src/main/java/com/unlikepaladin/pfm/mixin/fabric/PFMReloadableResourceManagerImplMixin.java b/fabric/src/main/java/com/unlikepaladin/pfm/mixin/fabric/PFMReloadableResourceManagerImplMixin.java index 9d06ee36c..0103f5d9b 100644 --- a/fabric/src/main/java/com/unlikepaladin/pfm/mixin/fabric/PFMReloadableResourceManagerImplMixin.java +++ b/fabric/src/main/java/com/unlikepaladin/pfm/mixin/fabric/PFMReloadableResourceManagerImplMixin.java @@ -19,6 +19,7 @@ private List createReload(List packs) { List resourcePacks = new ArrayList<>(packs); resourcePacks.removeIf(pack -> pack instanceof PathPackRPWrapper); PFMRuntimeResources.RESOURCE_PACK_LIST = resourcePacks; + PFMRuntimeResources.ready = true; return packs; } } \ No newline at end of file diff --git a/forge/src/main/java/com/unlikepaladin/pfm/mixin/forge/PFMReloadableResourceManagerImplMixin.java b/forge/src/main/java/com/unlikepaladin/pfm/mixin/forge/PFMReloadableResourceManagerImplMixin.java index 445201b18..46ada685c 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/mixin/forge/PFMReloadableResourceManagerImplMixin.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/mixin/forge/PFMReloadableResourceManagerImplMixin.java @@ -19,6 +19,7 @@ private List createReload(List packs) { List resourcePacks = new ArrayList<>(packs); resourcePacks.removeIf(pack -> pack instanceof PathPackRPWrapper); PFMRuntimeResources.RESOURCE_PACK_LIST = resourcePacks; + PFMRuntimeResources.ready = true; return packs; } } \ No newline at end of file diff --git a/forge/src/main/java/com/unlikepaladin/pfm/registry/forge/RecipeRegistryForge.java b/forge/src/main/java/com/unlikepaladin/pfm/registry/forge/RecipeRegistryForge.java index 248128068..aafd1626e 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/registry/forge/RecipeRegistryForge.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/registry/forge/RecipeRegistryForge.java @@ -29,7 +29,6 @@ public static void registerRecipeSerializers(RegistryEvent.Register