From 19756ea3f9f7703aa6d7fefe27a384fa8f369f9b Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Thu, 23 Jan 2025 15:12:10 -0500 Subject: [PATCH] Supply capes async --- CHANGELOG.md | 5 +-- gradle.properties | 2 +- .../frozenblock/lib/cape/api/CapeUtil.java | 40 ++++++++++++------- .../lib/cape/client/impl/ClientCapeData.java | 6 +-- src/main/resources/frozenlib.accesswidener | 4 +- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec3e6641..d574de16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,5 @@ Make sure to clear this after each release Put changelog here: ----------------- -- Exposed the `structure_upgrade` command to players outside development environments. -- Removed the Camera item in favor of the new `panorama` client command. -- Added the new loot pool modification api, by Kluski42! +- Fixed broken access widener entries in the loot pool modification api. +- FrozenLib's capes are now downloaded asynchronously to prevent slow boot times with poor connection. diff --git a/gradle.properties b/gradle.properties index 5b0cb6e2..ea75e1e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ min_loader_version=0.16.0 # Mod Properties - mod_version = 1.9.13 + mod_version = 1.9.14 maven_group = net.frozenblock archives_base_name = FrozenLib diff --git a/src/main/java/net/frozenblock/lib/cape/api/CapeUtil.java b/src/main/java/net/frozenblock/lib/cape/api/CapeUtil.java index 593d7836..87459234 100644 --- a/src/main/java/net/frozenblock/lib/cape/api/CapeUtil.java +++ b/src/main/java/net/frozenblock/lib/cape/api/CapeUtil.java @@ -35,6 +35,9 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; import net.frozenblock.lib.FrozenSharedConstants; @@ -91,21 +94,28 @@ public static void registerCapeWithWhitelist(ResourceLocation id, Component cape } public static void registerCapesFromURL(String urlString) { - if (CAPE_REPOS.contains(urlString)) - return; - - try { - URL url = URI.create(urlString).toURL(); - URLConnection request = url.openConnection(); - request.connect(); - - JsonElement parsedJson = JsonParser.parseReader(new InputStreamReader((InputStream) request.getContent())); - JsonObject capeDir = parsedJson.getAsJsonObject(); - JsonArray capeArray = capeDir.get("capes").getAsJsonArray(); - - capeArray.forEach(jsonElement -> registerCapeFromURL(jsonElement.getAsString())); - CAPE_REPOS.add(urlString); - } catch (IOException ignored) {} + if (CAPE_REPOS.contains(urlString)) return; + + CompletableFuture.supplyAsync( + () -> { + try { + URL url = URI.create(urlString).toURL(); + URLConnection request = url.openConnection(); + request.connect(); + + JsonElement parsedJson = JsonParser.parseReader(new InputStreamReader((InputStream) request.getContent())); + JsonObject capeDir = parsedJson.getAsJsonObject(); + JsonArray capeArray = capeDir.get("capes").getAsJsonArray(); + + capeArray.forEach(jsonElement -> registerCapeFromURL(jsonElement.getAsString())); + return Optional.of(urlString); + } catch (IOException ignored) {} + return Optional.empty(); + }, + Executors.newCachedThreadPool() + ).whenComplete((value, throwable) -> { + value.ifPresent(string -> CAPE_REPOS.add((String) string)); + }); } private static void registerCapeFromURL(String urlString) { diff --git a/src/main/java/net/frozenblock/lib/cape/client/impl/ClientCapeData.java b/src/main/java/net/frozenblock/lib/cape/client/impl/ClientCapeData.java index d336f6b9..6d599f06 100644 --- a/src/main/java/net/frozenblock/lib/cape/client/impl/ClientCapeData.java +++ b/src/main/java/net/frozenblock/lib/cape/client/impl/ClientCapeData.java @@ -52,11 +52,11 @@ public static void removeCapeForUUID(UUID uuid) { setPlayerCape(uuid, Optional.empty()); } - private static void setPlayerCape(UUID uuid, @NotNull Optional cape) { - cape.ifPresentOrElse(cape1 -> CAPES_IN_WORLD.put(uuid, cape1), () -> CAPES_IN_WORLD.remove(uuid)); + private static void setPlayerCape(UUID uuid, @NotNull Optional optionalCape) { + optionalCape.ifPresentOrElse(cape -> CAPES_IN_WORLD.put(uuid, cape), () -> CAPES_IN_WORLD.remove(uuid)); ClientLevel level = Minecraft.getInstance().level; if (level != null && level.getPlayerByUUID(uuid) instanceof AbstractClientPlayerCapeInterface capeInterface) { - capeInterface.frozenLib$setCape(cape.map(Cape::texture).orElse(null)); + capeInterface.frozenLib$setCape(optionalCape.map(Cape::texture).orElse(null)); } } diff --git a/src/main/resources/frozenlib.accesswidener b/src/main/resources/frozenlib.accesswidener index 6886b1b3..91a4d0e0 100644 --- a/src/main/resources/frozenlib.accesswidener +++ b/src/main/resources/frozenlib.accesswidener @@ -179,8 +179,8 @@ accessible field net/minecraft/world/level/storage/loot/LootTable randomSequence # Loot Table Builder accessible field net/minecraft/world/level/storage/loot/LootTable$Builder pools Lcom/google/common/collect/ImmutableList$Builder; accessible field net/minecraft/world/level/storage/loot/LootTable$Builder functions Lcom/google/common/collect/ImmutableList$Builder; -accessible field net/minecraft/world/level/storage/loot/LootTable$Builder paramSet Lcom/google/common/collect/ImmutableList$Builder; -accessible field net/minecraft/world/level/storage/loot/LootTable$Builder randomSequence Lcom/google/common/collect/ImmutableList$Builder; +accessible field net/minecraft/world/level/storage/loot/LootTable$Builder paramSet Lnet/minecraft/world/level/storage/loot/parameters/LootContextParamSet; +accessible field net/minecraft/world/level/storage/loot/LootTable$Builder randomSequence Ljava/util/Optional; #Loot Pool accessible field net/minecraft/world/level/storage/loot/LootPool$Builder entries Lcom/google/common/collect/ImmutableList$Builder;