2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ authors=ModFest
contributors=Prospector, Sisby folk, acikek
license=MIT
# Mod Version
baseVersion=0.6.1
baseVersion=0.6.2
# Branch Metadata
branch=1.21
tagBranch=1.21
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/net/modfest/ballotbox/BallotBoxPlatformClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.HashMultimap;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.JsonOps;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
Expand All @@ -11,9 +12,9 @@
import net.modfest.ballotbox.data.VotingSelections;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -28,11 +29,11 @@ public class BallotBoxPlatformClient {
public static void init(ResourceManager resourceManager) {
try {
categories.clear();
GSON.fromJson(new BufferedReader(new InputStreamReader(resourceManager.getResourceOrThrow(CATEGORIES_DATA).getInputStream())), JsonArray.class).asList().stream().map(e -> VotingCategory.CODEC.decode(JsonOps.INSTANCE, e).getOrThrow().getFirst()).forEach(category -> categories.put(category.id(), category));
options.clear();
GSON.fromJson(new BufferedReader(new InputStreamReader(resourceManager.getResourceOrThrow(OPTIONS_DATA).getInputStream())), JsonArray.class).asList().stream().map(e -> VotingOption.CODEC.decode(JsonOps.INSTANCE, e).getOrThrow().getFirst()).forEach(option -> options.put(option.id(), option));
} catch (IOException e) {
throw new RuntimeException(e);
GSON.fromJson(new BufferedReader(new InputStreamReader(resourceManager.getResourceOrThrow(CATEGORIES_DATA).getInputStream())), JsonArray.class).asList().stream().map(e -> VotingCategory.CODEC.decode(JsonOps.INSTANCE, e).mapOrElse(Pair::getFirst, a -> null)).filter(Objects::nonNull).forEach(category -> categories.put(category.id(), category));
GSON.fromJson(new BufferedReader(new InputStreamReader(resourceManager.getResourceOrThrow(OPTIONS_DATA).getInputStream())), JsonArray.class).asList().stream().map(e -> VotingOption.CODEC.decode(JsonOps.INSTANCE, e).mapOrElse(Pair::getFirst, a -> null)).filter(Objects::nonNull).forEach(option -> options.put(option.id(), option));
} catch (Exception e) {
BallotBox.LOGGER.info("[BallotBox] Failed to load ballotbox data!", e);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/modfest/ballotbox/client/VotingScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected void initSidePanel() {
Map<String, List<VotingCategory>> typedCategories = categories.stream().collect(Collectors.groupingBy(VotingCategory::type));
typedCategories.entrySet().stream().sorted(Comparator.comparing(e -> CATEGORY_TYPES.contains(e.getKey()) ? CATEGORY_TYPES.indexOf(e.getKey()) : 99)).forEach(e -> {
e.getValue().forEach(category -> addCategoryTab(tabs, category));
if (tabs.getList().children().size() < categories.size() + typedCategories.keySet().size() - 1) tabs.addSeparatorEntry(null);
if (tabs.getList().children().size() < categories.size() + typedCategories.size() - 1) tabs.addSeparatorEntry(null);
});
tabs.getList().setBackground(EmptyBackground.EMPTY_BACKGROUND);
addSelectableChild(tabs);
Expand Down Expand Up @@ -188,7 +188,8 @@ public VotingOptionButtonWidget(Position position, int width, int height, Voting
this.client.getTextureManager().registerTexture(modIconCache.get(option.id()), icon);
}
texture = modIconCache.get(option.id());
if (option.platform().type().equals("modrinth")) url = "https://modrinth.com/mod/%s".formatted(option.platform().project_id()); // Use project ID later
if (option.platform().type().equals("modrinth")) url = "https://modrinth.com/mod/%s".formatted(option.platform().project_id());
if (option.platform().type().equals("other")) url = option.platform().homepage_url().orElse(null);
setTooltip(url == null ? Text.literal(option.description()).formatted(Formatting.GRAY) : Text.literal(option.description()).formatted(Formatting.GRAY).append(Text.literal("\n")).append(Text.literal("Right-Click").formatted(Formatting.GOLD)).append(Text.literal(" to open the mod page.").formatted(Formatting.WHITE)));
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/modfest/ballotbox/data/VotingOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public record VotingOption(String id, Optional<String> mod_id, String name, Stri
Platform.CODEC.fieldOf("platform").forGetter(VotingOption::platform)
).apply(instance, VotingOption::new));

public record Platform(String type, String project_id, String version_id) {
public record Platform(String type, Optional<String> project_id, Optional<String> homepage_url) {
public static final Codec<Platform> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.fieldOf("type").forGetter(Platform::type),
Codec.STRING.fieldOf("project_id").forGetter(Platform::project_id),
Codec.STRING.fieldOf("version_id").forGetter(Platform::version_id)
Codec.STRING.optionalFieldOf("project_id").forGetter(Platform::project_id),
Codec.STRING.optionalFieldOf("homepage_url").forGetter(Platform::homepage_url)
).apply(instance, Platform::new));
}
}