Skip to content

Commit

Permalink
feat: add Twitch voting and more events
Browse files Browse the repository at this point in the history
  • Loading branch information
GaeaKat committed Feb 15, 2024
1 parent ec24938 commit 16e8f8c
Show file tree
Hide file tree
Showing 59 changed files with 1,439 additions and 90 deletions.
14 changes: 13 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(17)

//minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')
//minecraft.accessTransformers.entry public net.minecraft.client.Minecraft textureManager # textureManager

jarJar.enable()
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
Expand All @@ -41,6 +41,10 @@ runs {
systemProperty 'forge.logging.console.level', 'debug'

modSource project.sourceSets.main
dependencies {
runtime "com.github.pircbotx:pircbotx:${pircbotx_version}"
runtime 'org.java-websocket:Java-WebSocket:1.5.3'
}
}

client {
Expand Down Expand Up @@ -71,7 +75,12 @@ runs {

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
repositories {

// Repository for pircbotx.
maven { url 'https://jitpack.io' }

}

dependencies {
// Specify the version of Minecraft to use.
Expand All @@ -98,6 +107,9 @@ dependencies {

// Example project dependency using a sister or child project:
// implementation project(":myproject")
implementation 'org.java-websocket:Java-WebSocket:1.5.3'
implementation "com.github.pircbotx:pircbotx:${pircbotx_version}"
//include 'org.java-websocket:Java-WebSocket:1.5.3'

// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ mod_group_id=dev.katcodes.forgedentropy
mod_authors=KatGaea. Port of Entropy by bl4ckscor3.
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=Basic port of Entropy to a NeoForge base.

pircbotx_version=12f5639c5d
47 changes: 46 additions & 1 deletion src/main/java/dev/katcodes/forgedentropy/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dev.katcodes.forgedentropy;

import dev.katcodes.forgedentropy.client.integrations.Integration;
import dev.katcodes.forgedentropy.client.integrations.IntegrationTypes;
import dev.katcodes.forgedentropy.events.ChaosEventRegistry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -32,8 +35,22 @@ private static void InitializeGeneral()
ACCESSIBILITY = BUILDER.comment("Remove flashy effects").define("accessibilityMode", false);
BUILDER.pop();
}
private static void InitializeIntegration()
{
BUILDER.push("Integrations");
IntegrationSettings.INTEGRATION_TYPE = BUILDER.comment("what kind of voting should be enabled").defineEnum("integrationType",IntegrationTypes.None);
IntegrationSettings.SEND_CHAT_MESSAGES = BUILDER.comment("Should the vote options be sent as a chat message").define("sendChatMessages",false);
IntegrationSettings.SHOW_CURRENT_PERCENTAGE=BUILDER.comment("Should the current vote percentage be shown? (Note effects the overlay too)").define("showCurrentPercentage",true);
IntegrationSettings.SHOW_UPCOMING_EVENTS=BUILDER.comment("Show the upcoming events on minecraft screen").define("showUpcomingEvents",false);
BUILDER.push("Twitch");
IntegrationSettings.TwitchSettings.AUTH_TOKEN= BUILDER.comment("Twitch oauth token").define("authToken","");
IntegrationSettings.TwitchSettings.CHANNEL=BUILDER.comment("Twitch channel to watch/vote in").define("channel","");
BUILDER.pop();
BUILDER.pop();
}
static {
InitializeGeneral();
InitializeIntegration();
}


Expand All @@ -46,6 +63,8 @@ private static void InitializeGeneral()
private static ModConfigSpec.EnumValue<UIStyle> UI_STYLE;
private static ModConfigSpec.ConfigValue<List<? extends String>> DISABLED_EVENTS;
private static ModConfigSpec.BooleanValue ACCESSIBILITY;


static final ModConfigSpec SPEC = BUILDER.build();

public static int timerDuration;
Expand All @@ -56,8 +75,28 @@ private static void InitializeGeneral()
public static List<String> disabledEvents;
public static boolean accessibilityMode;

public static class IntegrationSettings {
public static IntegrationTypes integrationType;
public static boolean sendChatMessages = true;
public static boolean showCurrentPercentage = true;

public static boolean showUpcomingEvents = true;

private static ModConfigSpec.EnumValue<IntegrationTypes> INTEGRATION_TYPE;
private static ModConfigSpec.BooleanValue SEND_CHAT_MESSAGES;
private static ModConfigSpec.BooleanValue SHOW_CURRENT_PERCENTAGE;
private static ModConfigSpec.BooleanValue SHOW_UPCOMING_EVENTS;

public static class TwitchSettings {
public static String authToken;
public static String channel;
private static ModConfigSpec.ConfigValue<String> AUTH_TOKEN;
private static ModConfigSpec.ConfigValue<String> CHANNEL;
}
}

private static boolean validateEventName(final Object obj) {
return obj instanceof String;
return obj instanceof String; // && ChaosEventRegistry.EntropyEvents.keySet().contains();
}

@SubscribeEvent
Expand All @@ -71,6 +110,12 @@ static void onLoad(final ModConfigEvent event)
uiStyle = UI_STYLE.get();
disabledEvents = new ArrayList<>(DISABLED_EVENTS.get());
accessibilityMode = ACCESSIBILITY.get();
IntegrationSettings.integrationType=IntegrationSettings.INTEGRATION_TYPE.get();
IntegrationSettings.sendChatMessages= IntegrationSettings.SEND_CHAT_MESSAGES.get();
IntegrationSettings.showCurrentPercentage=IntegrationSettings.SHOW_CURRENT_PERCENTAGE.get();
IntegrationSettings.showUpcomingEvents=IntegrationSettings.SHOW_UPCOMING_EVENTS.get();
IntegrationSettings.TwitchSettings.authToken=IntegrationSettings.TwitchSettings.AUTH_TOKEN.get();
IntegrationSettings.TwitchSettings.channel= IntegrationSettings.TwitchSettings.CHANNEL.get();

}
}
7 changes: 7 additions & 0 deletions src/main/java/dev/katcodes/forgedentropy/CurrentState.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ public static CurrentState Get() {
*/
public boolean ignoreVariableFov=false;

/**
* Use Monitor shader
*/
public boolean monitor;



}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void registerNetwork(RegisterPayloadHandlerEvent event) {
registrar.play(NetworkingIdentifiers.REMOVE_ENDED, RemoveEndedPacket::new, handler -> handler.client(ClientNetworkHandler.Get()::remove_ended).server(ServerNetworkHandler.Get()::remove_ended));
registrar.play(NetworkingIdentifiers.ADD_EVENT, AddEventPacket::new, handler -> handler.client(ClientNetworkHandler.Get()::add_event).server(ServerNetworkHandler.Get()::add_event));
registrar.play(NetworkingIdentifiers.POLL_STATUS,PollStatePacket::new,handler -> handler.client(ClientNetworkHandler.Get()::update_poll).server(ServerNetworkHandler.Get()::update_poll));
registrar.play(NetworkingIdentifiers.NEW_POLL,NewPollPacket::new,handler -> handler.client(ClientNetworkHandler.Get()::new_poll).server(ServerNetworkHandler.Get()::new_poll));
registrar.play(NetworkingIdentifiers.JOIN_HANDSHAKE,JoinHandshakePacket::new,handler -> handler.client(ClientNetworkHandler.Get()::join_handshake).server(ServerNetworkHandler.Get()::join_handshake));
}
// You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import dev.katcodes.forgedentropy.ForgedEntropyMod;
import dev.katcodes.forgedentropy.UIStyle;
import dev.katcodes.forgedentropy.client.UIStyles.GTAVUIRenderer;
import dev.katcodes.forgedentropy.client.UIStyles.MinecraftUIRenderer;
import dev.katcodes.forgedentropy.client.UIStyles.UIRenderer;
import dev.katcodes.forgedentropy.client.integrations.twitch.TwitchIntegration;
import dev.katcodes.forgedentropy.events.ChaosEvent;
import dev.katcodes.forgedentropy.events.ChaosEventRegistry;
import net.minecraft.client.Minecraft;
Expand All @@ -16,6 +18,7 @@

public class ClientEventHandler {
public List<ChaosEvent> currentEvents = new ArrayList<>();
public VotingClient votingClient;
short timerDuration;
UIRenderer renderer = null;
final short timerDurationFinal;
Expand All @@ -29,19 +32,26 @@ public ClientEventHandler(short timerDuration, short baseEventDuration, boolean
this.serverIntegrations = serverIntegrations;
Config.baseEventDuration = baseEventDuration;

//todo: Add integrations here
if(Config.integrations && serverIntegrations) {
votingClient=new VotingClient();
votingClient.setIntegrations(switch (Config.IntegrationSettings.integrationType) {
case Twitch -> new TwitchIntegration(votingClient);
default -> new TwitchIntegration(votingClient);
});
votingClient.enable();
}

if(Config.uiStyle == UIStyle.GTAV) {
//todo: once voting client, pass it here
renderer = new GTAVUIRenderer();
}
renderer = new GTAVUIRenderer(votingClient);
} else
renderer = new MinecraftUIRenderer();
}

public void tick(short eventCountDown) {
this.timerDuration = (short) (timerDurationFinal / CurrentState.Get().timeMultiplier);
this.eventCountDown = eventCountDown;
if (eventCountDown % 10 == 0 && false) {//&& votingClient == null) {
// todo: send votes
if (eventCountDown % 10 == 0 && votingClient != null) {
votingClient.sendVotes();
}
if(!Minecraft.getInstance().player.isSpectator()) {
for(ChaosEvent event: currentEvents) {
Expand Down Expand Up @@ -69,27 +79,23 @@ public void render(GuiGraphics drawContext, float tickDelta) {
}

// todo: Render poll if needed
if(Config.integrations && serverIntegrations && votingClient!=null && votingClient.enabled) {
votingClient.render(drawContext);
}
}
public void remove(int i) {
currentEvents.remove(i);
}

public void updatePollStatus(int voteId, int[] totalVotes, int totalVotesCount) {

}

public void newPoll(int voteID, List<String> events) {

}

public void endChaos() {
ForgedEntropyMod.LOGGER.info("Ending events...");
currentEvents.forEach(eventPair -> {
if(!eventPair.hasEnded())
eventPair.endClient();
});

//todo: End voting
if(votingClient!=null && votingClient.enabled)
votingClient.disable();

//todo: Reset settings
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public void add_event(final AddEventPacket packet, PlayPayloadContext context) {
public void update_poll(final PollStatePacket packet, PlayPayloadContext context) {
if(ForgedEntropyClient.clientEventHandler==null)
return;
ForgedEntropyClient.clientEventHandler.updatePollStatus(packet.voteId,packet.totalVotes,packet.totalVotesCount);
ForgedEntropyClient.clientEventHandler.votingClient.updatePollStatus(packet.voteId,packet.totalVotes,packet.totalVotesCount);
}

public void new_poll(final NewPollPacket packet, PlayPayloadContext context) {
if(ForgedEntropyClient.clientEventHandler==null)
return;
ForgedEntropyClient.clientEventHandler.newPoll(packet.voteID,packet.events);
ForgedEntropyClient.clientEventHandler.votingClient.newPoll(packet.voteID,packet.events.size()+1,packet.events);
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static ForgedEntropyClient getInstance()
private PostChain shader_black_and_white;
private PostChain shader_blur;

private PostChain shader_monitor;


@SubscribeEvent
public static void renderHud(RenderGuiOverlayEvent.Post event) {
Expand All @@ -55,6 +57,13 @@ public void renderShaders(float tickDelta) {
assert shader_blur != null : "Blur shader is null";
ShaderManager.render(shader_blur,tickDelta);
}

else if(CurrentState.Get().monitor) {
if(shader_monitor==null)
shader_monitor=ShaderManager.register(new ResourceLocation(MODID,"shaders/post/crt.json"));
assert shader_monitor!=null : "CRT shader is null";
ShaderManager.render(shader_monitor,tickDelta);
}
}
public void initialize() {
LOGGER.info("Initializing Forged Entropy Client Mod");
Expand All @@ -66,5 +75,7 @@ public void resizeShaders(int pWidth, int pHeight) {
shader_black_and_white.resize(pWidth,pHeight);
if(shader_blur!=null)
shader_blur.resize(pWidth, pHeight);
if(shader_monitor!=null)
shader_monitor.resize(pWidth, pHeight);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package dev.katcodes.forgedentropy.client.UIStyles;

import dev.katcodes.forgedentropy.client.VotingClient;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.util.FastColor;

import static java.lang.Math.floor;

public class GTAVUIRenderer implements UIRenderer{

public final VotingClient votingClient;
//todo: Add voting client to client
public GTAVUIRenderer() {

public GTAVUIRenderer(VotingClient client) {
this.votingClient=client;
}

@Override
public void renderTimer(GuiGraphics guiGraphics, int width, double time, double timerDuration) {

guiGraphics.fill(0,0,width,10,150 << 24);
guiGraphics.fill(0,0, (int) floor(width*(time/timerDuration)),10, FastColor.ARGB32.color(255,70,150,70)); //(this.votingClient != null ? votingClient.getColor(255) : ColorHelper.Argb.getArgb(255,70,150,70)));
guiGraphics.fill(0,0, (int) floor(width*(time/timerDuration)),10, (this.votingClient != null ? votingClient.getColor(255) : FastColor.ARGB32.color(255,70,150,70)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.katcodes.forgedentropy.client.UIStyles;


import dev.katcodes.forgedentropy.mixin.BossBarAccessor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.BossHealthOverlay;
import net.minecraft.client.gui.components.LerpingBossEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.world.BossEvent;

import java.util.UUID;

public class MinecraftUIRenderer implements UIRenderer {
net.minecraft.client.gui.components.LerpingBossEvent bar;

public MinecraftUIRenderer() {
UUID uuid= UUID.randomUUID();
this.bar=new LerpingBossEvent(uuid, Component.translatable("entropy.title"),0, BossEvent.BossBarColor.GREEN, BossEvent.BossBarOverlay.NOTCHED_20,false,false,false);
((BossBarAccessor) Minecraft.getInstance().gui.getBossOverlay()).getEvents().put(uuid,bar);
}
@Override
public void renderTimer(GuiGraphics guiGraphics, int width, double time, double timerDuration) {
this.bar.setProgress((float) (time/timerDuration));

}
//private final BossB
}
Loading

0 comments on commit 16e8f8c

Please sign in to comment.