Bladeren bron

Close #322

Signed-off-by: shedaniel <daniel@shedaniel.me>
shedaniel 5 jaren geleden
bovenliggende
commit
8bac41d8d6

+ 1 - 1
gradle.properties

@@ -1,5 +1,5 @@
 org.gradle.jvmargs=-Xmx3G
-mod_version=4.9.4
+mod_version=4.9.5
 supported_version=1.16.x
 minecraft_version=1.16.1
 yarn_version=1.16.1+build.4+legacy.20w09a+build.8

+ 3 - 0
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

+ 10 - 4
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);
 }

+ 5 - 0
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

+ 31 - 0
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();
+}

+ 6 - 1
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();
     }

+ 3 - 1
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();
     }
     

+ 29 - 0
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);
+        }
+    }
 }

+ 6 - 6
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);

+ 6 - 0
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();