Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ authors=ModFest
contributors=Prospector, Sisby folk, acikek
license=MIT
# Mod Version
baseVersion=0.5.4
baseVersion=0.6.0
# Branch Metadata
branch=1.21
tagBranch=1.21
compatibleVersions=1.21, 1.21.1
compatibleLoaders=fabric, quilt, neoforge
Comment thread
ChrysanthCow marked this conversation as resolved.
branch=1.21.4
tagBranch=1.21.4
compatibleVersions=1.21.4
compatibleLoaders=fabric, quilt
10 changes: 5 additions & 5 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ minotaur = "2.+"

kaleidoConfig = "0.3.1+1.3.1"

mc = "1.21.1"
fl = "0.16.7"
yarn = "1.21.1+build.3"
fapi = "0.104.0+1.21.1"
mc = "1.21.4"
fl = "0.16.10"
yarn = "1.21.4+build.8"
fapi = "0.115.0+1.21.4"

spruceui = "5.1.0+1.21"
spruceui = "6.2.0+1.21.3"

[plugins]
loom = { id = "fabric-loom", version.ref = "loom" }
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/modfest/ballotbox/BallotBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void onInitialize() {
VotingSelections selections = STATE.selections().get(handler.getPlayer().getUuid());
int totalVotes = BallotBoxPlatformClient.categories.values().stream().mapToInt(VotingCategory::limit).sum();
int remainingVotes = totalVotes - (selections == null ? 0 : selections.votes().size());
sender.sendPacket(new S2CGameJoin(CONFIG.closingTime.value(), remainingVotes));
sender.sendPacket(new S2CGameJoin(CONFIG.closingTime.value(), !BallotBoxPlatformClient.categories.isEmpty() && !BallotBoxPlatformClient.options.isEmpty(), remainingVotes));
}));
LOGGER.info("[BallotBox] Initialized!");
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/modfest/ballotbox/BallotBoxCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ private static int vote(ServerPlayerEntity player, Consumer<Text> feedback) {
feedback.accept(Text.literal("[BallotBox] ").formatted(Formatting.GREEN).append(Text.literal("Voting is unavailable! Voting closed %s.".formatted(BallotBox.relativeTime(BallotBox.closingTime))).formatted(Formatting.RED)));
return 0;
}
if (BallotBoxPlatformClient.categories.isEmpty() || BallotBoxPlatformClient.options.isEmpty()) {
feedback.accept(Text.literal("[BallotBox] ").formatted(Formatting.GREEN).append(Text.literal("Voting is unavailable! Nothing to vote for.").formatted(Formatting.RED)));
return 0;
}
ServerPlayNetworking.send(player, new OpenVoteScreen());
BallotBoxNetworking.sendVoteScreenData(player);
return 1;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/net/modfest/ballotbox/BallotBoxPlatformClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.mojang.serialization.JsonOps;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.modfest.ballotbox.data.VotingCategory;
Expand All @@ -14,6 +15,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -28,9 +30,15 @@ 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));
Optional<Resource> categoriesData = resourceManager.getResource(CATEGORIES_DATA);
if (categoriesData.isPresent()) {
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));
Optional<Resource> optionsData = resourceManager.getResource(OPTIONS_DATA);
if (optionsData.isPresent()) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
public class BallotBoxClient implements ClientModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("%s-client".formatted(BallotBox.ID));
public static Instant closingTime = null;
public static boolean available = true;
Comment thread
ChrysanthCow marked this conversation as resolved.
Outdated
public static int remainingVotes = 0;

public static boolean isEnabled(MinecraftClient client) {
return !client.isIntegratedServerRunning() && ClientPlayNetworking.canSend(OpenVoteScreen.ID);
}

public static boolean isAvailable() {
return available;
}
Comment thread
ChrysanthCow marked this conversation as resolved.
Outdated

