Guest User

swapping mod code

a guest
Jul 19th, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public class SwappingKeybinds implements ModInitializer {
  2. public static final String MOD_ID = "swapping-keybinds";
  3. private static KeyBinding swapKey;
  4. private static KeyBinding swapSwapKey;
  5. private static int swapTo = 4;
  6. private static boolean toggleState = false;
  7. public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
  8.  
  9. @Override
  10. public void onInitialize() {
  11. LOGGER.info("swapping keys init");
  12. swapKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
  13. "swap",
  14. InputUtil.Type.KEYSYM,
  15. GLFW.GLFW_KEY_R,
  16. "swapping keybinds"
  17. ));
  18. swapSwapKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
  19. "change what to swap to",
  20. InputUtil.Type.KEYSYM,
  21. GLFW.GLFW_KEY_X,
  22. "swapping keybinds"
  23. ));
  24. ClientTickEvents.END_CLIENT_TICK.register(client -> {
  25. while (swapKey.wasPressed()) {
  26. toggleState = !toggleState;
  27. int newSlot = toggleState ? swapTo : 0;
  28. client.player.getInventory().selectedSlot = newSlot;
  29. }
  30. while (swapSwapKey.wasPressed()) {
  31. int newSlot;
  32. if (swapTo == 6) {
  33. newSlot = 4;
  34. swapTo = 4;
  35. } else {
  36. newSlot = ++swapTo;
  37. }
  38. client.player.getInventory().selectedSlot = newSlot;
  39. }
  40. });
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment