aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/impl/RecipeRegistryImpl.java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-02-05 21:55:26 +0800
committershedaniel <daniel@shedaniel.me>2021-02-05 21:55:26 +0800
commitdc92d0a4d262b633e9f322def3e89ab1a05417ab (patch)
tree75d51513b5d930f0456959c6034ba02e21cf12d5 /runtime/src/main/java/me/shedaniel/rei/impl/RecipeRegistryImpl.java
parentea634e7ba29146d4ebc2c05b61257fa6c3b0642e (diff)
downloadRoughlyEnoughItems-dc92d0a4d262b633e9f322def3e89ab1a05417ab.tar.gz
RoughlyEnoughItems-dc92d0a4d262b633e9f322def3e89ab1a05417ab.tar.bz2
RoughlyEnoughItems-dc92d0a4d262b633e9f322def3e89ab1a05417ab.zip
More
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/impl/RecipeRegistryImpl.java')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/RecipeRegistryImpl.java47
1 files changed, 16 insertions, 31 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/RecipeRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/RecipeRegistryImpl.java
index e983bc535..ff94be58c 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/RecipeRegistryImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/RecipeRegistryImpl.java
@@ -33,10 +33,14 @@ import me.shedaniel.rei.api.ingredient.EntryIngredient;
import me.shedaniel.rei.api.ingredient.EntryStack;
import me.shedaniel.rei.api.ingredient.util.EntryStacks;
import me.shedaniel.rei.api.plugins.REIPluginV0;
-import me.shedaniel.rei.api.registry.category.DisplayCategory;
+import me.shedaniel.rei.api.registry.CategoryRegistry;
+import me.shedaniel.rei.api.registry.ParentReloadable;
+import me.shedaniel.rei.api.registry.Reloadable;
+import me.shedaniel.rei.api.registry.display.Display;
+import me.shedaniel.rei.api.registry.display.DisplayCategory;
import me.shedaniel.rei.api.subsets.SubsetsRegistry;
+import me.shedaniel.rei.api.util.CollectionUtils;
import me.shedaniel.rei.impl.subsets.SubsetsRegistryImpl;
-import me.shedaniel.rei.utils.CollectionUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.Util;
@@ -58,14 +62,13 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
@ApiStatus.Internal
@Environment(EnvType.CLIENT)
-public class RecipeRegistryImpl implements RecipeRegistry {
- @SuppressWarnings("rawtypes")
- private static final Comparator<Recipe> RECIPE_COMPARATOR = Comparator.comparing((Recipe o) -> o.getId().getNamespace()).thenComparing(o -> o.getId().getPath());
+public class RecipeRegistryImpl implements RecipeRegistry, ParentReloadable {
+ private static final Comparator<Recipe<?>> RECIPE_COMPARATOR = Comparator.comparing((Recipe<?> o) -> o.getId().getNamespace()).thenComparing(o -> o.getId().getPath());
+ private final List<Reloadable> reloadables = new ArrayList<>();
private final List<FocusedStackProvider> focusedStackProviders = Lists.newArrayList();
private final List<AutoTransferHandler> autoTransferHandlers = Lists.newArrayList();
private final List<RecipeFunction<?>> recipeFunctions = Lists.newArrayList();
@@ -74,12 +77,15 @@ public class RecipeRegistryImpl implements RecipeRegistry {
private final Map<ResourceLocation, List<Display>> recipeDisplays = Maps.newHashMap();
private final BiMap<DisplayCategory<?>, ResourceLocation> categories = HashBiMap.create();
private final Map<ResourceLocation, ButtonAreaSupplier> autoCraftAreaSupplierMap = Maps.newHashMap();
- private final Map<ResourceLocation, List<List<? extends EntryStack<?>>>> categoryWorkingStations = Maps.newHashMap();
private final List<DisplayVisibilityHandler> displayVisibilityHandlers = Lists.newArrayList();
private final List<LiveRecipeGenerator<Display>> liveRecipeGenerators = Lists.newArrayList();
private RecipeManager recipeManager;
private boolean arePluginsLoading = false;
+ public RecipeRegistryImpl() {
+ reloadables.add(CategoryRegistry.getInstance());
+ }
+
@Override
public List<EntryStack<?>> findCraftableEntriesByItems(Iterable<? extends EntryStack<?>> inventoryItems) {
List<EntryStack<?>> craftables = new ArrayList<>();
@@ -113,29 +119,6 @@ public class RecipeRegistryImpl implements RecipeRegistry {
}
@Override
- public void registerCategory(DisplayCategory<?> category) {
- categories.put(category, category.getIdentifier());
- recipeDisplays.put(category.getIdentifier(), Lists.newArrayList());
- categoryWorkingStations.put(category.getIdentifier(), Lists.newArrayList());
- }
-
- @SafeVarargs
- @Override
- public final void registerWorkingStations(ResourceLocation category, List<? extends EntryStack<?>>... workingStations) {
- categoryWorkingStations.get(category).addAll(Arrays.asList(workingStations));
- }
-
- @Override
- public void registerWorkingStations(ResourceLocation category, EntryStack<?>... workingStations) {
- categoryWorkingStations.get(category).addAll(Stream.of(workingStations).map(Collections::singletonList).collect(Collectors.toList()));
- }
-
- @Override
- public List<List<? extends EntryStack<?>>> getWorkingStations(ResourceLocation category) {
- return categoryWorkingStations.getOrDefault(category, Collections.emptyList());
- }
-
- @Override
public void registerDisplay(Display display) {
ResourceLocation identifier = Objects.requireNonNull(display.getRecipeCategory());
if (!recipeDisplays.containsKey(identifier))
@@ -347,6 +330,9 @@ public class RecipeRegistryImpl implements RecipeRegistry {
MutablePair<Stopwatch, String> sectionData = new MutablePair<>(Stopwatch.createUnstarted(), "");
startSection(sectionData, "reset-data");
+ for (Reloadable reloadable : reloadables) {
+ reloadable.resetData();
+ }
arePluginsLoading = true;
ScreenHelper.clearLastRecipeScreenData();
recipeCount.setValue(0);
@@ -355,7 +341,6 @@ public class RecipeRegistryImpl implements RecipeRegistry {
this.categories.clear();
this.autoCraftAreaSupplierMap.clear();
this.screenClickAreas.clear();
- this.categoryWorkingStations.clear();
this.recipeFunctions.clear();
this.displayVisibilityHandlers.clear();
this.liveRecipeGenerators.clear();