diff options
Diffstat (limited to 'runtime/src')
60 files changed, 367 insertions, 337 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 93055513f..5c57aad51 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -23,8 +23,7 @@ package me.shedaniel.rei; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -34,13 +33,17 @@ import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.api.Executor; import me.shedaniel.rei.api.*; -import me.shedaniel.rei.api.entry.*; +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.ingredient.entry.*; import me.shedaniel.rei.api.favorites.FavoriteEntry; import me.shedaniel.rei.api.favorites.FavoriteEntryType; import me.shedaniel.rei.api.favorites.FavoriteMenuEntry; import me.shedaniel.rei.api.fluid.FluidSupportProvider; +import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.api.plugins.REIPluginV0; import me.shedaniel.rei.api.subsets.SubsetsRegistry; +import me.shedaniel.rei.api.util.DrawableConsumer; +import me.shedaniel.rei.api.util.Renderer; import me.shedaniel.rei.api.widgets.*; import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.gui.widget.EntryWidget; @@ -105,7 +108,7 @@ import static me.shedaniel.rei.impl.Internals.attachInstance; @Environment(EnvType.CLIENT) public class RoughlyEnoughItemsCore implements ClientModInitializer { @ApiStatus.Internal public static final Logger LOGGER = LogManager.getFormatterLogger("REI"); - private static final BiMap<ResourceLocation, REIPluginEntry> PLUGINS = HashBiMap.create(); + private static final List<REIPlugin> PLUGINS = new ArrayList<>(); private static final ExecutorService SYNC_RECIPES = Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "REI-SyncRecipes")); @ApiStatus.Experimental public static boolean isLeftModePressed = false; @@ -121,9 +124,9 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } return typeCache.computeIfAbsent(id, EntryTypeDeferred::new); }, "entryTypeDeferred"); - attachInstance(new RecipeHelperImpl(), RecipeHelper.class); + attachInstance(new RecipeRegistryImpl(), RecipeRegistry.class); attachInstance(new EntryRegistryImpl(), EntryRegistry.class); - attachInstance(new DisplayHelperImpl(), DisplayHelper.class); + attachInstance(new DisplayBoundsRegistryImpl(), DisplayBoundsRegistry.class); attachInstance(new FluidSupportProviderImpl(), FluidSupportProvider.class); attachInstance(new SubsetsRegistryImpl(), SubsetsRegistry.class); attachInstance(new Internals.EntryStackProvider() { @@ -145,24 +148,26 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return id; } + @SuppressWarnings("rawtypes") @Override public @NotNull EntryDefinition<Unit> getDefinition() { - return EmptyEntryDefinition.EMPTY; + return (EntryDefinition) EmptyEntryDefinition.EMPTY; } }; } @Override - public EntryType<Unit> renderingType(ResourceLocation id) { - return new EntryType<Unit>() { + public EntryType<Renderer> renderingType(ResourceLocation id) { + return new EntryType<Renderer>() { @Override public @NotNull ResourceLocation getId() { return id; } - + + @SuppressWarnings("rawtypes") @Override - public @NotNull EntryDefinition<Unit> getDefinition() { - return EmptyEntryDefinition.RENDERING; + public @NotNull EntryDefinition<Renderer> getDefinition() { + return (EntryDefinition) EmptyEntryDefinition.RENDERING; } }; } @@ -335,18 +340,14 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { * @return the plugin itself */ @ApiStatus.Internal - public static REIPluginEntry registerPlugin(REIPluginEntry plugin) { - PLUGINS.put(plugin.getPluginIdentifier(), plugin); - RoughlyEnoughItemsCore.LOGGER.debug("Registered plugin %s from %s", plugin.getPluginIdentifier().toString(), plugin.getClass().getSimpleName()); + public static <T extends REIPlugin> T registerPlugin(T plugin) { + PLUGINS.add(plugin); + RoughlyEnoughItemsCore.LOGGER.debug("Registered plugin %s", plugin.getPluginName()); return plugin; } - public static List<REIPluginEntry> getPlugins() { - return new ArrayList<>(PLUGINS.values()); - } - - public static Optional<ResourceLocation> getPluginIdentifier(REIPluginEntry plugin) { - return Optional.ofNullable(PLUGINS.inverse().get(plugin)); + public static List<REIPlugin> getPlugins() { + return Collections.unmodifiableList(PLUGINS); } public static boolean hasPermissionToUsePackets() { @@ -381,9 +382,9 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } RecipeManager recipeManager = Minecraft.getInstance().getConnection().getRecipeManager(); if (ConfigObject.getInstance().doesRegisterRecipesInAnotherThread()) { - CompletableFuture.runAsync(() -> ((RecipeHelperImpl) RecipeHelper.getInstance()).tryRecipesLoaded(recipeManager), SYNC_RECIPES); + CompletableFuture.runAsync(() -> ((RecipeRegistryImpl) RecipeRegistry.getInstance()).tryRecipesLoaded(recipeManager), SYNC_RECIPES); } else { - ((RecipeHelperImpl) RecipeHelper.getInstance()).tryRecipesLoaded(recipeManager); + ((RecipeRegistryImpl) RecipeRegistry.getInstance()).tryRecipesLoaded(recipeManager); } } @@ -451,7 +452,10 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } private void discoverPluginEntries() { - for (REIPluginEntry reiPlugin : FabricLoader.getInstance().getEntrypoints("rei_plugins", REIPluginEntry.class)) { + for (REIPlugin reiPlugin : Iterables.concat( + FabricLoader.getInstance().getEntrypoints("rei_plugins", REIPlugin.class), + FabricLoader.getInstance().getEntrypoints("rei", REIPlugin.class) + )) { try { if (!REIPluginV0.class.isAssignableFrom(reiPlugin.getClass())) throw new IllegalArgumentException("REI plugin is too old!"); @@ -480,7 +484,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } if (FabricLoader.getInstance().isModLoaded("libblockattributes-fluids")) { try { - registerPlugin((REIPluginEntry) Class.forName("me.shedaniel.rei.compat.LBASupportPlugin").getConstructor().newInstance()); + registerPlugin((REIPlugin) Class.forName("me.shedaniel.rei.compat.LBASupportPlugin").getConstructor().newInstance()); } catch (Throwable throwable) { throwable.printStackTrace(); } @@ -495,7 +499,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { private boolean shouldReturn(Class<?> screen) { try { - for (OverlayDecider decider : DisplayHelper.getInstance().getAllOverlayDeciders()) { + for (OverlayDecider decider : DisplayBoundsRegistry.getInstance().getAllOverlayDeciders()) { if (!decider.isHandingScreen(screen)) continue; InteractionResult result = decider.shouldScreenBeOverlaid(screen); diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index 7d73ac6c3..808116f6a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -26,7 +26,7 @@ package me.shedaniel.rei; import com.google.common.collect.Lists; import io.netty.buffer.Unpooled; import me.shedaniel.math.api.Executor; -import me.shedaniel.rei.server.InputSlotCrafter; +import me.shedaniel.rei.api.server.InputSlotCrafter; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.loader.api.FabricLoader; diff --git a/runtime/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java b/runtime/src/main/java/me/shedaniel/rei/api/server/InputSlotCrafter.java index 9e51a158d..5396d451c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java +++ b/runtime/src/main/java/me/shedaniel/rei/api/server/InputSlotCrafter.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.server; +package me.shedaniel.rei.api.server; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; diff --git a/runtime/src/main/java/me/shedaniel/rei/compat/LBASupportPlugin.java b/runtime/src/main/java/me/shedaniel/rei/compat/LBASupportPlugin.java index 5e227d603..58282ccf7 100644 --- a/runtime/src/main/java/me/shedaniel/rei/compat/LBASupportPlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/compat/LBASupportPlugin.java @@ -27,8 +27,8 @@ import alexiil.mc.lib.attributes.fluid.FluidAttributes; import alexiil.mc.lib.attributes.fluid.GroupedFluidInvView; import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; import me.shedaniel.architectury.utils.Fraction; -import me.shedaniel.rei.api.RecipeHelper; -import me.shedaniel.rei.api.entry.EntryStacks; +import me.shedaniel.rei.api.RecipeRegistry; +import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.api.fluid.FluidSupportProvider; import me.shedaniel.rei.api.plugins.REIPluginV0; import net.minecraft.resources.ResourceLocation; @@ -43,7 +43,7 @@ public class LBASupportPlugin implements REIPluginV0 { } @Override - public void registerOthers(RecipeHelper recipeHelper) { + public void registerOthers(RecipeRegistry registry) { FluidSupportProvider.getInstance().registerProvider(entry -> { GroupedFluidInvView view = FluidAttributes.GROUPED_INV_VIEW.get(entry.getValue()); if (view.getStoredFluids().size() > 0) diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/ConfigReloadingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/ConfigReloadingScreen.java index 68479589b..4b1f1cf63 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/ConfigReloadingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/ConfigReloadingScreen.java @@ -24,7 +24,7 @@ package me.shedaniel.rei.gui; import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.rei.api.RecipeHelper; +import me.shedaniel.rei.api.RecipeRegistry; import net.minecraft.Util; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.screens.Screen; @@ -49,7 +49,7 @@ public class ConfigReloadingScreen extends Screen { @Override public void render(PoseStack matrices, int int_1, int int_2, float float_1) { this.renderDirtBackground(0); - if (!RecipeHelper.getInstance().arePluginsLoading()) + if (!RecipeRegistry.getInstance().arePluginsLoading()) minecraft.setScreen(parent); drawCenteredString(matrices, this.font, I18n.get("text.rei.config.is.reloading"), this.width / 2, this.height / 2 - 50, 16777215); String string_3; diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 62daa5b07..5e5ec1ae3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -35,7 +35,8 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; -import me.shedaniel.rei.api.entry.EntryStacks; +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.api.favorites.FavoriteEntry; import me.shedaniel.rei.api.widgets.Button; import me.shedaniel.rei.api.widgets.Tooltip; @@ -214,7 +215,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl this.children().clear(); this.removeOverlayMenu(); this.window = Minecraft.getInstance().getWindow(); - this.bounds = DisplayHelper.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation(), Minecraft.getInstance().screen); + this.bounds = DisplayBoundsRegistry.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation(), Minecraft.getInstance().screen); widgets.add(ENTRY_LIST_WIDGET); if (ConfigObject.getInstance().isFavoritesEnabled()) { if (favoritesListWidget == null) @@ -454,9 +455,9 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl return getBottomSideSearchFieldArea(widthRemoved); default: case CENTER: { - for (OverlayDecider decider : DisplayHelper.getInstance().getSortedOverlayDeciders(Minecraft.getInstance().screen.getClass())) { - if (decider instanceof DisplayHelper.DisplayBoundsProvider) { - Rectangle containerBounds = ((DisplayHelper.DisplayBoundsProvider<Screen>) decider).getScreenBounds(Minecraft.getInstance().screen); + for (OverlayDecider decider : DisplayBoundsRegistry.getInstance().getSortedOverlayDeciders(Minecraft.getInstance().screen.getClass())) { + if (decider instanceof DisplayBoundsRegistry.DisplayBoundsProvider) { + Rectangle containerBounds = ((DisplayBoundsRegistry.DisplayBoundsProvider<Screen>) decider).getScreenBounds(Minecraft.getInstance().screen); return getBottomCenterSearchFieldArea(containerBounds, widthRemoved); } } @@ -510,7 +511,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl ENTRY_LIST_WIDGET.updateSearch(ScreenHelper.getSearchField().getText(), true); init(); } else { - for (OverlayDecider decider : DisplayHelper.getInstance().getSortedOverlayDeciders(minecraft.screen.getClass())) { + for (OverlayDecider decider : DisplayBoundsRegistry.getInstance().getSortedOverlayDeciders(minecraft.screen.getClass())) { if (decider != null && decider.shouldRecalculateArea(ConfigObject.getInstance().getDisplayPanelLocation(), bounds)) { init(); break; @@ -552,7 +553,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl return new Point(mouseX, mouseY); } }; - for (Map.Entry<Class<? extends Screen>, ClickAreaHandler<?>> area : ((RecipeHelperImpl) RecipeHelper.getInstance()).getClickAreas().entries()) { + for (Map.Entry<Class<? extends Screen>, ClickAreaHandler<?>> area : ((RecipeRegistryImpl) RecipeRegistry.getInstance()).getClickAreas().entries()) { if (area.getKey().equals(screen.getClass())) { ClickAreaHandler.Result result = area.getValue().handle(context); if (result.isSuccessful()) { @@ -563,7 +564,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl } } if (categories != null && !categories.isEmpty()) { - String collect = CollectionUtils.mapAndJoinToString(categories, identifier -> RecipeHelper.getInstance().getCategory(identifier).getCategoryName(), ", "); + String collect = CollectionUtils.mapAndJoinToString(categories, identifier -> RecipeRegistry.getInstance().getCategory(identifier).getCategoryName(), ", "); Tooltip.create(new TranslatableComponent("text.rei.view_recipes_for", collect)).queue(); } } @@ -679,7 +680,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl ScreenHelper.toggleOverlayVisible(); return true; } - EntryStack<?> stack = RecipeHelper.getInstance().getScreenFocusedStack(Minecraft.getInstance().screen); + EntryStack<?> stack = RecipeRegistry.getInstance().getScreenFocusedStack(Minecraft.getInstance().screen); if (stack != null && !stack.isEmpty()) { stack = stack.copy(); if (ConfigObject.getInstance().getRecipeKeybind().matchesKey(keyCode, scanCode)) { @@ -732,7 +733,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl ScreenHelper.toggleOverlayVisible(); return true; } - EntryStack<?> stack = RecipeHelper.getInstance().getScreenFocusedStack(Minecraft.getInstance().screen); + EntryStack<?> stack = RecipeRegistry.getInstance().getScreenFocusedStack(Minecraft.getInstance().screen); if (stack != null && !stack.isEmpty()) { stack = stack.copy(); if (ConfigObject.getInstance().getRecipeKeybind().matchesMouse(button)) { @@ -778,7 +779,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl return new Point(mouseX, mouseY); } }; - for (Map.Entry<Class<? extends Screen>, ClickAreaHandler<?>> area : ((RecipeHelperImpl) RecipeHelper.getInstance()).getClickAreas().entries()) { + for (Map.Entry<Clas |
