From fcb960140cabd7ea8e6767ad324b17748495f3b2 Mon Sep 17 00:00:00 2001
From: modmuss <modmuss50@gmail.com>
Date: Sun, 9 Feb 2025 13:39:08 +0000
Subject: [PATCH] Use page up/down to change creative inventory pages. (#4416)

* Use page up/down to change creative inventory pages.

* Swap keys
---
 .../client/CreativeInventoryScreenMixin.java       | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/fabric-item-group-api-v1/src/client/java/net/fabricmc/fabric/mixin/itemgroup/client/CreativeInventoryScreenMixin.java b/fabric-item-group-api-v1/src/client/java/net/fabricmc/fabric/mixin/itemgroup/client/CreativeInventoryScreenMixin.java
index d2b5ae035..13d01e935 100644
--- a/fabric-item-group-api-v1/src/client/java/net/fabricmc/fabric/mixin/itemgroup/client/CreativeInventoryScreenMixin.java
+++ b/fabric-item-group-api-v1/src/client/java/net/fabricmc/fabric/mixin/itemgroup/client/CreativeInventoryScreenMixin.java
@@ -20,6 +20,7 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.Objects;
 
+import org.lwjgl.glfw.GLFW;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.Shadow;
 import org.spongepowered.asm.mixin.Unique;
@@ -108,6 +109,19 @@ public abstract class CreativeInventoryScreenMixin extends HandledScreen<Creativ
 		}
 	}
 
+	@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true)
+	private void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
+		if (keyCode == GLFW.GLFW_KEY_PAGE_UP) {
+			if (switchToPreviousPage()) {
+				cir.setReturnValue(true);
+			}
+		} else if (keyCode == GLFW.GLFW_KEY_PAGE_DOWN) {
+			if (switchToNextPage()) {
+				cir.setReturnValue(true);
+			}
+		}
+	}
+
 	@Unique
 	private boolean isGroupVisible(ItemGroup itemGroup) {
 		return itemGroup.shouldDisplay() && currentPage == getPage(itemGroup);