From bd3f0329d0e391bd84b5f9e3ff207d9dd9815853 Mon Sep 17 00:00:00 2001 From: Yasin Date: Mon, 9 Oct 2023 12:58:02 +0200 Subject: new pr because fixing merge conflict would take too long --- .../hysky/skyblocker/skyblock/HotbarSlotLock.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/HotbarSlotLock.java (limited to 'src/main/java/de/hysky/skyblocker/skyblock/HotbarSlotLock.java') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/HotbarSlotLock.java b/src/main/java/de/hysky/skyblocker/skyblock/HotbarSlotLock.java new file mode 100644 index 00000000..13f09ec6 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/HotbarSlotLock.java @@ -0,0 +1,40 @@ +package de.hysky.skyblocker.skyblock; + +import de.hysky.skyblocker.config.SkyblockerConfigManager; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.option.KeyBinding; +import org.lwjgl.glfw.GLFW; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +public class HotbarSlotLock { + public static KeyBinding hotbarSlotLock; + + public static void init() { + hotbarSlotLock = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.hotbarSlotLock", + GLFW.GLFW_KEY_H, + "key.categories.skyblocker" + )); + } + + public static boolean isLocked(int slot) { + return SkyblockerConfigManager.get().general.lockedSlots.contains(slot); + } + + public static void handleDropSelectedItem(int slot, CallbackInfoReturnable cir) { + if (isLocked(slot)) cir.setReturnValue(false); + } + + public static void handleInputEvents(ClientPlayerEntity player) { + while (hotbarSlotLock.wasPressed()) { + List lockedSlots = SkyblockerConfigManager.get().general.lockedSlots; + int selected = player.getInventory().selectedSlot; + if (!isLocked(player.getInventory().selectedSlot)) lockedSlots.add(selected); + else lockedSlots.remove(Integer.valueOf(selected)); + SkyblockerConfigManager.save(); + } + } +} \ No newline at end of file -- cgit