Skip to content

Commit fa730c9

Browse files
committed
improve server list button detection
1 parent f0566cc commit fa730c9

3 files changed

Lines changed: 42 additions & 7 deletions

File tree

common/src/main/java/io/github/fishstiz/minecraftcursor/cursor/handler/multiplayer/MultiplayerServerListWidgetCursorHandler.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,40 @@
33
import io.github.fishstiz.minecraftcursor.MinecraftCursor;
44
import io.github.fishstiz.minecraftcursor.api.CursorHandler;
55
import io.github.fishstiz.minecraftcursor.api.CursorType;
6+
import io.github.fishstiz.minecraftcursor.mixin.cursorhandler.access.OnlineServerEntryAccessor;
67
import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList;
78

9+
import java.util.List;
10+
811
public class MultiplayerServerListWidgetCursorHandler implements CursorHandler<ServerSelectionList> {
9-
public static final int ICON_SIZE = 32;
12+
private static final int ICON_SIZE = 32;
13+
private static final int MOVE_ICON_SIZE = ICON_SIZE / 2;
1014

1115
@Override
1216
public CursorType getCursorType(ServerSelectionList serverList, double mouseX, double mouseY) {
1317
if (!MinecraftCursor.CONFIG.isServerIconEnabled()) return CursorType.DEFAULT;
1418

15-
ServerSelectionList.OnlineServerEntry serverEntry =
16-
(ServerSelectionList.OnlineServerEntry) serverList.getChildAt(mouseX, mouseY)
17-
.filter(entry -> entry instanceof ServerSelectionList.OnlineServerEntry)
18-
.orElse(null);
19-
if (serverEntry != null && mouseX >= serverList.getRowLeft() && mouseX <= serverList.getRowLeft() + ICON_SIZE) {
20-
return CursorType.POINTER;
19+
if (mouseX <= serverList.getRowLeft() + ICON_SIZE) {
20+
List<ServerSelectionList.Entry> entries = serverList.children();
21+
for (int i = 0; i <= entries.size(); i++) {
22+
if (entries.get(i) instanceof ServerSelectionList.OnlineServerEntry entry && entry.isMouseOver(mouseX, mouseY)) {
23+
OnlineServerEntryAccessor accessor = (OnlineServerEntryAccessor) entry;
24+
double relativeX = mouseX - serverList.getRowLeft();
25+
double relativeY = mouseY - serverList.getRowTop(i);
26+
27+
if (relativeX < ICON_SIZE && relativeX > MOVE_ICON_SIZE && accessor.invokeCanJoin()) {
28+
return CursorType.POINTER;
29+
}
30+
if (relativeX < MOVE_ICON_SIZE && relativeY < MOVE_ICON_SIZE && i > 0) {
31+
return CursorType.POINTER;
32+
}
33+
if (relativeX < MOVE_ICON_SIZE && relativeY > MOVE_ICON_SIZE && i < accessor.getScreen().getServers().size() - 1) {
34+
return CursorType.POINTER;
35+
}
36+
}
37+
}
2138
}
39+
2240
return CursorType.DEFAULT;
2341
}
2442
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.fishstiz.minecraftcursor.mixin.cursorhandler.access;
2+
3+
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
4+
import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.gen.Accessor;
7+
import org.spongepowered.asm.mixin.gen.Invoker;
8+
9+
@Mixin(ServerSelectionList.OnlineServerEntry.class)
10+
public interface OnlineServerEntryAccessor {
11+
@Accessor("screen")
12+
JoinMultiplayerScreen getScreen();
13+
14+
@Invoker("canJoin")
15+
boolean invokeCanJoin();
16+
}

common/src/main/resources/minecraft-cursor.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"cursorhandler.access.CreativeInventoryScreenAccessor",
1414
"cursorhandler.access.HandledScreenAccessor",
1515
"cursorhandler.access.LoomScreenAccessor",
16+
"cursorhandler.access.OnlineServerEntryAccessor",
1617
"cursorhandler.access.RecipeAlternativesWidgetAccessor",
1718
"cursorhandler.access.RecipeBookResultsAccessor",
1819
"cursorhandler.access.RecipeBookScreenAccessor",

0 commit comments

Comments
 (0)