diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-08-28 04:27:25 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-08-28 16:12:05 +0800 |
| commit | 88472ebfdce663fb3cbc5448cfa1137358ed9b16 (patch) | |
| tree | 1f0220f9df63c3cc4006320d4f1e73bedab8326b /api/src/main/java/me/shedaniel/rei | |
| parent | 8a0601c75fa2462494ed949797f04243fe9cb10e (diff) | |
| download | RoughlyEnoughItems-88472ebfdce663fb3cbc5448cfa1137358ed9b16.tar.gz RoughlyEnoughItems-88472ebfdce663fb3cbc5448cfa1137358ed9b16.tar.bz2 RoughlyEnoughItems-88472ebfdce663fb3cbc5448cfa1137358ed9b16.zip | |
Fix #500
Diffstat (limited to 'api/src/main/java/me/shedaniel/rei')
6 files changed, 70 insertions, 7 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java index 35817b419..6e83dfac2 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java @@ -109,6 +109,8 @@ public interface CategoryRegistry extends Reloadable<REIClientPlugin>, Iterable< <T extends Display> CategoryConfiguration<T> get(CategoryIdentifier<T> category); + <T extends Display> Optional<CategoryConfiguration<T>> tryGet(CategoryIdentifier<T> category); + <T extends Display> void configure(CategoryIdentifier<T> category, Consumer<CategoryConfiguration<T>> action); int size(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java index be9c107ef..2ecb40967 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java @@ -34,6 +34,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeType; +import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.function.Function; @@ -82,14 +83,31 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> { * * @param display the display */ - void add(Display display); + default void add(Display display) { + add(display, null); + } + + /** + * Registers a display with an origin attached. + * + * @param display the display + */ + void add(Display display, @Nullable Object origin); /** * Registers a display by the object provided, to be filled during {@link #tryFillDisplay(Object)}. * * @param object the object to be filled */ - void add(Object object); + default void add(Object object) { + if (object instanceof Display) { + add((Display) object, null); + } else { + for (Display display : tryFillDisplay(object)) { + add(display, object); + } + } + } /** * Returns an unmodifiable map of displays visible to the player @@ -271,4 +289,7 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> { * @return the collection of displays */ <T> Collection<Display> tryFillDisplay(T value); + + @Nullable + Object getDisplayOrigin(Display display); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java index 101f62b0d..ddd74a367 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java @@ -31,7 +31,6 @@ import net.fabricmc.api.Environment; import org.jetbrains.annotations.ApiStatus; @ApiStatus.Internal -@FunctionalInterface public interface PluginView<P extends REIPlugin<?>> { @Environment(EnvType.CLIENT) static PluginView<REIClientPlugin> getClientInstance() { @@ -54,9 +53,26 @@ public interface PluginView<P extends REIPlugin<?>> { void registerPlugin(REIPluginProvider<? extends P> plugin); default PluginView<P> then(PluginView<? super P> view) { - return plugin -> { - registerPlugin(plugin); - view.registerPlugin(plugin); + return new PluginView<P>() { + @Override + public void registerPlugin(REIPluginProvider<? extends P> plugin) { + PluginView.this.registerPlugin(plugin); + view.registerPlugin(plugin); + } + + @Override + public void pre() { + PluginView.this.pre(); + } + + @Override + public void post() { + PluginView.this.post(); + } }; } + + void pre(); + + void post(); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuTransferException.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuTransferException.java index 5fff31cb7..0016e0866 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuTransferException.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuTransferException.java @@ -28,16 +28,30 @@ import net.minecraft.network.chat.TranslatableComponent; public class MenuTransferException extends Exception { private final Component component; + private final boolean applicable; - public MenuTransferException(Component component) { + private MenuTransferException(Component component, boolean applicable) { this.component = component; + this.applicable = applicable; + } + + public MenuTransferException(Component component) { + this(component, true); } public MenuTransferException(String message) { this(new TranslatableComponent(message)); } + public static MenuTransferException createNotApplicable() { + return new MenuTransferException(null, false); + } + public Component getError() { return component; } + + public boolean isApplicable() { + return applicable; + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java index 3f4054cbc..97934437d 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java @@ -138,6 +138,14 @@ public class CollectionUtils { return l; } + public static <T, R> List<R> flatMap(T[] list, Function<T, Collection<R>> function) { + List<R> l = new ArrayList<>(); + for (T t : list) { + l.addAll(function.apply(t)); + } + return l; + } + public static <T> IntList mapToInt(Collection<T> list, ToIntFunction<T> function) { IntList l = new IntArrayList(list.size() + 1); for (T t : list) { diff --git a/api/src/main/java/me/shedaniel/rei/impl/Internals.java b/api/src/main/java/me/shedaniel/rei/impl/Internals.java index a5912535e..cbbc257ea 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/Internals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/Internals.java @@ -33,6 +33,7 @@ import me.shedaniel.rei.api.common.entry.type.EntryType; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.plugins.REIPlugin; import me.shedaniel.rei.api.common.plugins.REIServerPlugin; +import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry; import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Unit; @@ -51,6 +52,7 @@ public final class Internals { private static Supplier<PluginManager<REIServerPlugin>> serverPluginManager = Internals::throwNotSetup; private static Supplier<NbtHasherProvider> nbtHasherProvider = Internals::throwNotSetup; private static Function<String, CategoryIdentifier<?>> categoryIdentifier = (object) -> throwNotSetup(); + private static Supplier<MenuInfoRegistry> stubMenuInfoRegistry = Internals::throwNotSetup; private static <T> T throwNotSetup() { throw new AssertionError("REI Internals have not been initialized!"); |
