Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SalvageHelper #999

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.dungeons.croesusHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.dungeons.salvageHelper"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.dungeons.salvageHelper.@Tooltip")))
.binding(defaults.dungeons.salvageHelper,
() -> config.dungeons.salvageHelper,
newValue -> config.dungeons.salvageHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.dungeons.playerSecretsTracker"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.dungeons.playerSecretsTracker.@Tooltip")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class DungeonsConfig {
@SerialEntry
public boolean croesusHelper = true;

@SerialEntry
public boolean salvageHelper = true;

@SerialEntry
public boolean playerSecretsTracker = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.hysky.skyblocker.skyblock.dungeon;

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.container.ContainerSolverManager;
import de.hysky.skyblocker.utils.container.SimpleContainerSolver;
import de.hysky.skyblocker.utils.networth.NetworthCalculator;
import de.hysky.skyblocker.utils.render.gui.ColorHighlight;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.azureaaron.networth.NetworthResult;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
import net.minecraft.item.ItemStack;

import java.util.List;
import java.util.regex.Pattern;

public class SalvageHelper extends SimpleContainerSolver {
/**
* Pattern to match dungeon items that are salvageable, using a negative lookahead to exclude dungeon items.
*/
private static final Pattern DUNGEON_SALVAGABLE = Pattern.compile("DUNGEON(?! ITEM)");

public SalvageHelper() {
super("^Salvage Items");
}

@Override
public List<ColorHighlight> getColors(Int2ObjectMap<ItemStack> slots) {
Screen currentScreen = MinecraftClient.getInstance().currentScreen;
if (!(currentScreen instanceof GenericContainerScreen genericContainerScreen)) return List.of();
return ContainerSolverManager.slotMap(genericContainerScreen.getScreenHandler().slots.subList(genericContainerScreen.getScreenHandler().getRows() * 9, genericContainerScreen.getScreenHandler().slots.size())).int2ObjectEntrySet().stream()
.filter(entry -> ItemUtils.getLoreLineIfContainsMatch(entry.getValue(), DUNGEON_SALVAGABLE) != null)
.filter(entry -> isPriceWithinRange(entry.getValue()))
.map(entry -> ColorHighlight.green(entry.getIntKey() + genericContainerScreen.getScreenHandler().getRows() * 9))
.toList();
}

/**
* Checks if the price of the item is within the range of 0 to 100,000 coins, which should be safe to salvage.
*/
private boolean isPriceWithinRange(ItemStack stack) {
NetworthResult result = NetworthCalculator.getItemNetworth(stack);
return result.price() > 0 && result.price() < 100_000;
}

@Override
public boolean isEnabled() {
return SkyblockerConfigManager.get().dungeons.salvageHelper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import de.hysky.skyblocker.skyblock.chocolatefactory.ChocolateFactorySolver;
import de.hysky.skyblocker.skyblock.dungeon.CroesusHelper;
import de.hysky.skyblocker.skyblock.dungeon.CroesusProfit;
import de.hysky.skyblocker.skyblock.dungeon.SalvageHelper;
import de.hysky.skyblocker.skyblock.dungeon.terminal.ColorTerminal;
import de.hysky.skyblocker.skyblock.dungeon.terminal.LightsOnTerminal;
import de.hysky.skyblocker.skyblock.dungeon.terminal.OrderTerminal;
Expand Down Expand Up @@ -42,6 +43,7 @@ public class ContainerSolverManager {
new LightsOnTerminal(),
new CroesusHelper(),
new CroesusProfit(),
new SalvageHelper(),
new ChronomatronSolver(),
new CommissionHighlight(),
new SuperpairsSolver(),
Expand Down Expand Up @@ -72,7 +74,7 @@ public static void init() {
MatrixStack matrices = context.getMatrices();
matrices.push();
matrices.translate(((HandledScreenAccessor) genericContainerScreen).getX(), ((HandledScreenAccessor) genericContainerScreen).getY(), 300);
onDraw(context, genericContainerScreen.getScreenHandler().slots.subList(0, genericContainerScreen.getScreenHandler().getRows() * 9));
onDraw(context, genericContainerScreen, genericContainerScreen.getScreenHandler().slots);
matrices.pop();
});
ScreenEvents.remove(screen).register(screen1 -> clearScreen());
Expand Down Expand Up @@ -126,9 +128,9 @@ public static boolean onSlotClick(int slot, ItemStack stack) {
return currentSolver != null && currentSolver.onClickSlot(slot, stack, screenId);
}

public static void onDraw(DrawContext context, List<Slot> slots) {
public static void onDraw(DrawContext context, GenericContainerScreen genericContainerScreen, List<Slot> slots) {
if (currentSolver == null) return;
if (highlights == null) highlights = currentSolver.getColors(slotMap(slots));
if (highlights == null) highlights = currentSolver.getColors(slotMap(slots.subList(0, genericContainerScreen.getScreenHandler().getRows() * 9)));
RenderSystem.enableDepthTest();
RenderSystem.colorMask(true, true, true, false);
for (ColorHighlight highlight : highlights) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@
"skyblocker.config.dungeons.puzzle.solveWaterboard": "Solve Waterboard Puzzle",
"skyblocker.config.dungeons.puzzle.solveWaterboard.@Tooltip": "Click the levers with green boxes to solve the puzzle.",

"skyblocker.config.dungeons.salvageHelper": "Salvage Helper",
"skyblocker.config.dungeons.salvageHelper.@Tooltip": "Highlights items picked up in dungeons that can be salvaged.",

"skyblocker.config.dungeons.secretWaypoints": "Dungeon Secret Waypoints",
"skyblocker.config.dungeons.secretWaypoints.enableAotvWaypoints": "Enable AOTV Waypoints",
"skyblocker.config.dungeons.secretWaypoints.enableBatWaypoints": "Enable Bat Waypoints",
Expand Down