Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ loom {
log4jConfigs.from(file("log4j2.xml"))
launchConfigs {
"client" {
// If you don't want mixins, remove these lines
// If you don't want ms, remove these lines
property("mixin.debug", "true")
arg("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker")
}
Expand Down Expand Up @@ -107,6 +107,9 @@ dependencies {
// Spotify API
shadowImpl("com.github.LabyStudio:java-spotify-api:+:all")

// Discord RPC
shadowImpl("com.github.MinnDevelopment:java-discord-rpc:v2.0.2")

}

// Tasks:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
baseGroup = com.github.jtxofficial.flustclient
mcVersion = 1.8.9
modid = flustclient
version = beta-v0.1
version = v0.1.1-beta
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.github.jtxofficial.flustclient.manager.ModuleManager;
import com.github.jtxofficial.flustclient.manager.HudManager;
import com.github.jtxofficial.flustclient.manager.PlayerManager;
import com.github.jtxofficial.flustclient.manager.DiscordRPCManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
Expand All @@ -19,7 +20,7 @@
public class FlustClient {

public static final String MODID = "flustclient";
public static final String VERSION = "beta-v0.1";
public static final String VERSION = "v0.1.1-beta";
public static final String NAME = "FlustClient";

@Mod.Instance(MODID)
Expand All @@ -30,6 +31,7 @@ public class FlustClient {
private HudManager hudManager;
private PlayerManager playerManager;
private SocketEventHandler socketEventHandler;
private DiscordRPCManager discordRPCManager;

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
Expand All @@ -50,11 +52,13 @@ public void init(FMLInitializationEvent event) {
moduleManager = new ModuleManager();
hudManager = new HudManager();
playerManager = new PlayerManager();
discordRPCManager = new DiscordRPCManager();

// Initialize managers
moduleManager.init();
hudManager.init();
playerManager.init();
discordRPCManager.init();

// Register keybindings (must be done before event handler registration)
KeyHandler.registerKeybindings();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
package com.github.jtxofficial.flustclient.feature.hud;

import com.github.jtxofficial.flustclient.api.modules.FlustModule;
import com.github.jtxofficial.flustclient.api.modules.HudModule;
import com.github.jtxofficial.flustclient.api.modules.annotations.HudInfo;
import com.github.jtxofficial.flustclient.api.modules.annotations.ModInfo;
import com.github.jtxofficial.flustclient.api.modules.category.EnumModuleCategory;
import com.github.jtxofficial.flustclient.config.ConfigProperty;
import com.github.jtxofficial.flustclient.manager.hud.HudElement;
import net.minecraft.scoreboard.Score;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@ModInfo(fileName = "Scoreboard")
public class Scoreboard extends FlustModule implements HudModule {

private static final int MAX_SCOREBOARD_LINES = 15;
private static final int LINE_SPACING = 2;
private static final int HORIZONTAL_PADDING = 10;
private static final int TEXT_PADDING = 2;
private static final int TITLE_OFFSET = 1;
private static final int TITLE_BOTTOM_SPACING = 4;
private static final int TEXT_COLOR = 0xFFFFFF;

@ConfigProperty(settingName = "Hide Scoreboard")
public boolean hideScoreboard = false;

private transient ScoreObjective scoreObjective;
private transient HudElement<FlustModule> hudElement;
private HudInfo hudInfo;

public Scoreboard() {
super();
this.hudInfo = new HudInfo(0.8, 0.02, 120, 100, 2.0f);
}

@SubscribeEvent
public void onDisconnect(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
this.scoreObjective = null;
}

@Override
public void renderHudElement() {
if (shouldSkipRendering()) {
return;
}

net.minecraft.scoreboard.Scoreboard scoreboard = scoreObjective.getScoreboard();
Collection<Score> scores = scoreboard.getSortedScores(scoreObjective);

List<Score> processedScores = filterAndLimitScores(scores);
List<String> formattedLines = formatScoreLines(scoreboard, processedScores);

renderScoreboard(scoreObjective.getDisplayName(), formattedLines, processedScores);
}

private boolean shouldSkipRendering() {
return hideScoreboard || scoreObjective == null || mc.theWorld == null;
}

private List<Score> filterAndLimitScores(Collection<Score> scores) {
List<Score> filteredScores = scores.stream()
.filter(this::isValidScore)
.collect(Collectors.toList());

if (filteredScores.size() > MAX_SCOREBOARD_LINES) {
filteredScores = filteredScores.subList(0, MAX_SCOREBOARD_LINES);
}

Collections.reverse(filteredScores);
return filteredScores;
}

private boolean isValidScore(Score score) {
return score != null
&& score.getPlayerName() != null
&& !score.getPlayerName().startsWith("#");
}

private List<String> formatScoreLines(net.minecraft.scoreboard.Scoreboard scoreboard, List<Score> scores) {
List<String> lines = new ArrayList<>();
for (Score score : scores) {
String formattedName = ScorePlayerTeam.formatPlayerName(
scoreboard.getPlayersTeam(score.getPlayerName()),
score.getPlayerName()
);
lines.add(formattedName);
}
return lines;
}

private void renderScoreboard(String title, List<String> lines, List<Score> scores) {
int width = calculateScoreboardWidth(title, lines);
int height = calculateScoreboardHeight(lines.size());

updateHudDimensions(width, height);

int absoluteX = getHudAbsoluteX();
int absoluteY = getHudAbsoluteY();

renderTitle(title, absoluteX, absoluteY, width);
renderLines(lines, absoluteX, absoluteY);
}

private int calculateScoreboardWidth(String title, List<String> lines) {
int maxWidth = mc.fontRendererObj.getStringWidth(title);

for (String line : lines) {
int lineWidth = mc.fontRendererObj.getStringWidth(line);
if (lineWidth > maxWidth) {
maxWidth = lineWidth;
}
}

return maxWidth + HORIZONTAL_PADDING;
}

private int calculateScoreboardHeight(int lineCount) {
int lineHeight = mc.fontRendererObj.FONT_HEIGHT;
return lineHeight * (lineCount + 1) + (lineCount + 1) * LINE_SPACING;
}

private void updateHudDimensions(int width, int height) {
if (hudElement != null) {
hudElement.setWidth(width);
hudElement.setHeight(height);
}

hudInfo.setWidth(width);
hudInfo.setHeight(height);
}

private int getHudAbsoluteX() {
return hudElement != null ? hudElement.getX() : 0;
}

private int getHudAbsoluteY() {
return hudElement != null ? hudElement.getY() : 0;
}

private void renderTitle(String title, int x, int y, int width) {
int titleWidth = mc.fontRendererObj.getStringWidth(title);
int centeredX = x + (width / 2 - titleWidth / 2);
mc.fontRendererObj.drawStringWithShadow(title, centeredX, y + TITLE_OFFSET, TEXT_COLOR);
}

private void renderLines(List<String> lines, int x, int y) {
int lineHeight = mc.fontRendererObj.FONT_HEIGHT;
int currentY = y + lineHeight + TITLE_BOTTOM_SPACING;

for (String line : lines) {
mc.fontRendererObj.drawStringWithShadow(line, x + TEXT_PADDING, currentY, TEXT_COLOR);
currentY += lineHeight + LINE_SPACING;
}
}

@Override
public boolean isHudElementEnabled() {
return isEnabled() && !hideScoreboard;
}

@Override
public void setHudElement(HudElement<FlustModule> hudElement) {
this.hudElement = hudElement;
}

@Override
public HudInfo getHudInfo() {
return hudInfo;
}

@Override
public HudElement<FlustModule> getHudElement() {
if (hudElement == null) {
hudElement = createHudElement();
}
return hudElement;
}

@Override
public void save() {
// Sync position from HudElement before saving
if (hudElement != null && hudElement.getHudInfo() != null) {
HudInfo elementInfo = hudElement.getHudInfo();
this.hudInfo.setPercentX(elementInfo.getPercentX());
this.hudInfo.setPercentY(elementInfo.getPercentY());
this.hudInfo.setWidth(elementInfo.getWidth());
this.hudInfo.setHeight(elementInfo.getHeight());
this.hudInfo.setScale(elementInfo.getScale());
}
super.save();
}

@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
save();
}

@Override
protected String[] setAliases() {
return new String[]{};
}

@Override
public String getName() {
return "Scoreboard";
}

@Override
public String getDescription() {
return "Renders the scoreboard with customizable settings";
}

@Override
public Object getDescriptor() {
return HUD;
}

@Override
public EnumModuleCategory getCategory() {
return EnumModuleCategory.HUD;
}


public void setScoreObjective(ScoreObjective scoreObjective) {
this.scoreObjective = scoreObjective;
}

public ScoreObjective getScoreObjective() {
return scoreObjective;
}
}
Loading