From ea634e7ba29146d4ebc2c05b61257fa6c3b0642e Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 5 Feb 2021 10:08:44 +0800 Subject: More relocation Signed-off-by: shedaniel --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 56 +- .../shedaniel/rei/RoughlyEnoughItemsNetwork.java | 2 +- .../shedaniel/rei/api/server/InputSlotCrafter.java | 205 +++++++ .../me/shedaniel/rei/compat/LBASupportPlugin.java | 6 +- .../shedaniel/rei/gui/ConfigReloadingScreen.java | 4 +- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 25 +- .../java/me/shedaniel/rei/gui/RecipeScreen.java | 2 +- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 38 +- .../rei/gui/VillagerRecipeViewingScreen.java | 38 +- .../rei/gui/config/entry/FilteringEntry.java | 4 +- .../rei/gui/config/entry/FilteringScreen.java | 2 +- .../rei/gui/config/entry/NoFilteringEntry.java | 2 +- .../rei/gui/config/entry/ReloadPluginsEntry.java | 4 +- .../java/me/shedaniel/rei/gui/modules/Menu.java | 4 +- .../entries/EntryStackSubsetsMenuEntry.java | 3 +- .../gui/modules/entries/SubSubsetsMenuEntry.java | 3 +- .../rei/gui/plugin/DefaultRuntimePlugin.java | 30 +- .../rei/gui/plugin/entry/FluidEntryDefinition.java | 4 +- .../rei/gui/plugin/entry/ItemEntryDefinition.java | 5 +- .../rei/gui/widget/EntryListEntryWidget.java | 6 +- .../shedaniel/rei/gui/widget/EntryListWidget.java | 8 +- .../me/shedaniel/rei/gui/widget/EntryWidget.java | 1 + .../rei/gui/widget/FavoritesListWidget.java | 28 +- .../me/shedaniel/rei/gui/widget/TabWidget.java | 6 +- .../me/shedaniel/rei/impl/AbstractEntryStack.java | 8 +- .../rei/impl/AmountIgnoredEntryStackWrapper.java | 4 +- .../shedaniel/rei/impl/BaseBoundsHandlerImpl.java | 116 ---- .../me/shedaniel/rei/impl/ClientHelperImpl.java | 20 +- .../me/shedaniel/rei/impl/ConfigManagerImpl.java | 2 +- .../me/shedaniel/rei/impl/ConfigObjectImpl.java | 2 +- .../rei/impl/DisplayBoundsRegistryImpl.java | 120 ++++ .../me/shedaniel/rei/impl/DisplayHelperImpl.java | 121 ---- .../me/shedaniel/rei/impl/EntryRegistryImpl.java | 4 +- .../me/shedaniel/rei/impl/EntryTypeDeferred.java | 7 +- .../shedaniel/rei/impl/EntryTypeRegistryImpl.java | 8 +- .../me/shedaniel/rei/impl/ExclusionZonesImpl.java | 116 ++++ .../rei/impl/FluidSupportProviderImpl.java | 2 +- .../me/shedaniel/rei/impl/InternalWidgets.java | 11 +- .../me/shedaniel/rei/impl/RecipeHelperImpl.java | 648 -------------------- .../me/shedaniel/rei/impl/RecipeRegistryImpl.java | 649 +++++++++++++++++++++ .../java/me/shedaniel/rei/impl/ScreenHelper.java | 7 +- .../java/me/shedaniel/rei/impl/SearchArgument.java | 2 +- .../me/shedaniel/rei/impl/TypedEntryStack.java | 10 +- .../rei/impl/entry/EmptyEntryDefinition.java | 74 ++- .../rei/impl/filtering/FilteringContext.java | 2 +- .../rei/impl/filtering/FilteringContextImpl.java | 2 +- .../rei/impl/filtering/FilteringResult.java | 2 +- .../rei/impl/filtering/FilteringResultImpl.java | 2 +- .../impl/filtering/rules/ManualFilteringRule.java | 6 +- .../impl/filtering/rules/SearchFilteringRule.java | 2 +- .../rei/impl/search/AlwaysMatchingArgument.java | 2 +- .../me/shedaniel/rei/impl/search/Argument.java | 2 +- .../me/shedaniel/rei/impl/search/ModArgument.java | 2 +- .../shedaniel/rei/impl/search/RegexArgument.java | 2 +- .../me/shedaniel/rei/impl/search/TagArgument.java | 4 +- .../me/shedaniel/rei/impl/search/TextArgument.java | 2 +- .../shedaniel/rei/impl/search/TooltipArgument.java | 2 +- .../rei/impl/subsets/SubsetsRegistryImpl.java | 2 +- .../shedaniel/rei/impl/widgets/DrawableWidget.java | 2 +- .../widgets/FillRectangleDrawableConsumer.java | 2 +- .../rei/impl/widgets/TexturedDrawableConsumer.java | 2 +- .../autocrafting/DefaultCategoryHandler.java | 18 +- .../me/shedaniel/rei/server/InputSlotCrafter.java | 205 ------- .../shedaniel/rei/tests/plugin/REITestPlugin.java | 12 +- 64 files changed, 1361 insertions(+), 1331 deletions(-) create mode 100644 runtime/src/main/java/me/shedaniel/rei/api/server/InputSlotCrafter.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/DisplayBoundsRegistryImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/ExclusionZonesImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/RecipeRegistryImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java (limited to 'runtime/src/main/java') 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 PLUGINS = HashBiMap.create(); + private static final List 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 getDefinition() { - return EmptyEntryDefinition.EMPTY; + return (EntryDefinition) EmptyEntryDefinition.EMPTY; } }; } @Override - public EntryType renderingType(ResourceLocation id) { - return new EntryType() { + public EntryType renderingType(ResourceLocation id) { + return new EntryType() { @Override public @NotNull ResourceLocation getId() { return id; } - + + @SuppressWarnings("rawtypes") @Override - public @NotNull EntryDefinition getDefinition() { - return EmptyEntryDefinition.RENDERING; + public @NotNull EntryDefinition 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 registerPlugin(T plugin) { + PLUGINS.add(plugin); + RoughlyEnoughItemsCore.LOGGER.debug("Registered plugin %s", plugin.getPluginName()); return plugin; } - public static List getPlugins() { - return new ArrayList<>(PLUGINS.values()); - } - - public static Optional getPluginIdentifier(REIPluginEntry plugin) { - return Optional.ofNullable(PLUGINS.inverse().get(plugin)); + public static List 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/api/server/InputSlotCrafter.java b/runtime/src/main/java/me/shedaniel/rei/api/server/InputSlotCrafter.java new file mode 100644 index 000000000..5396d451c --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/api/server/InputSlotCrafter.java @@ -0,0 +1,205 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.server; + +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; +import me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.core.NonNullList; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.level.ItemLike; + +import java.util.Iterator; +import java.util.List; +import java.util.Objects; + +public class InputSlotCrafter implements RecipeGridAligner, ContainerContext { + + protected AbstractContainerMenu container; + protected ContainerInfo containerInfo; + private List gridStacks; + private List inventoryStacks; + private ServerPlayer player; + + private InputSlotCrafter(AbstractContainerMenu container, ContainerInfo containerInfo) { + this.container = container; + this.containerInfo = containerInfo; + } + + public static void start(ResourceLocation category, AbstractContainerMenu craftingContainer_1, ServerPlayer player, NonNullList> map, boolean hasShift) { + ContainerInfo containerInfo = Objects.requireNonNull(ContainerInfoHandler.getContainerInfo(category, craftingContainer_1.getClass()), "Container Info does not exist on the server!"); + new InputSlotCrafter(craftingContainer_1, containerInfo).fillInputSlots(player, map, hasShift); + } + + private void fillInputSlots(ServerPlayer player, NonNullList> map, boolean hasShift) { + this.player = player; + this.inventoryStacks = this.containerInfo.getInventoryStacks(this); + this.gridStacks = this.containerInfo.getGridStacks(this); + + player.ignoreSlotUpdateHack = true; + // Return the already placed items on the grid + this.returnInputs(); + + RecipeFinder recipeFinder = new RecipeFinder(); + this.containerInfo.getRecipeFinderPopulator().populate(this).accept(recipeFinder); + NonNullList ingredients = NonNullList.create(); + for (List itemStacks : map) { + ingredients.add(Ingredient.of(CollectionUtils.map(itemStacks, ItemStack::getItem).toArray(new ItemLike[0]))); + } + + if (recipeFinder.findRecipe(ingredients, null)) { + this.fillInputSlots(recipeFinder, ingredients, hasShift); + } else { + this.returnInputs(); + player.ignoreSlotUpdateHack = false; + this.containerInfo.markDirty(this); + throw new NotEnoughMaterialsException(); + } + + player.ignoreSlotUpdateHack = false; + this.containerInfo.markDirty(this); + } + + @Override + public void acceptAlignedInput(Iterator iterator_1, StackAccessor gridSlot, int craftsAmount) { + ItemStack toBeTakenStack = RecipeFinder.getStackFromId(iterator_1.next()); + if (!toBeTakenStack.isEmpty()) { + for (int i = 0; i < craftsAmount; ++i) { + this.fillInputSlot(gridSlot, toBeTakenStack); + } + } + } + + protected void fillInputSlot(StackAccessor slot, ItemStack toBeTakenStack) { + int takenSlotIndex = this.method_7371(toBeTakenStack); + if (takenSlotIndex != -1) { + ItemStack takenStack = this.inventoryStacks.get(takenSlotIndex).getItemStack().copy(); + if (!takenStack.isEmpty()) { + if (takenStack.getCount() > 1) { + this.inventoryStacks.get(takenSlotIndex).takeStack(1); + } else { + this.inventoryStacks.get(takenSlotIndex).setItemStack(ItemStack.EMPTY); + } + + takenStack.setCount(1); + if (slot.getItemStack().isEmpty()) { + slot.setItemStack(takenStack); + } else { + slot.getItemStack().grow(1); + } + } + } + } + + protected void fillInputSlots(RecipeFinder recipeFinder, NonNullList ingredients, boolean hasShift) { + int recipeCrafts = recipeFinder.countRecipeCrafts(ingredients, null); + int amountToFill = this.getAmountToFill(hasShift, recipeCrafts, false); + IntList intList_1 = new IntArrayList(); + if (recipeFinder.findRecipe(ingredients, intList_1, amountToFill)) { + int finalCraftsAmount = amountToFill; + + for (int itemId : intList_1) { + finalCraftsAmount = Math.min(finalCraftsAmount, RecipeFinder.getStackFromId(itemId).getMaxStackSize()); + } + + if (recipeFinder.findRecipe(ingredients, intList_1, finalCraftsAmount)) { + this.returnInputs(); + this.alignRecipeToGrid(gridStacks, intList_1.iterator(), finalCraftsAmount); + } + } + + } + + protected int getAmountToFill(boolean hasShift, int recipeCrafts, boolean boolean_2) { + int amountToFill = 1; + if (hasShift) { + amountToFill = recipeCrafts; + } else if (boolean_2) { + amountToFill = 64; + for (StackAccessor stackAccessor : gridStacks) { + ItemStack itemStack = stackAccessor.getItemStack(); + if (!itemStack.isEmpty() && amountToFill > itemStack.getCount()) { + amountToFill = itemStack.getCount(); + } + } + if (amountToFill < 64) { + ++amountToFill; + } + } + return amountToFill; + } + + protected void returnInputs() { + this.containerInfo.getGridCleanHandler().clean(this); + } + + public int method_7371(ItemStack itemStack) { + for (int i = 0; i < inventoryStacks.size(); i++) { + ItemStack itemStack1 = this.inventoryStacks.get(i).getItemStack(); + if (!itemStack1.isEmpty() && areItemsEqual(itemStack, itemStack1) && !itemStack1.isDamaged() && !itemStack1.isEnchanted() && !itemStack1.hasCustomHoverName()) { + return i; + } + } + + return -1; + } + + private static boolean areItemsEqual(ItemStack stack1, ItemStack stack2) { + return stack1.getItem() == stack2.getItem() && ItemStack.tagMatches(stack1, stack2); + } + + private int getFreeInventorySlots() { + int int_1 = 0; + for (StackAccessor inventoryStack : inventoryStacks) { + if (inventoryStack.getItemStack().isEmpty()) { + ++int_1; + } + } + return int_1; + } + + @Override + public AbstractContainerMenu getContainer() { + return container; + } + + @Override + public Player getPlayerEntity() { + return player; + } + + @Override + public ContainerInfo getContainerInfo() { + return containerInfo; + } + + public static class NotEnoughMaterialsException extends RuntimeException {} + +} 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) decider).getScreenBounds(Minecraft.getInstance().screen); + for (OverlayDecider decider : DisplayBoundsRegistry.getInstance().getSortedOverlayDeciders(Minecraft.getInstance().screen.getClass())) { + if (decider instanceof DisplayBoundsRegistry.DisplayBoundsProvider) { + Rectangle containerBounds = ((DisplayBoundsRegistry.DisplayBoundsProvider) 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, ClickAreaHandler> area : ((RecipeHelperImpl) RecipeHelper.getInstance()).getClickAreas().entries()) { + for (Map.Entry, 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, ClickAreaHandler> area : ((RecipeHelperImpl) RecipeHelper.getInstance()).getClickAreas().entries()) { + for (Map.Entry, ClickAreaHandler> area : ((RecipeRegistryImpl) RecipeRegistry.getInstance()).getClickAreas().entries()) { if (area.getKey().equals(screen.getClass())) { ClickAreaHandler.Result result = area.getValue().handle(context); if (result.isSuccessful()) { @@ -825,7 +826,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl } public boolean isNotInExclusionZones(double mouseX, double mouseY) { - for (OverlayDecider decider : DisplayHelper.getInstance().getSortedOverlayDeciders(Minecraft.getInstance().screen.getClass())) { + for (OverlayDecider decider : DisplayBoundsRegistry.getInstance().getSortedOverlayDeciders(Minecraft.getInstance().screen.getClass())) { InteractionResult in = decider.isInZone(mouseX, mouseY); if (in != InteractionResult.PASS) return in == InteractionResult.SUCCESS; diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/RecipeScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/RecipeScreen.java index 034f7a6e5..dc91068fd 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/RecipeScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/RecipeScreen.java @@ -23,7 +23,7 @@ package me.shedaniel.rei.gui; -import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.ingredient.EntryStack; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 094815ffb..e80a2a899 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -34,6 +34,8 @@ import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.registry.category.DisplayCategory; import me.shedaniel.rei.api.widgets.Button; import me.shedaniel.rei.api.widgets.Panel; import me.shedaniel.rei.api.widgets.Widgets; @@ -76,9 +78,9 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { private final List widgets = Lists.newArrayList(); private final Map> recipeBounds = Maps.newHashMap(); private final List tabs = Lists.newArrayList(); - private final Map, List> categoriesMap; - private final List> categories; - private final RecipeCategory selectedCategory; + private final Map, List> categoriesMap; + private final List> categories; + private final DisplayCategory selectedCategory; public int page; public int categoryPages = -1; public boolean choosePageActivated = false; @@ -91,21 +93,21 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { private EntryStack ingredientStackToNotice = EntryStack.empty(); private EntryStack resultStackToNotice = EntryStack.empty(); - public RecipeViewingScreen(Map, List> categoriesMap, @Nullable ResourceLocation category) { + public RecipeViewingScreen(Map, List> categoriesMap, @Nullable ResourceLocation category) { super(NarratorChatListener.NO_TITLE); this.bounds = new Rectangle(0, 0, 176, 150); this.categoriesMap = categoriesMap; this.categories = Lists.newArrayList(categoriesMap.keySet()); - RecipeCategory selected = categories.get(0); + DisplayCategory selected = categories.get(0); if (category != null) { - for (RecipeCategory recipeCategory : categories) { - if (recipeCategory.getIdentifier().equals(category)) { - selected = recipeCategory; + for (DisplayCategory displayCategory : categories) { + if (displayCategory.getIdentifier().equals(category)) { + selected = displayCategory; break; } } } - this.selectedCategory = (RecipeCategory) selected; + this.selectedCategory = (DisplayCategory) selected; } @ApiStatus.Internal @@ -308,12 +310,12 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { tab.setRenderer(categories.get(j), categories.get(j).getLogo(), categories.get(j).getCategoryName(), tab.getId() + categoryPages * tabsPerPage == categories.indexOf(selectedCategory)); } } - Optional supplier = RecipeHelper.getInstance().getAutoCraftButtonArea(selectedCategory); + Optional supplier = RecipeRegistry.getInstance().getAutoCraftButtonArea(selectedCategory); int recipeHeight = selectedCategory.getDisplayHeight(); - List currentDisplayed = getCurrentDisplayed(); + List currentDisplayed = getCurrentDisplayed(); for (int i = 0; i < currentDisplayed.size(); i++) { - final RecipeDisplay display = currentDisplayed.get(i); - final Supplier displaySupplier = () -> display; + final Display display = currentDisplayed.get(i); + final Supplier displaySupplier = () -> display; int displayWidth = selectedCategory.getDisplayWidth(displaySupplier.get()); final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().getCenterY() + 16 - recipeHeight * (getRecipesPerPage() + 1) / 2 - 2 * (getRecipesPerPage() + 1) + recipeHeight * i + 4 * i, displayWidth, recipeHeight); List setupDisplay = selectedCategory.setupDisplay(display, displayBounds); @@ -330,7 +332,7 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { recipeChoosePageWidget = null; workingStationsBaseWidget = null; - List>> workingStations = RecipeHelper.getInstance().getWorkingStations(selectedCategory.getIdentifier()); + List>> workingStations = RecipeRegistry.getInstance().getWorkingStations(selectedCategory.getIdentifier()); if (!workingStations.isEmpty()) { int hh = Mth.floor((bounds.height - 16) / 18f); int actualHeight = Math.min(hh, workingStations.size()); @@ -362,8 +364,8 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { return widgets; } - public List getCurrentDisplayed() { - List list = Lists.newArrayList(); + public List getCurrentDisplayed() { + List list = Lists.newArrayList(); int recipesPerPage = getRecipesPerPage(); for (int i = 0; i <= recipesPerPage; i++) if (page * (recipesPerPage + 1) + i < categoriesMap.get(selectedCategory).size()) @@ -371,7 +373,7 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { return list; } - public RecipeCategory getSelectedCategory() { + public DisplayCategory getSelectedCategory() { return selectedCategory; } @@ -463,7 +465,7 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { return super.keyReleased(keyCode, scanCode, modifiers); } - public int getTotalPages(RecipeCategory category) { + public int getTotalPages(DisplayCategory category) { return Mth.ceil(categoriesMap.get(category).size() / (double) (getRecipesPerPage() + 1)); } diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index aca21fd38..8643922bb 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -33,10 +33,12 @@ import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.registry.category.DisplayCategory; import me.shedaniel.rei.api.widgets.Button; import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.api.widgets.Widgets; -import me.shedaniel.rei.gui.entries.RecipeRenderer; +import me.shedaniel.rei.gui.entries.DisplayRenderer; import me.shedaniel.rei.gui.widget.TabWidget; import me.shedaniel.rei.gui.widget.Widget; import me.shedaniel.rei.impl.ClientHelperImpl; @@ -62,11 +64,11 @@ import java.util.Optional; @ApiStatus.Internal public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen { - private final Map, List> categoryMap; - private final List> categories; + private final Map, List> categoryMap; + private final List> categories; private final List widgets = Lists.newArrayList(); private final List