DisplayHelper.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.api;
  6. import me.shedaniel.math.api.Rectangle;
  7. import me.shedaniel.rei.RoughlyEnoughItemsCore;
  8. import net.minecraft.util.ActionResult;
  9. import java.util.List;
  10. import static net.minecraft.util.ActionResult.PASS;
  11. public interface DisplayHelper {
  12. /**
  13. * Gets the sorted version of all responsible bounds handlers
  14. *
  15. * @param screenClass the class for checking responsible bounds handlers
  16. * @return the sorted list of responsible bounds handlers
  17. * @see DisplayHelper#getResponsibleBoundsHandler(Class) for the unsorted version
  18. */
  19. List<DisplayBoundsHandler<?>> getSortedBoundsHandlers(Class<?> screenClass);
  20. /**
  21. * Gets all registered bounds handlers
  22. *
  23. * @return the list of registered bounds handlers
  24. */
  25. List<DisplayBoundsHandler<?>> getAllBoundsHandlers();
  26. /**
  27. * Gets all responsible bounds handlers
  28. *
  29. * @param screenClass the class for checking responsible bounds handlers
  30. * @return the the list of responsible bounds handlers
  31. * @see DisplayHelper#getSortedBoundsHandlers(Class) for the sorted version
  32. */
  33. DisplayBoundsHandler<?> getResponsibleBoundsHandler(Class<?> screenClass);
  34. /**
  35. * Registers a bounds handler
  36. *
  37. * @param handler the handler to register
  38. */
  39. void registerBoundsHandler(DisplayBoundsHandler<?> handler);
  40. /**
  41. * Gets the base bounds handler api for exclusion zones
  42. *
  43. * @return the base bounds handler
  44. */
  45. BaseBoundsHandler getBaseBoundsHandler();
  46. public static interface DisplayBoundsHandler<T> {
  47. /**
  48. * Gets the base supported class for the bounds handler
  49. *
  50. * @return the base class
  51. */
  52. Class<?> getBaseSupportedClass();
  53. /**
  54. * Gets the left bounds of the overlay
  55. *
  56. * @param screen the current screen
  57. * @return the left bounds
  58. */
  59. Rectangle getLeftBounds(T screen);
  60. /**
  61. * Gets the right bounds of the overlay
  62. *
  63. * @param screen the current screen
  64. * @return the right bounds
  65. */
  66. Rectangle getRightBounds(T screen);
  67. /**
  68. * Checks if item slot can fit the screen
  69. *
  70. * @param isOnRightSide whether the user has set the overlay to the right
  71. * @param left the left x coordinates of the stack
  72. * @param top the top y coordinates for the stack
  73. * @param screen the current screen
  74. * @param fullBounds the current bounds
  75. * @return whether the item slot can fit
  76. * @see BaseBoundsHandler#registerExclusionZones(Class, BaseBoundsHandler.ExclusionZoneSupplier) for easier api
  77. */
  78. default ActionResult canItemSlotWidgetFit(boolean isOnRightSide, int left, int top, T screen, Rectangle fullBounds) {
  79. return PASS;
  80. }
  81. /**
  82. * Checks if mouse is inside the overlay
  83. *
  84. * @param isOnRightSide whether the user has set the overlay to the right
  85. * @param mouseX mouse's x coordinates
  86. * @param mouseY mouse's y coordinates
  87. * @return whether mouse is inside the overlay
  88. */
  89. default ActionResult isInZone(boolean isOnRightSide, double mouseX, double mouseY) {
  90. return PASS;
  91. }
  92. /**
  93. * Gets the item list bounds by the overlay bounds
  94. *
  95. * @param rectangle the overlay bounds
  96. * @return the item list bounds
  97. */
  98. default Rectangle getItemListArea(Rectangle rectangle) {
  99. return new Rectangle(rectangle.x + 1, rectangle.y + 2 + (RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() ? 0 : 22), rectangle.width - 2, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().isSideSearchField() ? 27 + 22 : 27) + (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() ? 0 : 22));
  100. }
  101. /**
  102. * Checks if REI should recalculate the overlay bounds
  103. *
  104. * @param isOnRightSide whether the user has set the overlay to the right
  105. * @param rectangle the current overlay bounds
  106. * @return whether REI should recalculate the overlay bounds
  107. */
  108. default boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) {
  109. return false;
  110. }
  111. /**
  112. * Gets the priority of the handler, the higher it is, the earlier it is called.
  113. *
  114. * @return the priority in float
  115. */
  116. default float getPriority() {
  117. return 0f;
  118. }
  119. }
  120. }