Extract toggle magnet keybind handling into method and add support for mouse buttons

This commit is contained in:
Wilhelm Schuster committed 2024-11-22 09:31:19 +01:00
1 parent cec5824df1
commit f19cdb58c6
1 file changed
+11 -5
@@ -49,11 +49,7 @@ public class KeyInputHandler {
} else if (KeyBindings.toggleFlight.isPressed() && player != null) {
handleToggleFlightKey(player);
} else if (KeyBindings.toggleMagnet.isPressed()) {
Optional<ItemStack> magnetOptional = InventoryUtils.getItemInAnyPlayerInventory(player, Magnet.class);
if (magnetOptional.isPresent()) {
DraconicEvolution.network.sendToServer(new MagnetTogglePacket());
}
handleToggleMagnetKey(player);
}
}
@@ -70,6 +66,8 @@ public class KeyInputHandler {
handleToolProfileChangeKey(player);
} else if (KeyBindings.toggleFlight.isPressed() && player != null) {
handleToggleFlightKey(player);
} else if (KeyBindings.toggleMagnet.isPressed()) {
handleToggleMagnetKey(player);
}
if (player != null) {
@@ -133,6 +131,14 @@ public class KeyInputHandler {
}
}
private void handleToggleMagnetKey(EntityClientPlayerMP player) {
Optional<ItemStack> magnetOptional = InventoryUtils.getItemInAnyPlayerInventory(player, Magnet.class);
if (magnetOptional.isPresent()) {
DraconicEvolution.network.sendToServer(new MagnetTogglePacket());
}
}
private int previouseSlot(int i, int c) {
if (c > 0 && c < 8) return c + i;
if (c == 0 && i < 0) return 8;