|
| 1 | +package de.hysky.skyblocker.skyblock.item.slottext.adders; |
| 2 | + |
| 3 | +import de.hysky.skyblocker.skyblock.item.slottext.SlotText; |
| 4 | +import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; |
| 5 | +import de.hysky.skyblocker.utils.ItemUtils; |
| 6 | +import de.hysky.skyblocker.utils.RomanNumerals; |
| 7 | +import net.minecraft.item.ItemStack; |
| 8 | +import net.minecraft.item.Items; |
| 9 | +import net.minecraft.screen.slot.Slot; |
| 10 | +import net.minecraft.text.Text; |
| 11 | +import net.minecraft.util.Formatting; |
| 12 | +import org.jetbrains.annotations.NotNull; |
| 13 | + |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +public class CommunityShopAdder extends SlotTextAdder { |
| 17 | + private static final byte CATEGORIES_START = 10; |
| 18 | + private static final byte CATEGORIES_END = 14; //Inclusive |
| 19 | + |
| 20 | + public CommunityShopAdder() { |
| 21 | + super("^Community Shop"); |
| 22 | + } |
| 23 | + |
| 24 | + @Override |
| 25 | + public @NotNull List<SlotText> getText(Slot slot) { |
| 26 | + for (byte i = CATEGORIES_START; i <= CATEGORIES_END; i++) { |
| 27 | + if (slot.inventory.getStack(i).isOf(Items.LIME_STAINED_GLASS_PANE)) { //Only the selected category has a lime stained glass pane, the others have a gray one. |
| 28 | + return switch (i) { //This is a switch to allow adding more categories easily in the future, if we ever add more. |
| 29 | + case 11 -> getTextForUpgradesScreen(slot); |
| 30 | + default -> List.of(); |
| 31 | + }; |
| 32 | + } |
| 33 | + } |
| 34 | + return List.of(); |
| 35 | + } |
| 36 | + |
| 37 | + private static List<SlotText> getTextForUpgradesScreen(Slot slot) { |
| 38 | + final ItemStack stack = slot.getStack(); |
| 39 | + switch (slot.id) { |
| 40 | + case 30, 31, 32, 33, 34, 38, 39, 40, 41, 42, 43, 44 -> { |
| 41 | + String name = stack.getName().getString(); |
| 42 | + int lastIndex = name.lastIndexOf(' '); |
| 43 | + String roman = name.substring(lastIndex + 1); // + 1 as we don't want the space |
| 44 | + if (!RomanNumerals.isValidRomanNumeral(roman)) return List.of(); |
| 45 | + |
| 46 | + List<Text> lore = ItemUtils.getLore(stack); |
| 47 | + if (lore.isEmpty()) return List.of(); |
| 48 | + String lastLine = lore.getLast().getString(); |
| 49 | + return List.of(SlotText.bottomLeft(switch (lastLine) { |
| 50 | + case "Maxed out!" -> Text.literal("Max").withColor(0xfab387); |
| 51 | + case "Currently upgrading!" -> Text.literal("⏰").withColor(0xf9e2af).formatted(Formatting.BOLD); |
| 52 | + case "Click to claim!" -> Text.literal("✅").withColor(0xa6e3a1).formatted(Formatting.BOLD); |
| 53 | + default -> Text.literal(String.valueOf(RomanNumerals.romanToDecimal(roman))).withColor(0xcba6f7); |
| 54 | + })); |
| 55 | + |
| 56 | + } |
| 57 | + } |
| 58 | + return List.of(); |
| 59 | + } |
| 60 | +} |
0 commit comments