Skip to content

Commit

Permalink
Merge pull request #512 from Emirlol/anita-fortune-tabhud
Browse files Browse the repository at this point in the history
Add anita's talisman fortune boost indicator next to the relevant crop
  • Loading branch information
LifeIsAParadox committed Jan 25, 2024
2 parents 7af455c + 8d1c345 commit f3877c4
Showing 1 changed file with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package de.hysky.skyblocker.skyblock.tabhud.widget;

import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent;
Expand All @@ -14,6 +10,12 @@
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.Map.entry;

// this widget shows info about the current jacob's contest (garden only)

public class JacobsContestWidget extends Widget {
Expand All @@ -22,23 +24,20 @@ public class JacobsContestWidget extends Widget {
Formatting.BOLD);

//TODO Properly match the contest placement and display it
private static final Pattern CROP_PATTERN = Pattern.compile("(?:☘|○) (?<crop>[A-Za-z ]+)(?:.+)?");
private static final Pattern CROP_PATTERN = Pattern.compile("(?<fortune>[☘○]) (?<crop>[A-Za-z ]+).*");

private static final HashMap<String, ItemStack> FARM_DATA = new HashMap<>();

// again, there HAS to be a better way to do this
static {
FARM_DATA.put("Wheat", new ItemStack(Items.WHEAT));
FARM_DATA.put("Sugar Cane", new ItemStack(Items.SUGAR_CANE));
FARM_DATA.put("Carrot", new ItemStack(Items.CARROT));
FARM_DATA.put("Potato", new ItemStack(Items.POTATO));
FARM_DATA.put("Melon", new ItemStack(Items.MELON_SLICE));
FARM_DATA.put("Pumpkin", new ItemStack(Items.PUMPKIN));
FARM_DATA.put("Cocoa Beans", new ItemStack(Items.COCOA_BEANS));
FARM_DATA.put("Nether Wart", new ItemStack(Items.NETHER_WART));
FARM_DATA.put("Cactus", new ItemStack(Items.CACTUS));
FARM_DATA.put("Mushroom", new ItemStack(Items.RED_MUSHROOM));
}
private static final Map<String, ItemStack> FARM_DATA = Map.ofEntries(
entry("Wheat", new ItemStack(Items.WHEAT)),
entry("Sugar Cane", new ItemStack(Items.SUGAR_CANE)),
entry("Carrot", new ItemStack(Items.CARROT)),
entry("Potato", new ItemStack(Items.POTATO)),
entry("Melon", new ItemStack(Items.MELON_SLICE)),
entry("Pumpkin", new ItemStack(Items.PUMPKIN)),
entry("Cocoa Beans", new ItemStack(Items.COCOA_BEANS)),
entry("Nether Wart", new ItemStack(Items.NETHER_WART)),
entry("Cactus", new ItemStack(Items.CACTUS)),
entry("Mushroom", new ItemStack(Items.RED_MUSHROOM))
);

public JacobsContestWidget() {
super(TITLE, Formatting.YELLOW.getColorValue());
Expand All @@ -54,7 +53,7 @@ public void updateContent() {
this.addSimpleIcoText(Ico.CLOCK, "Starts in:", Formatting.GOLD, 76);
}

TableComponent tc = new TableComponent(1, 3, Formatting.YELLOW .getColorValue());
TableComponent tc = new TableComponent(1, 3, Formatting.YELLOW.getColorValue());

for (int i = 77; i < 80; i++) {
Matcher item = PlayerListMgr.regexAt(i, CROP_PATTERN);
Expand All @@ -63,7 +62,11 @@ public void updateContent() {
itc = new IcoTextComponent();
} else {
String cropName = item.group("crop").trim(); //Trimming is needed because during a contest the space separator will be caught
itc = new IcoTextComponent(FARM_DATA.get(cropName), Text.of(cropName));
if (item.group("fortune").equals("☘")) {
itc = new IcoTextComponent(FARM_DATA.get(cropName), Text.literal(cropName).append(Text.literal(" ☘").formatted(Formatting.GOLD)));
} else {
itc = new IcoTextComponent(FARM_DATA.get(cropName), Text.of(cropName));
}
}
tc.addToCell(0, i - 77, itc);
}
Expand Down

0 comments on commit f3877c4

Please sign in to comment.