forked from SkyblockerMod/Skyblocker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
81 additions
and
5 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
65 changes: 65 additions & 0 deletions
65
src/main/java/de/hysky/skyblocker/skyblock/WardrobeKeybinds.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,65 @@ | ||
package de.hysky.skyblocker.skyblock; | ||
|
||
import de.hysky.skyblocker.annotations.Init; | ||
import de.hysky.skyblocker.config.SkyblockerConfigManager; | ||
import de.hysky.skyblocker.utils.container.RegexContainerMatcher; | ||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; | ||
import net.fabricmc.fabric.api.client.screen.v1.ScreenKeyboardEvents; | ||
import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.client.option.KeyBinding; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.screen.slot.SlotActionType; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
import java.util.function.Predicate; | ||
|
||
@SuppressWarnings("unused") | ||
public class WardrobeKeybinds extends RegexContainerMatcher { | ||
private static final WardrobeKeybinds INSTANCE = new WardrobeKeybinds(); | ||
|
||
public WardrobeKeybinds() { | ||
super("Wardrobe \\([12]/2\\)"); | ||
} | ||
|
||
@Init | ||
public static void init() { | ||
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> { | ||
if (!(screen instanceof HandledScreen<?> handledScreen) || !INSTANCE.test(handledScreen) || !INSTANCE.isEnabled() || client.interactionManager == null) return; | ||
ScreenKeyboardEvents.allowKeyPress(handledScreen).register((ignored, keyCode, scanCode, modifiers) -> | ||
allowInput(client, handledScreen, keybinding -> keybinding.matchesKey(keyCode, scanCode)) | ||
); | ||
ScreenMouseEvents.allowMouseClick(handledScreen).register((ignored, mouseX, mouseY, button) -> | ||
allowInput(client, handledScreen, keybinding -> keybinding.matchesMouse(button)) | ||
); | ||
}); | ||
} | ||
|
||
private static boolean allowInput(MinecraftClient client, HandledScreen<?> handledScreen, Predicate<KeyBinding> predicate) { | ||
boolean found = false; | ||
int i; | ||
for (i = 0; i < client.options.hotbarKeys.length; i++) { | ||
if (predicate.test(client.options.hotbarKeys[i])) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (!found) return true; | ||
// 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. | ||
i += 9 * 4; | ||
ItemStack itemStack = handledScreen.getScreenHandler().getSlot(i).getStack(); | ||
// Check if the item in the slot is a swap/unequip item before going further. | ||
// This prevents usage when the inventory hasn't loaded fully or when the slot pressed is locked (which would be meaningless to click) | ||
if (!itemStack.isOf(Items.PINK_DYE) && !itemStack.isOf(Items.LIME_DYE)) return true; | ||
assert client.interactionManager != null; | ||
client.interactionManager.clickSlot(handledScreen.getScreenHandler().syncId, i, GLFW.GLFW_MOUSE_BUTTON_1, SlotActionType.PICKUP, client.player); | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return SkyblockerConfigManager.get().helpers.enableWardrobeHelper; | ||
} | ||
} |
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