From 23c820ea583052744232e84a6c99114223c43a69 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 25 Mar 2021 02:50:16 +0800 Subject: Refactor MenuInfo, split client and server apis, new dual PluginManager system, remove @NotNull Signed-off-by: shedaniel --- .../main/java/me/shedaniel/rei/impl/Internals.java | 134 ++++----------------- 1 file changed, 22 insertions(+), 112 deletions(-) (limited to 'api/src/main/java/me/shedaniel/rei/impl/Internals.java') 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 035a77bc3..5ae71b025 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/Internals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/Internals.java @@ -23,98 +23,39 @@ package me.shedaniel.rei.impl; -import com.google.gson.JsonObject; -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.ClientHelper; -import me.shedaniel.rei.api.favorites.FavoriteEntry; -import me.shedaniel.rei.api.gui.DrawableConsumer; -import me.shedaniel.rei.api.gui.Renderer; -import me.shedaniel.rei.api.gui.widgets.*; -import me.shedaniel.rei.api.ingredient.EntryIngredient; -import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.renderer.EntryRenderer; -import me.shedaniel.rei.api.ingredient.entry.type.EntryDefinition; -import me.shedaniel.rei.api.ingredient.entry.type.EntryType; -import me.shedaniel.rei.api.plugins.BuiltinPlugin; -import me.shedaniel.rei.api.plugins.PluginManager; -import me.shedaniel.rei.api.registry.screen.ClickArea; -import me.shedaniel.rei.api.view.ViewSearchBuilder; -import me.shedaniel.rei.api.view.Views; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.ingredient.EntryIngredient; +import me.shedaniel.rei.api.common.ingredient.EntryStack; +import me.shedaniel.rei.api.common.ingredient.entry.type.EntryDefinition; +import me.shedaniel.rei.api.common.ingredient.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 net.minecraft.nbt.Tag; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.FormattedText; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Unit; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.lang.reflect.Field; -import java.util.Collection; -import java.util.List; -import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; import java.util.function.ToLongFunction; @ApiStatus.Internal public final class Internals { - private static Supplier clientHelper = Internals::throwNotSetup; private static Supplier entryStackProvider = Internals::throwNotSetup; private static Supplier entryIngredientProvider = Internals::throwNotSetup; - private static Supplier widgetsProvider = Internals::throwNotSetup; - private static Supplier viewSearchBuilder = Internals::throwNotSetup; private static Function> entryTypeDeferred = (object) -> throwNotSetup(); - private static Supplier views = Internals::throwNotSetup; - private static Supplier pluginManager = Internals::throwNotSetup; + private static Supplier>> commonPluginManager = Internals::throwNotSetup; + private static Supplier> serverPluginManager = Internals::throwNotSetup; private static Supplier nbtHasherProvider = Internals::throwNotSetup; - private static Supplier> emptyEntryRenderer = Internals::throwNotSetup; - private static BiFunction, Supplier, FavoriteEntry> delegateFavoriteEntry = (supplier, toJson) -> throwNotSetup(); - private static Function favoriteEntryFromJson = (object) -> throwNotSetup(); - private static Function<@NotNull Boolean, ClickArea.Result> clickAreaHandlerResult = (result) -> throwNotSetup(); - private static BiFunction<@Nullable Point, Collection, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); - private static Supplier builtinPlugin = Internals::throwNotSetup; - private static Supplier> jeiCompatMods = Internals::throwNotSetup; + private static Function> categoryIdentifier = (object) -> throwNotSetup(); private static T throwNotSetup() { throw new AssertionError("REI Internals have not been initialized!"); } - public static ClientHelper getClientHelper() { - return clientHelper.get(); - } - - public static EntryStackProvider getEntryStackProvider() { - return entryStackProvider.get(); - } - - public static EntryIngredientProvider getEntryIngredientProvider() { - return entryIngredientProvider.get(); - } - - public static WidgetsProvider getWidgetsProvider() { - return widgetsProvider.get(); - } - - public static ViewSearchBuilder createViewSearchBuilder() { - return viewSearchBuilder.get(); - } - - public static ClickArea.Result createClickAreaHandlerResult(boolean applicable) { - return clickAreaHandlerResult.apply(applicable); - } - - public static Tooltip createTooltip(@Nullable Point point, Collection texts) { - return tooltipProvider.apply(point, texts); - } - - public static BuiltinPlugin getBuiltinPlugin() { - return builtinPlugin.get(); - } - @ApiStatus.Internal public static void attachInstance(T instance, Class clazz) { attachInstance((Supplier) () -> instance, clazz.getSimpleName()); @@ -136,46 +77,38 @@ public final class Internals { } } - public static FavoriteEntry delegateFavoriteEntry(Supplier supplier, Supplier toJoin) { - return delegateFavoriteEntry.apply(supplier, toJoin); + public static EntryStackProvider getEntryStackProvider() { + return entryStackProvider.get(); } - public static FavoriteEntry favoriteEntryFromJson(JsonObject object) { - return favoriteEntryFromJson.apply(object); + public static EntryIngredientProvider getEntryIngredientProvider() { + return entryIngredientProvider.get(); } public static EntryType deferEntryType(ResourceLocation id) { return entryTypeDeferred.apply(id); } - public static Views getViews() { - return views.get(); + public static PluginManager> getPluginManager() { + return commonPluginManager.get(); } - public static PluginManager getPluginManager() { - return pluginManager.get(); + public static PluginManager getServerPluginManager() { + return serverPluginManager.get(); } public static ToLongFunction getNbtHasher(String[] ignoredKeys) { return nbtHasherProvider.get().provide(ignoredKeys); } - public static EntryRenderer getEmptyEntryRenderer() { - return emptyEntryRenderer.get().cast(); - } - - public static List getJeiCompatMods() { - return jeiCompatMods.get(); + public static CategoryIdentifier getCategoryIdentifier(ResourceLocation location) { + return (CategoryIdentifier) categoryIdentifier.apply(location); } public interface EntryStackProvider { EntryStack empty(); EntryStack of(EntryDefinition definition, T value); - - EntryType emptyType(ResourceLocation id); - - EntryType renderingType(ResourceLocation id); } public interface EntryIngredientProvider { @@ -188,29 +121,6 @@ public final class Internals { EntryIngredient of(Iterable> stacks); } - @Environment(EnvType.CLIENT) - public interface WidgetsProvider { - boolean isRenderingPanel(Panel panel); - - Widget createDrawableWidget(DrawableConsumer drawable); - - Slot createSlot(Point point); - - Button createButton(Rectangle bounds, Component text); - - Panel createPanelWidget(Rectangle bounds); - - Label createLabel(Point point, FormattedText text); - - Arrow createArrow(Rectangle rectangle); - - BurningFire createBurningFire(Rectangle rectangle); - - DrawableConsumer createTexturedConsumer(ResourceLocation texture, int x, int y, int width, int height, float u, float v, int uWidth, int vHeight, int textureWidth, int textureHeight); - - DrawableConsumer createFillRectangleConsumer(Rectangle rectangle, int color); - } - public interface NbtHasherProvider { ToLongFunction provide(String... ignoredKeys); } -- cgit