From fd494eb06de4ed01edb3074a7c59c0d55877875a Mon Sep 17 00:00:00 2001 From: ThatGravyBoat Date: Tue, 30 Jan 2024 22:10:27 -0330 Subject: [PATCH] Check if mouse is in bounds to do cursor operations. backport cursor bound check from 1.20.4 --- .../client/screens/BaseCursorScreen.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/BaseCursorScreen.java b/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/BaseCursorScreen.java index 654815b..baa8255 100644 --- a/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/BaseCursorScreen.java +++ b/common/src/main/java/com/teamresourceful/resourcefullib/client/screens/BaseCursorScreen.java @@ -16,21 +16,26 @@ protected BaseCursorScreen(Component component) { @Override public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float f) { - setCursor(Cursor.DEFAULT); - actuallyRender(graphics, mouseX, mouseY, f); - setCursor(children(), mouseX, mouseY); - - switch (cursor) { - case DEFAULT -> CursorUtils.setDefault(); - case POINTER -> CursorUtils.setPointing(); - case DISABLED -> CursorUtils.setDisabled(); - case TEXT -> CursorUtils.setText(); - case CROSSHAIR -> CursorUtils.setCrosshair(); - case RESIZE_EW -> CursorUtils.setResizeEastWest(); - case RESIZE_NS -> CursorUtils.setResizeNorthSouth(); - case RESIZE_NESW -> CursorUtils.setResizeNorthEastSouthWest(); - case RESIZE_NWSE -> CursorUtils.setResizeNorthWestSouthEast(); - case RESIZE_ALL -> CursorUtils.setResizeAll(); + boolean wihinBounds = mouseX >= 0 && mouseY >= 0 && mouseX < this.width && mouseY < this.height; + if (!wihinBounds) { + actuallyRender(graphics, mouseX, mouseY, f); + } else { + setCursor(Cursor.DEFAULT); + actuallyRender(graphics, mouseX, mouseY, f); + setCursor(children(), mouseX, mouseY); + + switch (cursor) { + case DEFAULT -> CursorUtils.setDefault(); + case POINTER -> CursorUtils.setPointing(); + case DISABLED -> CursorUtils.setDisabled(); + case TEXT -> CursorUtils.setText(); + case CROSSHAIR -> CursorUtils.setCrosshair(); + case RESIZE_EW -> CursorUtils.setResizeEastWest(); + case RESIZE_NS -> CursorUtils.setResizeNorthSouth(); + case RESIZE_NESW -> CursorUtils.setResizeNorthEastSouthWest(); + case RESIZE_NWSE -> CursorUtils.setResizeNorthWestSouthEast(); + case RESIZE_ALL -> CursorUtils.setResizeAll(); + } } }