diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-03-20 17:20:54 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-03-20 17:20:54 +0800 |
| commit | 0292fa5317106c46a39cd39e9664936f807b6270 (patch) | |
| tree | f92cf071d1361be177af6c966148b8fd1c26613a /runtime/src/main/java/me/shedaniel/rei/impl | |
| parent | 2cd3f0737b2008e37f8eaadf479312c60d36e7bc (diff) | |
| download | RoughlyEnoughItems-0292fa5317106c46a39cd39e9664936f807b6270.tar.gz RoughlyEnoughItems-0292fa5317106c46a39cd39e9664936f807b6270.tar.bz2 RoughlyEnoughItems-0292fa5317106c46a39cd39e9664936f807b6270.zip | |
Refactor exclusion zones, wrap JEI exclusion zones
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/impl')
3 files changed, 18 insertions, 17 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/ExclusionZonesImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/ExclusionZonesImpl.java index 8bdd2c472..e7cc29564 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/ExclusionZonesImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/ExclusionZonesImpl.java @@ -29,6 +29,7 @@ import com.google.common.collect.Multimap; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.gui.config.DisplayPanelLocation; import me.shedaniel.rei.api.registry.screen.ExclusionZones; +import me.shedaniel.rei.api.registry.screen.ExclusionZonesProvider; import me.shedaniel.rei.api.registry.screen.ScreenRegistry; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -49,7 +50,7 @@ public class ExclusionZonesImpl implements ExclusionZones { private static final Comparator<? super Rectangle> RECTANGLE_COMPARER = Comparator.comparingLong(Rectangle::hashCode); private long lastArea = -1; - private Multimap<Class<?>, Supplier<List<Rectangle>>> list = HashMultimap.create(); + private Multimap<Class<?>, Supplier<Collection<Rectangle>>> list = HashMultimap.create(); @Override public <R extends Screen> boolean isHandingScreen(Class<R> screen) { @@ -65,9 +66,9 @@ public class ExclusionZonesImpl implements ExclusionZones { public InteractionResult isInZone(double mouseX, double mouseY) { Class<? extends Screen> screenClass = Minecraft.getInstance().screen.getClass(); - for (Map.Entry<Class<?>, Collection<Supplier<List<Rectangle>>>> collectionEntry : list.asMap().entrySet()) { + for (Map.Entry<Class<?>, Collection<Supplier<Collection<Rectangle>>>> collectionEntry : list.asMap().entrySet()) { if (collectionEntry.getKey().isAssignableFrom(screenClass)) { - for (Supplier<List<Rectangle>> listSupplier : collectionEntry.getValue()) { + for (Supplier<Collection<Rectangle>> listSupplier : collectionEntry.getValue()) { for (Rectangle zone : listSupplier.get()) { if (zone.contains(mouseX, mouseY)) { return InteractionResult.FAIL; @@ -97,9 +98,9 @@ public class ExclusionZonesImpl implements ExclusionZones { @Override public List<Rectangle> getExclusionZones(Class<?> currentScreenClass, boolean sort) { List<Rectangle> rectangles = Lists.newArrayList(); - for (Map.Entry<Class<?>, Collection<Supplier<List<Rectangle>>>> collectionEntry : list.asMap().entrySet()) { + for (Map.Entry<Class<?>, Collection<Supplier<Collection<Rectangle>>>> collectionEntry : list.asMap().entrySet()) { if (collectionEntry.getKey().isAssignableFrom(currentScreenClass)) { - for (Supplier<List<Rectangle>> listSupplier : collectionEntry.getValue()) { + for (Supplier<Collection<Rectangle>> listSupplier : collectionEntry.getValue()) { rectangles.addAll(listSupplier.get()); } } @@ -116,8 +117,8 @@ public class ExclusionZonesImpl implements ExclusionZones { } @Override - public void register(Class<?> screenClass, Supplier<List<Rectangle>> supplier) { - list.put(screenClass, supplier); + public <T> void register(Class<? extends T> screenClass, ExclusionZonesProvider<? extends T> provider) { + list.put(screenClass, () -> ((ExclusionZonesProvider<T>) provider).provide((T) Minecraft.getInstance().screen)); } private long areasHashCode(Rectangle rectangle, List<Rectangle> exclusionZones) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/REIHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/REIHelperImpl.java index cef610c4a..0884d70d7 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/REIHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/REIHelperImpl.java @@ -29,10 +29,10 @@ import com.mojang.blaze3d.platform.Window; import me.shedaniel.architectury.event.events.GuiEvent; import me.shedaniel.architectury.event.events.client.ClientTickEvent; import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.config.ConfigManager; -import me.shedaniel.rei.api.config.ConfigObject; import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.api.REIOverlay; +import me.shedaniel.rei.api.config.ConfigManager; +import me.shedaniel.rei.api.config.ConfigObject; import me.shedaniel.rei.api.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.gui.widgets.TextField; import me.shedaniel.rei.api.gui.widgets.Tooltip; @@ -175,7 +175,7 @@ public class REIHelperImpl implements REIHelper { @Override public SearchFieldLocation getContextualSearchFieldLocation() { Window window = Minecraft.getInstance().getWindow(); - for (OverlayDecider decider : ScreenRegistry.getInstance().getDeciders(Minecraft.getInstance().screen.getClass())) { + for (OverlayDecider decider : ScreenRegistry.getInstance().getDeciders(Minecraft.getInstance().screen)) { if (decider instanceof DisplayBoundsProvider) { Rectangle containerBounds = ((DisplayBoundsProvider<Screen>) decider).getScreenBounds(Minecraft.getInstance().screen); if (window.getGuiScaledHeight() - 20 <= containerBounds.getMaxY()) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java index bc21380b8..ff7dca9a2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/ScreenRegistryImpl.java @@ -26,9 +26,8 @@ package me.shedaniel.rei.impl; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.mojang.blaze3d.platform.Window; +import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.registry.screen.FocusedStackProvider; -import me.shedaniel.rei.api.registry.screen.SimpleClickArea; import me.shedaniel.rei.api.gui.config.DisplayPanelLocation; import me.shedaniel.rei.api.ingredient.EntryStack; import me.shedaniel.rei.api.ingredient.util.EntryStacks; @@ -70,7 +69,8 @@ public class ScreenRegistryImpl implements ScreenRegistry { } @Override - public <R extends Screen> List<OverlayDecider> getDeciders(Class<R> screenClass) { + public <R extends Screen> List<OverlayDecider> getDeciders(R screen) { + Class<? extends Screen> screenClass = screen.getClass(); List<OverlayDecider> possibleCached = cache.get(screenClass); if (possibleCached != null) { return possibleCached; @@ -97,7 +97,7 @@ public class ScreenRegistryImpl implements ScreenRegistry { Window window = Minecraft.getInstance().getWindow(); int scaledWidth = window.getGuiScaledWidth(); int scaledHeight = window.getGuiScaledHeight(); - for (OverlayDecider decider : getDeciders(screen.getClass())) { + for (OverlayDecider decider : getDeciders(screen)) { if (decider instanceof DisplayBoundsProvider) { Rectangle containerBounds = ((DisplayBoundsProvider<T>) decider).getScreenBounds(screen); if (location == DisplayPanelLocation.LEFT) { @@ -114,9 +114,9 @@ public class ScreenRegistryImpl implements ScreenRegistry { @Nullable @Override - public <T extends Screen> EntryStack<?> getFocusedStack(T screen) { + public <T extends Screen> EntryStack<?> getFocusedStack(T screen, Point mouse) { for (FocusedStackProvider provider : focusedStackProviders) { - InteractionResultHolder<EntryStack<?>> result = Objects.requireNonNull(provider.provide(screen)); + InteractionResultHolder<EntryStack<?>> result = Objects.requireNonNull(provider.provide(screen, mouse)); if (result.getResult() == InteractionResult.SUCCESS) { if (result != null && !result.getObject().isEmpty()) return result.getObject(); @@ -211,7 +211,7 @@ public class ScreenRegistryImpl implements ScreenRegistry { registerFocusedStack(new FocusedStackProvider() { @Override @NotNull - public InteractionResultHolder<EntryStack<?>> provide(Screen screen) { + public InteractionResultHolder<EntryStack<?>> provide(Screen screen, Point mouse) { if (screen instanceof AbstractContainerScreen) { AbstractContainerScreen<?> containerScreen = (AbstractContainerScreen<?>) screen; if (containerScreen.hoveredSlot != null && !containerScreen.hoveredSlot.getItem().isEmpty()) |
