|
@@ -3,10 +3,11 @@ package me.shedaniel;
|
|
|
import me.shedaniel.api.IREIPlugin;
|
|
|
import me.shedaniel.gui.REIRenderHelper;
|
|
|
import me.shedaniel.impl.REIRecipeManager;
|
|
|
-import me.shedaniel.library.KeyBindManager;
|
|
|
+import me.shedaniel.library.KeyBindFunction;
|
|
|
import me.shedaniel.listenerdefinitions.DoneLoading;
|
|
|
import me.shedaniel.listenerdefinitions.RecipeLoadListener;
|
|
|
import net.fabricmc.api.ClientModInitializer;
|
|
|
+import net.fabricmc.api.ModInitializer;
|
|
|
import net.minecraft.client.settings.KeyBinding;
|
|
|
import net.minecraft.enchantment.Enchantment;
|
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
|
@@ -18,19 +19,25 @@ import net.minecraft.util.DefaultedList;
|
|
|
import net.minecraft.util.registry.Registry;
|
|
|
|
|
|
import java.awt.event.KeyEvent;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
-public class ClientListener implements DoneLoading, ClientModInitializer, RecipeLoadListener {
|
|
|
- public static KeyBinding recipeKeybind;
|
|
|
- public static KeyBinding hideKeybind;
|
|
|
- public static KeyBinding useKeybind;
|
|
|
+public class ClientListener implements DoneLoading, RecipeLoadListener {
|
|
|
+
|
|
|
+ public static KeyBindFunction recipeKeybind;
|
|
|
+ public static KeyBindFunction hideKeybind;
|
|
|
+ public static KeyBindFunction useKeybind;
|
|
|
+ public static List<KeyBindFunction> keyBinds = new ArrayList<>();
|
|
|
|
|
|
private List<IREIPlugin> plugins;
|
|
|
public static List<ItemStack> 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<>();
|
|
@@ -39,11 +46,32 @@ public class ClientListener implements DoneLoading, ClientModInitializer, Recipe
|
|
|
buildItemList();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onInitializeClient() {
|
|
|
- recipeKeybind = KeyBindManager.createKeybinding("key.rei.recipe", KeyEvent.VK_R, "key.rei.category", REIRenderHelper::recipeKeybind);
|
|
|
- hideKeybind = KeyBindManager.createKeybinding("key.rei.hide", KeyEvent.VK_O, "key.rei.category", REIRenderHelper::hideKeybind);
|
|
|
- useKeybind = KeyBindManager.createKeybinding("key.rei.use", KeyEvent.VK_U, "key.rei.category", REIRenderHelper::useKeybind);
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ useKeybind = 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, useKeybind));
|
|
|
}
|
|
|
|
|
|
private void buildItemList() {
|
|
@@ -67,10 +95,6 @@ public class ClientListener implements DoneLoading, ClientModInitializer, Recipe
|
|
|
item.addStacksForDisplay(item.getItemGroup(), items);
|
|
|
items.forEach(stackList::add);
|
|
|
} catch (NullPointerException e) {
|
|
|
-// if (item == Items.ENCHANTED_BOOK) {
|
|
|
-// item.fillItemGroup(ItemGroup.TOOLS, items);
|
|
|
-// items.forEach(stackList::add);
|
|
|
-// }
|
|
|
}
|
|
|
}
|
|
|
|