public static boolean isOpen() {
return closingTime == null || closingTime.isAfter(Instant.now());
}
Expand All @@ -30,6 +35,7 @@ public void onInitializeClient() {
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> {
remainingVotes = 0;
closingTime = null;
available = true;
});
BallotBoxClientNetworking.init();
BallotBoxKeybinds.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static void init() {

private static void handleGameJoin(S2CGameJoin packet, ClientPlayNetworking.Context context) {
BallotBoxClient.closingTime = BallotBox.parseClosingTime(packet.closingTime());
BallotBoxClient.available = packet.available();
BallotBoxClient.remainingVotes = packet.remainingVotes();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ private static void tick(MinecraftClient client) {
while (OPEN_VOTING_SCREEN.wasPressed() && BallotBoxClient.isEnabled(client)) {
if (!BallotBoxClient.isOpen()) {
client.inGameHud.setOverlayMessage(Text.literal("[BallotBox] ").formatted(Formatting.GREEN).append(Text.literal("Voting is unavailable! Voting closed %s.".formatted(BallotBox.relativeTime(BallotBoxClient.closingTime))).formatted(Formatting.RED)), false);
} else if (client.currentScreen == null) {
} else if (!BallotBoxClient.isAvailable()) {
client.inGameHud.setOverlayMessage(Text.literal("[BallotBox] ").formatted(Formatting.GREEN).append(Text.literal("Voting is unavailable! Nothing to vote for.").formatted(Formatting.RED)), false);
} else if (client.currentScreen == null) {
client.setScreen(new VotingScreen());
ClientPlayNetworking.send(new OpenVoteScreen());
}
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/net/modfest/ballotbox/client/VotingScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void renderBackground(DrawContext context, int mouseX, int mouseY, float
public void renderLockup(DrawContext context) {
RenderSystem.enableBlend();
int drawHeight = sidePanelWidth * LOCKUP_TEXTURE_HEIGHT / LOCKUP_TEXTURE_WIDTH;
context.drawTexture(LOCKUP_TEXTURE, 0, (sidePanelVerticalPadding - drawHeight) / 2, sidePanelWidth, drawHeight, 0, 0, LOCKUP_TEXTURE_WIDTH, LOCKUP_TEXTURE_HEIGHT, LOCKUP_TEXTURE_WIDTH, LOCKUP_TEXTURE_HEIGHT);
context.drawTexture(RenderLayer::getGuiTextured, LOCKUP_TEXTURE, 0, (sidePanelVerticalPadding - drawHeight) / 2, sidePanelWidth, drawHeight, 0, 0, LOCKUP_TEXTURE_WIDTH, LOCKUP_TEXTURE_HEIGHT, LOCKUP_TEXTURE_WIDTH, LOCKUP_TEXTURE_HEIGHT);
RenderSystem.disableBlend();
}

Expand Down Expand Up @@ -179,6 +180,7 @@ public VotingOptionButtonWidget(Position position, int width, int height, Voting
this.parent = parent;
selected = selections.containsEntry(category.id(), option.id());
this.prohibited = prohibited;
this.active = prohibited;
if (!modIconCache.containsKey(option.id())) {
modIconCache.put(option.id(), Identifier.of(BallotBox.ID, option.id() + "_icon"));
Optional<ModContainer> mod = FabricLoader.getInstance().getModContainer(option.mod_id().isPresent() ? option.mod_id().get() : option.id())
Expand All @@ -192,14 +194,9 @@ public VotingOptionButtonWidget(Position position, int width, int height, Voting
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)));
}

@Override
public boolean isActive() {
return !prohibited && super.isActive();
}

@Override
public Optional<Text> getTooltip() {
return isActive() ? super.getTooltip() : prohibited ? Optional.of(Text.literal("Prohibited by another category!").formatted(Formatting.GRAY)) : Optional.of(Text.literal("You've reached the category vote limit!").formatted(Formatting.GRAY));
return active ? super.getTooltip() : prohibited ? Optional.of(Text.literal("Prohibited by another category!").formatted(Formatting.GRAY)) : Optional.of(Text.literal("You've reached the category vote limit!").formatted(Formatting.GRAY));
}

@Override
Expand All @@ -226,7 +223,7 @@ protected void renderButton(DrawContext context, int mouseX, int mouseY, float d
int bottom = getY() + getHeight();
int textY = (getY() * 2 + getHeight() - 9) / 2 + 1;
if (texture != null) {
context.drawTexture(texture, left, getY() + 2, 16, 16, 0, 0, 16, 16, 16, 16);
context.drawTexture(RenderLayer::getGuiTextured, texture, left, getY() + 2, 16, 16, 0, 0, 16, 16, 16, 16);
}
if (textWidth <= getWidth()) {
context.drawCenteredTextWithShadow(client.textRenderer, getMessage(), left + getWidth() / 2, textY, 0xFFFFFFFF);
Expand All @@ -246,7 +243,7 @@ protected void renderButton(DrawContext context, int mouseX, int mouseY, float d
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
super.renderWidget(context, mouseX, mouseY, delta);
if (selected) {
context.drawTexture(CHECKMARK_TEXTURE, getX() + getWidth() - 11, getY() + getHeight() - 9, 0, 0, 7, 6, 7, 6);
context.drawTexture(RenderLayer::getGuiTextured, CHECKMARK_TEXTURE, getX() + getWidth() - 11, getY() + getHeight() - 9, 0, 0, 7, 6, 7, 6);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.GridWidget;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.sound.MusicInstance;
import net.minecraft.sound.MusicType;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.modfest.ballotbox.BallotBox;
import net.modfest.ballotbox.client.BallotBoxClient;
import net.modfest.ballotbox.client.BallotBoxClientNetworking;
import net.modfest.ballotbox.client.VotingScreen;
import net.modfest.ballotbox.packet.OpenVoteScreen;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -35,8 +37,8 @@ private static Widget replaceSendFeedback(GridWidget.Adder instance, Widget widg
ballotbox$voteButton = ButtonWidget.builder(Text.of("Submission Voting"), b -> {
MinecraftClient.getInstance().setScreen(new VotingScreen());
ClientPlayNetworking.send(new OpenVoteScreen());
}).width(98).tooltip(BallotBoxClient.isOpen() ? null : Tooltip.of(Text.literal("Closed %s.".formatted(BallotBox.relativeTime(BallotBoxClient.closingTime))).formatted(Formatting.GRAY))).build();
ballotbox$voteButton.active = BallotBoxClient.isOpen();
}).width(98).tooltip(BallotBoxClient.isOpen() && BallotBoxClient.isAvailable() ? null : BallotBoxClient.isAvailable() ? Tooltip.of(Text.literal("Closed %s.".formatted(BallotBox.relativeTime(BallotBoxClient.closingTime))).formatted(Formatting.GRAY)) : Tooltip.of(Text.literal("Nothing to vote for.").formatted(Formatting.GRAY))).build();
ballotbox$voteButton.active = BallotBoxClient.isOpen() && BallotBoxClient.isAvailable();
return instance.add(ballotbox$voteButton);
}

Expand All @@ -52,15 +54,15 @@ private Widget replacePlayerReporting(GridWidget.Adder instance, Widget widget,
return instance.add(ButtonWidget.builder(Text.of(BallotBox.CONFIG.credits_text.value()), b -> {
MinecraftClient.getInstance().setScreen(new CreditsScreen(false, () -> MinecraftClient.getInstance().setScreen((GameMenuScreen) (Object) this)));
MinecraftClient.getInstance().getMusicTracker().stop();
MinecraftClient.getInstance().getMusicTracker().play(MusicType.CREDITS);
MinecraftClient.getInstance().getMusicTracker().play(new MusicInstance(MusicType.CREDITS));
}).width(98).build());
}

@Inject(method = "render", at = @At("TAIL"))
private void addReminder(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (ballotbox$voteButton == null) return;
ballotbox$voteButton.active = BallotBoxClient.isOpen();
if (BallotBoxClient.isOpen() && BallotBoxClient.remainingVotes > 0) {
ballotbox$voteButton.active = BallotBoxClient.isOpen() && BallotBoxClient.isAvailable();
if (ballotbox$voteButton.active && BallotBoxClient.remainingVotes > 0) {
Text remainingText = Text.literal("%s vote%s available!".formatted(BallotBoxClient.remainingVotes, BallotBoxClient.remainingVotes > 1 ? "s" : "")).formatted(Formatting.GREEN);
context.drawText(MinecraftClient.getInstance().textRenderer, remainingText, ballotbox$voteButton.getX() - MinecraftClient.getInstance().textRenderer.getWidth(remainingText) - 2, ballotbox$voteButton.getY() + 2, 0xFFFFFFFF, true);
if (BallotBoxClient.closingTime != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.sound.MusicInstance;
import net.minecraft.sound.MusicType;
import net.minecraft.text.Text;
import net.modfest.ballotbox.BallotBox;
Expand All @@ -20,15 +21,15 @@ protected TitleScreenMixin(Text title) {
super(title);
}

@WrapOperation(method = "initWidgetsNormal", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/TitleScreen;addDrawableChild(Lnet/minecraft/client/gui/Element;)Lnet/minecraft/client/gui/Element;", ordinal = 2))
@WrapOperation(method = "addNormalWidgets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/TitleScreen;addDrawableChild(Lnet/minecraft/client/gui/Element;)Lnet/minecraft/client/gui/Element;", ordinal = 2))
private Element replaceRealms(TitleScreen instance, Element element, Operation<Element> original, int y, int spacingY) {
if (!BallotBox.CONFIG.replace_realms_credits.value()) return original.call(instance, element);
return addDrawableChild(ButtonWidget.builder(Text.of(BallotBox.CONFIG.credits_text.value()), b -> {
MinecraftClient.getInstance().setScreen(new CreditsScreen(false, () -> MinecraftClient.getInstance().setScreen((TitleScreen) (Object) this)));
MinecraftClient.getInstance().getMusicTracker().stop();
MinecraftClient.getInstance().getMusicTracker().play(MusicType.CREDITS);
MinecraftClient.getInstance().getMusicTracker().play(new MusicInstance(MusicType.CREDITS));
})
.dimensions(this.width / 2 - 100, y + spacingY * 2, 200, 20)
.dimensions(this.width / 2 - 100, y, 200, 20)
.build()
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/modfest/ballotbox/packet/S2CGameJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import net.minecraft.util.Identifier;
import net.modfest.ballotbox.BallotBox;

public record S2CGameJoin(String closingTime, int remainingVotes) implements CustomPayload {
public record S2CGameJoin(String closingTime, boolean available, int remainingVotes) implements CustomPayload {
public static final Id<S2CGameJoin> ID = new Id<>(Identifier.of(BallotBox.ID, "game_join"));
public static final PacketCodec<RegistryByteBuf, S2CGameJoin> CODEC = PacketCodec.tuple(
PacketCodecs.STRING, S2CGameJoin::closingTime,
PacketCodecs.BOOLEAN, S2CGameJoin::available,
PacketCodecs.INTEGER, S2CGameJoin::remainingVotes,
S2CGameJoin::new
);
Expand Down
44 changes: 0 additions & 44 deletions src/main/resources/data/ballotbox/ballot/categories.json

This file was deleted.

Loading