diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-08-28 04:27:25 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-08-28 04:27:25 +0800 |
| commit | 118ea6f24289185d33dcc9359493ff697ef87051 (patch) | |
| tree | cb86d0b22456adcd3fbc75fe51a560e15c1208d4 /runtime/src/main/java | |
| parent | 0e1c2c118a6fcd997089565da6f9edf7c5989445 (diff) | |
| download | RoughlyEnoughItems-118ea6f24289185d33dcc9359493ff697ef87051.tar.gz RoughlyEnoughItems-118ea6f24289185d33dcc9359493ff697ef87051.tar.bz2 RoughlyEnoughItems-118ea6f24289185d33dcc9359493ff697ef87051.zip | |
Fix #500
Diffstat (limited to 'runtime/src/main/java')
5 files changed, 50 insertions, 30 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 448af4174..840c3b34a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -115,8 +115,14 @@ public class RoughlyEnoughItemsCore { public static void _reloadPlugins() { try { for (PluginManager<? extends REIPlugin<?>> instance : PluginManager.getActiveInstances()) { + instance.view().pre(); + } + for (PluginManager<? extends REIPlugin<?>> instance : PluginManager.getActiveInstances()) { instance.startReload(); } + for (PluginManager<? extends REIPlugin<?>> instance : PluginManager.getActiveInstances()) { + instance.view().post(); + } } catch (Throwable throwable) { throwable.printStackTrace(); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java index 6cc34b3b1..8df053102 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java @@ -177,7 +177,7 @@ public final class InternalWidgets { } } if (Minecraft.getInstance().options.advancedItemTooltips && displaySupplier.get().getDisplayLocation().isPresent()) { - str.add(new TranslatableComponent("text.rei.recipe_id", new TextComponent(displaySupplier.get().getDisplayLocation().get().toString()).withStyle(ChatFormatting.GRAY)).withStyle(ChatFormatting.GRAY)); + str.add(new TranslatableComponent("text.rei.recipe_id", "", new TextComponent(displaySupplier.get().getDisplayLocation().get().toString()).withStyle(ChatFormatting.GRAY)).withStyle(ChatFormatting.GRAY)); } return str.toArray(new Component[0]); }); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java index 0af7766f4..f267274dc 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java @@ -38,6 +38,7 @@ import me.shedaniel.rei.impl.common.registry.RecipeManagerContextImpl; import net.minecraft.world.item.crafting.Recipe; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.mutable.MutableInt; +import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -45,6 +46,7 @@ import java.util.function.Function; import java.util.function.Predicate; public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugin> implements DisplayRegistry { + private final WeakHashMap<Display, Object> displaysBase = new WeakHashMap<>(); private final Map<CategoryIdentifier<?>, List<Display>> displays = new ConcurrentHashMap<>(); private final Map<CategoryIdentifier<?>, List<DynamicDisplayGenerator<?>>> displayGenerators = new ConcurrentHashMap<>(); private final List<DynamicDisplayGenerator<?>> globalDisplayGenerators = new ArrayList<>(); @@ -67,25 +69,17 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi } @Override - public void add(Display display) { + public void add(Display display, @Nullable Object origin) { displays.computeIfAbsent(display.getCategoryIdentifier(), location -> new ArrayList<>()) .add(display); displayCount.increment(); - } - - @Override - public void add(Object object) { - for (Display display : tryFillDisplay(object)) { - add(display); + if (origin != null) { + synchronized (displaysBase) { + displaysBase.put(display, origin); + } } } - public void registerDisplay(int index, Display display) { - displays.computeIfAbsent(display.getCategoryIdentifier(), location -> new ArrayList<>()) - .add(index, display); - displayCount.increment(); - } - @Override public Map<CategoryIdentifier<?>, List<Display>> getAll() { return Collections.unmodifiableMap(displays); @@ -167,10 +161,7 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi List<Recipe<?>> allSortedRecipes = getAllSortedRecipes(); for (int i = allSortedRecipes.size() - 1; i >= 0; i--) { Recipe<?> recipe = allSortedRecipes.get(i); - Collection<Display> displays = tryFillDisplay(recipe); - for (Display display : displays) { - registerDisplay(0, display); - } + add(recipe); } } } @@ -207,26 +198,32 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi return null; } + @Override + @Nullable + public Object getDisplayOrigin(Display display) { + return displaysBase.get(display); + } + private static class DisplayFiller<D extends Display> { private final Predicate<Object> predicate; private final Function<Object, D> mappingFunction; - + public DisplayFiller(Predicate<Object> predicate, Function<Object, D> mappingFunction) { this.predicate = predicate; this.mappingFunction = mappingFunction; } - + @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof DisplayFiller)) return false; - + DisplayFiller<?> that = (DisplayFiller<?>) o; - + if (!Objects.equals(predicate, that.predicate)) return false; return Objects.equals(mappingFunction, that.mappingFunction); } - + @Override public int hashCode() { int result = predicate != null ? predicate.hashCode() : 0; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java index 0c43edeee..5225c1afb 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java @@ -149,6 +149,24 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager< } @Override + public void pre() { + List<P> plugins = new ArrayList<>(getPlugins().toList()); + plugins.sort(Comparator.comparingDouble(P::getPriority).reversed()); + Collections.reverse(plugins); + MutablePair<Stopwatch, String> sectionData = new MutablePair<>(Stopwatch.createUnstarted(), ""); + pluginSection(sectionData, "pre-register", plugins, REIPlugin::preRegister); + } + + @Override + public void post() { + List<P> plugins = new ArrayList<>(getPlugins().toList()); + plugins.sort(Comparator.comparingDouble(P::getPriority).reversed()); + Collections.reverse(plugins); + MutablePair<Stopwatch, String> sectionData = new MutablePair<>(Stopwatch.createUnstarted(), ""); + pluginSection(sectionData, "post-register", plugins, REIPlugin::postRegister); + } + + @Override public void startReload() { try { reloading = true; @@ -169,12 +187,10 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager< RoughlyEnoughItemsCore.LOGGER.info("Reloading Plugin Manager [%s], registered %d plugins: %s", pluginClass.getSimpleName(), plugins.size(), CollectionUtils.mapAndJoinToString(plugins, REIPlugin::getPluginProviderName, ", ")); Collections.reverse(plugins); - pluginSection(sectionData, "pre-register", plugins, REIPlugin::preRegister); for (Reloadable<P> reloadable : getReloadables()) { Class<?> reloadableClass = reloadable.getClass(); pluginSection(sectionData, "reloadable-plugin-" + MoreObjects.firstNonNull(reloadableClass.getSimpleName(), reloadableClass.getName()), plugins, reloadable::acceptPlugin); } - pluginSection(sectionData, "post-register", plugins, REIPlugin::postRegister); for (Reloadable<P> reloadable : reloadables) { Class<?> reloadableClass = reloadable.getClass(); diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java b/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java index 98fa3ea3f..0e6e3c4d1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java @@ -32,7 +32,6 @@ import me.shedaniel.rei.api.client.ClientHelper; import me.shedaniel.rei.api.client.registry.transfer.TransferHandler; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; -import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay; import me.shedaniel.rei.api.common.transfer.RecipeFinder; import me.shedaniel.rei.api.common.transfer.info.MenuInfo; import me.shedaniel.rei.api.common.transfer.info.MenuInfoContext; @@ -56,9 +55,7 @@ import java.util.List; public class DefaultCategoryHandler implements TransferHandler { @Override public Result handle(Context context) { - if (!(context.getDisplay() instanceof SimpleGridMenuDisplay)) - return Result.createNotApplicable(); - SimpleGridMenuDisplay display = (SimpleGridMenuDisplay) context.getDisplay(); + Display display = context.getDisplay(); AbstractContainerScreen<?> containerScreen = context.getContainerScreen(); if (containerScreen == null) { return Result.createNotApplicable(); @@ -72,7 +69,11 @@ public class DefaultCategoryHandler implements TransferHandler { try { menuInfo.validate(menuInfoContext); } catch (MenuTransferException e) { - return Result.createFailed(e.getError()); + if (e.isApplicable()) { + return Result.createFailed(e.getError()); + } else { + return Result.createNotApplicable(); + } } List<List<ItemStack>> input = menuInfo.getInputs(menuInfoContext); IntList intList = hasItems(menu, menuInfo, display, input); |
