diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-08-11 23:28:33 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-08-11 23:28:33 +0800 |
| commit | 28025895e0da1e6079264dbfe951e7fd9bf069d8 (patch) | |
| tree | bd28e2f6bf02a2806c4b7802fac912ed43444e43 /src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java | |
| parent | 019aa13875ca639dda2f34c66e3160f72b923cfd (diff) | |
| download | RoughlyEnoughItems-28025895e0da1e6079264dbfe951e7fd9bf069d8.tar.gz RoughlyEnoughItems-28025895e0da1e6079264dbfe951e7fd9bf069d8.tar.bz2 RoughlyEnoughItems-28025895e0da1e6079264dbfe951e7fd9bf069d8.zip | |
Scrollable Entry List?
Diffstat (limited to 'src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java b/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java deleted file mode 100644 index dfef934e7..000000000 --- a/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -import com.google.common.collect.Lists; -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.BaseBoundsHandler; -import me.shedaniel.rei.api.DisplayHelper; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Pair; - -import java.awt.*; -import java.util.Comparator; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class BaseBoundsHandlerImpl implements BaseBoundsHandler { - - 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 { - Comparator<Pair<Pair<Class<?>, Float>, Function<Boolean, List<Rectangle>>>> comparator = Comparator.comparingDouble(value -> value.getLeft().getRight()); - LIST_PAIR_COMPARATOR = comparator.reversed(); - } - - private long lastArea = -1; - private List<Pair<Pair<Class<?>, Float>, Function<Boolean, List<Rectangle>>>> list = Lists.newArrayList(); - - @Override - public Class<?> getBaseSupportedClass() { - return Screen.class; - } - - @Override - public Rectangle getLeftBounds(Screen screen) { - return new Rectangle(); - } - - @Override - public Rectangle getRightBounds(Screen screen) { - return new Rectangle(); - } - - @Override - public float getPriority() { - return -5f; - } - - @Override - public ActionResult isInZone(boolean isOnRightSide, double mouseX, double mouseY) { - for (Rectangle zone : getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide)) - if (zone.contains(mouseX, mouseY)) - return ActionResult.FAIL; - return ActionResult.PASS; - } - - @Override - public boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) { - long current = getStringFromCurrent(isOnRightSide); - if (lastArea == current) - return false; - lastArea = current; - return true; - } - - private DisplayHelper.DisplayBoundsHandler getHandler() { - return RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); - } - - 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 - public ActionResult canItemSlotWidgetFit(boolean isOnRightSide, int left, int top, Screen screen, Rectangle fullBounds) { - List<Rectangle> currentExclusionZones = getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide); - for (Rectangle currentExclusionZone : currentExclusionZones) - if (left + 18 >= currentExclusionZone.x && top + 18 >= currentExclusionZone.y && left <= currentExclusionZone.x + currentExclusionZone.width && top <= currentExclusionZone.y + currentExclusionZone.height) - return ActionResult.FAIL; - return ActionResult.PASS; - } - - public List<Rectangle> getCurrentExclusionZones(Class<?> currentScreenClass, boolean isOnRightSide) { - List<Pair<Pair<Class<?>, Float>, Function<Boolean, List<Rectangle>>>> only = list.stream().filter(pair -> pair.getLeft().getLeft().isAssignableFrom(currentScreenClass)).collect(Collectors.toList()); - only.sort(LIST_PAIR_COMPARATOR); - List<Rectangle> rectangles = Lists.newArrayList(); - only.forEach(pair -> rectangles.addAll(pair.getRight().apply(isOnRightSide))); - return rectangles; - } - - @Override - public void registerExclusionZones(Class<?> screenClass, Function<Boolean, List<Rectangle>> supplier) { - list.add(new Pair<>(new Pair<>(screenClass, 0f), supplier)); - } - - 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; - } - -} |
