Skip to content

Commit bd6ed47

Browse files
authored
Add wardrobe helper based on hotbar keybinds (SkyblockerMod#943)
* Wardrobe helper initial commit * Remove unnecessary getter from RegexContainerMatcher * Clarify config description * Allow mouse keys to work with wardrobe
1 parent d241b8c commit bd6ed47

File tree

5 files changed

+81
-5
lines changed

5 files changed

+81
-5
lines changed

Diff for: src/main/java/de/hysky/skyblocker/config/categories/HelperCategory.java

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
2626
.controller(ConfigUtils::createBooleanController)
2727
.build())
2828

29+
.option(Option.<Boolean>createBuilder()
30+
.name(Text.translatable("skyblocker.config.helpers.enableWardrobeHelper"))
31+
.description(OptionDescription.of(Text.translatable("skyblocker.config.helpers.enableWardrobeHelper.@Tooltip")))
32+
.binding(defaults.helpers.enableWardrobeHelper,
33+
() -> config.helpers.enableWardrobeHelper,
34+
newValue -> config.helpers.enableWardrobeHelper = newValue)
35+
.controller(ConfigUtils::createBooleanController)
36+
.build())
37+
2938
//Mythological Ritual
3039
.group(OptionGroup.createBuilder()
3140
.name(Text.translatable("skyblocker.config.helpers.mythologicalRitual"))

Diff for: src/main/java/de/hysky/skyblocker/config/configs/HelperConfig.java

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ public class HelperConfig {
88
@SerialEntry
99
public boolean enableNewYearCakesHelper = true;
1010

11+
@SerialEntry
12+
public boolean enableWardrobeHelper = true;
13+
1114
@SerialEntry
1215
public MythologicalRitual mythologicalRitual = new MythologicalRitual();
1316

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package de.hysky.skyblocker.skyblock;
2+
3+
import de.hysky.skyblocker.annotations.Init;
4+
import de.hysky.skyblocker.config.SkyblockerConfigManager;
5+
import de.hysky.skyblocker.utils.container.RegexContainerMatcher;
6+
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
7+
import net.fabricmc.fabric.api.client.screen.v1.ScreenKeyboardEvents;
8+
import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents;
9+
import net.minecraft.client.MinecraftClient;
10+
import net.minecraft.client.gui.screen.ingame.HandledScreen;
11+
import net.minecraft.client.option.KeyBinding;
12+
import net.minecraft.item.ItemStack;
13+
import net.minecraft.item.Items;
14+
import net.minecraft.screen.slot.SlotActionType;
15+
import org.lwjgl.glfw.GLFW;
16+
17+
import java.util.function.Predicate;
18+
19+
@SuppressWarnings("unused")
20+
public class WardrobeKeybinds extends RegexContainerMatcher {
21+
private static final WardrobeKeybinds INSTANCE = new WardrobeKeybinds();
22+
23+
public WardrobeKeybinds() {
24+
super("Wardrobe \\([12]/2\\)");
25+
}
26+
27+
@Init
28+
public static void init() {
29+
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
30+
if (!(screen instanceof HandledScreen<?> handledScreen) || !INSTANCE.test(handledScreen) || !INSTANCE.isEnabled() || client.interactionManager == null) return;
31+
ScreenKeyboardEvents.allowKeyPress(handledScreen).register((ignored, keyCode, scanCode, modifiers) ->
32+
allowInput(client, handledScreen, keybinding -> keybinding.matchesKey(keyCode, scanCode))
33+
);
34+
ScreenMouseEvents.allowMouseClick(handledScreen).register((ignored, mouseX, mouseY, button) ->
35+
allowInput(client, handledScreen, keybinding -> keybinding.matchesMouse(button))
36+
);
37+
});
38+
}
39+
40+
private static boolean allowInput(MinecraftClient client, HandledScreen<?> handledScreen, Predicate<KeyBinding> predicate) {
41+
boolean found = false;
42+
int i;
43+
for (i = 0; i < client.options.hotbarKeys.length; i++) {
44+
if (predicate.test(client.options.hotbarKeys[i])) {
45+
found = true;
46+
break;
47+
}
48+
}
49+
if (!found) return true;
50+
// The items start from the 5th row in the inventory. The i number we have is the column in the first row, so we have to offset it by 4 rows to get the 5th row, which is where the items start.
51+
i += 9 * 4;
52+
ItemStack itemStack = handledScreen.getScreenHandler().getSlot(i).getStack();
53+
// Check if the item in the slot is a swap/unequip item before going further.
54+
// This prevents usage when the inventory hasn't loaded fully or when the slot pressed is locked (which would be meaningless to click)
55+
if (!itemStack.isOf(Items.PINK_DYE) && !itemStack.isOf(Items.LIME_DYE)) return true;
56+
assert client.interactionManager != null;
57+
client.interactionManager.clickSlot(handledScreen.getScreenHandler().syncId, i, GLFW.GLFW_MOUSE_BUTTON_1, SlotActionType.PICKUP, client.player);
58+
return false;
59+
}
60+
61+
@Override
62+
public boolean isEnabled() {
63+
return SkyblockerConfigManager.get().helpers.enableWardrobeHelper;
64+
}
65+
}

Diff for: src/main/java/de/hysky/skyblocker/utils/container/RegexContainerMatcher.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public abstract class RegexContainerMatcher implements ContainerMatcher {
2323
public final Pattern titlePattern;
2424

2525
@Nullable
26-
public String[] groups = null;
26+
protected String[] groups = null;
2727

2828
@Override
2929
public boolean test(@NotNull Screen screen) {
@@ -61,8 +61,4 @@ protected RegexContainerMatcher(@Nullable Pattern titlePattern) {
6161
public @Nullable Pattern getTitlePattern() {
6262
return titlePattern;
6363
}
64-
65-
public final @Nullable String[] getGroups() {
66-
return groups;
67-
}
6864
}

Diff for: src/main/resources/assets/skyblocker/lang/en_us.json

+3
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@
356356
"skyblocker.config.helpers.enableNewYearCakesHelper": "Enable New Year Cakes Helper",
357357
"skyblocker.config.helpers.enableNewYearCakesHelper.@Tooltip": "Highlights the missing new year cakes green and the cakes you have already red.\n\nRequires you to open your cake bag at least once to work.",
358358

359+
"skyblocker.config.helpers.enableWardrobeHelper": "Enable Wardrobe Helper",
360+
"skyblocker.config.helpers.enableWardrobeHelper.@Tooltip": "Allows changing armor from the wardrobe by pressing hotbar keys 1-9 while the menu is open. The corresponding armor set in the wardrobe menu will be equipped.",
361+
359362
"skyblocker.config.helpers.experiments": "Experiments Solver",
360363
"skyblocker.config.helpers.experiments.enableChronomatronSolver": "Enable Chronomatron Solver",
361364
"skyblocker.config.helpers.experiments.enableSuperpairsSolver": "Enable Superpairs Solver",

0 commit comments

Comments
 (0)