|
@@ -22,8 +22,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
public class BaseBoundsHandlerImpl implements BaseBoundsHandler {
|
|
|
|
|
|
- private static final Function<Rectangle, String> RECTANGLE_STRING_FUNCTION = rectangle -> rectangle.x + "," + rectangle.y + "," + rectangle.width + "," + rectangle.height;
|
|
|
- private static final Comparator<Rectangle> RECTANGLE_COMPARATOR = BaseBoundsHandlerImpl::compare;
|
|
|
+ private static final Function<Rectangle, Long> RECTANGLE_LONG_FUNCTION = r -> r.x + 1000l * r.y + 1000000l * r.width + 1000000000l * r.height;
|
|
|
private static final Comparator<Pair<Pair<Class<?>, Float>, Function<Boolean, List<Rectangle>>>> LIST_PAIR_COMPARATOR;
|
|
|
|
|
|
static {
|
|
@@ -31,13 +30,11 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler {
|
|
|
LIST_PAIR_COMPARATOR = comparator.reversed();
|
|
|
}
|
|
|
|
|
|
- private String lastArea = null;
|
|
|
+ private long lastArea = -1;
|
|
|
private List<Pair<Pair<Class<?>, Float>, Function<Boolean, List<Rectangle>>>> list = Lists.newArrayList();
|
|
|
|
|
|
- private static int compare(Rectangle o1, Rectangle o2) {return RECTANGLE_STRING_FUNCTION.apply(o1).compareTo(RECTANGLE_STRING_FUNCTION.apply(o2));}
|
|
|
-
|
|
|
@Override
|
|
|
- public Class getBaseSupportedClass() {
|
|
|
+ public Class<?> getBaseSupportedClass() {
|
|
|
return Screen.class;
|
|
|
}
|
|
|
|
|
@@ -66,13 +63,10 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler {
|
|
|
|
|
|
@Override
|
|
|
public boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) {
|
|
|
- if (lastArea == null) {
|
|
|
- lastArea = getStringFromCurrent(isOnRightSide);
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (lastArea.contentEquals(getStringFromCurrent(isOnRightSide)))
|
|
|
+ long current = getStringFromCurrent(isOnRightSide);
|
|
|
+ if (lastArea == current)
|
|
|
return false;
|
|
|
- lastArea = getStringFromCurrent(isOnRightSide);
|
|
|
+ lastArea = current;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -80,8 +74,8 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler {
|
|
|
return RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass());
|
|
|
}
|
|
|
|
|
|
- private String getStringFromCurrent(boolean isOnRightSide) {
|
|
|
- return getStringFromAreas(isOnRightSide ? getHandler().getRightBounds(MinecraftClient.getInstance().currentScreen) : getHandler().getLeftBounds(MinecraftClient.getInstance().currentScreen), getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide));
|
|
|
+ private long getStringFromCurrent(boolean isOnRightSide) {
|
|
|
+ return getLongFromAreas(isOnRightSide ? getHandler().getRightBounds(MinecraftClient.getInstance().currentScreen) : getHandler().getLeftBounds(MinecraftClient.getInstance().currentScreen), getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -106,10 +100,11 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler {
|
|
|
list.add(new Pair<>(new Pair<>(screenClass, 0f), supplier));
|
|
|
}
|
|
|
|
|
|
- public String getStringFromAreas(Rectangle rectangle, List<Rectangle> exclusionZones) {
|
|
|
- List<Rectangle> sorted = Lists.newArrayList(exclusionZones);
|
|
|
- sorted.sort(RECTANGLE_COMPARATOR);
|
|
|
- return RECTANGLE_STRING_FUNCTION.apply(rectangle) + ":" + sorted.stream().map(RECTANGLE_STRING_FUNCTION::apply).collect(Collectors.joining("|"));
|
|
|
+ public long getLongFromAreas(Rectangle rectangle, List<Rectangle> exclusionZones) {
|
|
|
+ long a = RECTANGLE_LONG_FUNCTION.apply(rectangle);
|
|
|
+ for(Rectangle exclusionZone : exclusionZones)
|
|
|
+ a -= RECTANGLE_LONG_FUNCTION.apply(exclusionZone);
|
|
|
+ return a;
|
|
|
}
|
|
|
|
|
|
}
|