void (@NotNull Rectangle rect) { int screenX = rect.x; int screenY = rect.y; final Rectangle screen = getScreenRectangle(screenX, screenY); if (rect.getMaxX() > screen.getMaxX()) { rect.width = (int)screen.getMaxX() - rect.x; } if (rect.getMinX() < screen.getMinX()) { rect.x = (int)screen.getMinX(); } if (rect.getMaxY() > screen.getMaxY()) { rect.height = (int)screen.getMaxY() - rect.y; } if (rect.getMinY() < screen.getMinY()) { rect.y = (int)screen.getMinY(); } }