Skip to content

Commit 2768fcf

Browse files
committed
Allow navigating books using the mouse scroll wheel
1 parent cd670a9 commit 2768fcf

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/main/java/meteordevelopment/meteorclient/mixin/BookEditScreenMixin.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package meteordevelopment.meteorclient.mixin;
77

88
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream;
9+
import meteordevelopment.meteorclient.MeteorClient;
910
import net.minecraft.client.gui.screen.Screen;
1011
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
1112
import net.minecraft.client.gui.widget.ButtonWidget;
@@ -36,6 +37,12 @@ public abstract class BookEditScreenMixin extends Screen {
3637
@Shadow
3738
protected abstract void updatePage();
3839

40+
@Shadow
41+
protected abstract void openNextPage();
42+
43+
@Shadow
44+
protected abstract void openPreviousPage();
45+
3946
public BookEditScreenMixin(Text title) {
4047
super(title);
4148
}
@@ -56,7 +63,7 @@ private void onInit(CallbackInfo info) {
5663
try {
5764
NbtIo.write(tag, out);
5865
} catch (IOException e) {
59-
e.printStackTrace();
66+
MeteorClient.LOG.error("Error writing the book to the output stream", e);
6067
}
6168

6269
try {
@@ -101,12 +108,21 @@ private void onInit(CallbackInfo info) {
101108

102109
updatePage();
103110
} catch (IOException e) {
104-
e.printStackTrace();
111+
MeteorClient.LOG.error("Error reading the data from your clipboard", e);
105112
}
106113
})
107114
.position(4, 4 + 20 + 2)
108115
.size(120, 20)
109116
.build()
110117
);
111118
}
119+
120+
@Override
121+
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
122+
if (verticalAmount == 0) return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
123+
124+
if (verticalAmount < 0) this.openNextPage(); // scroll down
125+
else this.openPreviousPage(); // scroll up
126+
return true;
127+
}
112128
}

src/main/java/meteordevelopment/meteorclient/mixin/BookScreenMixin.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package meteordevelopment.meteorclient.mixin;
77

88
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream;
9+
import meteordevelopment.meteorclient.MeteorClient;
910
import meteordevelopment.meteorclient.gui.GuiThemes;
1011
import meteordevelopment.meteorclient.gui.screens.EditBookTitleAndAuthorScreen;
1112
import meteordevelopment.meteorclient.utils.player.ChatUtils;
@@ -43,6 +44,12 @@ public abstract class BookScreenMixin extends Screen {
4344
@Shadow
4445
private int pageIndex;
4546

47+
@Shadow
48+
protected abstract void goToNextPage();
49+
50+
@Shadow
51+
protected abstract void goToPreviousPage();
52+
4653
public BookScreenMixin(Text title) {
4754
super(title);
4855
}
@@ -63,7 +70,7 @@ private void onInit(CallbackInfo info) {
6370
try {
6471
NbtIo.write(tag, out);
6572
} catch (IOException e) {
66-
e.printStackTrace();
73+
MeteorClient.LOG.error("Error writing the book to the output stream", e);
6774
}
6875

6976
String encoded = Base64.getEncoder().encodeToString(bytes.array);
@@ -105,4 +112,13 @@ private void onInit(CallbackInfo info) {
105112
.build()
106113
);
107114
}
115+
116+
@Override
117+
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
118+
if (verticalAmount == 0) return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
119+
120+
if (verticalAmount < 0) this.goToNextPage(); // scroll down
121+
else this.goToPreviousPage(); // scroll up
122+
return true;
123+
}
108124
}

0 commit comments

Comments
 (0)