Skip to content

Commit

Permalink
Supply capes async
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Jan 23, 2025
1 parent aafa931 commit 19756ea
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 25 additions & 15 deletions src/main/java/net/frozenblock/lib/cape/api/CapeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public static void removeCapeForUUID(UUID uuid) {
setPlayerCape(uuid, Optional.empty());
}

private static void setPlayerCape(UUID uuid, @NotNull Optional<Cape> cape) {
cape.ifPresentOrElse(cape1 -> CAPES_IN_WORLD.put(uuid, cape1), () -> CAPES_IN_WORLD.remove(uuid));
private static void setPlayerCape(UUID uuid, @NotNull Optional<Cape> 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));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/frozenlib.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 19756ea

Please sign in to comment.