From 1b21d26487636e50d03979acd5ca4a2a07761a25 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 9 Jan 2019 23:35:45 +0800 Subject: Starting off rewrite --- src/main/java/me/shedaniel/ClientListener.java | 106 ------ src/main/java/me/shedaniel/Core.java | 122 ------- .../java/me/shedaniel/api/IDisplayCategory.java | 32 -- .../shedaniel/api/IDisplayCategoryCraftable.java | 19 - src/main/java/me/shedaniel/api/IDrawable.java | 12 - src/main/java/me/shedaniel/api/IREIPlugin.java | 16 - src/main/java/me/shedaniel/api/IRecipe.java | 20 -- src/main/java/me/shedaniel/api/IRecipeManager.java | 21 -- .../java/me/shedaniel/api/TriBooleanSupplier.java | 8 - src/main/java/me/shedaniel/config/REIConfig.java | 22 -- .../me/shedaniel/config/REIItemListOrdering.java | 21 -- .../java/me/shedaniel/config/REIRuntimeConfig.java | 8 - src/main/java/me/shedaniel/gui/ConfigGui.java | 154 -------- src/main/java/me/shedaniel/gui/Drawable.java | 35 -- src/main/java/me/shedaniel/gui/GuiItemList.java | 397 --------------------- .../java/me/shedaniel/gui/REIRenderHelper.java | 280 --------------- .../java/me/shedaniel/gui/RecipeContainer.java | 14 - src/main/java/me/shedaniel/gui/RecipeGui.java | 287 --------------- src/main/java/me/shedaniel/gui/SearchArgument.java | 36 -- src/main/java/me/shedaniel/gui/widget/Button.java | 63 ---- src/main/java/me/shedaniel/gui/widget/Control.java | 127 ------- .../gui/widget/CraftableToggleButton.java | 76 ---- .../java/me/shedaniel/gui/widget/IFocusable.java | 12 - .../me/shedaniel/gui/widget/KeyBindButton.java | 59 --- src/main/java/me/shedaniel/gui/widget/REISlot.java | 188 ---------- .../java/me/shedaniel/gui/widget/SmallButton.java | 73 ---- src/main/java/me/shedaniel/gui/widget/Tab.java | 101 ------ src/main/java/me/shedaniel/gui/widget/TextBox.java | 85 ----- .../java/me/shedaniel/gui/widget/WidgetArrow.java | 50 --- .../java/me/shedaniel/impl/REIRecipeManager.java | 220 ------------ .../java/me/shedaniel/library/KeyBindFunction.java | 23 -- src/main/java/me/shedaniel/library/Sink.java | 8 - .../shedaniel/listenerdefinitions/CharInput.java | 10 - .../listenerdefinitions/ClientTickable.java | 7 - .../shedaniel/listenerdefinitions/DoneLoading.java | 10 - .../listenerdefinitions/DrawContainer.java | 12 - .../me/shedaniel/listenerdefinitions/GuiClick.java | 10 - .../shedaniel/listenerdefinitions/GuiKeyDown.java | 10 - .../listenerdefinitions/GuiMouseScroll.java | 7 - .../me/shedaniel/listenerdefinitions/IEvent.java | 4 - .../listenerdefinitions/IMixinContainerGui.java | 20 -- .../listenerdefinitions/IMixinRecipeBookGui.java | 9 - .../listenerdefinitions/MinecraftResize.java | 10 - .../listenerdefinitions/PotionCraftingAdder.java | 10 - .../listenerdefinitions/RecipeLoadListener.java | 9 - .../shedaniel/listeners/DrawContainerListener.java | 65 ---- .../mixins/MixinBrewingRecipeRegistry.java | 21 -- .../me/shedaniel/mixins/MixinContainerGui.java | 97 ----- .../mixins/MixinCreativePlayerInventoryGui.java | 64 ---- .../java/me/shedaniel/mixins/MixinDoneLoading.java | 23 -- .../me/shedaniel/mixins/MixinKeyboardListener.java | 29 -- .../me/shedaniel/mixins/MixinMinecraftResize.java | 31 -- .../me/shedaniel/mixins/MixinRecipeBookGui.java | 20 -- .../me/shedaniel/mixins/MixinRecipeManager.java | 27 -- .../java/me/shedaniel/network/CheatPacket.java | 49 --- .../java/me/shedaniel/network/DeletePacket.java | 33 -- .../java/me/shedaniel/plugin/RandomRecipe.java | 40 --- .../me/shedaniel/plugin/TestRandomCategory.java | 70 ---- .../java/me/shedaniel/plugin/VanillaPlugin.java | 105 ------ .../blastfurnace/VanillaBlastFurnaceCategory.java | 126 ------- .../blastfurnace/VanillaBlastFurnaceRecipe.java | 58 --- .../plugin/crafting/VanillaCraftingCategory.java | 157 -------- .../plugin/crafting/VanillaCraftingRecipe.java | 28 -- .../crafting/VanillaShapedCraftingRecipe.java | 59 --- .../crafting/VanillaShapelessCraftingRecipe.java | 61 ---- .../plugin/furnace/VanillaFurnaceCategory.java | 126 ------- .../plugin/furnace/VanillaFurnaceRecipe.java | 60 ---- .../plugin/potion/VanillaPotionCategory.java | 189 ---------- .../plugin/potion/VanillaPotionRecipe.java | 56 --- .../plugin/smoker/VanillaSmokerCategory.java | 126 ------- .../plugin/smoker/VanillaSmokerRecipe.java | 55 --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 46 +++ .../me/shedaniel/rei/gui/ContainerGuiOverlay.java | 68 ++++ .../java/me/shedaniel/rei/gui/widget/IWidget.java | 9 + .../me/shedaniel/rei/gui/widget/LabelWidget.java | 24 ++ .../me/shedaniel/rei/listeners/ClientTick.java | 9 + .../java/me/shedaniel/rei/listeners/IListener.java | 4 + .../me/shedaniel/rei/mixin/IMixinContainerGui.java | 17 + .../me/shedaniel/rei/mixin/MixinContainerGui.java | 67 ++++ 79 files changed, 244 insertions(+), 4598 deletions(-) delete mode 100755 src/main/java/me/shedaniel/ClientListener.java delete mode 100755 src/main/java/me/shedaniel/Core.java delete mode 100755 src/main/java/me/shedaniel/api/IDisplayCategory.java delete mode 100644 src/main/java/me/shedaniel/api/IDisplayCategoryCraftable.java delete mode 100755 src/main/java/me/shedaniel/api/IDrawable.java delete mode 100755 src/main/java/me/shedaniel/api/IREIPlugin.java delete mode 100755 src/main/java/me/shedaniel/api/IRecipe.java delete mode 100755 src/main/java/me/shedaniel/api/IRecipeManager.java delete mode 100755 src/main/java/me/shedaniel/api/TriBooleanSupplier.java delete mode 100644 src/main/java/me/shedaniel/config/REIConfig.java delete mode 100644 src/main/java/me/shedaniel/config/REIItemListOrdering.java delete mode 100644 src/main/java/me/shedaniel/config/REIRuntimeConfig.java delete mode 100644 src/main/java/me/shedaniel/gui/ConfigGui.java delete mode 100755 src/main/java/me/shedaniel/gui/Drawable.java delete mode 100755 src/main/java/me/shedaniel/gui/GuiItemList.java delete mode 100755 src/main/java/me/shedaniel/gui/REIRenderHelper.java delete mode 100755 src/main/java/me/shedaniel/gui/RecipeContainer.java delete mode 100755 src/main/java/me/shedaniel/gui/RecipeGui.java delete mode 100644 src/main/java/me/shedaniel/gui/SearchArgument.java delete mode 100755 src/main/java/me/shedaniel/gui/widget/Button.java delete mode 100755 src/main/java/me/shedaniel/gui/widget/Control.java delete mode 100644 src/main/java/me/shedaniel/gui/widget/CraftableToggleButton.java delete mode 100755 src/main/java/me/shedaniel/gui/widget/IFocusable.java delete mode 100644 src/main/java/me/shedaniel/gui/widget/KeyBindButton.java delete mode 100755 src/main/java/me/shedaniel/gui/widget/REISlot.java delete mode 100644 src/main/java/me/shedaniel/gui/widget/SmallButton.java delete mode 100644 src/main/java/me/shedaniel/gui/widget/Tab.java delete mode 100755 src/main/java/me/shedaniel/gui/widget/TextBox.java delete mode 100755 src/main/java/me/shedaniel/gui/widget/WidgetArrow.java delete mode 100755 src/main/java/me/shedaniel/impl/REIRecipeManager.java delete mode 100644 src/main/java/me/shedaniel/library/KeyBindFunction.java delete mode 100755 src/main/java/me/shedaniel/library/Sink.java delete mode 100755 src/main/java/me/shedaniel/listenerdefinitions/CharInput.java delete mode 100644 src/main/java/me/shedaniel/listenerdefinitions/ClientTickable.java delete mode 100755 src/main/java/me/shedaniel/listenerdefinitions/DoneLoading.java delete mode 100755 src/main/java/me/shedaniel/listenerdefinitions/DrawContainer.java delete mode 100755 src/main/java/me/shedaniel/listenerdefinitions/GuiClick.java delete mode 100755 src/main/java/me/shedaniel/listenerdefinitions/GuiKeyDown.java delete mode 100755 src/main/java/me/shedaniel/listenerdefinitions/GuiMouseScroll.java delete mode 100644 src/main/java/me/shedaniel/listenerdefinitions/IEvent.java delete mode 100755 src/main/java/me/shedaniel/listenerdefinitions/IMixinContainerGui.java delete mode 100644 src/main/java/me/shedaniel/listenerdefinitions/IMixinRecipeBookGui.java delete mode 100755 src/main/java/me/shedaniel/listenerdefinitions/MinecraftResize.java delete mode 100644 src/main/java/me/shedaniel/listenerdefinitions/PotionCraftingAdder.java delete mode 100755 src/main/java/me/shedaniel/listenerdefinitions/RecipeLoadListener.java delete mode 100755 src/main/java/me/shedaniel/listeners/DrawContainerListener.java delete mode 100644 src/main/java/me/shedaniel/mixins/MixinBrewingRecipeRegistry.java delete mode 100755 src/main/java/me/shedaniel/mixins/MixinContainerGui.java delete mode 100644 src/main/java/me/shedaniel/mixins/MixinCreativePlayerInventoryGui.java delete mode 100755 src/main/java/me/shedaniel/mixins/MixinDoneLoading.java delete mode 100755 src/main/java/me/shedaniel/mixins/MixinKeyboardListener.java delete mode 100755 src/main/java/me/shedaniel/mixins/MixinMinecraftResize.java delete mode 100644 src/main/java/me/shedaniel/mixins/MixinRecipeBookGui.java delete mode 100755 src/main/java/me/shedaniel/mixins/MixinRecipeManager.java delete mode 100755 src/main/java/me/shedaniel/network/CheatPacket.java delete mode 100755 src/main/java/me/shedaniel/network/DeletePacket.java delete mode 100644 src/main/java/me/shedaniel/plugin/RandomRecipe.java delete mode 100644 src/main/java/me/shedaniel/plugin/TestRandomCategory.java delete mode 100755 src/main/java/me/shedaniel/plugin/VanillaPlugin.java delete mode 100755 src/main/java/me/shedaniel/plugin/blastfurnace/VanillaBlastFurnaceCategory.java delete mode 100755 src/main/java/me/shedaniel/plugin/blastfurnace/VanillaBlastFurnaceRecipe.java delete mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaCraftingCategory.java delete mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaCraftingRecipe.java delete mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaShapedCraftingRecipe.java delete mode 100755 src/main/java/me/shedaniel/plugin/crafting/VanillaShapelessCraftingRecipe.java delete mode 100755 src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java delete mode 100755 src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceRecipe.java delete mode 100644 src/main/java/me/shedaniel/plugin/potion/VanillaPotionCategory.java delete mode 100755 src/main/java/me/shedaniel/plugin/potion/VanillaPotionRecipe.java delete mode 100755 src/main/java/me/shedaniel/plugin/smoker/VanillaSmokerCategory.java delete mode 100755 src/main/java/me/shedaniel/plugin/smoker/VanillaSmokerRecipe.java create mode 100644 src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java create mode 100644 src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java create mode 100644 src/main/java/me/shedaniel/rei/gui/widget/IWidget.java create mode 100644 src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java create mode 100644 src/main/java/me/shedaniel/rei/listeners/ClientTick.java create mode 100644 src/main/java/me/shedaniel/rei/listeners/IListener.java create mode 100644 src/main/java/me/shedaniel/rei/mixin/IMixinContainerGui.java create mode 100644 src/main/java/me/shedaniel/rei/mixin/MixinContainerGui.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/ClientListener.java b/src/main/java/me/shedaniel/ClientListener.java deleted file mode 100755 index ec1061e2f..000000000 --- a/src/main/java/me/shedaniel/ClientListener.java +++ /dev/null @@ -1,106 +0,0 @@ -package me.shedaniel; - -import me.shedaniel.api.IREIPlugin; -import me.shedaniel.gui.REIRenderHelper; -import me.shedaniel.impl.REIRecipeManager; -import me.shedaniel.library.KeyBindFunction; -import me.shedaniel.listenerdefinitions.DoneLoading; -import me.shedaniel.listenerdefinitions.RecipeLoadListener; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.recipe.RecipeManager; -import net.minecraft.util.DefaultedList; -import net.minecraft.util.registry.Registry; - -import java.util.*; - -public class ClientListener implements DoneLoading, RecipeLoadListener { - - public static KeyBindFunction recipeKeyBind; - public static KeyBindFunction hideKeyBind; - public static KeyBindFunction usageKeyBind; - public static List keyBinds = new ArrayList<>(); - - private List plugins; - public static List stackList; - - public static boolean processGuiKeyBinds(int typedChar) { - for(KeyBindFunction keyBind : keyBinds) - if (keyBind.apply(typedChar)) - return true; - return false; - } - - @Override - public void onDoneLoading() { - plugins = new ArrayList<>(); - stackList = new ArrayList<>(); - - buildItemList(); - } - - public void onInitializeKeyBind() { - recipeKeyBind = new KeyBindFunction(Core.config.recipeKeyBind) { - @Override - public boolean apply(int key) { - if (key == this.getKey()) - REIRenderHelper.recipeKeyBind(); - return key == this.getKey(); - } - }; - hideKeyBind = new KeyBindFunction(Core.config.hideKeyBind) { - @Override - public boolean apply(int key) { - if (key == this.getKey()) - REIRenderHelper.hideKeyBind(); - return key == this.getKey(); - } - }; - usageKeyBind = new KeyBindFunction(Core.config.usageKeyBind) { - @Override - public boolean apply(int key) { - if (key == this.getKey()) - REIRenderHelper.useKeyBind(); - return key == this.getKey(); - } - }; - keyBinds.addAll(Arrays.asList(recipeKeyBind, hideKeyBind, usageKeyBind)); - } - - private void buildItemList() { - if (!Registry.ITEM.isEmpty()) - Registry.ITEM.forEach(this::processItem); - if (Registry.ENCHANTMENT.stream().count() > 0) - Registry.ENCHANTMENT.forEach(enchantment -> { - for(int i = enchantment.getMinimumLevel(); i < enchantment.getMaximumLevel(); i++) { - ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK); - Map map = new HashMap<>(); - map.put(enchantment, i); - EnchantmentHelper.set(map, stack); - processItemStack(stack); - } - }); - } - - private void processItem(Item item) { - DefaultedList items = DefaultedList.create(); - try { - item.addStacksForDisplay(item.getItemGroup(), items); - items.forEach(stackList::add); - } catch (NullPointerException e) { - } - } - - private void processItemStack(ItemStack item) { - stackList.add(item); - } - - @Override - public void recipesLoaded(RecipeManager recipeManager) { - REIRecipeManager.instance().RecipesLoaded(recipeManager); - } - -} diff --git a/src/main/java/me/shedaniel/Core.java b/src/main/java/me/shedaniel/Core.java deleted file mode 100755 index 2cc74161b..000000000 --- a/src/main/java/me/shedaniel/Core.java +++ /dev/null @@ -1,122 +0,0 @@ -package me.shedaniel; - -import me.shedaniel.config.REIConfig; -import me.shedaniel.config.REIRuntimeConfig; -import me.shedaniel.listenerdefinitions.ClientTickable; -import me.shedaniel.listenerdefinitions.IEvent; -import me.shedaniel.listeners.DrawContainerListener; -import me.shedaniel.network.CheatPacket; -import me.shedaniel.plugin.VanillaPlugin; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.events.client.ClientTickEvent; -import net.fabricmc.loader.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.item.ItemStack; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -/** - * Created by James on 7/27/2018. - */ -public class Core implements ClientModInitializer { - - private static List events = new LinkedList<>(); - public static final File configFile = new File(FabricLoader.INSTANCE.getConfigDirectory(), "rei.json"); - public static REIConfig config; - public static REIRuntimeConfig runtimeConfig; - public static ClientListener clientListener; - public static Logger LOGGER = LogManager.getFormatterLogger("REI"); - - @Override - public void onInitializeClient() { - this.clientListener = new ClientListener(); - registerSelfEvents(); - registerFabricEvents(); - try { - loadConfig(); - runtimeConfig = new REIRuntimeConfig(); - } catch (IOException e) { - e.printStackTrace(); - } - this.clientListener.onInitializeKeyBind(); - } - - private void registerFabricEvents() { - ClientTickEvent.CLIENT.register(minecraftClient -> { - getListeners(ClientTickable.class).forEach(ClientTickable::clientTick); - if (!Core.config.enableCraftableOnlyButton) - Core.runtimeConfig.craftableOnly = false; - }); - } - - private void registerSelfEvents() { - registerEvent(new DrawContainerListener()); - registerEvent(clientListener); - registerPlugin(new VanillaPlugin()); - } - - public static void registerPlugin(VanillaPlugin vanillaPlugin) { - registerEvent(vanillaPlugin); - } - - private static void registerEvent(IEvent event) { - events.add(event); - } - - public static List getListeners(Class listenerInterface) { - List list = new ArrayList<>(); - events.forEach(iEvent -> { - if (listenerInterface.isAssignableFrom(iEvent.getClass())) - list.add(listenerInterface.cast(iEvent)); - }); - return list; - } - - public static void loadConfig() throws IOException { - if (!configFile.exists() || !configFile.canRead()) { - config = new REIConfig(); - saveConfig(); - return; - } - boolean failed = false; - try { - config = REIConfig.GSON.fromJson(new InputStreamReader(Files.newInputStream(configFile.toPath())), REIConfig.class); - } catch (Exception e) { - failed = true; - } - if (failed || config == null) { - Core.LOGGER.error("REI: Failed to load config! Overwriting with default config."); - config = new REIConfig(); - } - saveConfig(); - } - - public static void saveConfig() throws IOException { - configFile.getParentFile().mkdirs(); - if (!configFile.exists() && !configFile.createNewFile()) { - Core.LOGGER.error("REI: Failed to save config! Overwriting with default config."); - config = new REIConfig(); - return; - } - FileWriter writer = new FileWriter(configFile, false); - try { - REIConfig.GSON.toJson(config, writer); - } finally { - writer.close(); - } - } - - public static void cheatItems(ItemStack cheatedStack) { - MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CheatPacket(cheatedStack)); - } - -} diff --git a/src/main/java/me/shedaniel/api/IDisplayCategory.java b/src/main/java/me/shedaniel/api/IDisplayCategory.java deleted file mode 100755 index 309a836ac..000000000 --- a/src/main/java/me/shedaniel/api/IDisplayCategory.java +++ /dev/null @@ -1,32 +0,0 @@ -package me.shedaniel.api; - -import me.shedaniel.gui.widget.Control; -import me.shedaniel.gui.widget.REISlot; -import net.minecraft.item.ItemStack; - -import java.util.List; - -/** - * Created by James on 8/7/2018. - */ -public interface IDisplayCategory { - - public String getId(); - - public String getDisplayName(); - - public void addRecipe(T recipe); - - public void resetRecipes(); - - public List setupDisplay(int number); - - public boolean canDisplay(T recipe); - - public void drawExtras(); - - public void addWidget(List controls, int number); - - public ItemStack getCategoryIcon(); - -} diff --git a/src/main/java/me/shedaniel/api/IDisplayCategoryCraftable.java b/src/main/java/me/shedaniel/api/IDisplayCategoryCraftable.java deleted file mode 100644 index c34c1e37b..000000000 --- a/src/main/java/me/shedaniel/api/IDisplayCategoryCraftable.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.shedaniel.api; - -import me.shedaniel.api.IDisplayCategory; -import me.shedaniel.api.IRecipe; -import me.shedaniel.gui.RecipeGui; -import me.shedaniel.gui.widget.Control; -import net.minecraft.client.gui.Gui; - -import java.util.List; - -public interface IDisplayCategoryCraftable extends IDisplayCategory { - - public boolean canAutoCraftHere(Class guiClass, T recipe); - - public boolean performAutoCraft(Gui gui, T recipe); - - public void registerAutoCraftButton(List control, RecipeGui recipeGui, Gui parentGui, T recipe, int number); - -} diff --git a/src/main/java/me/shedaniel/api/IDrawable.java b/src/main/java/me/shedaniel/api/IDrawable.java deleted file mode 100755 index 48294bea7..000000000 --- a/src/main/java/me/shedaniel/api/IDrawable.java +++ /dev/null @@ -1,12 +0,0 @@ -package me.shedaniel.api; - -/** - * Created by James on 8/7/2018. - */ -public interface IDrawable { - - public void draw(); - - public boolean isHighlighted(); - -} diff --git a/src/main/java/me/shedaniel/api/IREIPlugin.java b/src/main/java/me/shedaniel/api/IREIPlugin.java deleted file mode 100755 index 2736cbf1d..000000000 --- a/src/main/java/me/shedaniel/api/IREIPlugin.java +++ /dev/null @@ -1,16 +0,0 @@ -package me.shedaniel.api; - -import me.shedaniel.listenerdefinitions.IEvent; - -/** - * Created by James on 7/27/2018. - */ -public interface IREIPlugin extends IEvent { - - public void registerCategories(); - - public void registerRecipes(); - - public void registerSpecialGuiExclusion(); - -} diff --git a/src/main/java/me/shedaniel/api/IRecipe.java b/src/main/java/me/shedaniel/api/IRecipe.java deleted file mode 100755 index 096c6fe1f..000000000 --- a/src/main/java/me/shedaniel/api/IRecipe.java +++ /dev/null @@ -1,20 +0,0 @@ -package me.shedaniel.api; - -import net.minecraft.item.ItemStack; - -import java.util.List; - -/** - * Created by James on 7/27/2018. - */ -public interface IRecipe { - - public String getId(); - - public List getOutput(); - - public List> getInput(); - - public List> getRecipeRequiredInput(); - -} diff --git a/src/main/java/me/shedaniel/api/IRecipeManager.java b/src/main/java/me/shedaniel/api/IRecipeManager.java deleted file mode 100755 index 82135bf3f..000000000 --- a/src/main/java/me/shedaniel/api/IRecipeManager.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.shedaniel.api; - -import net.minecraft.item.ItemStack; - -import java.util.List; -import java.util.Map; - -/** - * Created by James on 8/5/2018. - */ -public interface IRecipeManager { - - public void addRecipe(String id, IRecipe recipe); - - public void addRecipe(String id, List recipes); - - public void addDisplayAdapter(IDisplayCategory adapter); - - public Map> getRecipesFor(ItemStack stack); - -} diff --git a/src/main/java/me/shedaniel/api/TriBooleanSupplier.java b/src/main/java/me/shedaniel/api/TriBooleanSupplier.java deleted file mode 100755 index 241307740..000000000 --- a/src/main/java/me/shedaniel/api/TriBooleanSupplier.java +++ /dev/null @@ -1,8 +0,0 @@ -package me.shedaniel.api; - -/** - * Created by James on 8/4/2018. - */ -public interface TriBooleanSupplier { - public boolean accept(int first, int second, int third); -} diff --git a/src/main/java/me/shedaniel/config/REIConfig.java b/src/main/java/me/shedaniel/config/REIConfig.java deleted file mode 100644 index 06dfbfc8d..000000000 --- a/src/main/java/me/shedaniel/config/REIConfig.java +++ /dev/null @@ -1,22 +0,0 @@ -package me.shedaniel.config; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import java.awt.event.KeyEvent; - -public class REIConfig { - - public static Gson GSON = new GsonBuilder() - .setPrettyPrinting() - .create(); - - public int recipeKeyBind = KeyEvent.VK_R; - public int usageKeyBind = KeyEvent.VK_U; - public int hideKeyBind = KeyEvent.VK_O; - public boolean centreSearchBox = false; - public REIItemListOrdering itemListOrdering = REIItemListOrdering.REGISTRY; - public boolean isAscending = true; - public boolean enableCraftableOnlyButton = true; - -} diff --git a/src/main/java/me/shedaniel/config/REIItemListOrdering.java b/src/main/java/me/shedaniel/config/REIItemListOrdering.java deleted file mode 100644 index f0a6b5356..000000000 --- a/src/main/java/me/shedaniel/config/REIItemListOrdering.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.shedaniel.config; - -import com.google.gson.annotations.SerializedName; - -public enum REIItemListOrdering { - - @SerializedName("registry") REGISTRY("ordering.rei.registry"), - @SerializedName("name") NAME("ordering.rei.name"), - @SerializedName("item_groups") ITEM_GROUPS("ordering.rei.item_groups"); - - private String nameTranslationKey; - - REIItemListOrdering(String nameTranslationKey) { - this.nameTranslationKey = nameTranslationKey; - } - - public String getNameTranslationKey() { - return nameTranslationKey; - } - -} diff --git a/src/main/java/me/shedaniel/config/REIRuntimeConfig.java b/src/main/java/me/shedaniel/config/REIRuntimeConfig.java deleted file mode 100644 index b13a72bfb..000000000 --- a/src/main/java/me/shedaniel/config/REIRuntimeConfig.java +++ /dev/null @@ -1,8 +0,0 @@ -package me.shedaniel.config; - -public class REIRuntimeConfig { - - public boolean craftableOnly = false; - public boolean centreSearchBox = false; - -} diff --git a/src/main/java/me/shedaniel/gui/ConfigGui.java b/src/main/java/me/shedaniel/gui/ConfigGui.java deleted file mode 100644 index 6deeb24ea..000000000 --- a/src/main/java/me/shedaniel/gui/ConfigGui.java +++ /dev/null @@ -1,154 +0,0 @@ -package me.shedaniel.gui; - -import me.shedaniel.ClientListener; -import me.shedaniel.Core; -import me.shedaniel.config.REIItemListOrdering; -import me.shedaniel.gui.widget.KeyBindButton; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.render.GuiLighting; -import net.minecraft.client.resource.language.I18n; - -import java.io.IOException; -import java.util.Arrays; - -public class ConfigGui extends Gui { - - private Gui parent; - - public ConfigGui(Gui parent) { - this.parent = parent; - } - - @Override - protected void onInitialized() { - addButton(new KeyBindButton(997, parent.width / 2 - 20, 30, 80, 20, Core.config.recipeKeyBind, key -> { - Core.config.recipeKeyBind = key; - ClientListener.recipeKeyBind.setKey(key); - try { - Core.saveConfig(); - } catch (IOException e) { - e.printStackTrace(); - } - })); - addButton(new KeyBindButton(998, parent.width / 2 - 20, 60, 80, 20, Core.config.usageKeyBind, key -> { - Core.config.usageKeyBind = key; - ClientListener.usageKeyBind.setKey(key); - try { - Core.saveConfig(); - } catch (IOException e) { - e.printStackTrace(); - } - })); - addButton(new KeyBindButton(999, parent.width / 2 - 20, 90, 80, 20, Core.config.hideKeyBind, key -> { - Core.config.hideKeyBind = key; - ClientListener.hideKeyBind.setKey(key); - try { - Core.saveConfig(); - } catch (IOException e) { - e.printStackTrace(); - } - })); - addButton(new ButtonWidget(1000, parent.width / 2 - 90, 120, 150, 20, "") { - @Override - public void onPressed(double double_1, double double_2) { - Core.config.centreSearchBox = !Core.config.centreSearchBox; - try { - Core.saveConfig(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void draw(int int_1, int int_2, float float_1) { - this.text = I18n.translate("text.rei.centre_searchbox", Core.config.centreSearchBox ? "§a" : "§c", Core.config.centreSearchBox); - super.draw(int_1, int_2, float_1); - if (this.hovered) - drawSuggestion(int_1, int_2); - } - - protected void drawSuggestion(int x, int y) { - drawTooltip(Arrays.asList(I18n.translate("text.rei.centre_searchbox.tooltip").split("\n")), x, y); - } - }); - addButton(new ButtonWidget(1001, parent.width / 2 - 90, 150, 150, 20, "") { - @Override - public void onPressed(double double_1, double double_2) { - Core.config.enableCraftableOnlyButton = !Core.config.enableCraftableOnlyButton; - try { - Core.saveConfig(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void draw(int int_1, int int_2, float float_1) { - GuiLighting.disable(); - this.text = I18n.translate("text.rei.enable_craftable_only.button", Core.config.enableCraftableOnlyButton ? "§a" : "§c", Core.config.enableCraftableOnlyButton); - super.draw(int_1, int_2, float_1); - if (this.hovered) - drawSuggestion(int_1, int_2); - } - - protected void drawSuggestion(int x, int y) { - drawTooltip(Arrays.asList(I18n.translate("text.rei.enable_craftable_only.tooltip").split("\n")), x, y); - } - }); - addButton(new ButtonWidget(1002, parent.width / 2 - 90, 180, 150, 20, "") { - @Override - public void onPressed(double double_1, double double_2) { - int index = Arrays.asList(REIItemListOrdering.values()).indexOf(Core.config.itemListOrdering) + 1; - if (index >= REIItemListOrdering.values().length) { - index = 0; - Core.config.isAscending = !Core.config.isAscending; - } - Core.config.itemListOrdering = REIItemListOrdering.values()[index]; - try { - Core.saveConfig(); - REIRenderHelper.reiGui.updateView(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void draw(int int_1, int int_2, float float_1) { - GuiLighting.disable(); - this.text = I18n.translate("text.rei.list_ordering_button", I18n.translate(Core.config.itemListOrdering.getNameTranslationKey()), - I18n.translate(Core.config.isAscending ? "ordering.rei.ascending" : "ordering.rei.descending")); - super.draw(int_1, int_2, float_1); - } - }); - } - - @Override - public void draw(int mouseX, int mouseY, float partialTicks) { - drawBackground(); - super.draw(mouseX, mouseY, partialTicks); - GuiLighting.disable(); - String text = I18n.translate("key.rei.recipe") + ": "; - drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 25 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 30 + 6, -1); - text = I18n.translate("key.rei.use") + ": "; - drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 25 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 60 + 6, -1); - text = I18n.translate("key.rei.hide") + ": "; - drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 25 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 90 + 6, -1); - text = I18n.translate("text.rei.list_ordering") + ": "; - drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 95 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 180 + 6, -1); - } - - @Override - public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) { - if (p_keyPressed_1_ == 256 && this.doesEscapeKeyClose()) { - this.close(); - if (parent != null) - MinecraftClient.getInstance().openGui(parent); - return true; - } else { - return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); - } - } - -} diff --git a/src/main/java/me/shedaniel/gui/Drawable.java b/src/main/java/me/shedaniel/gui/Drawable.java deleted file mode 100755 index a2e5740a4..000000000 --- a/src/main/java/me/shedaniel/gui/Drawable.java +++ /dev/null @@ -1,35 +0,0 @@ -package me.shedaniel.gui; - -import me.shedaniel.api.IDrawable; -import me.shedaniel.gui.widget.Control; - -import java.awt.*; - -/** - * Created by James on 7/28/2018. - */ -public abstract class Drawable implements IDrawable { - - protected Rectangle rect; - - public Drawable(int x, int y, int width, int height) { - rect = new Rectangle(x, y, width, height); - } - - public Drawable(Rectangle rect) { - this.rect = rect; - } - - public abstract void draw(); - - public boolean isHighlighted() { - Point mousePoint = REIRenderHelper.getMouseLoc(); - if (rect.contains(mousePoint.x, mousePoint.y)) { - if (this instanceof Control) - REIRenderHelper.reiGui.setLastHovered((Control) this); - return true; - } - return false; - } - -} diff --git a/src/main/java/me/shedaniel/gui/GuiItemList.java b/src/main/java/me/shedaniel/gui/GuiItemList.java deleted file mode 100755 index e62f21490..000000000 --- a/src/main/java/me/shedaniel/gui/GuiItemList.java +++ /dev/null @@ -1,397 +0,0 @@ -package me.shedaniel.gui; - -import com.google.common.collect.ImmutableList; -import com.mojang.blaze3d.platform.GlStateManager; -import me.shedaniel.ClientListener; -import me.shedaniel.Core; -import me.shedaniel.config.REIItemListOrdering; -import me.shedaniel.gui.widget.*; -import me.shedaniel.gui.widget.Button; -import me.shedaniel.impl.REIRecipeManager; -import me.shedaniel.listenerdefinitions.IMixinContainerGui; -import net.fabricmc.fabric.client.itemgroup.FabricCreativeGuiComponents; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.ContainerGui; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.render.GuiLighting; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.client.util.Window; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.DefaultedList; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.registry.Registry; - -import java.awt.*; -import java.util.*; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class GuiItemList extends Drawable { - - public final int FOOTERSIZE; - private ContainerGui overlayedGui; - private static int page = 0; - private ArrayList displaySlots; - protected ArrayList controls; - private boolean needsResize = false; - Button buttonLeft, buttonRight, buttonCheating, buttonConfig; - private TextBox searchBox; - private ArrayList view; - private Control lastHovered; - protected boolean visible = true; - private int oldGuiLeft = 0; - private boolean cheatMode = false; - private List lastPlayerItems = new ArrayList<>(); - - public GuiItemList(ContainerGui overlayedGui) { - super(calculateRect(overlayedGui)); - FOOTERSIZE = Core.runtimeConfig.centreSearchBox ? 18 : 44; - displaySlots = new ArrayList<>(); - controls = new ArrayList<>(); - this.overlayedGui = overlayedGui; - view = new ArrayList<>(); - resize(); - } - - public boolean canCheat() { - ClientPlayerEntity player = MinecraftClient.getInstance().player; - if (cheatMode) { - if (!player.allowsPermissionLevel(1)) { - cheatClicked(0); - return false; - } - return true; - } - return false; - } - - private static Rectangle calculateRect(ContainerGui overlayedGui) { - Window res = REIRenderHelper.getResolution(); - int startX = (((IMixinContainerGui) overlayedGui).getGuiLeft() + ((IMixinContainerGui) overlayedGui).getXSize()) + 10; - int width = res.getScaledWidth() - startX; - return new Rectangle(startX, 0, width, res.getScaledHeight()); - } - - protected void resize() { - Window res = REIRenderHelper.getResolution(); - - if (overlayedGui != MinecraftClient.getInstance().currentGui) { - if (MinecraftClient.getInstance().currentGui instanceof ContainerGui) { - overlayedGui = (ContainerGui) MinecraftClient.getInstance().currentGui; - } else { - needsResize = true; - return; - } - } - oldGuiLeft = ((IMixinContainerGui) overlayedGui).getGuiLeft(); - rect = calculateRect(overlayedGui); - page = 0; - buttonLeft = new Button(rect.x, rect.y + 3, 16, 20, "<"); - buttonLeft.onClick = this::btnLeftClicked; - buttonRight = new Button(rect.x + rect.width - 18, rect.y + 3, 16, 20, ">"); - buttonRight.onClick = this::btnRightClicked; - controls.clear(); - controls.add(buttonLeft); - controls.add(buttonRight); - String savedText = ""; - if (searchBox != null) { - savedText = searchBox.getText(); - } - searchBox = new TextBox(getSearchBoxArea()); - searchBox.setText(savedText); - if (Core.config.enableCraftableOnlyButton) { - CraftableToggleButton buttonCraftableOnly = new CraftableToggleButton(getCraftableToggleArea()); - buttonCraftableOnly.setOnClick(i -> { - Core.runtimeConfig.craftableOnly = !Core.runtimeConfig.craftableOnly; - REIRenderHelper.updateSearch(); - return true; - }); - controls.add(buttonCraftableOnly); - } - controls.add(searchBox); - buttonCheating = new Button(5, 5, 45, 20, getCheatModeText()); - buttonCheating.onClick = this::cheatClicked; - buttonConfig = new Button(5, 28, 45, 20, I18n.translate("text.rei.config")); - buttonConfig.onClick = i -> { - MinecraftClient.getInstance().openGui(null); - MinecraftClient.getInstance().openGui(new ConfigGui(overlayedGui)); - return true; - }; - controls.add(buttonConfig); - controls.add(buttonCheating); - calculateSlots(); - updateView(); - fillSlots(); - controls.addAll(displaySlots); - } - - private Rectangle getSearchBoxArea() { - int widthOffset = Core.config.enableCraftableOnlyButton ? -24 : 0; - int ch = ((IMixinContainerGui) overlayedGui).getContainerHeight(), cw = ((IMixinContainerGui) overlayedGui).getContainerWidth(); - if (Core.runtimeConfig.centreSearchBox) { - if (ch + 4 + 18 > MinecraftClient.getInstance().window.getScaledHeight()) //Will be out of bounds - return new Rectangle(overlayedGui.width / 2 - cw / 2, rect.height + 100, cw + widthOffset, 18); - return new Rectangle(overlayedGui.width / 2 - cw / 2, rect.height - 31, cw + widthOffset, 18); - } - return new Rectangle(rect.x, rect.height - 31, rect.width - 4 + widthOffset, 18); - } - - private Rectangle getCraftableToggleArea() { - Rectangle searchBoxArea = getSearchBoxArea(); - searchBoxArea.setLocation(searchBoxArea.x + searchBoxArea.width + 4, searchBoxArea.y - 1); - searchBoxArea.setSize(20, 20); - return searchBoxArea; - } - - private void fillSlots() { - page = MathHelper.clamp(page, 0, MathHelper.ceil(view.size() / displaySlots.size())); - int firstSlot = page * displaySlots.size(); - for(int i = 0; i < displaySlots.size(); i++) { - if (firstSlot + i < view.size() && firstSlot + i >= 0) { - displaySlots.get(i).setStack(view.get(firstSlot + i)); - } else { - displaySlots.get(i).setStack(ItemStack.EMPTY); - } - } - } - - private void calculateSlots() { - int x = rect.x, y = rect.y + 20; - Window res = REIRenderHelper.getResolution(); - displaySlots.clear(); - int xOffset = 0, yOffset = 0, row = 0, perRow = 0, currentX = 0, currentY = 0; - while (true) { - xOffset += 18; - if (row == 0) - perRow++; - if (x + xOffset + 22 > res.getScaledWidth()) { - xOffset = 0; - yOffset += 18; - row++; - } - if (y + yOffset + 9 + FOOTERSIZE > rect.height) { - xOffset = 0; - yOffset = 0; - break; - } - } - x += (rect.width - perRow * 18) / 2; - y += (rect.height - FOOTERSIZE - 2 - row * 18) / 2; - while (true) { - REISlot slot = new REISlot(x + xOffset, y + yOffset); - slot.setCheatable(true); - if (REIRecipeManager.instance().canAddSlot(MinecraftClient.getInstance().currentGui.getClass(), slot.rect)) - displaySlots.add(slot); - xOffset += 18; - currentX++; - if (currentX >= perRow) { - xOffset = 0; - yOffset += 18; - currentX = 0; - currentY++; - } - if (currentY >= row) - break; - } - } - - @Override - public void draw() { - if (!visible) - return; - if (MinecraftClient.getInstance().currentGui instanceof ContainerGui) - overlayedGui = (ContainerGui) MinecraftClient.getInstance().currentGui; - if (needsResize == true || oldGuiLeft != ((IMixinContainerGui) overlayedGui).getGuiLeft()) - resize(); - else if (Core.runtimeConfig.craftableOnly && (!hasSameListContent(new LinkedList<>(lastPlayerItems), getInventoryItemsTypes()) || (getInventoryItemsTypes().size() != lastPlayerItems.size()))) { - this.lastPlayerItems = new LinkedList<>(getInventoryItemsTypes()); - updateView(); - } - GlStateManager.pushMatrix(); - updateButtons(); - controls.forEach(Control::draw); - GuiLighting.disable(); - String header = String.format("%s/%s", page + 1, MathHelper.ceil(view.size() / displaySlots.size()) + 1); - MinecraftClient.getInstance().fontRenderer.drawWithShadow(header, rect.x + (rect.width / 2) - (MinecraftClient.getInstance().fontRenderer.getStringWidth(header) / 2), rect.y + 10, -1); - GlStateManager.popMatrix(); - } - - private boolean hasSameListContent(List list1, List list2) { - Collections.sort(list1, (itemStack, t1) -> { - return itemStack.getDisplayName().getFormattedText().compareToIgnoreCase(t1.getDisplayName().getFormattedText()); - }); - Collections.sort(list2, (itemStack, t1) -> { - return itemStack.getDisplayName().getFormattedText().compareToIgnoreCase(t1.getDisplayName().getFormattedText()); - }); - String lastString = String.join("", list1.stream().map(itemStack -> { - return itemStack.getDisplayName().getFormattedText(); - }).collect(Collectors.toList())), currentString = String.join("", list2.stream().map(itemStack -> { - return itemStack.getDisplayName().getFormattedText(); - }).collect(Collectors.toList())); - return lastString.equals(currentString); - } - - private void updateButtons() { - buttonLeft.setEnabled(MathHelper.ceil(view.size() / displaySlots.size()) > 1); - buttonRight.setEnabled(MathHelper.ceil(view.size() / displaySlots.size()) > 1); - } - - public boolean btnRightClicked(int button) { - if (button == 0) { - page++; - if (page > MathHelper.ceil(view.size() / displaySlots.size())) - page = 0; - fillSlots(); - return true; - } - return false; - } - - public boolean btnLeftClicked(int button) { - if (button == 0) { - page--; - if (page < 0) - page = MathHelper.ceil(view.size() / displaySlots.size()); - fillSlots(); - return true; - } - return false; - } - - public boolean cheatClicked(int button) { - if (button == 0) { - cheatMode = !cheatMode; - buttonCheating.setString(getCheatModeText()); - return true; - } - return false; - } - - private String getCheatModeText() { - return I18n.translate(String.format("%s%s", "text.rei.", cheatMode ? "cheat" : "nocheat")); - } - - protected void updateView() { - String searchText = searchBox.getText(); - view.clear(); - List stacks = new ArrayList<>(); - if (ClientListener.stackList == null && !Registry.ITEM.isEmpty()) - Core.getListeners(ClientListener.class).forEach(ClientListener::onDoneLoading); - if (ClientListener.stackList != null) { - List stackList = new LinkedList<>(ClientListener.stackList); - List itemGroups = new LinkedList<>(Arrays.asList(ItemGroup.GROUPS)); - FabricCreativeGuiComponents.COMMON_GROUPS.forEach(itemGroups::add); - itemGroups.add(null); - if (Core.config.itemListOrdering != REIItemListOrdering.REGISTRY) - Collections.sort(stackList, (itemStack, t1) -> { - if (Core.config.itemListOrdering.equals(REIItemListOrdering.NAME)) - return itemStack.getDisplayName().getFormattedText().compareToIgnoreCase(t1.getDisplayName().getFormattedText()); - if (Core.config.itemListOrdering.equals(REIItemListOrdering.ITEM_GROUPS)) - return itemGroups.indexOf(itemStack.getItem().getItemGroup()) - itemGroups.indexOf(t1.getItem().getItemGroup()); - return 0; - }); - if (!Core.config.isAscending) - Collections.reverse(stackList); - Arrays.stream(searchText.split("\\|")).forEachOrdered(s -> { - List arguments = new ArrayList<>(); - while (s.startsWith(" ")) s = s.substring(1); - while (s.endsWith(" ")) s = s.substring(0, s.length()); - if (s.startsWith("@-") || s.startsWith("-@")) - arguments.add(new SearchArgument(SearchArgument.ArgumentType.MOD, s.substring(2), false)); - else if (s.startsWith("@")) - arguments.add(new SearchArgument(SearchArgument.ArgumentType.MOD, s.substring(1), true)); - else if (s.startsWith("#-") || s.startsWith("-#")) - arguments.add(new SearchArgument(SearchArgument.ArgumentType.TOOLTIP, s.substring(2), false)); - else if (s.startsWith("#")) - arguments.add(new SearchArgument(SearchArgument.ArgumentType.TOOLTIP, s.substring(1), true)); - else if (s.startsWith("-")) - arguments.add(new SearchArgument(SearchArgument.ArgumentType.TEXT, s.substring(1), false)); - else - arguments.add(new SearchArgument(SearchArgument.ArgumentType.TEXT, s, true)); - stackList.stream().filter(itemStack -> filterItem(itemStack, arguments)).forEachOrdered(stacks::add); - }); - } - List workingItems = ClientListener.stackList == null || (Core.runtimeConfig.craftableOnly && lastPlayerItems.size() > 0) ? new ArrayList<>() : ClientListener.stackList; - if (Core.runtimeConfig.craftableOnly) { - REIRecipeManager.instance().findCraftableByItems(lastPlayerItems).forEach(workingItems::add); - workingItems.addAll(lastPlayerItems); - } - final List finalWorkingItems = workingItems; - view.addAll(stacks.stream().filter(itemStack -> { - if (!Core.runtimeConfig.craftableOnly) - return true; - for(ItemStack workingItem : finalWorkingItems) - if (itemStack.isEqualIgnoreTags(workingItem)) - return true; - return false; - }).distinct().collect(Collectors.toList())); - page = 0; - fillSlots(); - } - - private 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.getItem().equals(Items.AIR)) - inventoryStacks.add(itemStack); - })); - return inventoryStacks; - } - - private boolean filterItem(ItemStack itemStack, List arguments) { - String mod = getMod(itemStack); - List toolTipsList = REIRenderHelper.getOverlayedGui().getStackTooltip(itemStack); - String toolTipsMixed = toolTipsList.stream().skip(1).collect(Collectors.joining()).toLowerCase(); - String allMixed = Stream.of(itemStack.getDisplayName().getString(), toolTipsMixed).collect(Collectors.joining()).toLowerCase(); - for(SearchArgument searchArgument : arguments.stream().filter(searchArgument -> !searchArgument.isInclude()).collect(Collectors.toList())) { - if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.MOD)) - if (mod.toLowerCase().contains(searchArgument.getText().toLowerCase())) - return false; - if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.TOOLTIP)) - if (toolTipsMixed.contains(searchArgument.getText().toLowerCase())) - return false; - if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.TEXT)) - if (allMixed.contains(searchArgument.getText().toLowerCase())) - return false; - } - for(SearchArgument searchArgument : arguments.stream().filter(SearchArgument::isInclude).collect(Collectors.toList())) { - if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.MOD)) - if (!mod.toLowerCase().contains(searchArgument.getText().toLowerCase())) - return false; - if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.TOOLTIP)) - if (!toolTipsMixed.contains(searchArgument.getText().toLowerCase())) - return false; - if (searchArgument.getArgumentType().equals(SearchArgument.ArgumentType.TEXT)) - if (!allMixed.contains(searchArgument.getText().toLowerCase())) - return false; - } - return true; - } - - public void tick() { - controls.forEach(f -> f.tick()); - } - - public void setLastHovered(Control ctrl) { - lastHovered = ctrl; - } - - public Control getLastHovered() { - return lastHovered; - } - - private String getMod(ItemStack stack) { - if (stack != null && !stack.isEmpty()) { - Identifier location = Registry.ITEM.getId(stack.getItem()); - return location.getNamespace(); - } - return ""; - } - -} diff --git a/src/main/java/me/shedaniel/gui/REIRenderHelper.java b/src/main/java/me/shedaniel/gui/REIRenderHelper.java deleted file mode 100755 index 81d5be801..000000000 --- a/src/main/java/me/shedaniel/gui/REIRenderHelper.java +++ /dev/null @@ -1,280 +0,0 @@ -package me.shedaniel.gui; - -import me.shedaniel.ClientListener; -import me.shedaniel.gui.widget.Control; -import me.shedaniel.gui.widget.IFocusable; -import me.shedaniel.gui.widget.REISlot; -import me.shedaniel.impl.REIRecipeManager; -import me.shedaniel.listenerdefinitions.IMixinContainerGui; -import net.fabricmc.loader.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.FontRenderer; -import net.minecraft.client.gui.ContainerGui; -import net.minecraft.client.render.item.ItemRenderer; -import net.minecraft.client.util.Window; -import net.minecraft.item.ItemStack; - -import java.awt.*; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - - -/** - * Created by James on 7/28/2018. - */ -public class REIRenderHelper { - - static Point mouseLoc; - static public GuiItemList reiGui; - static ContainerGui overlayedGui; - static List tooltipsToRender = new ArrayList<>(); - - public static void setMouseLoc(int x, int y) { - mouseLoc = new Point(x, y); - } - - static public IFocusable focusedControl; - - public static Point getMouseLoc() { - return mouseLoc; - } - - public static Window getResolution() { - return MinecraftClient.getInstance().window; - } - - public static String tryGettingModName(String modid) { - if (modid.equalsIgnoreCase("minecraft")) - return "Minecraft"; - return FabricLoader.INSTANCE.getModContainers().stream() - .map(modContainer -> { - return modContainer.getInfo(); - }) - .filter(modInfo -> modInfo.getId().equals(modid) || (modInfo.getName() != null && modInfo.getName().equals(modid))) - .findFirst().map(modInfo -> { - if (modInfo.getName() != null) - return modInfo.getName(); - return modid; - }).orElse(modid); - } - - public static void drawREI(ContainerGui overlayedGui) { - REIRenderHelper.overlayedGui = overlayedGui; - if (reiGui == null) { - reiGui = new GuiItemList(overlayedGui); - } - reiGui.draw(); - renderTooltips(); - } - - public static void resize(int scaledWidth, int scaledHeight) { - if (reiGui != null) { - reiGui.resize(); - } - if (overlayedGui instanceof RecipeGui) { - overlayedGui.onScaleChanged(MinecraftClient.getInstance(), scaledWidth, scaledHeight); - } - } - - public static ItemRenderer getItemRender() { - return MinecraftClient.getInstance().getItemRenderer(); - } - - public static FontRenderer getFontRenderer() { - return MinecraftClient.getInstance().fontRenderer; - } - - public static ContainerGui getOverlayedGui() { - if (overlayedGui instanceof ContainerGui) - return overlayedGui; - return null; - } - - public static void addToolTip(List text, int x, int y) { - tooltipsToRender.add(new TooltipData(text, x, y)); - } - - - private static void renderTooltips() { - tooltipsToRender.forEach(tooltipData -> getOverlayedGui().drawTooltip(tooltipData.text, tooltipData.x, tooltipData.y)); - tooltipsToRender.clear(); - } - - public static boolean mouseClick(int x, int y, int button) { - if (reiGui.visible) { - for(Control control : reiGui.controls) { - if (control.isHighlighted() && control.isEnabled() && control.onClick != null) { - if (focusedControl != null) - focusedControl.setFocused(false); - if (control instanceof IFocusable) { - focusedControl = (IFocusable) control; - ((IFocusable) control).setFocused(true); - } - return control.onClick.apply(button); - } - } - if (focusedControl != null) { - focusedControl.setFocused(false); - focusedControl = null; - } - } - if (overlayedGui instanceof RecipeGui) { - List controls = new LinkedList<>(((RecipeGui) overlayedGui).controls); - if (((RecipeGui) overlayedGui).slots != null) - controls.addAll(((RecipeGui) overlayedGui).slots); - controls.addAll(reiGui.controls.stream().filter(control -> { - return control instanceof REISlot; - }).collect(Collectors.toList())); - Optional ctrl = controls.stream().filter(Control::isHighlighted).filter(Control::isEnabled).findFirst(); - if (ctrl.isPresent()) { - try { - return ctrl.get().onClick.apply(button); - } catch (Exception e) { - } - } - } - return false; - } - - public static boolean keyDown(int typedChar, int keyCode, int unknown) { - boolean handled = false; - if (focusedControl != null && focusedControl instanceof Control) { - Control control = (Control) focusedControl; - if (control.onKeyDown != null) { - handled = control.onKeyDown.accept(typedChar, keyCode, unknown); - } - if (control.charPressed != null) - if (typedChar == 256) { - ((IFocusable) control).setFocused(false); - focusedControl = null; - } - handled = true; - } - if (!handled) { - return ClientListener.processGuiKeyBinds(typedChar); - } - return handled; - } - - public static boolean charInput(long num, int keyCode, int unknown) { - if (focusedControl != null && focusedControl instanceof Control) { - Control control = (Control) focusedControl; - if (control.charPressed != null) { - int numChars = Character.charCount(keyCode); - if (num == numChars) - control.charPressed.accept((char) keyCode, unknown); - else { - char[] chars = Character.toChars(keyCode); - for(int x = 0; x < chars.length; x++) { - control.charPressed.accept(chars[x], unknown); - } - } - return true; - } - } - return false; - } - - public static boolean mouseScrolled(double direction) { - if (!reiGui.visible) - return false; - if (MinecraftClient.getInstance().currentGui instanceof RecipeGui) { - Window window = REIRenderHelper.getResolution(); - Point mouse = new Point((int) MinecraftClient.getInstance().mouse.getX(), (int) MinecraftClient.getInstance().mouse.getY()); - int mouseX = (int) (mouse.x * (double) window.getScaledWidth() / (double) window.method_4480()); - int mouseY = (int) (mouse.y * (double) window.getScaledHeight() / (double) window.method_4507()); - mouse = new Point(mouseX, mouseY); - - RecipeGui recipeGui = (RecipeGui) MinecraftClient.getInstance().currentGui; - if (mouse.getX() < window.getScaledWidth() / 2 + recipeGui.guiWidth / 2 && mouse.getX() > window.getScaledWidth() / 2 - recipeGui.guiWidth / 2 && - mouse.getY() < window.getScaledHeight() / 2 + recipeGui.guiHeight / 2 && mouse.getY() > window.getScaledHeight() / 2 - recipeGui.guiHeight / 2 && - recipeGui.recipes.get(recipeGui.selectedCategory).size() > 2) { - boolean failed = false; - if (direction > 0 && reiGui.buttonLeft.isEnabled()) - recipeGui.btnRecipeLeft.onClick.apply(0); - else if (direction < 0 && reiGui.buttonRight.isEnabled()) - recipeGui.btnRecipeRight.onClick.apply(0); - else failed = true; - if (!failed) - return true; - } - } - if (direction > 0 && reiGui.buttonLeft.isEnabled()) - reiGui.buttonLeft.onClick.apply(0); - else if (direction < 0 && reiGui.buttonRight.isEnabled()) - reiGui.buttonRight.onClick.apply(0); - return true; - } - - private static class TooltipData { - - private final List text; - private final int x; - private final int y; - - public TooltipData(List text, int x, int y) { - this.text = text; - this.x = x; - this.y = y; - } - } - - public static void updateSearch() { - reiGui.updateView(); - } - - public static void tick() { - if (reiGui != null && MinecraftClient.getInstance().currentGui == overlayedGui) - reiGui.tick(); - } - - public static boolean isGuiVisible() { - return reiGui != null && reiGui.visible; - } - - public static boolean recipeKeyBind() { - if (!(MinecraftClient.getInstance().currentGui instanceof ContainerGui)) - return false; - Control control = reiGui.getLastHovered(); - if (control != null && control.isHighlighted() && control instanceof REISlot) { - REISlot slot = (REISlot) control; - REIRecipeManager.instance().displayRecipesFor(slot.getStack()); - return true; - } - if (((IMixinContainerGui) overlayedGui).getHoveredSlot() != null) { - ItemStack stack = ((IMixinContainerGui) overlayedGui).getHoveredSlot().getStack(); - REIRecipeManager.instance().displayRecipesFor(stack); - return true; - } - return false; - } - - public static boolean useKeyBind() { - if (!(MinecraftClient.getInstance().currentGui instanceof ContainerGui)) - return false; - Control control = reiGui.getLastHovered(); - if (control != null && control.isHighlighted() && control instanceof REISlot) { - REISlot slot = (REISlot) control; - REIRecipeManager.instance().displayUsesFor(slot.getStack()); - return true; - } - if (((IMixinContainerGui) overlayedGui).getHoveredSlot() != null) { - ItemStack stack = ((IMixinContainerGui) overlayedGui).getHoveredSlot().getStack(); - REIRecipeManager.instance().displayUsesFor(stack); - return true; - } - return false; - } - - public static boolean hideKeyBind() { - if (MinecraftClient.getInstance().currentGui == overlayedGui && reiGui != null) { - reiGui.visible = !reiGui.visible; - return true; - } - return false; - } - -} diff --git a/src/main/java/me/shedaniel/gui/RecipeContainer.java b/src/main/