From dc92d0a4d262b633e9f322def3e89ab1a05417ab Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 5 Feb 2021 21:55:26 +0800 Subject: More Signed-off-by: shedaniel --- .../me/shedaniel/rei/impl/RecipeRegistryImpl.java | 47 ++++++++-------------- 1 file changed, 16 insertions(+), 31 deletions(-) (limited to 'runtime/src/main/java/me/shedaniel/rei/impl/RecipeRegistryImpl.java') 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_COMPARATOR = Comparator.comparing((Recipe o) -> o.getId().getNamespace()).thenComparing(o -> o.getId().getPath()); +public class RecipeRegistryImpl implements RecipeRegistry, ParentReloadable { + private static final Comparator> RECIPE_COMPARATOR = Comparator.comparing((Recipe o) -> o.getId().getNamespace()).thenComparing(o -> o.getId().getPath()); + private final List reloadables = new ArrayList<>(); private final List focusedStackProviders = Lists.newArrayList(); private final List autoTransferHandlers = Lists.newArrayList(); private final List> recipeFunctions = Lists.newArrayList(); @@ -74,12 +77,15 @@ public class RecipeRegistryImpl implements RecipeRegistry { private final Map> recipeDisplays = Maps.newHashMap(); private final BiMap, ResourceLocation> categories = HashBiMap.create(); private final Map autoCraftAreaSupplierMap = Maps.newHashMap(); - private final Map>>> categoryWorkingStations = Maps.newHashMap(); private final List displayVisibilityHandlers = Lists.newArrayList(); private final List> liveRecipeGenerators = Lists.newArrayList(); private RecipeManager recipeManager; private boolean arePluginsLoading = false; + public RecipeRegistryImpl() { + reloadables.add(CategoryRegistry.getInstance()); + } + @Override public List> findCraftableEntriesByItems(Iterable> inventoryItems) { List> craftables = new ArrayList<>(); @@ -112,29 +118,6 @@ public class RecipeRegistryImpl implements RecipeRegistry { return arePluginsLoading; } - @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>... 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>> getWorkingStations(ResourceLocation category) { - return categoryWorkingStations.getOrDefault(category, Collections.emptyList()); - } - @Override public void registerDisplay(Display display) { ResourceLocation identifier = Objects.requireNonNull(display.getRecipeCategory()); @@ -347,6 +330,9 @@ public class RecipeRegistryImpl implements RecipeRegistry { MutablePair 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(); -- cgit