|
3 | 3 | import io.github.fishstiz.minecraftcursor.MinecraftCursor; |
4 | 4 | import io.github.fishstiz.minecraftcursor.api.CursorHandler; |
5 | 5 | import io.github.fishstiz.minecraftcursor.api.CursorType; |
| 6 | +import io.github.fishstiz.minecraftcursor.mixin.cursorhandler.access.OnlineServerEntryAccessor; |
6 | 7 | import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList; |
7 | 8 |
|
| 9 | +import java.util.List; |
| 10 | + |
8 | 11 | 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; |
10 | 14 |
|
11 | 15 | @Override |
12 | 16 | public CursorType getCursorType(ServerSelectionList serverList, double mouseX, double mouseY) { |
13 | 17 | if (!MinecraftCursor.CONFIG.isServerIconEnabled()) return CursorType.DEFAULT; |
14 | 18 |
|
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 | + } |
21 | 38 | } |
| 39 | + |
22 | 40 | return CursorType.DEFAULT; |
23 | 41 | } |
24 | 42 | } |
0 commit comments