From 8d77ad86b203de62aa08a5ee62f91e27fd0fbd00 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 30 Aug 2020 21:29:58 +0800 Subject: Fix brewing potions not appearing and allow scrolling in the tabs for villager like recipe viewing screen Signed-off-by: shedaniel --- .../me/shedaniel/rei/impl/RecipeHelperImpl.java | 51 +++++++++++----------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java') diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java index 7e3f57868..2e254962e 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl; +import com.google.common.base.Stopwatch; import com.google.common.collect.*; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; @@ -42,6 +43,7 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeManager; +import org.apache.commons.lang3.tuple.MutablePair; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -77,7 +79,7 @@ public class RecipeHelperImpl implements RecipeHelper { private boolean arePluginsLoading = false; @Override - public List findCraftableEntriesByItems(List inventoryItems) { + public List findCraftableEntriesByItems(Iterable inventoryItems) { List craftables = new ArrayList<>(); for (List value : recipeDisplays.values()) for (RecipeDisplay recipeDisplay : Lists.newArrayList(value)) { @@ -149,7 +151,7 @@ public class RecipeHelperImpl implements RecipeHelper { @Override public Map, List> buildMapFor(ClientHelper.ViewSearchBuilder builder) { - long start = Util.getNanos(); + Stopwatch stopwatch = Stopwatch.createStarted(); Set categories = builder.getCategories(); List recipesFor = builder.getRecipesFor(); List usagesFor = builder.getUsagesFor(); @@ -244,9 +246,8 @@ public class RecipeHelperImpl implements RecipeHelper { } } - long end = Util.getNanos(); - String message = String.format("Built Recipe View in %dμs for %d categories, %d recipes for, %d usages for and %d live recipe generators.", - (end - start) / 1000, categories.size(), recipesFor.size(), usagesFor.size(), liveRecipeGenerators.size()); + String message = String.format("Built Recipe View in %s for %d categories, %d recipes for, %d usages for and %d live recipe generators.", + stopwatch.stop().toString(), categories.size(), recipesFor.size(), usagesFor.size(), liveRecipeGenerators.size()); if (ConfigObject.getInstance().doDebugSearchTimeRequired()) { RoughlyEnoughItemsCore.LOGGER.info(message); } else { @@ -305,24 +306,20 @@ public class RecipeHelperImpl implements RecipeHelper { autoCraftAreaSupplierMap.put(category, rectangle); } - private void startSection(Object[] sectionData, String section) { - sectionData[0] = Util.getNanos(); - sectionData[2] = section; + private void startSection(MutablePair sectionData, String section) { + sectionData.setRight(section); RoughlyEnoughItemsCore.LOGGER.debug("Reloading Section: \"%s\"", section); + sectionData.getLeft().start(); } - private void endSection(Object[] sectionData) { - sectionData[1] = Util.getNanos(); - long time = (long) sectionData[1] - (long) sectionData[0]; - String section = (String) sectionData[2]; - if (time >= 1000000) { - RoughlyEnoughItemsCore.LOGGER.debug("Reloading Section: \"%s\" done in %.2fms", section, time / 1000000.0F); - } else { - RoughlyEnoughItemsCore.LOGGER.debug("Reloading Section: \"%s\" done in %.2fμs", section, time / 1000.0F); - } + private void endSection(MutablePair sectionData) { + sectionData.getLeft().stop(); + String section = sectionData.getRight(); + RoughlyEnoughItemsCore.LOGGER.debug("Reloading Section: \"%s\" done in %s", section, sectionData.getLeft().toString()); + sectionData.getLeft().reset(); } - private void pluginSection(Object[] sectionData, String sectionName, List list, Consumer consumer) { + private void pluginSection(MutablePair sectionData, String sectionName, List list, Consumer consumer) { for (REIPluginV0 plugin : list) { try { startSection(sectionData, sectionName + " for " + plugin.getPluginIdentifier().toString()); @@ -345,7 +342,7 @@ public class RecipeHelperImpl implements RecipeHelper { public void recipesLoaded(RecipeManager recipeManager) { long startTime = Util.getMillis(); - Object[] sectionData = {0L, 0L, ""}; + MutablePair sectionData = new MutablePair<>(Stopwatch.createUnstarted(), ""); startSection(sectionData, "reset-data"); arePluginsLoading = true; @@ -401,14 +398,16 @@ public class RecipeHelperImpl implements RecipeHelper { startSection(sectionData, "recipe-functions"); if (!recipeFunctions.isEmpty()) { @SuppressWarnings("rawtypes") List allSortedRecipes = getAllSortedRecipes(); - Collections.reverse(allSortedRecipes); - for (RecipeFunction recipeFunction : recipeFunctions) { - try { - for (Recipe recipe : CollectionUtils.filter(allSortedRecipes, recipe -> recipeFunction.recipeFilter.test(recipe))) { - registerDisplay(recipeFunction.category, (RecipeDisplay) recipeFunction.mappingFunction.apply(recipe), 0); + for (int i = allSortedRecipes.size() - 1; i >= 0; i--) { + Recipe recipe = allSortedRecipes.get(i); + for (RecipeFunction recipeFunction : recipeFunctions) { + try { + if (recipeFunction.recipeFilter.test(recipe)) { + registerDisplay(recipeFunction.category, (RecipeDisplay) recipeFunction.mappingFunction.apply(recipe), 0); + } + } catch (Throwable e) { + RoughlyEnoughItemsCore.LOGGER.error("Failed to add recipes!", e); } - } catch (Throwable e) { - RoughlyEnoughItemsCore.LOGGER.error("Failed to add recipes!", e); } } } -- cgit