Skip to content

Commit

Permalink
option to show only own stats for stats overlay, as well as duels div…
Browse files Browse the repository at this point in the history
…ision and prestige on xp bar (like in bedwars)
  • Loading branch information
PepperLola committed Jul 3, 2021
1 parent fc6c8c0 commit 02a558b
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 89 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sourceSets {
main.resources.srcDirs += '../shared/main/resources'
}

version = "1.17.10"
version = "1.17.11"
group= "com.palight.playerinfo" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "playerinfo"

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/palight/playerinfo/PlayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class PlayerInfo
//TODO update version here and in build.gradle
public static final String NAME = "playerinfo";
public static final String MODID = "playerinfo";
public static final String VERSION = "1.17.10";
public static final String VERSION = "1.17.11";
public static String commitHash;
public static String defaultBranchName = "master";
public static String githubAPIURL = "https://api.github.com/repos/PepperLola/playerinfo/git/refs/heads/" + defaultBranchName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class StatsOverlayWidget extends GuiIngameWidget {
private StatsMod module;

private static final String[] ROMAN_NUMERALS = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"};
private static final String[] ROMAN_NUMERALS = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"};

public StatsOverlayWidget() {
super(-1, 4, 288, 256);
Expand Down Expand Up @@ -70,63 +70,78 @@ public void render(Minecraft mc) {
System.out.println("SORTED: " + module.toDisplay.toString());
}

int i = 0;
for (StatsMod.PlayerStats playerStats : module.toDisplay) {
String playerName = playerStats.name;
boolean nicked = playerStats.nicked;
int level = playerStats.level;
double wlr = NumberUtil.round(playerStats.wlr, 2);
double kdr = NumberUtil.round(playerStats.kdr, 2);
int gameLevel = playerStats.gameLevel;
HypixelUtil.Rank rank = playerStats.rank;
if (module.onlyShowOwnStats) {
if (StatsMod.getPlayerStats().containsKey(clientUUID)) {
renderStats(StatsMod.getPlayerStats().get(clientUUID), fr, x, y, 0, padding, offset);
}
} else {
int i = 0;
for (StatsMod.PlayerStats playerStats : module.toDisplay) {
renderStats(playerStats, fr, x, y, i, padding, offset);
i++;
}
}
}

int rowY = y + (2 + fr.FONT_HEIGHT) * (i + 1);
public void renderStats(StatsMod.PlayerStats playerStats, FontRenderer fr, int x, int y, int i, int padding, int offset) {
String playerName = playerStats.name;
boolean nicked = playerStats.nicked;
int level = playerStats.level;
double wlr = NumberUtil.round(playerStats.wlr, 2);
double kdr = NumberUtil.round(playerStats.kdr, 2);
int gameLevel = playerStats.gameLevel;
HypixelUtil.Rank rank = playerStats.rank;

int rowY = y + (2 + fr.FONT_HEIGHT) * (i + 1);

// Minecraft.getMinecraft().getTextureManager().bindTexture(playerStats.networkPlayerInfo.getLocationSkin());

if(rank == HypixelUtil.Rank.NONE) {
drawText(playerName, x + padding, rowY, rank.getColor());
} else {
String rankTextBeforePlus = "[" + rank.getDisplayName().replaceAll("[+]", "");
drawText(rankTextBeforePlus, x + padding, rowY, rank.getColor());
int textWidth = (int) Math.floor(PlayerInfo.instance.fontRendererObj.getWidth(rankTextBeforePlus));
String plusText = "+" + (rank == HypixelUtil.Rank.SUPERSTAR ? "+" : "");
if (rank == HypixelUtil.Rank.MVP_PLUS || rank == HypixelUtil.Rank.SUPERSTAR) {
drawText(plusText, x + padding + textWidth, rowY, playerStats.plusColor.getColor());
} else if (rank == HypixelUtil.Rank.VIP_PLUS) {
drawText("+", x + padding + textWidth, rowY, HypixelUtil.PlusColor.GOLD.getColor());
}
if (rank != HypixelUtil.Rank.VIP && rank != HypixelUtil.Rank.MVP) {
textWidth += (int) Math.floor(PlayerInfo.instance.fontRendererObj.getWidth(plusText));
}
drawText("] " + playerName, x + padding + textWidth, rowY, rank.getColor());
if(rank == HypixelUtil.Rank.NONE) {
drawText(playerName, x + padding, rowY, rank.getColor());
} else {
String rankTextBeforePlus = "[" + rank.getDisplayName().replaceAll("[+]", "");
drawText(rankTextBeforePlus, x + padding, rowY, rank.getColor());
int textWidth = (int) Math.floor(PlayerInfo.instance.fontRendererObj.getWidth(rankTextBeforePlus));
String plusText = "+" + (rank == HypixelUtil.Rank.SUPERSTAR ? "+" : "");
HypixelUtil.PlusColor plusColor = playerStats.plusColor;
if (plusColor == null) plusColor = HypixelUtil.PlusColor.RED;
if (rank == HypixelUtil.Rank.MVP_PLUS || rank == HypixelUtil.Rank.SUPERSTAR) {
drawText(plusText, x + padding + textWidth, rowY, plusColor.getColor());
} else if (rank == HypixelUtil.Rank.VIP_PLUS) {
drawText("+", x + padding + textWidth, rowY, HypixelUtil.PlusColor.GOLD.getColor());
}
if (rank != HypixelUtil.Rank.VIP && rank != HypixelUtil.Rank.MVP) {
textWidth += (int) Math.floor(PlayerInfo.instance.fontRendererObj.getWidth(plusText));
}
drawText("] " + playerName, x + padding + textWidth, rowY, rank.getColor());
}

if (nicked) {
drawText("NICKED", x + padding + 90, rowY, 11141120);
} else {

drawText(String.valueOf(level), x + padding + 125 + offset - 10, rowY);
drawText(String.valueOf(wlr), x + padding + 125 + offset * 2, rowY);
drawText(String.valueOf(kdr), x + padding + 125 + offset * 3, rowY);
StatsMod.GameType gameType = playerStats.getGameType();
if (gameType == null) continue;
switch (playerStats.getGameType()) {
case BEDWARS:
double fkdr = NumberUtil.round(playerStats.fkdr, 2);
double bblr = NumberUtil.round(playerStats.bblr, 2);
drawText(String.valueOf(gameLevel) + "✫", x + padding + 125 + offset * 4, rowY);
drawText(String.valueOf(fkdr), x + padding + 125 + offset * 5, rowY);
drawText(String.valueOf(bblr), x + padding + 125 + offset * 6, rowY);
break;
case DUELS:
String title = playerStats.title;
int prestige = playerStats.prestige;
drawText(StringUtils.capitalize(title) + " " + ROMAN_NUMERALS[prestige], x + padding + 125 + offset * 4, rowY, HypixelUtil.TitleColor.getTitleColorFromName(title).getTitleColor());
break;
}
if (nicked) {
drawText("NICKED", x + padding + 90, rowY, 11141120);
} else {

drawText(String.valueOf(level), x + padding + 125 + offset - 10, rowY);
drawText(String.valueOf(wlr), x + padding + 125 + offset * 2, rowY);
drawText(String.valueOf(kdr), x + padding + 125 + offset * 3, rowY);
StatsMod.GameType gameType = playerStats.getGameType();
if (gameType == null) return;
switch (playerStats.getGameType()) {
case BEDWARS:
double fkdr = NumberUtil.round(playerStats.fkdr, 2);
double bblr = NumberUtil.round(playerStats.bblr, 2);
drawText(gameLevel + "✫", x + padding + 125 + offset * 4, rowY);
drawText(String.valueOf(fkdr), x + padding + 125 + offset * 5, rowY);
drawText(String.valueOf(bblr), x + padding + 125 + offset * 6, rowY);
break;
case DUELS:
StatsMod.DuelsDivision division = playerStats.division;
if (division == null) return;
String title = division.toString();
int prestige = playerStats.prestige;
if (prestige == 0) prestige = 1;
drawText(StringUtils.capitalize(title.toLowerCase()) + " " + ROMAN_NUMERALS[prestige - 1], x + padding + 125 + offset * 4, rowY, HypixelUtil.TitleColor.getTitleColorFromName(title).getTitleColor());
break;
}
i++;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.palight.playerinfo.gui.screens.impl.options.modules.gui;

import com.palight.playerinfo.PlayerInfo;
import com.palight.playerinfo.gui.screens.CustomGuiScreenScrollable;
import com.palight.playerinfo.gui.widgets.GuiCustomWidget;
import com.palight.playerinfo.gui.widgets.impl.GuiCheckBox;
import com.palight.playerinfo.modules.impl.gui.StatsMod;
import com.palight.playerinfo.options.ModConfiguration;

import java.util.Arrays;

public class StatsGui extends CustomGuiScreenScrollable {

private int buttonX;
private int buttonY;

private GuiCheckBox onlyShowOwnStats;

private StatsMod module;

public StatsGui() {
super("screen.stats");
}

@Override
public void initGui() {
super.initGui();

if (module == null) {
module = (StatsMod) PlayerInfo.getModules().get("stats");
}

buttonX = guiX + 32;
buttonY = guiY + 32;

onlyShowOwnStats = new GuiCheckBox(1, buttonX, buttonY, "Only show your stats", module.onlyShowOwnStats);

this.guiElements.addAll(Arrays.asList(
this.onlyShowOwnStats
));
}

@Override
protected void widgetClicked(GuiCustomWidget widget) {
if (module == null) {
module = (StatsMod) PlayerInfo.getModules().get("stats");
}

super.widgetClicked(widget);
if (widget.id == onlyShowOwnStats.id) {
module.onlyShowOwnStats = onlyShowOwnStats.checked;
}
ModConfiguration.syncFromGUI();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import com.palight.playerinfo.gui.screens.impl.options.modules.WidgetEditorGui;
import com.palight.playerinfo.modules.Module;
import com.palight.playerinfo.modules.impl.gui.DisplayTweaksMod;
import com.palight.playerinfo.modules.impl.gui.StatsMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiIngame;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
Expand All @@ -21,7 +20,7 @@
import net.minecraftforge.client.GuiIngameForge;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.MinecraftForge;
import org.spongepowered.asm.mixin.Final;
import org.apache.commons.lang3.StringUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -31,25 +30,8 @@

@Mixin(value = GuiIngameForge.class, remap = false)
public class MixinGuiIngameForge extends GuiIngame {
@Shadow @Final private static int WHITE;
@Shadow public static boolean renderHelmet;
@Shadow public static boolean renderPortal;
@Shadow public static boolean renderHotbar;
@Shadow public static boolean renderCrosshairs;
@Shadow public static boolean renderBossHealth;
@Shadow public static boolean renderHealth;
@Shadow public static boolean renderArmor;
@Shadow public static boolean renderFood;
@Shadow public static boolean renderHealthMount;
@Shadow public static boolean renderAir;
@Shadow public static boolean renderExperiance;
@Shadow public static boolean renderJumpBar;
@Shadow public static boolean renderObjective;
@Shadow public static int left_height;
@Shadow public static int right_height;
@Shadow private ScaledResolution res;
@Shadow private FontRenderer fontrenderer;
@Shadow private RenderGameOverlayEvent eventParent;

private boolean sentTitle = false;

Expand Down Expand Up @@ -224,4 +206,73 @@ protected void renderTitle(int width, int height, float partialTicks) {
sentTitle = false;
}
}

/**
* @author palight
* @reason Render Hypixel Duels division
*/
@Overwrite
public void renderExperience(int width, int height) {
handleRenderExperience(width, height);
}

private void handleRenderExperience(int width, int height) {
((IMixinGuiIngameForge) this).callBind(icons);
if (!((IMixinGuiIngameForge) this).callPre(RenderGameOverlayEvent.ElementType.EXPERIENCE)) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableBlend();
if (this.mc.playerController.gameIsSurvivalOrAdventure()) {
this.mc.mcProfiler.startSection("expBar");
int cap = this.mc.thePlayer.xpBarCap();
int left = width / 2 - 91;
// color initially is actually the width of the filled-in bar
int color;
StatsMod.PlayerStats clientStats = null;
if (Minecraft.getMinecraft().thePlayer != null) {
clientStats = StatsMod.getPlayerStats().get(Minecraft.getMinecraft().thePlayer.getUniqueID());
}
if (cap > 0 || !StatsMod.currentDuelsType.isEmpty()) {
short barWidth = 182;
color = (int)(this.mc.thePlayer.experience * (float)(barWidth + 1));
if (!StatsMod.currentDuelsType.isEmpty()) {
if (clientStats != null && clientStats.division != null) {
StatsMod.DuelsDivision nextDiv = StatsMod.DuelsDivision.getNext(clientStats.division);
color = (int) Math.floor(((clientStats.wins * 1.0f) / nextDiv.getRequiredWins()) * (float)(barWidth + 1));
}
}
int top = height - 32 + 3;
this.drawTexturedModalRect(left, top, 0, 64, barWidth, 5);
if (color > 0) {
this.drawTexturedModalRect(left, top, 0, 69, color, 5);
}
}

this.mc.mcProfiler.endSection();
if (this.mc.playerController.gameIsSurvivalOrAdventure() && this.mc.thePlayer.experienceLevel > 0 || !StatsMod.currentDuelsType.isEmpty()) {
this.mc.mcProfiler.startSection("expLevel");
color = 8453920;
String text = "" + this.mc.thePlayer.experienceLevel;

if (!StatsMod.currentDuelsType.isEmpty()) {
if (clientStats != null && clientStats.division != null) {
text = StringUtils.capitalize(clientStats.division.name().toLowerCase()) + " " + (clientStats.prestige);
}
}

int x = (width - this.getFontRenderer().getStringWidth(text)) / 2;
int y = height - 31 - 4;
this.getFontRenderer().drawString(text, x + 1, y, 0);
this.getFontRenderer().drawString(text, x - 1, y, 0);
this.getFontRenderer().drawString(text, x, y + 1, 0);
this.getFontRenderer().drawString(text, x, y - 1, 0);
this.getFontRenderer().drawString(text, x, y, color);
this.mc.mcProfiler.endSection();
}
}

GlStateManager.enableBlend();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
((IMixinGuiIngameForge) this).callPost(RenderGameOverlayEvent.ElementType.EXPERIENCE);
}
}
}
Loading

0 comments on commit 02a558b

Please sign in to comment.