aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/impl/ExclusionZonesImpl.java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-03-20 17:20:54 +0800
committershedaniel <daniel@shedaniel.me>2021-03-20 17:20:54 +0800
commit0292fa5317106c46a39cd39e9664936f807b6270 (patch)
treef92cf071d1361be177af6c966148b8fd1c26613a /runtime/src/main/java/me/shedaniel/rei/impl/ExclusionZonesImpl.java
parent2cd3f0737b2008e37f8eaadf479312c60d36e7bc (diff)
downloadRoughlyEnoughItems-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/ExclusionZonesImpl.java')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/ExclusionZonesImpl.java15
1 files changed, 8 insertions, 7 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) {