From f43d8f566c6140eda00867b2ccfdbc2e967e5596 Mon Sep 17 00:00:00 2001 From: Cow Date: Tue, 16 Mar 2021 15:46:08 +0100 Subject: Added Bestiary Overview - plus small cleanup here and there --- .../cowtipper/cowlection/data/BestiaryEntry.java | 151 +++++++++++++++++++++ .../de/cowtipper/cowlection/data/DataHelper.java | 2 +- .../cowtipper/cowlection/data/HySkyBlockStats.java | 16 +-- 3 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 src/main/java/de/cowtipper/cowlection/data/BestiaryEntry.java (limited to 'src/main/java/de/cowtipper/cowlection/data') diff --git a/src/main/java/de/cowtipper/cowlection/data/BestiaryEntry.java b/src/main/java/de/cowtipper/cowlection/data/BestiaryEntry.java new file mode 100644 index 0000000..a6c78e7 --- /dev/null +++ b/src/main/java/de/cowtipper/cowlection/data/BestiaryEntry.java @@ -0,0 +1,151 @@ +package de.cowtipper.cowlection.data; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import org.apache.commons.lang3.StringUtils; + +import java.text.NumberFormat; +import java.util.Locale; + +public class BestiaryEntry { + public static ItemStack triggerItem; + + public static int highestKillsToGo; + public static int highestKillGoal; + public static int highestPercentageToGo; + public static int widestMobNameWidth; + + private static int widestKillsToGoWidth; + private static int widestKillGoalToGoWidth; + private static int widestPercentageToGoWidth; + + private static final NumberFormat numberFormatter; + private static final char dashSpacerChar; + private static final char spacerChar; + private static int dashSpacerWidth; + private static int spacerWidth; + + private final String mobName; + private final int mobNameWidth; + private final int killsToGo; + private final int killsGoal; + private final int percentageToGo; + + static { + numberFormatter = NumberFormat.getNumberInstance(Locale.US); + numberFormatter.setMaximumFractionDigits(0); + dashSpacerChar = '·'; + spacerChar = ' '; + } + + public BestiaryEntry(String mobName, int currentKills, int killsGoal) { + this.mobName = mobName; + this.killsToGo = killsGoal - currentKills; + this.killsGoal = killsGoal; + this.percentageToGo = 100 - (currentKills * 100 / killsGoal); + if (killsToGo > highestKillsToGo) { + highestKillsToGo = killsToGo; + } + if (killsGoal > highestKillGoal) { + highestKillGoal = killsGoal; + } + if (percentageToGo > highestPercentageToGo) { + highestPercentageToGo = percentageToGo; + } + this.mobNameWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(mobName); + if (mobNameWidth > widestMobNameWidth) { + widestMobNameWidth = mobNameWidth; + } + } + + /** + * Bestiary not unlocked yet + */ + public BestiaryEntry(String mobName) { + this.mobName = mobName; + mobNameWidth = -1; + killsToGo = Integer.MAX_VALUE; + killsGoal = -1; + percentageToGo = Integer.MAX_VALUE; + } + + public static void reinitialize(ItemStack triggerItem) { + BestiaryEntry.triggerItem = triggerItem; + + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + dashSpacerWidth = fontRenderer.getCharWidth(dashSpacerChar); + spacerWidth = fontRenderer.getCharWidth(spacerChar); + + highestKillsToGo = 0; + highestKillGoal = 0; + highestPercentageToGo = 0; + widestMobNameWidth = 0; + } + + public static void calculateWidestEntries() { + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + widestKillsToGoWidth = fontRenderer.getStringWidth(numberFormatter.format(highestKillsToGo)); + widestKillGoalToGoWidth = fontRenderer.getStringWidth(numberFormatter.format(highestKillGoal)); + widestPercentageToGoWidth = fontRenderer.getStringWidth(numberFormatter.format(highestPercentageToGo)); + } + + public static boolean isDifferentTriggerItem(ItemStack triggerItem) { + return BestiaryEntry.triggerItem == null || !BestiaryEntry.triggerItem.getIsItemStackEqual(triggerItem); + } + + public String getFormattedOutput(boolean sortBestiaryOverviewByKills) { + if (percentageToGo == Integer.MAX_VALUE) { + return mobName + EnumChatFormatting.GRAY + ": not unlocked yet"; + } + + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + StringBuilder currentEntry = new StringBuilder(); + String formattedKillsToGo = numberFormatter.format(killsToGo); + String formattedKillsGoal = numberFormatter.format(killsGoal); + String formattedPercentageToGo = numberFormatter.format(percentageToGo); + + int gapSize = (widestMobNameWidth - mobNameWidth) + (sortBestiaryOverviewByKills + ? widestKillsToGoWidth - fontRenderer.getStringWidth(formattedKillsToGo) + : widestPercentageToGoWidth - fontRenderer.getStringWidth(formattedPercentageToGo)); + int amountOfSpacerChars = Math.max(gapSize, 0) / dashSpacerWidth; + + currentEntry.append(mobName).append(EnumChatFormatting.RESET).append(EnumChatFormatting.DARK_GRAY).append(StringUtils.repeat(dashSpacerChar, amountOfSpacerChars)).append(' '); + int remainingGap = gapSize % dashSpacerWidth; + if (remainingGap >= 3) { + // quite a large gap left = add another smaller spacer + currentEntry.append(spacerChar); + remainingGap -= spacerWidth; + } + + StringBuilder killsInfo = new StringBuilder().append(sortBestiaryOverviewByKills ? EnumChatFormatting.AQUA : EnumChatFormatting.DARK_AQUA) + .append(formattedKillsToGo).append(EnumChatFormatting.DARK_GRAY).append('/').append(formattedKillsGoal).append(EnumChatFormatting.GRAY).append(" kills"); + StringBuilder percentageInfo = new StringBuilder().append(sortBestiaryOverviewByKills ? EnumChatFormatting.DARK_AQUA : EnumChatFormatting.AQUA) + .append(formattedPercentageToGo).append(EnumChatFormatting.DARK_GRAY).append("%"); + String spacer = EnumChatFormatting.DARK_GRAY + " ⬌ "; + + currentEntry.append(sortBestiaryOverviewByKills ? killsInfo : percentageInfo).append(spacer); + int gapSize2 = ((sortBestiaryOverviewByKills + ? (widestPercentageToGoWidth - fontRenderer.getStringWidth(formattedPercentageToGo) + widestKillGoalToGoWidth - fontRenderer.getStringWidth(formattedKillsGoal)) + : (widestKillsToGoWidth - fontRenderer.getStringWidth(formattedKillsToGo))) + + remainingGap); + int amountOf2ndSpacerChars = Math.max(gapSize2, 0) / spacerWidth; + currentEntry.append(StringUtils.repeat(spacerChar, amountOf2ndSpacerChars)); + + currentEntry.append(sortBestiaryOverviewByKills ? percentageInfo : killsInfo).append(EnumChatFormatting.GRAY).append(" to go"); + return currentEntry.toString(); + } + + public int getKillsToGo() { + return killsToGo; + } + + public int getPercentageToGo() { + return percentageToGo; + } + + public String getMobName() { + return mobName; + } +} diff --git a/src/main/java/de/cowtipper/cowlection/data/DataHelper.java b/src/main/java/de/cowtipper/cowlection/data/DataHelper.java index e491867..9f529a4 100644 --- a/src/main/java/de/cowtipper/cowlection/data/DataHelper.java +++ b/src/main/java/de/cowtipper/cowlection/data/DataHelper.java @@ -164,7 +164,7 @@ public final class DataHelper { public static Map getMinions() { // key = skin id, value = minion type and tier Map minions = new HashMap<>(); - // TODO currently Fishing VI + VII use the same skull texture (server-side) - thus can't be distinguished + // TODO currently Fishing VI + VII and Revenant I + XII use the same skull texture (server-side) - thus can't be distinguished minions.put("2f93289a82bd2a06cbbe61b733cfdc1f1bd93c4340f7a90abd9bdda774109071", "Cobblestone I"); minions.put("3fd87486dc94cb8cd04a3d7d06f191f027f38dad7b4ed34c6681fb4d08834c06", "Cobblestone II"); minions.put("cc088ed6bb8763af4eb7d006e00fda7dc11d7681e97c983b7011c3e872f6aab9", "Cobblestone III"); diff --git a/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java b/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java index fb9fcff..98fab87 100644 --- a/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java +++ b/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java @@ -160,7 +160,7 @@ public class HySkyBlockStats { skills.put(XpTables.Skill.MINING, XpTables.Skill.MINING.getLevel(experience_skill_mining, 60)); } if (experience_skill_combat >= 0) { - skills.put(XpTables.Skill.COMBAT, XpTables.Skill.COMBAT.getLevel(experience_skill_combat)); + skills.put(XpTables.Skill.COMBAT, XpTables.Skill.COMBAT.getLevel(experience_skill_combat, 60)); } if (experience_skill_foraging >= 0) { skills.put(XpTables.Skill.FORAGING, XpTables.Skill.FORAGING.getLevel(experience_skill_foraging)); @@ -428,26 +428,12 @@ public class HySkyBlockStats { public static class Banking { private double balance; - // private List transactions; /** * No-args constructor for GSON */ private Banking() { } - - // private class Transaction { - // private int amount; - // private long timestamp; - // private Transaction.Action action; - // private String initiator_name; - // - // /** - // * No-args constructor for GSON - // */ - // private Transaction() { - // } - // } } } } -- cgit