-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #728 from Emirlol/bazaar-highlight
Bazaar Helper
- Loading branch information
Showing
14 changed files
with
246 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/de/hysky/skyblocker/skyblock/bazaar/BazaarHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package de.hysky.skyblocker.skyblock.bazaar; | ||
|
||
import de.hysky.skyblocker.config.SkyblockerConfigManager; | ||
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; | ||
import net.minecraft.text.MutableText; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import org.apache.commons.lang3.math.NumberUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class BazaarHelper extends SlotTextAdder { | ||
private static final Pattern FILLED_PATTERN = Pattern.compile("Filled: \\S+ \\(?([\\d.]+)%\\)?!?"); | ||
private static final int RED = 0xe60b1e; | ||
private static final int YELLOW = 0xe6ba0b; | ||
private static final int GREEN = 0x1ee60b; | ||
|
||
public BazaarHelper() { | ||
super("(?:Co-op|Your) Bazaar Orders"); | ||
} | ||
|
||
@Override | ||
public @NotNull List<SlotText> getText(Slot slot) { | ||
if (!SkyblockerConfigManager.get().helpers.bazaar.enableBazaarHelper) return List.of(); | ||
// Skip the first row as it's always glass panes. | ||
if (slot.id < 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) | ||
|
||
int column = slot.id % 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(); | ||
if (item.isEmpty()) return List.of(); //We've skipped all invalid slots, so we can just check if it's not air here. | ||
|
||
Matcher matcher = ItemUtils.getLoreLineIfMatch(item, FILLED_PATTERN); | ||
if (matcher != null) { | ||
List<Text> lore = ItemUtils.getLore(item); | ||
if (!lore.isEmpty() && lore.getLast().getString().equals("Click to claim!")) { //Only show the filled icon when there are items to claim | ||
int filled = NumberUtils.toInt(matcher.group(1)); | ||
return SlotText.topLeftList(getFilledIcon(filled)); | ||
} | ||
} | ||
|
||
if (ItemUtils.getLoreLineIf(item, str -> str.equals("Expired!")) != null) { | ||
return SlotText.topLeftList(getExpiredIcon()); | ||
} else if (ItemUtils.getLoreLineIf(item, str -> str.startsWith("Expires in")) != null) { | ||
return SlotText.topLeftList(getExpiringIcon()); | ||
} | ||
|
||
return List.of(); | ||
} | ||
|
||
public static @NotNull MutableText getExpiredIcon() { | ||
return Text.literal("⏰").withColor(RED).formatted(Formatting.BOLD); | ||
} | ||
|
||
public static @NotNull MutableText getExpiringIcon() { | ||
return Text.literal("⏰").withColor(YELLOW).formatted(Formatting.BOLD); | ||
} | ||
|
||
public static @NotNull MutableText getFilledIcon(int filled) { | ||
if (filled < 100) return Text.literal("%").withColor(YELLOW).formatted(Formatting.BOLD); | ||
return Text.literal("✅").withColor(GREEN).formatted(Formatting.BOLD); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/de/hysky/skyblocker/skyblock/bazaar/ReorderHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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.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; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class ReorderHelper extends ContainerSolver { | ||
private static final Pattern BUY_PATTERN = Pattern.compile("([\\d,]+)x missing items\\."); | ||
private static final Pattern SELL_PATTERN = Pattern.compile("([\\d,]+)x items\\."); | ||
|
||
public ReorderHelper() { | ||
super("^Order options"); | ||
} | ||
|
||
@Override | ||
protected boolean isEnabled() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) { | ||
// 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; | ||
// The terracotta is at slot 13 on sell orders and at slot 11 on buy orders | ||
if (slot == 13) matcher = ItemUtils.getLoreLineIfContainsMatch(stack, SELL_PATTERN); | ||
else matcher = ItemUtils.getLoreLineIfContainsMatch(stack, BUY_PATTERN); | ||
if (matcher != null) { | ||
MinecraftClient.getInstance().keyboard.setClipboard(matcher.group(1).replace(",", "")); | ||
return false; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
protected List<ColorHighlight> getColors(String[] groups, 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)); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.