aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-07-15 22:27:07 +0800
committershedaniel <daniel@shedaniel.me>2020-07-15 22:27:07 +0800
commitcd57003454840efd74ef072072402ea3822ab2ba (patch)
tree481af32e3a330d48eba88e1fa4c4fa5a976f5377 /src/main/java
parent7d1e39007a1e7de6fd0381fa1e21cf9b6e927f97 (diff)
downloadRoughlyEnoughItems-cd57003454840efd74ef072072402ea3822ab2ba.tar.gz
RoughlyEnoughItems-cd57003454840efd74ef072072402ea3822ab2ba.tar.bz2
RoughlyEnoughItems-cd57003454840efd74ef072072402ea3822ab2ba.zip
Close #322
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/me/shedaniel/rei/api/DisplayHelper.java3
-rw-r--r--src/main/java/me/shedaniel/rei/api/EntryRegistry.java14
-rw-r--r--src/main/java/me/shedaniel/rei/api/REIHelper.java5
-rw-r--r--src/main/java/me/shedaniel/rei/api/REIOverlay.java31
-rw-r--r--src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java7
-rw-r--r--src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java4
-rw-r--r--src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java29
-rw-r--r--src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java12
-rw-r--r--src/main/java/me/shedaniel/rei/impl/ScreenHelper.java6
9 files changed, 99 insertions, 12 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java
index fe5c77950..33752431f 100644
--- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java
+++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java
@@ -99,6 +99,9 @@ public interface DisplayHelper {
*/
<T> Rectangle getOverlayBounds(DisplayPanelLocation location, T screen);
+ @ApiStatus.Experimental
+ void resetCache();
+
interface DisplayBoundsProvider<T> extends OverlayDecider {
/**
* @param screen the screen
diff --git a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java
index 449dae8d7..da334aac4 100644
--- a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java
+++ b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java
@@ -24,7 +24,6 @@
package me.shedaniel.rei.api;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
-import me.shedaniel.rei.utils.CollectionUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.item.Item;
@@ -36,6 +35,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -68,6 +68,9 @@ public interface EntryRegistry {
@NotNull
List<EntryStack> getPreFilteredList();
+ @ApiStatus.Experimental
+ void refilter();
+
@NotNull
List<ItemStack> appendStacksForItem(@NotNull Item item);
@@ -145,8 +148,11 @@ public interface EntryRegistry {
* @param stack the stack to check
* @return whether the stack has been registered
*/
- default boolean alreadyContain(EntryStack stack) {
- return CollectionUtils.anyMatchEqualsAll(getStacksList(), stack);
- }
+ boolean alreadyContain(EntryStack stack);
+
+ @ApiStatus.Experimental
+ void removeEntry(EntryStack stack);
+ @ApiStatus.Experimental
+ void removeEntryIf(Predicate<EntryStack> stackPredicate);
}
diff --git a/src/main/java/me/shedaniel/rei/api/REIHelper.java b/src/main/java/me/shedaniel/rei/api/REIHelper.java
index 2a0dffc64..0c0275b70 100644
--- a/src/main/java/me/shedaniel/rei/api/REIHelper.java
+++ b/src/main/java/me/shedaniel/rei/api/REIHelper.java
@@ -30,9 +30,11 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ingame.ContainerScreen;
import net.minecraft.item.ItemStack;
+import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.List;
+import java.util.Optional;
@Environment(EnvType.CLIENT)
public interface REIHelper {
@@ -44,6 +46,9 @@ public interface REIHelper {
return ScreenHelper.getInstance();
}
+ @ApiStatus.Experimental
+ Optional<REIOverlay> getOverlay();
+
ContainerScreen<?> getPreviousContainerScreen();
@Deprecated
diff --git a/src/main/java/me/shedaniel/rei/api/REIOverlay.java b/src/main/java/me/shedaniel/rei/api/REIOverlay.java
new file mode 100644
index 000000000..24eaf15bd
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/api/REIOverlay.java
@@ -0,0 +1,31 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.api;
+
+import org.jetbrains.annotations.ApiStatus;
+
+@ApiStatus.Experimental
+public interface REIOverlay {
+ void queueReloadOverlay();
+}
diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java
index 8a3cd5a6f..7b4b9ead7 100644
--- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java
+++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java
@@ -79,7 +79,7 @@ import java.util.LinkedList;
import java.util.List;
@ApiStatus.Internal
-public class ContainerScreenOverlay extends WidgetWithBounds {
+public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverlay {
private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
private static final List<Tooltip> TOOLTIPS = Lists.newArrayList();
@@ -172,6 +172,11 @@ public class ContainerScreenOverlay extends WidgetWithBounds {
this.wrappedGameModeMenu = null;
}
+ @Override
+ public void queueReloadOverlay() {
+ shouldReInit = true;
+ }
+
public void init(boolean useless) {
init();
}
diff --git a/src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java b/src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java
index a4132e043..99411bb34 100644
--- a/src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java
+++ b/src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java
@@ -159,9 +159,11 @@ public class DisplayHelperImpl implements DisplayHelper {
screenDisplayBoundsHandlers.clear();
}
- @ApiStatus.Internal
+ @ApiStatus.Experimental
+ @Override
public void resetCache() {
handlerCache.clear();
+ deciderSortedCache.clear();
handlerSortedCache.clear();
}
diff --git a/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java b/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java
index fcc62fe23..b4849b4e9 100644
--- a/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java
+++ b/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java
@@ -42,6 +42,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
+import java.util.function.Predicate;
import java.util.stream.Stream;
@ApiStatus.Internal
@@ -82,6 +83,8 @@ public class EntryRegistryImpl implements EntryRegistry {
return preFilteredList;
}
+ @Override
+ @ApiStatus.Experimental
public void refilter() {
long started = System.currentTimeMillis();
@@ -155,4 +158,30 @@ public class EntryRegistryImpl implements EntryRegistry {
} else entries.addAll(stacks);
}
}
+
+ @Override
+ public boolean alreadyContain(EntryStack stack) {
+ if (reloading) {
+ return reloadingRegistry.parallelStream().anyMatch(s -> s.unwrap().equalsAll(stack));
+ }
+ return entries.parallelStream().anyMatch(s -> s.equalsAll(stack));
+ }
+
+ @Override
+ public void removeEntry(EntryStack stack) {
+ if (reloading) {
+ reloadingRegistry.remove(new AmountIgnoredEntryStackWrapper(stack));
+ } else {
+ entries.remove(stack);
+ }
+ }
+
+ @Override
+ public void removeEntryIf(Predicate<EntryStack> stackPredicate) {
+ if (reloading) {
+ reloadingRegistry.removeIf(wrapper -> stackPredicate.test(wrapper.unwrap()));
+ } else {
+ entries.removeIf(stackPredicate);
+ }
+ }
}
diff --git a/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java
index 60f01a738..b9d23b679 100644
--- a/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java
+++ b/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java
@@ -365,7 +365,7 @@ public class RecipeHelperImpl implements RecipeHelper {
((SubsetsRegistryImpl) SubsetsRegistry.INSTANCE).reset();
((FluidSupportProviderImpl) FluidSupportProvider.INSTANCE).reset();
((DisplayHelperImpl) DisplayHelper.getInstance()).resetData();
- ((DisplayHelperImpl) DisplayHelper.getInstance()).resetCache();
+ DisplayHelper.getInstance().resetCache();
BaseBoundsHandler baseBoundsHandler = new BaseBoundsHandlerImpl();
DisplayHelper.getInstance().registerHandler(baseBoundsHandler);
((DisplayHelperImpl) DisplayHelper.getInstance()).setBaseBoundsHandler(baseBoundsHandler);
@@ -443,8 +443,8 @@ public class RecipeHelperImpl implements RecipeHelper {
endSection(sectionData);
// Clear Cache
- ((DisplayHelperImpl) DisplayHelper.getInstance()).resetCache();
- ScreenHelper.getOptionalOverlay().ifPresent(overlay -> overlay.shouldReInit = true);
+ DisplayHelper.getInstance().resetCache();
+ REIHelper.getInstance().getOverlay().ifPresent(REIOverlay::queueReloadOverlay);
startSection(sectionData, "entry-registry-finalise");
@@ -455,14 +455,14 @@ public class RecipeHelperImpl implements RecipeHelper {
startSection(sectionData, "entry-registry-refilter");
arePluginsLoading = false;
- ((EntryRegistryImpl) EntryRegistry.getInstance()).refilter();
+ EntryRegistry.getInstance().refilter();
endSection(sectionData);
startSection(sectionData, "finalizing");
// Clear Cache Again!
- ((DisplayHelperImpl) DisplayHelper.getInstance()).resetCache();
- ScreenHelper.getOptionalOverlay().ifPresent(overlay -> overlay.shouldReInit = true);
+ DisplayHelper.getInstance().resetCache();
+ REIHelper.getInstance().getOverlay().ifPresent(REIOverlay::queueReloadOverlay);
displayVisibilityHandlers.sort(VISIBILITY_HANDLER_COMPARATOR);
endSection(sectionData);
diff --git a/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java b/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
index 7068e15ce..e1c4da05c 100644
--- a/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
+++ b/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
@@ -34,6 +34,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsState;
import me.shedaniel.rei.api.ConfigManager;
import me.shedaniel.rei.api.ConfigObject;
import me.shedaniel.rei.api.REIHelper;
+import me.shedaniel.rei.api.REIOverlay;
import me.shedaniel.rei.api.widgets.Tooltip;
import me.shedaniel.rei.gui.ContainerScreenOverlay;
import me.shedaniel.rei.gui.OverlaySearchField;
@@ -143,6 +144,11 @@ public class ScreenHelper implements ClientModInitializer, REIHelper {
return Optional.ofNullable(overlay);
}
+ @Override
+ public Optional<REIOverlay> getOverlay() {
+ return Optional.ofNullable(overlay);
+ }
+
public static ContainerScreenOverlay getLastOverlay(boolean reset, boolean setPage) {
if (overlay == null || reset) {
overlay = new ContainerScreenOverlay();