diff options
| author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2024-07-22 14:55:03 +0800 |
|---|---|---|
| committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2024-07-22 14:55:03 +0800 |
| commit | a846b52122422887e464d83ca01f0b771f3882f5 (patch) | |
| tree | 62e62aa64d7baec12d41fabdc4ba45decebd835a /src/main/java/de | |
| parent | e316a165d8f7f812afa6d3c9f2f0f576fd1e6f93 (diff) | |
| download | Skyblocker-a846b52122422887e464d83ca01f0b771f3882f5.tar.gz Skyblocker-a846b52122422887e464d83ca01f0b771f3882f5.tar.bz2 Skyblocker-a846b52122422887e464d83ca01f0b771f3882f5.zip | |
Clean up rebased code
Diffstat (limited to 'src/main/java/de')
25 files changed, 271 insertions, 228 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/bazaar/BazaarHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/bazaar/BazaarHelper.java index 8b83b06b..8fbeb6e0 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/bazaar/BazaarHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/bazaar/BazaarHelper.java @@ -1,8 +1,8 @@ package de.hysky.skyblocker.skyblock.bazaar; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; @@ -11,12 +11,13 @@ import net.minecraft.text.Text; import net.minecraft.util.Formatting; import org.apache.commons.lang3.math.NumberUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class BazaarHelper extends SlotTextAdder { +public class BazaarHelper extends SimpleSlotTextAdder { private static final Pattern FILLED_PATTERN = Pattern.compile("Filled: \\S+ \\(?([\\d.]+)%\\)?!?"); private static final int RED = 0xe60b1e; private static final int YELLOW = 0xe6ba0b; @@ -27,14 +28,19 @@ public class BazaarHelper extends SlotTextAdder { } @Override - public @NotNull List<SlotText> getText(Slot slot) { - if (!SkyblockerConfigManager.get().helpers.bazaar.enableBazaarHelper) return List.of(); + public boolean isEnabled() { + return SkyblockerConfigManager.get().helpers.bazaar.enableBazaarHelper; + } + + @Override + public @NotNull List<SlotText> getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (slot == null) return List.of(); // Skip the first row as it's always glass panes. - if (slot.id < 10) return List.of(); + if (slotId < 10) return List.of(); // Skip the last 10 items. 11 is subtracted because size is 1-based so the last slot is size - 1. - if (slot.id > slot.inventory.size() - 11) return List.of(); //Note that this also skips the slots in player's inventory (anything above 36/45/54 depending on the order count) + if (slotId > slot.inventory.size() - 11) return List.of(); //Note that this also skips the slots in player's inventory (anything above 36/45/54 depending on the order count) - int column = slot.id % 9; + int column = slotId % 9; if (column == 0 || column == 8) return List.of(); // Skip the first and last column as those are always glass panes as well. ItemStack item = slot.getStack(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/bazaar/ReorderHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/bazaar/ReorderHelper.java index c2b11926..f6c53528 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/bazaar/ReorderHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/bazaar/ReorderHelper.java @@ -1,9 +1,9 @@ package de.hysky.skyblocker.skyblock.bazaar; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; import de.hysky.skyblocker.utils.ItemUtils; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; +import de.hysky.skyblocker.utils.container.TooltipAdder; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.InputUtil; @@ -19,7 +19,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class ReorderHelper extends ContainerSolver { +public class ReorderHelper extends SimpleContainerSolver implements TooltipAdder { private static final Pattern BUY_PATTERN = Pattern.compile("([\\d,]+)x missing items\\."); private static final Pattern SELL_PATTERN = Pattern.compile("([\\d,]+)x items\\."); @@ -28,12 +28,12 @@ public class ReorderHelper extends ContainerSolver { } @Override - protected boolean isEnabled() { + public boolean isEnabled() { return true; } @Override - protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) { + public boolean onClickSlot(int slot, ItemStack stack, int screenId) { // V This part is so that it short-circuits if not necessary if ((slot == 11 || slot == 13) && stack.isOf(Items.GREEN_TERRACOTTA) && InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_KEY_LEFT_CONTROL)) { Matcher matcher; @@ -49,25 +49,24 @@ public class ReorderHelper extends ContainerSolver { } @Override - protected List<ColorHighlight> getColors(String[] groups, Int2ObjectMap<ItemStack> slots) { + public List<ColorHighlight> getColors(Int2ObjectMap<ItemStack> slots) { return List.of(); } - public static class Tooltip extends TooltipAdder { - public Tooltip() { - super("^Order options", Integer.MIN_VALUE); - } - - @Override - public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) { - if (focusedSlot == null || !stack.isOf(Items.GREEN_TERRACOTTA)) return; - switch (focusedSlot.id) { - case 11, 13 -> { - lines.add(Text.empty()); - lines.add(Text.empty().append(Text.translatable("skyblocker.reorderHelper.tooltip.line1")).formatted(Formatting.DARK_GRAY, Formatting.ITALIC)); - lines.add(Text.empty().append(Text.translatable("skyblocker.reorderHelper.tooltip.line2")).formatted(Formatting.DARK_GRAY, Formatting.ITALIC)); - } + @Override + public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) { + if (focusedSlot == null || !stack.isOf(Items.GREEN_TERRACOTTA)) return; + switch (focusedSlot.id) { + case 11, 13 -> { + lines.add(Text.empty()); + lines.add(Text.empty().append(Text.translatable("skyblocker.reorderHelper.tooltip.line1")).formatted(Formatting.DARK_GRAY, Formatting.ITALIC)); + lines.add(Text.empty().append(Text.translatable("skyblocker.reorderHelper.tooltip.line2")).formatted(Formatting.DARK_GRAY, Formatting.ITALIC)); } } } + + @Override + public int getPriority() { + return Integer.MIN_VALUE; + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java index bd863fc2..edb6aa0d 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java @@ -1,12 +1,12 @@ package de.hysky.skyblocker.skyblock.chocolatefactory; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.adders.LineSmoothener; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.RegexUtils; -import de.hysky.skyblocker.utils.render.gui.ColorHighlight; import de.hysky.skyblocker.utils.container.SimpleContainerSolver; +import de.hysky.skyblocker.utils.container.TooltipAdder; +import de.hysky.skyblocker.utils.render.gui.ColorHighlight; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; @@ -28,7 +28,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class ChocolateFactorySolver extends SimpleContainerSolver { +public class ChocolateFactorySolver extends SimpleContainerSolver implements TooltipAdder { //Patterns private static final Pattern CPS_PATTERN = Pattern.compile("([\\d,.]+) Chocolate per second"); private static final Pattern CPS_INCREASE_PATTERN = Pattern.compile("\\+([\\d,]+) Chocolate per second"); @@ -52,19 +52,18 @@ public class ChocolateFactorySolver extends SimpleContainerSolver { private static final byte STRAY_RABBIT_START = 0; private static final byte STRAY_RABBIT_END = 26; - // TODO: Convert to instance fields in #788 - private static final ObjectArrayList<Rabbit> cpsIncreaseFactors = new ObjectArrayList<>(8); - private static long totalChocolate = -1L; - private static double totalCps = -1.0; - private static double totalCpsMultiplier = -1.0; - private static long requiredUntilNextPrestige = -1L; - private static boolean canPrestige = false; - private static boolean reachedMaxPrestige = false; - private static double timeTowerMultiplier = -1.0; - private static boolean isTimeTowerMaxed = false; - private static boolean isTimeTowerActive = false; - private static int bestUpgrade = -1; - private static int bestAffordableUpgrade = -1; + private final ObjectArrayList<Rabbit> cpsIncreaseFactors = new ObjectArrayList<>(8); + private long totalChocolate = -1L; + private double totalCps = -1.0; + private double totalCpsMultiplier = -1.0; + private long requiredUntilNextPrestige = -1L; + private boolean canPrestige = false; + private boolean reachedMaxPrestige = false; + private double timeTowerMultiplier = -1.0; + private boolean isTimeTowerMaxed = false; + private boolean isTimeTowerActive = false; + private int bestUpgrade = -1; + private int bestAffordableUpgrade = -1; private static StraySound ding = StraySound.NONE; private static int dingTick = 0; @@ -93,6 +92,8 @@ public class ChocolateFactorySolver extends SimpleContainerSolver { return SkyblockerConfigManager.get().helpers.chocolateFactory.enableChocolateFactoryHelper; } + // ======== Container Solver ======== + @Override public List<ColorHighlight> getColors(Int2ObjectMap<ItemStack> slots) { updateFactoryInfo(slots); @@ -239,166 +240,163 @@ public class ChocolateFactorySolver extends SimpleContainerSolver { return highlights; } - @Override - public void reset() { - cpsIncreaseFactors.clear(); - totalChocolate = -1L; - totalCps = -1.0; - totalCpsMultiplier = -1.0; - requiredUntilNextPrestige = -1L; - canPrestige = false; - reachedMaxPrestige = false; - timeTowerMultiplier = -1.0; - isTimeTowerMaxed = false; - isTimeTowerActive = false; - bestUpgrade = -1; - bestAffordableUpgrade = -1; - ding = StraySound.NONE; - } - - private enum StraySound { - NONE, - NORMAL, - GOLDEN - } - - private record Rabbit(double cpsIncrease, long cost, int slot) {} + // ======== Tooltip Adder ======== - //Todo: Merge this into the outer class once #786 is merged - public static final class Tooltip extends SimpleTooltipAdder { - public Tooltip() { - super("^Chocolate Factory$", 0); //The priority doesn't really matter here as this is the only tooltip adder for the Chocolate Factory. - } + @Override + public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) { + if (focusedSlot == null) return; - @Override - public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) { - if (!SkyblockerConfigManager.get().helpers.chocolateFactory.enableChocolateFactoryHelper || focusedSlot == null) return; + int lineIndex = lines.size(); + //This boolean is used to determine if we should add a smooth line to separate the added information from the rest of the tooltip. + //It should be set to true if there's any information added, false otherwise. + boolean shouldAddLine = false; - int lineIndex = lines.size(); - //This boolean is used to determine if we should add a smooth line to separate the added information from the rest of the tooltip. - //It should be set to true if there's any information added, false otherwise. - boolean shouldAddLine = false; + String lore = ItemUtils.concatenateLore(lines); + Matcher costMatcher = COST_PATTERN.matcher(lore); + OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher); + //Available on all items with a chocolate cost + if (cost.isPresent()) shouldAddLine |= addUpgradeTimerToLore(lines, cost.getAsLong()); - String lore = ItemUtils.concatenateLore(lines); - Matcher costMatcher = COST_PATTERN.matcher(lore); - OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher); - //Available on all items with a chocolate cost - if (cost.isPresent()) shouldAddLine |= addUpgradeTimerToLore(lines, cost.getAsLong()); + int index = focusedSlot.id; - int index = focusedSlot.id; + //Prestige item + if (index == PRESTIGE_SLOT) { + shouldAddLine |= addPrestigeTimerToLore(lines); + } + //Time tower + else if (index == TIME_TOWER_SLOT) { + shouldAddLine |= addTimeTowerStatsToLore(lines); + } + //Rabbits + else if (index == COACH_SLOT || (index >= RABBITS_START && index <= RABBITS_END)) { + shouldAddLine |= addRabbitStatsToLore(lines, index); + } - //Prestige item - if (index == PRESTIGE_SLOT) { - shouldAddLine |= addPrestigeTimerToLore(lines); - } - //Time tower - else if (index == TIME_TOWER_SLOT) { - shouldAddLine |= addTimeTowerStatsToLore(lines); - } - //Rabbits - else if (index == COACH_SLOT || (index >= RABBITS_START && index <= RABBITS_END)) { - shouldAddLine |= addRabbitStatsToLore(lines, index); - } + //This is an ArrayList, so this operation is probably not very efficient, but logically it's pretty much the only way I can think of + if (shouldAddLine) lines.add(lineIndex, LineSmoothener.createSmoothLine()); + } - //This is an ArrayList, so this operation is probably not very efficient, but logically it's pretty much the only way I can think of - if (shouldAddLine) lines.add(lineIndex, LineSmoothener.createSmoothLine()); - } + private boolean addUpgradeTimerToLore(List<Text> lines, long cost) { + if (totalChocolate < 0L || totalCps < 0.0) return false; + lines.add(Text.empty() + .append(Text.literal("Time until upgrade: ").formatted(Formatting.GRAY)) + .append(formatTime((cost - totalChocolate) / totalCps))); + return true; + } - private boolean addUpgradeTimerToLore(List<Text> lines, long cost) { - if (totalChocolate < 0L || totalCps < 0.0) return false; + private boolean addPrestigeTimerToLore(List<Text> lines) { + if (totalCps < 0.0 || reachedMaxPrestige) return false; + if (requiredUntilNextPrestige > 0 && !canPrestige) { lines.add(Text.empty() - .append(Text.literal("Time until upgrade: ").formatted(Formatting.GRAY)) - .append(formatTime((cost - totalChocolate) / totalCps))); - return true; - } - - private boolean addPrestigeTimerToLore(List<Text> lines) { - if (totalCps < 0.0 || reachedMaxPrestige) return false; - if (requiredUntilNextPrestige > 0 && !canPrestige) { - lines.add(Text.empty() - .append(Text.literal("Chocolate until next prestige: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(requiredUntilNextPrestige)).formatted(Formatting.GOLD))); - } - lines.add(Text.empty() //Keep this outside of the `if` to match the format of the upgrade tooltips, that say "Time until upgrade: Now" when it's possible - .append(Text.literal("Time until next prestige: ").formatted(Formatting.GRAY)) - .append(formatTime(requiredUntilNextPrestige / totalCps))); - return true; + .append(Text.literal("Chocolate until next prestige: ").formatted(Formatting.GRAY)) + .append(Text.literal(DECIMAL_FORMAT.format(requiredUntilNextPrestige)).formatted(Formatting.GOLD))); } + lines.add(Text.empty() //Keep this outside of the `if` to match the format of the upgrade tooltips, that say "Time until upgrade: Now" when it's possible + .append(Text.literal("Time until next prestige: ").formatted(Formatting.GRAY)) + .append(formatTime(requiredUntilNextPrestige / totalCps))); + return true; + } - private boolean addTimeTowerStatsToLore(List<Text> lines) { - if (totalCps < 0.0 || totalCpsMultiplier < 0.0 || timeTowerMultiplier < 0.0) return false; - lines.add(Text.literal("Current stats:").formatted(Formatting.GRAY)); + private boolean addTimeTowerStatsToLore(List<Text> lines) { + if (totalCps < 0.0 || totalCpsMultiplier < 0.0 || timeTowerMultiplier < 0.0) return false; + lines.add(Text.literal("Current stats:").formatted(Formatting.GRAY)); + lines.add(Text.empty() + .append(Text.literal(" CPS increase: ").formatted(Formatting.GRAY)) + .append(Text.literal(DECIMAL_FORMAT.format(totalCps / totalCpsMultiplier * timeTowerMultiplier)).formatted(Formatting.GOLD))); + lines.add(Text.empty() + .append(Text.literal(" CPS when active: ").formatted(Formatting.GRAY)) + .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps : totalCps / totalCpsMultiplier * (timeTowerMultiplier + totalCpsMultiplier))).formatted(Formatting.GOLD))); + if (!isTimeTowerMaxed) { + lines.add(Text.literal("Stats after upgrade:").formatted(Formatting.GRAY)); lines.add(Text.empty() .append(Text.literal(" CPS increase: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(totalCps / totalCpsMultiplier * timeTowerMultiplier)).formatted(Formatting.GOLD))); + .append(Text.literal(DECIMAL_FORMAT.format(totalCps / (totalCpsMultiplier) * (timeTowerMultiplier + 0.1))).formatted(Formatting.GOLD))); lines.add(Text.empty() .append(Text.literal(" CPS when active: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps : totalCps / totalCpsMultiplier * (timeTowerMultiplier + totalCpsMultiplier))).formatted(Formatting.GOLD))); - if (!isTimeTowerMaxed) { - lines.add(Text.literal("Stats after upgrade:").formatted(Formatting.GRAY)); - lines.add(Text.empty() - .append(Text.literal(" CPS increase: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(totalCps / (totalCpsMultiplier) * (timeTowerMultiplier + 0.1))).formatted(Formatting.GOLD))); - lines.add(Text.empty() - .append(Text.literal(" CPS when active: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps / totalCpsMultiplier * (totalCpsMultiplier + 0.1) : totalCps / totalCpsMultiplier * (timeTowerMultiplier + 0.1 + totalCpsMultiplier))).formatted(Formatting.GOLD))); - } - return true; + .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps / totalCpsMultiplier * (totalCpsMultiplier + 0.1) : totalCps / totalCpsMultiplier * (timeTowerMultiplier + 0.1 + totalCpsMultiplier))).formatted(Formatting.GOLD))); } + return true; + } + + private boolean addRabbitStatsToLore(List<Text> lines, int slot) { + if (cpsIncreaseFactors.isEmpty()) return false; + for (Rabbit rabbit : cpsIncreaseFactors) { + if (rabbit.slot == slot) { + lines.add(Text.empty() + .append(Text.literal("CPS Increase: ").formatted(Formatting.GRAY)) + .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cpsIncrease)).formatted(Formatting.GOLD))); - private boolean addRabbitStatsToLore(List<Text> lines, int slot) { - if (cpsIncreaseFactors.isEmpty()) return false; - for (Rabbit rabbit : cpsIncreaseFactors) { - if (rabbit.slot == slot) { - lines.add(Text.empty() - .append(Text.literal("CPS Increase: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cpsIncrease)).formatted(Formatting.GOLD))); - - lines.add(Text.empty() - .append(Text.literal("Cost per CPS: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cost / rabbit.cpsIncrease)).formatted(Formatting.GOLD))); - - if (rabbit.slot == bestUpgrade) { - if (rabbit.cost <= totalChocolate) { - lines.add(Text.literal("Best upgrade").formatted(Formatting.GREEN)); - } else { - lines.add(Text.literal("Best upgrade, can't afford").formatted(Formatting.YELLOW)); - } - } else if (rabbit.slot == bestAffordableUpgrade && rabbit.cost <= totalChocolate) { - lines.add(Text.literal("Best upgrade you can afford").formatted(Formatting.GREEN)); + lines.add(Text.empty() + .append(Text.literal("Cost per CPS: ").formatted(Formatting.GRAY)) + .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cost / rabbit.cpsIncrease)).formatted(Formatting.GOLD))); + + if (rabbit.slot == bestUpgrade) { + if (rabbit.cost <= totalChocolate) { + lines.add(Text.literal("Best upgrade").formatted(Formatting.GREEN)); + } else { + lines.add(Text.literal("Best upgrade, can't afford").formatted(Formatting.YELLOW)); } - return true; + } else if (rabbit.slot == bestAffordableUpgrade && rabbit.cost <= totalChocolate) { + lines.add(Text.literal("Best upgrade you can afford").formatted(Formatting.GREEN)); } + return true; } - return false; } + return false; + } - private MutableText formatTime(double seconds) { - seconds = Math.ceil(seconds); - if (seconds <= 0) return Text.literal("Now").formatted(Formatting.GREEN); + private MutableText formatTime(double seconds) { + seconds = Math.ceil(seconds); + if (seconds <= 0) return Text.literal("Now").formatted(Formatting.GREEN); - StringBuilder builder = new StringBuilder(); - if (seconds >= 86400) { - builder.append((int) (seconds / 86400)).append("d "); - seconds %= 86400; - } - if (seconds >= 3600) { - builder.append((int) (seconds / 3600)).append("h "); - seconds %= 3600; - } - if (seconds >= 60) { - builder.append((int) (seconds / 60)).append("m "); - seconds %= 60; - } - if (seconds >= 1) { - builder.append((int) seconds).append("s"); - } - return Text.literal(builder.toString()).formatted(Formatting.GOLD); + StringBuilder builder = new StringBuilder(); + if (seconds >= 86400) { + builder.append((int) (seconds / 86400)).append("d "); + seconds %= 86400; } - - @Override - public boolean isEnabled() { - return SkyblockerConfigManager.get().helpers.chocolateFactory.enableChocolateFactoryHelper; + if (seconds >= 3600) { + builder.append((int) (seconds / 3600)).append("h "); + seconds %= 3600; + } + if (seconds >= 60) { + builder.append((int) (seconds / 60)).append("m "); + seconds %= 60; } + if (seconds >= 1) { + builder.append((int) seconds).append("s"); + } + return Text.literal(builder.toString()).formatted(Formatting.GOLD); + } + + @Override + public int getPriority() { + return 0; //The priority doesn't really matter here as this is the only tooltip adder for the Chocolate Factory. + } + + // ======== Reset and Other Classes ======== + + @Override + public void reset() { + cpsIncreaseFactors.clear(); + totalChocolate = -1L; + totalCps = -1.0; + totalCpsMultiplier = -1.0; + requiredUntilNextPrestige = -1L; + canPrestige = false; + reachedMaxPrestige = false; + timeTowerMultiplier = -1.0; + isTimeTowerMaxed = false; + isTimeTowerActive = false; + bestUpgrade = -1; + bestAffordableUpgrade = -1; + ding = StraySound.NONE; } + + private enum StraySound { + NONE, + NORMAL, + GOLDEN + } + + private record Rabbit(double cpsIncrease, long cost, int slot) {} } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java index 7ab7570c..91971985 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java @@ -16,6 +16,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; import java.util.ArrayList; @@ -86,21 +87,21 @@ public class SlotTextManager { * The order of the adders remains the same as they were added to the {@link SlotTextManager#adders} array. */ @NotNull - public static List<SlotText> getText(@NotNull ItemStack itemStack, int slotId) { + public static List<SlotText> getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { if (currentScreenAdders.isEmpty() || !isEnabled()) return List.of(); for (SlotTextAdder adder : currentScreenAdders) { - List<SlotText> text = adder.getText(itemStack, slotId); + List<SlotText> text = adder.getText(slot, stack, slotId); if (!text.isEmpty()) return text; } return List.of(); } - public static void renderSlotText(DrawContext context, TextRenderer textRenderer, Slot slot) { - renderSlotText(context, textRenderer, slot.getStack(), slot.id, slot.x, slot.y); + public static void renderSlotText(DrawContext context, TextRenderer textRenderer, @NotNull Slot slot) { + renderSlotText(context, textRenderer, slot, slot.getStack(), slot.id, slot.x, slot.y); } - public static void renderSlotText(DrawContext context, TextRenderer textRenderer, ItemStack itemStack, int slotId, int x, int y) { - List<SlotText> textList = getText(itemStack, slotId); + public static void renderSlotText(DrawContext context, TextRenderer textRenderer, @Nullable Slot slot, ItemStack stack, int slotId, int x, int y) { + List<SlotText> textList = getText(slot, stack, slotId); if (textList.isEmpty()) return; MatrixStack matrices = context.getMatrices(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java index 8f3e55a2..27856ab8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java @@ -8,8 +8,10 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; +import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -68,7 +70,7 @@ public class AttributeShardAdder extends SimpleSlotTextAdder { } @Override - public @NotNull List<SlotText> getText(@NotNull ItemStack stack, int slotId) { + public @NotNull List<SlotText> getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { NbtCompound customData = ItemUtils.getCustomData(stack); if (!ItemUtils.getItemId(stack).equals("ATTRIBUTE_SHARD")) return List.of(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CatacombsLevelAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CatacombsLevelAdder.java index 6c95c11e..ce0e3872 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CatacombsLevelAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CatacombsLevelAdder.java @@ -4,10 +4,12 @@ import de.hysky.skyblocker.skyblock.item.slottext.SlotText; import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.RomanNumerals; import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import org.apache.commons.lang3.math.NumberUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Matcher; @@ -26,10 +28,10 @@ public class CatacombsLevelAdder { } @Override - public @NotNull List<SlotText> getText(@NotNull ItemStack itemStack, int slotId) { + public @NotNull List<SlotText> getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { switch (slotId) { case 12, 29, 30, 31, 32, 33 -> { - Matcher matcher = LEVEL_PATTERN.matcher(itemStack.getName().getString()); + Matcher matcher = LEVEL_PATTERN.matcher(stack.getName().getString()); if (!matcher.matches()) return List.of(); String arabic = matcher.group("arabic"); String roman = matcher.group("roman"); @@ -59,10 +61,10 @@ public class CatacombsLevelAdder { } @Override - public @NotNull List<SlotText> getText(@NotNull ItemStack itemStack, int slotId) { + public @NotNull List<SlotText> getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { switch (slotId) { case 11, 12, 13, 14, 15 -> { - String level = getBracketedLevelFromName(itemStack); + String level = getBracketedLevelFromName(stack); if (!NumberUtils.isDigits(level)) return List.of(); return List.of(SlotText.bottomLeft(Text.literal(level).withColor(0xFFDDC1))); } @@ -80,10 +82,10 @@ public class CatacombsLevelAdder { } @Override - public @NotNull List<SlotText> getText(@NotNull ItemStack itemStack, int slotId) { + public @NotNull List<SlotText> getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { switch (slotId) { case 29, 30, 31, 32, 33 -> { - String level = getBracketedLevelFromName(itemStack); + String level = getBracketedLevelFromName(stack); if (!NumberUtils.isDigits(level)) return List.of(); return List.of(SlotText.bottomLeft(Text.literal(level).withColor(0xFFDDC1))); } di |
