From 28025895e0da1e6079264dbfe951e7fd9bf069d8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 11 Aug 2019 23:28:33 +0800 Subject: Scrollable Entry List? --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 6 +- .../me/shedaniel/rei/api/AutoTransferHandler.java | 2 +- .../java/me/shedaniel/rei/api/ClientHelper.java | 2 +- .../java/me/shedaniel/rei/api/ConfigObject.java | 6 +- .../java/me/shedaniel/rei/api/DisplayHelper.java | 2 +- src/main/java/me/shedaniel/rei/api/Entry.java | 4 +- .../java/me/shedaniel/rei/api/RecipeCategory.java | 2 +- .../java/me/shedaniel/rei/api/RecipeHelper.java | 2 +- .../rei/client/BaseBoundsHandlerImpl.java | 110 ----- .../me/shedaniel/rei/client/ClientHelperImpl.java | 266 ----------- .../me/shedaniel/rei/client/ConfigManagerImpl.java | 145 ------ .../me/shedaniel/rei/client/ConfigObjectImpl.java | 308 ------------- .../me/shedaniel/rei/client/DisplayHelperImpl.java | 91 ---- .../me/shedaniel/rei/client/EntryRegistryImpl.java | 66 --- .../java/me/shedaniel/rei/client/FluidEntry.java | 33 -- .../me/shedaniel/rei/client/ItemStackEntry.java | 33 -- .../me/shedaniel/rei/client/RecipeHelperImpl.java | 442 ------------------ .../java/me/shedaniel/rei/client/ScreenHelper.java | 97 ---- .../me/shedaniel/rei/client/SearchArgument.java | 58 --- src/main/java/me/shedaniel/rei/client/Weather.java | 44 -- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 195 ++++---- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 2 +- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 2 +- .../rei/gui/VillagerRecipeViewingScreen.java | 2 +- .../shedaniel/rei/gui/credits/CreditsScreen.java | 2 +- .../rei/gui/renderers/ItemStackRenderer.java | 6 +- .../rei/gui/widget/AutoCraftingButtonWidget.java | 2 +- .../me/shedaniel/rei/gui/widget/ButtonWidget.java | 2 +- .../rei/gui/widget/ClickableLabelWidget.java | 2 +- .../shedaniel/rei/gui/widget/EntryListOverlay.java | 383 ---------------- .../shedaniel/rei/gui/widget/EntryListWidget.java | 508 +++++++++++++++++++++ .../shedaniel/rei/gui/widget/RecipeBaseWidget.java | 2 +- .../rei/gui/widget/RecipeChoosePageWidget.java | 4 +- .../shedaniel/rei/gui/widget/SlotBaseWidget.java | 2 +- .../me/shedaniel/rei/gui/widget/SlotWidget.java | 28 +- .../me/shedaniel/rei/gui/widget/TabWidget.java | 2 +- .../shedaniel/rei/impl/BaseBoundsHandlerImpl.java | 110 +++++ .../me/shedaniel/rei/impl/ClientHelperImpl.java | 266 +++++++++++ .../me/shedaniel/rei/impl/ConfigManagerImpl.java | 145 ++++++ .../me/shedaniel/rei/impl/ConfigObjectImpl.java | 320 +++++++++++++ .../me/shedaniel/rei/impl/DisplayHelperImpl.java | 91 ++++ .../me/shedaniel/rei/impl/EntryRegistryImpl.java | 66 +++ .../java/me/shedaniel/rei/impl/FluidEntry.java | 33 ++ .../java/me/shedaniel/rei/impl/ItemStackEntry.java | 33 ++ .../me/shedaniel/rei/impl/RecipeHelperImpl.java | 442 ++++++++++++++++++ .../java/me/shedaniel/rei/impl/ScreenHelper.java | 97 ++++ .../java/me/shedaniel/rei/impl/SearchArgument.java | 58 +++ src/main/java/me/shedaniel/rei/impl/Weather.java | 44 ++ .../me/shedaniel/rei/plugin/DefaultPlugin.java | 60 +-- .../plugin/DefaultPotionEffectExclusionZones.java | 2 +- .../plugin/DefaultRecipeBookExclusionZones.java | 2 +- .../autocrafting/AutoBlastingBookHandler.java | 2 +- .../autocrafting/AutoCraftingTableBookHandler.java | 2 +- .../autocrafting/AutoFurnaceBookHandler.java | 2 +- .../autocrafting/AutoInventoryBookHandler.java | 2 +- .../plugin/autocrafting/AutoSmokerBookHandler.java | 2 +- .../plugin/campfire/DefaultCampfireCategory.java | 2 +- src/main/resources/fabric.mod.json | 10 +- 58 files changed, 2405 insertions(+), 2249 deletions(-) delete mode 100644 src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java delete mode 100644 src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java delete mode 100644 src/main/java/me/shedaniel/rei/client/ConfigManagerImpl.java delete mode 100644 src/main/java/me/shedaniel/rei/client/ConfigObjectImpl.java delete mode 100644 src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java delete mode 100644 src/main/java/me/shedaniel/rei/client/EntryRegistryImpl.java delete mode 100644 src/main/java/me/shedaniel/rei/client/FluidEntry.java delete mode 100644 src/main/java/me/shedaniel/rei/client/ItemStackEntry.java delete mode 100644 src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java delete mode 100644 src/main/java/me/shedaniel/rei/client/ScreenHelper.java delete mode 100644 src/main/java/me/shedaniel/rei/client/SearchArgument.java delete mode 100644 src/main/java/me/shedaniel/rei/client/Weather.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/widget/EntryListOverlay.java create mode 100644 src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java create mode 100644 src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java create mode 100644 src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java create mode 100644 src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java create mode 100644 src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java create mode 100644 src/main/java/me/shedaniel/rei/impl/DisplayHelperImpl.java create mode 100644 src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java create mode 100644 src/main/java/me/shedaniel/rei/impl/FluidEntry.java create mode 100644 src/main/java/me/shedaniel/rei/impl/ItemStackEntry.java create mode 100644 src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java create mode 100644 src/main/java/me/shedaniel/rei/impl/ScreenHelper.java create mode 100644 src/main/java/me/shedaniel/rei/impl/SearchArgument.java create mode 100644 src/main/java/me/shedaniel/rei/impl/Weather.java diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index b5e259553..4d57b3242 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -11,9 +11,9 @@ import me.shedaniel.cloth.api.ClientUtils; import me.shedaniel.cloth.hooks.ClothClientHooks; import me.shedaniel.rei.api.*; import me.shedaniel.rei.api.plugins.REIPluginV0; -import me.shedaniel.rei.client.*; +import me.shedaniel.rei.impl.*; import me.shedaniel.rei.gui.ContainerScreenOverlay; -import me.shedaniel.rei.gui.widget.EntryListOverlay; +import me.shedaniel.rei.gui.widget.EntryListWidget; import me.shedaniel.rei.listeners.RecipeBookButtonWidgetHooks; import me.shedaniel.rei.listeners.RecipeBookGuiHooks; import net.fabricmc.api.ClientModInitializer; @@ -143,7 +143,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { ClientSidePacketRegistry.INSTANCE.register(RoughlyEnoughItemsNetwork.CREATE_ITEMS_MESSAGE_PACKET, (packetContext, packetByteBuf) -> { ItemStack stack = packetByteBuf.readItemStack(); String player = packetByteBuf.readString(32767); - packetContext.getPlayer().addChatMessage(new LiteralText(I18n.translate("text.rei.cheat_items").replaceAll("\\{item_name}", EntryListOverlay.tryGetItemStackName(stack.copy())).replaceAll("\\{item_count}", stack.copy().getCount() + "").replaceAll("\\{player_name}", player)), false); + packetContext.getPlayer().addChatMessage(new LiteralText(I18n.translate("text.rei.cheat_items").replaceAll("\\{item_name}", EntryListWidget.tryGetItemStackName(stack.copy())).replaceAll("\\{item_count}", stack.copy().getCount() + "").replaceAll("\\{player_name}", player)), false); }); ClientSidePacketRegistry.INSTANCE.register(RoughlyEnoughItemsNetwork.NOT_ENOUGH_ITEMS_PACKET, (packetContext, packetByteBuf) -> { Screen currentScreen = MinecraftClient.getInstance().currentScreen; diff --git a/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java b/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java index a328c16c8..c0eaa26e6 100644 --- a/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java +++ b/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java @@ -7,7 +7,7 @@ package me.shedaniel.rei.api; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; -import me.shedaniel.rei.client.ScreenHelper; +import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.gui.ContainerScreenOverlay; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java index 7b6c8b0e7..68b8f2e0d 100644 --- a/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -5,7 +5,7 @@ package me.shedaniel.rei.api; -import me.shedaniel.rei.client.ClientHelperImpl; +import me.shedaniel.rei.impl.ClientHelperImpl; import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; diff --git a/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/src/main/java/me/shedaniel/rei/api/ConfigObject.java index de6911c96..b9519132a 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -9,16 +9,18 @@ public interface ConfigObject { ConfigNode getConfigNode(); - void setCheating(boolean cheating); - boolean isCheating(); + void setCheating(boolean cheating); + ItemListOrdering getItemListOrdering(); boolean isItemListAscending(); boolean isUsingDarkTheme(); + boolean isEntryListWidgetScrolled(); + boolean shouldAppendModNames(); RecipeScreenType getRecipeScreenType(); diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index 8b745f846..2d8fc5991 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -112,7 +112,7 @@ public interface DisplayHelper { * @return the item list bounds */ default Rectangle getItemListArea(Rectangle rectangle) { - return new Rectangle(rectangle.x + 2, rectangle.y + 24, rectangle.width - 4, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().isSideSearchField() ? 27 + 22 : 27)); + return new Rectangle(rectangle.x + 1, rectangle.y + 2 + (RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() ? 0 : 22), rectangle.width - 2, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().isSideSearchField() ? 27 + 22 : 27) + (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() ? 0 : 22)); } /** diff --git a/src/main/java/me/shedaniel/rei/api/Entry.java b/src/main/java/me/shedaniel/rei/api/Entry.java index 148c0c242..e38fc4835 100644 --- a/src/main/java/me/shedaniel/rei/api/Entry.java +++ b/src/main/java/me/shedaniel/rei/api/Entry.java @@ -1,7 +1,7 @@ package me.shedaniel.rei.api; -import me.shedaniel.rei.client.FluidEntry; -import me.shedaniel.rei.client.ItemStackEntry; +import me.shedaniel.rei.impl.FluidEntry; +import me.shedaniel.rei.impl.ItemStackEntry; import net.minecraft.fluid.Fluid; import net.minecraft.item.ItemStack; diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 5204fcbc8..1e71d7c00 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -5,7 +5,7 @@ package me.shedaniel.rei.api; -import me.shedaniel.rei.client.ScreenHelper; +import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.renderers.RecipeRenderer; import me.shedaniel.rei.gui.widget.CategoryBaseWidget; diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index 9deec1c0e..b0a02f1ba 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -22,7 +22,7 @@ import java.util.function.Predicate; public interface RecipeHelper { /** - * @return the api instance of {@link me.shedaniel.rei.client.RecipeHelperImpl} + * @return the api instance of {@link me.shedaniel.rei.impl.RecipeHelperImpl} */ static RecipeHelper getInstance() { return RoughlyEnoughItemsCore.getRecipeHelper(); diff --git a/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java b/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java deleted file mode 100644 index dfef934e7..000000000 --- a/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -import com.google.common.collect.Lists; -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.BaseBoundsHandler; -import me.shedaniel.rei.api.DisplayHelper; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Pair; - -import java.awt.*; -import java.util.Comparator; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class BaseBoundsHandlerImpl implements BaseBoundsHandler { - - private static final Function RECTANGLE_LONG_FUNCTION = r -> r.x + 1000l * r.y + 1000000l * r.width + 1000000000l * r.height; - private static final Comparator, Float>, Function>>> LIST_PAIR_COMPARATOR; - - static { - Comparator, Float>, Function>>> comparator = Comparator.comparingDouble(value -> value.getLeft().getRight()); - LIST_PAIR_COMPARATOR = comparator.reversed(); - } - - private long lastArea = -1; - private List, Float>, Function>>> list = Lists.newArrayList(); - - @Override - public Class getBaseSupportedClass() { - return Screen.class; - } - - @Override - public Rectangle getLeftBounds(Screen screen) { - return new Rectangle(); - } - - @Override - public Rectangle getRightBounds(Screen screen) { - return new Rectangle(); - } - - @Override - public float getPriority() { - return -5f; - } - - @Override - public ActionResult isInZone(boolean isOnRightSide, double mouseX, double mouseY) { - for (Rectangle zone : getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide)) - if (zone.contains(mouseX, mouseY)) - return ActionResult.FAIL; - return ActionResult.PASS; - } - - @Override - public boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) { - long current = getStringFromCurrent(isOnRightSide); - if (lastArea == current) - return false; - lastArea = current; - return true; - } - - private DisplayHelper.DisplayBoundsHandler getHandler() { - return RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); - } - - private long getStringFromCurrent(boolean isOnRightSide) { - return getLongFromAreas(isOnRightSide ? getHandler().getRightBounds(MinecraftClient.getInstance().currentScreen) : getHandler().getLeftBounds(MinecraftClient.getInstance().currentScreen), getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide)); - } - - @Override - public ActionResult canItemSlotWidgetFit(boolean isOnRightSide, int left, int top, Screen screen, Rectangle fullBounds) { - List currentExclusionZones = getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide); - for (Rectangle currentExclusionZone : currentExclusionZones) - if (left + 18 >= currentExclusionZone.x && top + 18 >= currentExclusionZone.y && left <= currentExclusionZone.x + currentExclusionZone.width && top <= currentExclusionZone.y + currentExclusionZone.height) - return ActionResult.FAIL; - return ActionResult.PASS; - } - - public List getCurrentExclusionZones(Class currentScreenClass, boolean isOnRightSide) { - List, Float>, Function>>> only = list.stream().filter(pair -> pair.getLeft().getLeft().isAssignableFrom(currentScreenClass)).collect(Collectors.toList()); - only.sort(LIST_PAIR_COMPARATOR); - List rectangles = Lists.newArrayList(); - only.forEach(pair -> rectangles.addAll(pair.getRight().apply(isOnRightSide))); - return rectangles; - } - - @Override - public void registerExclusionZones(Class screenClass, Function> supplier) { - list.add(new Pair<>(new Pair<>(screenClass, 0f), supplier)); - } - - public long getLongFromAreas(Rectangle rectangle, List exclusionZones) { - long a = RECTANGLE_LONG_FUNCTION.apply(rectangle); - for (Rectangle exclusionZone : exclusionZones) - a -= RECTANGLE_LONG_FUNCTION.apply(exclusionZone); - return a; - } - -} diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java deleted file mode 100644 index 700a0ab97..000000000 --- a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Maps; -import io.netty.buffer.Unpooled; -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.RoughlyEnoughItemsNetwork; -import me.shedaniel.rei.api.ClientHelper; -import me.shedaniel.rei.api.RecipeCategory; -import me.shedaniel.rei.api.RecipeDisplay; -import me.shedaniel.rei.api.RecipeHelper; -import me.shedaniel.rei.gui.PreRecipeViewingScreen; -import me.shedaniel.rei.gui.RecipeViewingScreen; -import me.shedaniel.rei.gui.VillagerRecipeViewingScreen; -import me.shedaniel.rei.gui.config.RecipeScreenType; -import me.zeroeightsix.fiber.exception.FiberException; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; -import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; -import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; -import net.fabricmc.loader.api.metadata.ModMetadata; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; -import net.minecraft.client.util.InputUtil; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.text.TranslatableText; -import net.minecraft.util.DefaultedList; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; -import net.minecraft.util.PacketByteBuf; -import net.minecraft.util.registry.Registry; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -public class ClientHelperImpl implements ClientHelper, ClientModInitializer { - - public static ClientHelperImpl instance; - private final Identifier recipeKeybind = new Identifier("roughlyenoughitems", "recipe_keybind"); - private final Identifier usageKeybind = new Identifier("roughlyenoughitems", "usage_keybind"); - private final Identifier hideKeybind = new Identifier("roughlyenoughitems", "hide_keybind"); - private final Identifier previousPageKeybind = new Identifier("roughlyenoughitems", "previous_page"); - private final Identifier nextPageKeybind = new Identifier("roughlyenoughitems", "next_page"); - private final Identifier focusSearchFieldKeybind = new Identifier("roughlyenoughitems", "focus_search"); - private final Map modNameCache = Maps.newHashMap(); - public FabricKeyBinding recipe, usage, hide, previousPage, nextPage, focusSearchField; - - @Override - public String getFormattedModFromItem(Item item) { - String mod = getModFromItem(item); - if (mod.isEmpty()) - return ""; - return Formatting.BLUE.toString() + Formatting.ITALIC.toString() + mod; - } - - @Override - public String getFormattedModFromIdentifier(Identifier identifier) { - String mod = getModFromIdentifier(identifier); - if (mod.isEmpty()) - return ""; - return Formatting.BLUE.toString() + Formatting.ITALIC.toString() + mod; - } - - @Override - public FabricKeyBinding getRecipeKeyBinding() { - return recipe; - } - - @Override - public FabricKeyBinding getUsageKeyBinding() { - return usage; - } - - @Override - public FabricKeyBinding getHideKeyBinding() { - return hide; - } - - @Override - public FabricKeyBinding getPreviousPageKeyBinding() { - return previousPage; - } - - @Override - public FabricKeyBinding getNextPageKeyBinding() { - return nextPage; - } - - @Override - public FabricKeyBinding getFocusSearchFieldKeyBinding() { - return focusSearchField; - } - - @Override - public String getModFromItem(Item item) { - if (item.equals(Items.AIR)) - return ""; - return getModFromIdentifier(Registry.ITEM.getId(item)); - } - - @Override - public String getModFromIdentifier(Identifier identifier) { - if (identifier == null) - return ""; - Optional any = Optional.ofNullable(modNameCache.getOrDefault(identifier.getNamespace(), null)); - if (any.isPresent()) - return any.get(); - String modid = identifier.getNamespace(); - String s = FabricLoader.getInstance().getModContainer(modid).map(ModContainer::getMetadata).map(ModMetadata::getName).orElse(modid); - modNameCache.put(modid, s); - return s; - } - - @Override - public boolean isCheating() { - return RoughlyEnoughItemsCore.getConfigManager().getConfig().isCheating(); - } - - @Override - public void setCheating(boolean cheating) { - RoughlyEnoughItemsCore.getConfigManager().getConfig().setCheating(cheating); - try { - RoughlyEnoughItemsCore.getConfigManager().saveConfig(); - } catch (IOException | FiberException e) { - e.printStackTrace(); - } - } - - @Override - public void sendDeletePacket() { - if (ScreenHelper.getLastContainerScreen() instanceof CreativeInventoryScreen) { - MinecraftClient.getInstance().player.inventory.setCursorStack(ItemStack.EMPTY); - return; - } - ClientSidePacketRegistry.INSTANCE.sendToServer(RoughlyEnoughItemsNetwork.DELETE_ITEMS_PACKET, new PacketByteBuf(Unpooled.buffer())); - } - - @Override - public boolean tryCheatingStack(ItemStack cheatedStack) { - if (RoughlyEnoughItemsCore.canUsePackets()) { - try { - ClientSidePacketRegistry.INSTANCE.sendToServer(RoughlyEnoughItemsNetwork.CREATE_ITEMS_PACKET, new PacketByteBuf(Unpooled.buffer()).writeItemStack(cheatedStack.copy())); - return true; - } catch (Exception e) { - return false; - } - } else { - Identifier identifier = Registry.ITEM.getId(cheatedStack.getItem()); - String tagMessage = cheatedStack.copy().getTag() != null && !cheatedStack.copy().getTag().isEmpty() ? cheatedStack.copy().getTag().asString() : ""; - String og = cheatedStack.getCount() == 1 ? RoughlyEnoughItemsCore.getConfigManager().getConfig().getGiveCommand().replaceAll(" \\{count}", "") : RoughlyEnoughItemsCore.getConfigManager().getConfig().getGiveCommand(); - String madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_name}", identifier.getPath()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", tagMessage).replaceAll("\\{count}", String.valueOf(cheatedStack.getCount())); - if (madeUpCommand.length() > 256) { - madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_name}", identifier.getPath()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", "").replaceAll("\\{count}", String.valueOf(cheatedStack.getCount())); - MinecraftClient.getInstance().player.addChatMessage(new TranslatableText("text.rei.too_long_nbt"), false); - } - MinecraftClient.getInstance().player.sendChatMessage(madeUpCommand); - return true; - } - } - - @Override - public boolean executeRecipeKeyBind(ItemStack stack) { - Map, List> map = RecipeHelper.getInstance().getRecipesFor(stack); - if (map.keySet().size() > 0) - openRecipeViewingScreen(map); - return map.keySet().size() > 0; - } - - @Override - public boolean executeUsageKeyBind(ItemStack stack) { - Map, List> map = RecipeHelper.getInstance().getUsagesFor(stack); - if (map.keySet().size() > 0) - openRecipeViewingScreen(map); - return map.keySet().size() > 0; - } - - @Override - public List getInventoryItemsTypes() { - List> field_7543 = ImmutableList.of(MinecraftClient.getInstance().player.inventory.main, MinecraftClient.getInstance().player.inventory.armor, MinecraftClient.getInstance().player.inventory.offHand); - List inventoryStacks = new ArrayList<>(); - field_7543.forEach(itemStacks -> itemStacks.forEach(itemStack -> { - if (!itemStack.isEmpty()) - inventoryStacks.add(itemStack); - })); - return inventoryStacks; - } - - @Override - public boolean executeViewAllRecipesKeyBind() { - Map, List> map = RecipeHelper.getInstance().getAllRecipes(); - if (map.keySet().size() > 0) - openRecipeViewingScreen(map); - return map.keySet().size() > 0; - } - - @Override - public boolean executeViewAllRecipesFromCategory(Identifier category) { - Map, List> map = Maps.newLinkedHashMap(); - Optional any = RecipeHelper.getInstance().getAllCategories().stream().filter(c -> c.getIdentifier().equals(category)).findAny(); - if (!any.isPresent()) - return false; - RecipeCategory recipeCategory = any.get(); - map.put(recipeCategory, RecipeHelper.getInstance().getAllRecipesFromCategory(recipeCategory)); - if (map.keySet().size() > 0) - openRecipeViewingScreen(map); - return map.keySet().size() > 0; - } - - @Override - public boolean executeViewAllRecipesFromCategories(List categories) { - Map, List> map = Maps.newLinkedHashMap(); - for (Identifier category : categories) { - Optional any = RecipeHelper.getInstance().getAllCategories().stream().filter(c -> c.getIdentifier().equals(category)).findAny(); - if (!any.isPresent()) - continue; - RecipeCategory recipeCategory = any.get(); - map.put(recipeCategory, RecipeHelper.getInstance().getAllRecipesFromCategory(recipeCategory)); - } - if (map.keySet().size() > 0) - openRecipeViewingScreen(map); - return map.keySet().size() > 0; - } - - @Override - public void openRecipeViewingScreen(Map, List> map) { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getRecipeScreenType() == RecipeScreenType.VILLAGER) - MinecraftClient.getInstance().openScreen(new VillagerRecipeViewingScreen(map)); - else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getRecipeScreenType() == RecipeScreenType.UNSET) - MinecraftClient.getInstance().openScreen(new PreRecipeViewingScreen(map)); - else - MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(map)); - } - - @Override - public void onInitializeClient() { - ClientHelperImpl.instance = (ClientHelperImpl) this; - registerFabricKeyBinds(); - modNameCache.put("minecraft", "Minecraft"); - modNameCache.put("c", "Common"); - } - - @Override - public void registerFabricKeyBinds() { - String category = "key.rei.category"; - KeyBindingRegistryImpl.INSTANCE.addCategory(category); - KeyBindingRegistryImpl.INSTANCE.register(recipe = FabricKeyBinding.Builder.create(recipeKeybind, InputUtil.Type.KEYSYM, 82, category).build()); - KeyBindingRegistryImpl.INSTANCE.register(usage = FabricKeyBinding.Builder.create(usageKeybind, InputUtil.Type.KEYSYM, 85, category).build()); - KeyBindingRegistryImpl.INSTANCE.register(hide = FabricKeyBinding.Builder.create(hideKeybind, InputUtil.Type.KEYSYM, 79, category).build()); - KeyBindingRegistryImpl.INSTANCE.register(previousPage = FabricKeyBinding.Builder.create(previousPageKeybind, InputUtil.Type.KEYSYM, -1, category).build()); - KeyBindingRegistryImpl.INSTANCE.register(nextPage = FabricKeyBinding.Builder.create(nextPageKeybind, InputUtil.Type.KEYSYM, -1, category).build()); - KeyBindingRegistryImpl.INSTANCE.register(focusSearchField = FabricKeyBinding.Builder.create(focusSearchFieldKeybind, InputUtil.Type.KEYSYM, -1, category).build()); - } - -} diff --git a/src/main/java/me/shedaniel/rei/client/ConfigManagerImpl.java b/src/main/java/me/shedaniel/rei/client/ConfigManagerImpl.java deleted file mode 100644 index fe0a23101..000000000 --- a/src/main/java/me/shedaniel/rei/client/ConfigManagerImpl.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.ConfigManager; -import me.shedaniel.rei.api.ConfigObject; -import me.zeroeightsix.fiber.JanksonSettings; -import me.zeroeightsix.fiber.exception.FiberException; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.text.LiteralText; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.List; - -public class ConfigManagerImpl implements ConfigManager { - - private final File configFile; - private ConfigObject config; - private boolean craftableOnly; - - public ConfigManagerImpl() { - this.configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json5"); - this.craftableOnly = false; - try { - loadConfig(); - RoughlyEnoughItemsCore.LOGGER.info("[REI] Config is loaded."); - } catch (IOException | FiberException e) { - e.printStackTrace(); - } - } - - @Override - public void saveConfig() throws IOException, FiberException { - configFile.getParentFile().mkdirs(); - if (!configFile.exists() && !configFile.createNewFile()) { - RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to save config! Overwriting with default config."); - config = new ConfigObjectImpl(); - return; - } - try { - new JanksonSettings().serialize(config.getConfigNode(), Files.newOutputStream(configFile.toPath()), false); - } catch (Exception e) { - e.printStackTrace(); - RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to save config! Overwriting with default config."); - config = new ConfigObjectImpl(); - return; - } - } - - @Override - public void loadConfig() throws IOException, FiberException { - configFile.getParentFile().mkdirs(); - if (!configFile.exists() || !configFile.canRead()) { - RoughlyEnoughItemsCore.LOGGER.warn("[REI] Config not found! Creating one."); - config = new ConfigObjectImpl(); - saveConfig(); - return; - } - boolean failed = false; - try { - config = new ConfigObjectImpl(); - new JanksonSettings().deserialize(config.getConfigNode(), Files.newInputStream(configFile.toPath())); - } catch (Exception e) { - e.printStackTrace(); - failed = true; - } - if (failed || config == null) { - RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to load config! Overwriting with default config."); - config = new ConfigObjectImpl(); - } - saveConfig(); - } - - @Override - public ConfigObject getConfig() { - return config; - } - - @Override - public boolean isCraftableOnlyEnabled() { - return craftableOnly; - } - - @Override - public void toggleCraftableOnly() { - craftableOnly = !craftableOnly; - } - - @Override - public void openConfigScreen(Screen parent) { - MinecraftClient.getInstance().openScreen(getConfigScreen(parent)); - } - - @Override - public Screen getConfigScreen(Screen parent) { - if (FabricLoader.getInstance().isModLoaded("cloth-config2")) { - try { - return Screen.class.cast(Class.forName("me.shedaniel.rei.utils.ClothScreenRegistry").getDeclaredMethod("getConfigScreen", Screen.class).invoke(null, parent)); - } catch (Exception e) { - e.printStackTrace(); - } - } - return new Screen(new LiteralText("")) { - @Override - public void render(int int_1, int int_2, float float_1) { - renderDirtBackground(0); - List list = minecraft.textRenderer.wrapStringToWidthAsList(I18n.translate("text.rei.config_api_failed"), width - 100); - int y = (int) (height / 2 - minecraft.textRenderer.fontHeight * 1.3f / 2 * list.size()); - for (int i = 0; i < list.size(); i++) { - String s = list.get(i); - drawCenteredString(minecraft.textRenderer, s, width / 2, y, -1); - y += minecraft.textRenderer.fontHeight; - } - super.render(int_1, int_2, float_1); - } - - @Override - protected void init() { - super.init(); - addButton(new net.minecraft.client.gui.widget.ButtonWidget(width / 2 - 100, height - 26, 200, 20, I18n.translate("text.rei.back"), buttonWidget -> { - this.minecraft.openScreen(parent); - })); - } - - @Override - public boolean keyPressed(int int_1, int int_2, int int_3) { - if (int_1 == 256 && this.shouldCloseOnEsc()) { - this.minecraft.openScreen(parent); - return true; - } - return super.keyPressed(int_1, int_2, int_3); - } - }; - } - -} diff --git a/src/main/java/me/shedaniel/rei/client/ConfigObjectImpl.java b/src/main/java/me/shedaniel/rei/client/ConfigObjectImpl.java deleted file mode 100644 index a4f308bca..000000000 --- a/src/main/java/me/shedaniel/rei/client/ConfigObjectImpl.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -import me.shedaniel.rei.api.ConfigObject; -import me.shedaniel.rei.gui.config.ItemCheatingMode; -import me.shedaniel.rei.gui.config.ItemListOrdering; -import me.shedaniel.rei.gui.config.ItemListOrderingConfig; -import me.shedaniel.rei.gui.config.RecipeScreenType; -import me.zeroeightsix.fiber.exception.FiberException; -import me.zeroeightsix.fiber.tree.ConfigNode; -import me.zeroeightsix.fiber.tree.ConfigValue; -import me.zeroeightsix.fiber.tree.Node; - -public class ConfigObjectImpl implements ConfigObject { - - public ConfigNode configNode = new ConfigNode(); - - private Node general = configNode.fork("!general"); - private Node appearance = configNode.fork("appearance"); - private Node modules = configNode.fork("modules"); - private Node technical = configNode.fork("technical"); - - private ConfigValue cheating = ConfigValue.builder(Boolean.class) - .withParent(general) - .withDefaultValue(false) - .withComment("Declares whether cheating mode is on.") - .withName("cheating") - .build(); - - private ConfigValue itemListOrdering = ConfigValue.builder(ItemListOrderingConfig.class) - .withParent(appearance) - .withDefaultValue(ItemListOrderingConfig.REGISTRY_ASCENDING) - .withComment("The ordering of the items on the item panel.") - .withName("itemListOrdering") - .build(); - - private ConfigValue darkTheme = ConfigValue.builder(Boolean.class) - .withParent(appearance) - .withDefaultValue(false) - .withComment("Declares the appearance of REI windows.") - .withName("darkTheme") - .build(); - - private ConfigValue recipeScreenType = ConfigValue.builder(RecipeScreenType.class) - .withParent(appearance) - .withDefaultValue(RecipeScreenType.UNSET) - .withComment("The ordering of the items on the item panel.") - .withName("recipeScreenType") - .build(); - - private ConfigValue loadDefaultPlugin = ConfigValue.builder(Boolean.class) - .withParent(technical) - .withDefaultValue(true) - .withComment("To disable REI's default plugin.\nDon't change this unless you understand what you are doing") - .withName("loadDefaultPlugin") - .build(); - - private ConfigValue sideSearchField = ConfigValue.builder(Boolean.class) - .withParent(appearance) - .withDefaultValue(false) - .withComment("Declares the position of the search field.") - .withName("sideSearchField") - .build(); - - private ConfigValue mirrorItemPanel = ConfigValue.builder(Boolean.class) - .withParent(appearance) - .withDefaultValue(false) - .withComment("Declares the position of the item list panel.") - .withName("mirrorItemPanel") - .build(); - - private ConfigValue enableCraftableOnlyButton = ConfigValue.builder(Boolean.class) - .withParent(modules) - .withDefaultValue(true) - .withComment("Declares whether the craftable filter button is enabled.") - .withName("enableCraftableOnlyButton") - .build(); - - private ConfigValue gamemodeCommand = ConfigValue.builder(String.class) - .withParent(technical) - .withDefaultValue("/gamemode {gamemode}") - .withComment("Declares the command used to change gamemode.") - .withName("gamemodeCommand") - .build(); - - private ConfigValue giveCommand = ConfigValue.builder(String.class) - .withParent(technical) - .withDefaultValue("/give {player_name} {item_identifier}{nbt} {count}") - .withComment("Declares the command used in servers to cheat items.") - .withName("giveCommand") - .build(); - - private ConfigValue weatherCommand = ConfigValue.builder(String.class) - .withParent(technical) - .withDefaultValue("/weather {weather}") - .withComment("Declares the command used to change weather.") - .withName("weatherCommand") - .build(); - - private ConfigValue maxRecipePerPage = ConfigValue.builder(Integer.class) - .withParent(appearance) - .withDefaultValue(3) - .withComment("Declares the maximum amount of recipes displayed in a page if possible.") - .withName("maxRecipePerPage") - .constraints() - .minNumerical(2) - .maxNumerical(99) - .finish() - .build(); - - private ConfigValue showUtilsButtons = ConfigValue.builder(Boolean.class) - .withParent(modules) - .withDefaultValue(false) - .withComment("Declares whether the utils buttons are shown.") - .withName("showUtilsButtons") - .build(); - - private ConfigValue disableRecipeBook = ConfigValue.builder(Boolean.class) - .withParent(modules) - .withDefaultValue(false) - .withComment("Declares whether REI should remove the recipe book.") - .withName("disableRecipeBook") - .build(); - - private ConfigValue clickableRecipeArrows = ConfigValue.builder(Boolean.class) - .withParent(appearance) - .withDefaultValue(true) - .withName("clickableRecipeArrows") - .build(); - - private ConfigValue itemCheatingMode = ConfigValue.builder(ItemCheatingMode.class) - .withParent(appearance) - .withDefaultValue(ItemCheatingMode.REI_LIKE) - .withName("itemCheatingMode") - .build(); - - private ConfigValue lightGrayRecipeBorder = ConfigValue.builder(Boolean.class) - .withParent(appearance) - .withDefaultValue(false) - .withComment("Declares the appearance of recipe's border.") - .withName("lightGrayRecipeBorder") - .build(); - - private ConfigValue appendModNames = ConfigValue.builder(Boolean.class) - .withParent(appearance) - .withDefaultValue(false) - .withComment("Declares whether REI should append mod names to item stacks.") - .withName("appendModNames") - .build(); - - private ConfigValue villagerScreenPermanentScrollBar = ConfigValue.builder(Boolean.class) - .withParent(appearance) - .withDefaultValue(false) - .withComment("Declares how the scrollbar in villager screen act.") - .withName("villagerScreenPermanentScrollBar") - .build(); - - private ConfigValue registerRecipesInAnotherThread = ConfigValue.builder(Boolean.class) - .withParent(technical) - .withDefaultValue(true) - .withName("registerRecipesInAnotherThread") - .build(); - - // private ConfigValue choosePageDialogPoint = ConfigValue.builder(RelativePoint.class) - // .withParent(technical) - // .withDefaultValue(new RelativePoint(.5, .5)) - // .withName("choosePageDialogPoint") - // .build(); - - public ConfigObjectImpl() throws FiberException { - - } - - @Override - public ConfigNode getConfigNode() { - return configNode; - } - - @Override - public boolean isCheating() { - return cheating.getValue(); - } - - @Override - public void setCheating(boolean cheating) { - this.cheating.setValue(cheating); - } - - @Override - public ItemListOrdering getItemListOrdering() { - return itemListOrdering.getValue().getOrdering(); - } - - @Override - public boolean isItemListAscending() { - return itemListOrdering.getValue().isAscending(); - } - - @Override - public boolean isUsingDarkTheme() { - return darkTheme.getValue().booleanValue(); - } - - @Override - public boolean shouldAppendModNames() { - return appendModNames.getValue().booleanValue(); - } - - @Override - public RecipeScreenType getRecipeScreenType() { - return recipeScreenType.getValue(); - } - - @Override - public void setRecipeScreenType(RecipeScreenType recipeScreenType) { - this.recipeScreenType.setValue(recipeScreenType); - } - - @Override - public boolean isLoadingDefaultPlugin() { - return loadDefaultPlugin.getValue().booleanValue(); - } - - @Override - public boolean isSideSearchField() { - return sideSearchField.getValue().booleanValue(); - } - - @Override - public boolean isLeftHandSidePanel() { - return mirrorItemPanel.getValue().booleanValue(); - } - - @Override - public boolean isCraftableFilterEnabled() { - return enableCraftableOnlyButton.getValue().booleanValue(); - } - - @Override - public String getGamemodeCommand() { - return gamemodeCommand.getValue(); - } - - @Override - public String getGiveCommand() { - return giveCommand.getValue(); - } - - @Override - public String getWeatherCommand() { - return weatherCommand.getValue(); - } - - @Override - public int getMaxRecipePerPage() { - return maxRecipePerPage.getValue().intValue(); - } - - @Override - public boolean doesShowUtilsButtons() { - return showUtilsButtons.getValue().booleanValue(); - } - - @Override - public boolean doesDisableRecipeBook() { - return disableRecipeBook.getValue().booleanValue(); - } - - @Override - public boolean areClickableRecipeArrowsEnabled() { - return clickableRecipeArrows.getValue().booleanValue(); - } - - @Override - public ItemCheatingMode getItemCheatingMode() { - return itemCheatingMode.getValue(); - } - - @Override - public boolean isUsingLightGrayRecipeBorder() { - return lightGrayRecipeBorder.getValue().booleanValue(); - } - - @Override - public boolean doesVillagerScreenHavePermanentScrollBar() { - return villagerScreenPermanentScrollBar.getValue().booleanValue(); - } - - @Override - public boolean doesRegisterRecipesInAnotherThread() { - return registerRecipesInAnotherThread.getValue().booleanValue(); - } - - @Override - public RelativePoint getChoosePageDialogPoint() { - // return choosePageDialogPoint.getValue(); - return new RelativePoint(.5, .5); - } - - @Override - public void setChoosePageDialogPoint(RelativePoint choosePageDialogPoint) { - // this.choosePageDialogPoint.setValue(choosePageDialogPoint); - } -} diff --git a/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java b/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java deleted file mode 100644 index ac6d581bf..000000000 --- a/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import me.shedaniel.rei.api.BaseBoundsHandler; -import me.shedaniel.rei.api.DisplayHelper; - -import java.awt.*; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -public class DisplayHelperImpl implements DisplayHelper { - - private static final Comparator> BOUNDS_HANDLER_COMPARATOR; - private static final DisplayBoundsHandler EMPTY = new DisplayBoundsHandler() { - @Override - public Class getBaseSupportedClass() { - return null; - } - - @Override - public Rectangle getLeftBounds(Object screen) { - return new Rectangle(); - } - - @Override - public Rectangle getRightBounds(Object screen) { - return new Rectangle(); - } - - @Override - public float getPriority() { - return -10f; - } - }; - - static { - Comparator> comparator = Comparator.comparingDouble(DisplayBoundsHandler::getPriority); - BOUNDS_HANDLER_COMPARATOR = comparator.reversed(); - } - - private List> screenDisplayBoundsHandlers = Lists.newArrayList(); - private Map, DisplayBoundsHandler> handlerCache = Maps.newHashMap(); - private BaseBoundsHandler baseBoundsHandler; - - @Override - public List> getSortedBoundsHandlers(Class screenClass) { - return screenDisplayBoundsHandlers.stream().filter(handler -> handler.getBaseSupportedClass().isAssignableFrom(screenClass)).sorted(BOUNDS_HANDLER_COMPARATOR).collect(Collectors.toList()); - } - - @Override - public List> getAllBoundsHandlers() { - return screenDisplayBoundsHandlers; - } - - @Override - public DisplayBoundsHandler getResponsibleBoundsHandler(Class screenClass) { - Optional> any = handlerCache.entrySet().stream().filter(entry -> entry.getKey().equals(screenClass)).map(Map.Entry::getValue).findAny(); - if (any.isPresent()) - return any.get(); - handlerCache.put(screenClass, screenDisplayBoundsHandlers.stream().filter(handler -> handler.getBaseSupportedClass().isAssignableFrom(screenClass)).sorted(BOUNDS_HANDLER_COMPARATOR).findAny().orElse(EMPTY)); - return handlerCache.get(screenClass); - } - - @Override - public void registerBoundsHandler(DisplayBoundsHandler handler) { - screenDisplayBoundsHandlers.add(handler); - } - - @Override - public BaseBoundsHandler getBaseBoundsHandler() { - return baseBoundsHandler; - } - - public void setBaseBoundsHandler(BaseBoundsHandler baseBoundsHandler) { - this.baseBoundsHandler = baseBoundsHandler; - } - - public void resetCache() { - handlerCache.clear(); - } - -} diff --git a/src/main/java/me/shedaniel/rei/client/EntryRegistryImpl.java b/src/main/java/me/shedaniel/rei/client/EntryRegistryImpl.java deleted file mode 100644 index 9e4f72ff3..000000000 --- a/src/main/java/me/shedaniel/rei/client/EntryRegistryImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -import com.google.common.collect.Lists; -import me.shedaniel.rei.api.Entry; -import me.shedaniel.rei.api.EntryRegistry; -import net.minecraft.fluid.Fluid; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.DefaultedList; - -import java.util.Collections; -import java.util.List; -import java.util.TreeSet; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.stream.Collectors; - -public class EntryRegistryImpl implements EntryRegistry { - - private final CopyOnWriteArrayList entries = Lists.newCopyOnWriteArrayList(); - - @Override - public List getEntryList() { - return Collections.unmodifiableList(entries); - } - - @SuppressWarnings("deprecation") - @Override - public List getModifiableEntryList() { - return entries; - } - - @Override - public ItemStack[] getAllStacksFromItem(Item item) { - DefaultedList list = DefaultedList.create(); - list.add(item.getStackForRender()); - item.appendStacks(item.getGroup(), list); - TreeSet stackSet = list.stream().collect(Collectors.toCollection(() -> new TreeSet((p1, p2) -> ItemStack.areEqualIgnoreDamage(p1, p2) ? 0 : 1))); - return Lists.newArrayList(stackSet).toArray(new ItemStack[0]); - } - - @Override - public void registerItemStack(Item afterItem, ItemStack stack) { - if (!stack.isEmpty() && !alreadyContain(stack)) - if (afterItem == null || afterItem.equals(Items.AIR)) - entries.add(Entry.create(stack)); - else { - int last = entries.size(); - for (int i = 0; i < entries.size(); i++) - if (entries.get(i).getEntryType() == Entry.Type.ITEM && entries.get(i).getItemStack().getItem().equals(afterItem)) - last = i + 1; - entries.add(last, Entry.create(stack)); - } - } - - @Override - public void registerFluid(Fluid fluid) { - entries.add(Entry.create(fluid)); - } - -} diff --git a/src/main/java/me/shedaniel/rei/client/FluidEntry.java b/src/main/java/me/shedaniel/rei/client/FluidEntry.java deleted file mode 100644 index 27c37fae2..000000000 --- a/src/main/java/me/shedaniel/rei/client/FluidEntry.java +++ /dev/null @@ -1,33 +0,0 @@ -package me.shedaniel.rei.client; - -import me.shedaniel.rei.api.Entry; -import net.minecraft.fluid.Fluid; -import net.minecraft.item.ItemStack; - -import javax.annotation.Nullable; - -public class FluidEntry implements Entry { - private Fluid fluid; - - @Deprecated - public FluidEntry(Fluid fluid) { - this.fluid = fluid; - } - - @Override - public Type getEntryType() { - return Type.FLUID; - } - - @Nullable - @Override - public ItemStack getItemStack() { - return null; - } - - @Nullable - @Override - public Fluid getFluid() { - return fluid; - } -} diff --git a/src/main/java/me/shedaniel/rei/client/ItemStackEntry.java b/src/main/java/me/shedaniel/rei/client/ItemStackEntry.java deleted file mode 100644 index 49855fb7d..000000000 --- a/src/main/java/me/shedaniel/rei/client/ItemStackEntry.java +++ /dev/null @@ -1,33 +0,0 @@ -package me.shedaniel.rei.client; - -import me.shedaniel.rei.api.Entry; -import net.minecraft.fluid.Fluid; -import net.minecraft.item.ItemStack; - -import javax.annotation.Nullable; - -public class ItemStackEntry implements Entry { - private ItemStack itemStack; - - @Deprecated - public ItemStackEntry(ItemStack itemStack) { - this.itemStack = itemStack; - } - - @Override - public Type getEntryType() { - return Type.ITEM; - } - - @Nullable - @Override - public ItemStack getItemStack() { - return itemStack; - } - - @Nullable - @Override - public Fluid getFluid() { - return null; - } -} diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java deleted file mode 100644 index 92f7299ff..000000000 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.*; -import me.shedaniel.rei.api.plugins.REIPluginV0; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.SemanticVersion; -import net.fabricmc.loader.api.Version; -import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.Recipe; -import net.minecraft.recipe.RecipeManager; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Identifier; - -import java.awt.*; -import java.util.List; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -public class RecipeHelperImpl implements RecipeHelper { - - private static final Comparator VISIBILITY_HANDLER_COMPARATOR; - private static final Comparator RECIPE_COMPARATOR = (o1, o2) -> { - int int_1 = o1.getId().getNamespace().compareTo(o2.getId().getNamespace()); - if (int_1 == 0) - int_1 = o1.getId().getPath().compareTo(o2.getId().getPath()); - return int_1; - }; - - static { - Comparator comparator = Comparator.comparingDouble(DisplayVisibilityHandler::getPriority); - VISIBILITY_HANDLER_COMPARATOR = comparator.reversed(); - } - - private final List autoTransferHandlers = Lists.newArrayList(); - private final List recipeFunctions = Lists.newArrayList(); - private final List screenClickAreas = Lists.newArrayList(); - private final AtomicInteger recipeCount = new AtomicInteger(); - private final Map> recipeCategoryListMap = Maps.newHashMap(); - private final List categories = Lists.newArrayList(); - private final Map speedCraftAreaSupplierMap = Maps.newHashMap(); - private final Map>> categoryWorkingStations = Maps.newHashMap(); - private final List displayVisibilityHandlers = Lists.newArrayList(); - private final List> liveRecipeGenerators = Lists.newArrayList(); - private RecipeManager recipeManager; - - @Override - public List findCraftableByItems(List inventoryItems) { - List craftables = new ArrayList<>(); - for (List value : recipeCategoryListMap.values()) - for (RecipeDisplay recipeDisplay : value) { - int slotsCraftable = 0; - List> requiredInput = (List>) recipeDisplay.getRequiredItems(); - for (List slot : requiredInput) { - if (slot.isEmpty()) { - slotsCraftable++; - continue; - } - boolean slotDone = false; - for (ItemStack possibleType : inventoryItems) { - for (ItemStack slotPossible : slot) - if (ItemStack.areItemsEqualIgnoreDamage(slotPossible, possibleType)) { - slotsCraftable++; - slotDone = true; - break; - } - if (slotDone) - break; - } - } - if (slotsCraftable == recipeDisplay.getRequiredItems().size()) - craftables.addAll((List) recipeDisplay.getOutput()); - } - return craftables.stream().distinct().collect(Collectors.toList()); - } - - @Override - public void registerCategory(RecipeCategory category) { - categories.add(category); - recipeCategoryListMap.put(category.getIdentifier(), Lists.newLinkedList()); - categoryWorkingStations.put(category.getIdentifier(), Lists.newLinkedList()); - } - - @Override - public void registerWorkingStations(Identifier category, List... workingStations) { - categoryWorkingStations.get(category).addAll(Arrays.asList(workingStations)); - } - - @Override - public void registerWorkingStations(Identifier category, ItemStack... workingStations) { - categoryWorkingStations.get(category).addAll(Arrays.asList(workingStations).stream().map(Collections::singletonList).collect(Collectors.toList())); - } - - @Override - public List> getWorkingStations(Identifier category) { - return categoryWorkingStations.get(category); - } - - @Override - public void registerDisplay(Identifier categoryIdentifier, RecipeDisplay display) { - if (!recipeCategoryListMap.containsKey(categoryIdentifier)) - return; - recipeCount.incrementAndGet(); - recipeCategoryListMap.get(categoryIdentifier).add(display); - } - - private void registerDisplay(Identifier categoryIdentifier, RecipeDisplay display, int index) { - if (!recipeCategoryListMap.containsKey(categoryIdentifier)) - return; - recipeCount.incrementAndGet(); - recipeCategoryListMap.get(categoryIdentifier).add(index, display); - } - - @Override - public Map, List> getRecipesFor(ItemStack stack) { - Map> categoriesMap = new HashMap<>(); - categories.forEach(f -> categoriesMap.put(f.getIdentifier(), Lists.newArrayList())); - for (Map.Entry> entry : recipeCategoryListMap.entrySet()) { - RecipeCategory category = getCategory(entry.getKey()); - for (RecipeDisplay recipeDisplay : entry.getValue()) - for (ItemStack outputStack : (List) recipeDisplay.getOutput()) - if (category.checkTags() ? ItemStack.areEqualIgnoreDamage(stack, outputStack) : ItemStack.areItemsEqualIgnoreDamage(stack, outputStack)) - categoriesMap.get(recipeDisplay.getRecipeCategory()).add(recipeDisplay); - } - for (LiveRecipeGenerator liveRecipeGenerator : liveRecipeGenerators) - ((Optional) liveRecipeGenerator.getRecipeFor(stack)).ifPresent(o -> categoriesMap.get(liveRecipeGenerator.getCategoryIdentifier()).addAll(o)); - Map, List> recipeCategoryListMap = Maps.newLinkedHashMap(); - categories.forEach(category -> { - if (categoriesMap.containsKey(category.getIdentifier()) && !categoriesMap.get(category.getIdentifier()).isEmpty()) - recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display)).collect(Collectors.toList())); - }); - for (RecipeCategory category : Lists.newArrayList(recipeCategoryListMap.keySet())) - if (recipeCategoryListMap.get(category).isEmpty()) - recipeCategoryListMap.remove(category); - return recipeCategoryListMap; - } - - @Override - public RecipeCategory getCategory(Identifier identifier) { - return categories.stream().filter(category -> category.getIdentifier().equals(identifier)).findFirst().orElse(null); - } - - @Override - public RecipeManager getRecipeManager() { - return recipeManager; - } - - @Override - public Map, List> getUsagesFor(ItemStack stack) { - Map> categoriesMap = new HashMap<>(); - categories.forEach(f -> categoriesMap.put(f.getIdentifier(), Lists.newArrayList())); - for (Map.Entry> entry : recipeCategoryListMap.entrySet()) { - RecipeCategory category = getCategory(entry.getKey()); - for (RecipeDisplay recipeDisplay : entry.getValue()) { - boolean found = false; - for (List input : (List>) recipeDisplay.getInput()) { - for (ItemStack itemStack : input) { - if (category.checkTags() ? ItemStack.areEqualIgnoreDamage(itemStack, stack) : ItemStack.areItemsEqualIgnoreDamage(itemStack, stack)) { - categoriesMap.get(recipeDisplay.getRecipeCategory()).add(recipeDisplay); -