Skip to content

Commit

Permalink
Merge pull request #710 from AzureAaron/block-incorrect-term-clicks
Browse files Browse the repository at this point in the history
Block Incorrect Terminal Clicks
  • Loading branch information
AzureAaron authored May 14, 2024
2 parents 992ee43 + b01f60e commit 1a7c706
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.dungeons.terminals.solveStartsWith = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.dungeons.terminals.blockIncorrectClicks"))
.binding(defaults.dungeons.terminals.blockIncorrectClicks,
() -> config.dungeons.terminals.blockIncorrectClicks,
newValue -> config.dungeons.terminals.blockIncorrectClicks = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.build())

// Dungeon Secret Waypoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public static class Terminals {

@SerialEntry
public boolean solveStartsWith = true;

@SerialEntry
public boolean blockIncorrectClicks = false;
}

public static class SecretWaypoints {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ protected HandledScreenMixin(Text title) {
}

if (currentSolver != null) {
SkyblockerMod.getInstance().containerSolverManager.onSlotClick(slotId, stack);
boolean disallowed = SkyblockerMod.getInstance().containerSolverManager.onSlotClick(slotId, stack);

if (disallowed) ci.cancel();
}

// Experiment Solvers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.*;


public class ColorTerminal extends ContainerSolver {
public class ColorTerminal extends ContainerSolver implements TerminalSolver {
private static final Logger LOGGER = LoggerFactory.getLogger(ColorTerminal.class.getName());
private static final Map<String, DyeColor> colorFromName;
private DyeColor targetColor;
Expand Down Expand Up @@ -53,6 +53,14 @@ protected List<ColorHighlight> getColors(String[] groups, Int2ObjectMap<ItemStac
return highlights;
}

@Override
protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) {
if (stack.hasGlint() || !targetColor.equals(itemColor.get(stack.getItem()))) {
return shouldBlockIncorrectClicks();
}

return false;
}

static {
colorFromName = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.hysky.skyblocker.skyblock.dungeon.terminal;

import java.util.List;

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.item.ItemStack;
import net.minecraft.item.Items;

/**
* The terminal where you change all the panes that are red to green.
*
* This doesn't solve the terminal because you don't need a solver for it, but rather to simply allow for click blocking.
*/
public class LightsOnTerminal extends ContainerSolver implements TerminalSolver {
private static final List<ColorHighlight> EMPTY = List.of();

public LightsOnTerminal() {
super("^Correct all the panes!$");
}

@Override
protected boolean isEnabled() {
return shouldBlockIncorrectClicks();
}

@Override
protected List<ColorHighlight> getColors(String[] groups, Int2ObjectMap<ItemStack> slots) {
return EMPTY;
}

@Override
protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) {
return stack.isOf(Items.LIME_STAINED_GLASS_PANE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Collections;
import java.util.List;

public class OrderTerminal extends ContainerSolver {
public class OrderTerminal extends ContainerSolver implements TerminalSolver {
private final int PANES_NUM = 14;
private int[] orderedSlots;
private int currentNum = Integer.MAX_VALUE;
Expand Down Expand Up @@ -55,4 +55,15 @@ public boolean orderSlots(Int2ObjectMap<ItemStack> slots) {
currentNum = 0;
return true;
}

@Override
protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) {
if (stack == null || stack.isEmpty()) return false;

if (!stack.isOf(Items.RED_STAINED_GLASS_PANE) || stack.getCount() != currentNum + 1) {
return shouldBlockIncorrectClicks();
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.List;
import java.util.function.Predicate;

public class StartsWithTerminal extends ContainerSolver {
public class StartsWithTerminal extends ContainerSolver implements TerminalSolver {
private final Int2ObjectOpenHashMap<ItemState> trackedItemStates = new Int2ObjectOpenHashMap<>();
private int lastKnownScreenId = Integer.MIN_VALUE;

Expand Down Expand Up @@ -50,9 +50,9 @@ protected List<ColorHighlight> getColors(String[] groups, Int2ObjectMap<ItemStac
}

@Override
protected void onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) {
protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) {
//Some random glass pane was clicked or something
if (!trackedItemStates.containsKey(slot) || stack == null || stack.isEmpty()) return;
if (!trackedItemStates.containsKey(slot) || stack == null || stack.isEmpty()) return false;

ItemState state = trackedItemStates.get(slot);
String prefix = groups[0];
Expand All @@ -61,16 +61,17 @@ protected void onClickSlot(int slot, ItemStack stack, int screenId, String[] gro
//Also, since Hypixel closes & reopens the GUI after every click we check if the last known screen id is the same that way in case the server lags and
//either a player tries to click a second item or if the player puts the clicked item back and tries to click another that we don't mark multiple items
//as clicked when only the first one will count.

//While Hypixel does use a different syncId each time they open the screen we opt to use our own so as to avoid them potentially changing that
//and in turn breaking this logic
if (stack.getName().getString().startsWith(prefix) && !state.clicked() && lastKnownScreenId != screenId) {
trackedItemStates.put(slot, state.click());
lastKnownScreenId = screenId;
} else {
return shouldBlockIncorrectClicks();
}
//In the future we could add an else branch and return a boolean to cancel the click since it would be wrong

return;
return false;
}

//We only setup the state when all items aren't null or empty. This prevents the state from being reset due to unsent items or server lag spikes/bad TPS (fix ur servers Hypixel)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package de.hysky.skyblocker.skyblock.dungeon.terminal;

import de.hysky.skyblocker.config.SkyblockerConfigManager;

public interface TerminalSolver {

default boolean shouldBlockIncorrectClicks() {
return SkyblockerConfigManager.get().dungeons.terminals.blockIncorrectClicks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected ContainerSolver(String containerName) {

protected abstract boolean isEnabled();

public Pattern getName() {
public final Pattern getName() {
return containerName;
}

Expand All @@ -34,12 +34,13 @@ protected void markHighlightsDirty() {
SkyblockerMod.getInstance().containerSolverManager.markDirty();
}

protected void onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) {
protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) {
return false;
}

protected abstract List<ColorHighlight> getColors(String[] groups, Int2ObjectMap<ItemStack> slots);

protected void trimEdges(Int2ObjectMap<ItemStack> slots, int rows) {
protected final void trimEdges(Int2ObjectMap<ItemStack> slots, int rows) {
for (int i = 0; i < rows; i++) {
slots.remove(9 * i);
slots.remove(9 * i + 8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import de.hysky.skyblocker.skyblock.dungeon.CroesusHelper;
import de.hysky.skyblocker.skyblock.dungeon.CroesusProfit;
import de.hysky.skyblocker.skyblock.dungeon.terminal.ColorTerminal;
import de.hysky.skyblocker.skyblock.dungeon.terminal.LightsOnTerminal;
import de.hysky.skyblocker.skyblock.dungeon.terminal.OrderTerminal;
import de.hysky.skyblocker.skyblock.dungeon.terminal.StartsWithTerminal;
import de.hysky.skyblocker.skyblock.experiment.ChronomatronSolver;
Expand Down Expand Up @@ -47,6 +48,7 @@ public ContainerSolverManager() {
new ColorTerminal(),
new OrderTerminal(),
new StartsWithTerminal(),
new LightsOnTerminal(),
new CroesusHelper(),
new CroesusProfit(),
new ChronomatronSolver(),
Expand Down Expand Up @@ -114,10 +116,15 @@ public void markDirty() {
highlights = null;
}

public void onSlotClick(int slot, ItemStack stack) {
/**
* @return Whether the click should be disallowed.
*/
public boolean onSlotClick(int slot, ItemStack stack) {
if (currentSolver != null) {
currentSolver.onClickSlot(slot, stack, screenId, groups);
return currentSolver.onClickSlot(slot, stack, screenId, groups);
}

return false;
}

public void onDraw(DrawContext context, List<Slot> slots) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"skyblocker.config.dungeons.starredMobGlow.@Tooltip": "Applies the glowing effect to starred mobs that are visible.\n\nWARNING: This feature is experimental and you may encounter issues with it.",

"skyblocker.config.dungeons.terminals": "Terminal Solvers (F7/M7)",
"skyblocker.config.dungeons.terminals.blockIncorrectClicks": "Block Incorrect Clicks",
"skyblocker.config.dungeons.terminals.solveColor": "Solve Select Colored",
"skyblocker.config.dungeons.terminals.solveOrder": "Solve Click In Order",
"skyblocker.config.dungeons.terminals.solveStartsWith": "Solve Starts With",
Expand Down

0 comments on commit 1a7c706

Please sign in to comment.