From e22929648a3b5d74bb52224b10b88c1c06cf8b31 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 19 Jun 2020 14:52:32 +0800 Subject: Migrate to fabric-key-binding-api-v1, fix crash. Signed-off-by: shedaniel --- .../java/me/shedaniel/rei/api/ClientHelper.java | 15 ++++---- .../me/shedaniel/rei/impl/ClientHelperImpl.java | 41 ++++++++++++---------- 2 files changed, 30 insertions(+), 26 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java index b72e86ea0..ff52a2acb 100644 --- a/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -7,6 +7,7 @@ package me.shedaniel.rei.api; import me.shedaniel.rei.impl.ClientHelperImpl; import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; +import net.minecraft.client.options.KeyBinding; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; @@ -90,9 +91,9 @@ public interface ClientHelper { return executeUsageKeyBind(EntryStack.create(stack)); } - FabricKeyBinding getFocusSearchFieldKeyBinding(); + KeyBinding getFocusSearchFieldKeyBinding(); - FabricKeyBinding getCopyRecipeIdentifierKeyBinding(); + KeyBinding getCopyRecipeIdentifierKeyBinding(); /** * Gets the mod from an item @@ -134,27 +135,27 @@ public interface ClientHelper { /** * @return the recipe keybind, defaulted R */ - FabricKeyBinding getRecipeKeyBinding(); + KeyBinding getRecipeKeyBinding(); /** * @return the usage keybind, defaulted U */ - FabricKeyBinding getUsageKeyBinding(); + KeyBinding getUsageKeyBinding(); /** * @return the hide keybind, defaulted O */ - FabricKeyBinding getHideKeyBinding(); + KeyBinding getHideKeyBinding(); /** * @return the previous page keybind, defaulted not set */ - FabricKeyBinding getPreviousPageKeyBinding(); + KeyBinding getPreviousPageKeyBinding(); /** * @return the next page keybind, defaulted not set */ - FabricKeyBinding getNextPageKeyBinding(); + KeyBinding getNextPageKeyBinding(); /** * Finds all recipes and open them in a recipe screen. diff --git a/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java index 0115104fb..ef64d43fa 100644 --- a/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java @@ -17,15 +17,15 @@ 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.client.keybinding.v1.KeyBindingHelper; 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.Screen; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; +import net.minecraft.client.options.KeyBinding; import net.minecraft.client.util.InputUtil; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -54,7 +54,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { private final Identifier focusSearchFieldKeybind = new Identifier("roughlyenoughitems", "focus_search"); private final Identifier copyRecipeIdentifierKeybind = new Identifier("roughlyenoughitems", "copy_recipe_id"); private final Map modNameCache = Maps.newHashMap(); - public FabricKeyBinding recipe, usage, hide, previousPage, nextPage, focusSearchField, copyRecipeIdentifier; + public KeyBinding recipe, usage, hide, previousPage, nextPage, focusSearchField, copyRecipeIdentifier; @Override public String getFormattedModFromItem(Item item) { @@ -73,37 +73,37 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { } @Override - public FabricKeyBinding getRecipeKeyBinding() { + public KeyBinding getRecipeKeyBinding() { return recipe; } @Override - public FabricKeyBinding getUsageKeyBinding() { + public KeyBinding getUsageKeyBinding() { return usage; } @Override - public FabricKeyBinding getHideKeyBinding() { + public KeyBinding getHideKeyBinding() { return hide; } @Override - public FabricKeyBinding getPreviousPageKeyBinding() { + public KeyBinding getPreviousPageKeyBinding() { return previousPage; } @Override - public FabricKeyBinding getNextPageKeyBinding() { + public KeyBinding getNextPageKeyBinding() { return nextPage; } @Override - public FabricKeyBinding getFocusSearchFieldKeyBinding() { + public KeyBinding getFocusSearchFieldKeyBinding() { return focusSearchField; } @Override - public FabricKeyBinding getCopyRecipeIdentifierKeyBinding() { + public KeyBinding getCopyRecipeIdentifierKeyBinding() { return copyRecipeIdentifier; } @@ -257,7 +257,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { @Override public void onInitializeClient() { - ClientHelperImpl.instance = (ClientHelperImpl) this; + ClientHelperImpl.instance = this; registerFabricKeyBinds(); modNameCache.put("minecraft", "Minecraft"); modNameCache.put("c", "Common"); @@ -266,14 +266,17 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { @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()); - KeyBindingRegistryImpl.INSTANCE.register(copyRecipeIdentifier = FabricKeyBinding.Builder.create(copyRecipeIdentifierKeybind, InputUtil.Type.KEYSYM, -1, category).build()); + recipe = registerKeyBinding(recipeKeybind, InputUtil.Type.KEYSYM, 82, category); + usage = registerKeyBinding(usageKeybind, InputUtil.Type.KEYSYM, 85, category); + hide = registerKeyBinding(hideKeybind, InputUtil.Type.KEYSYM, 79, category); + previousPage = registerKeyBinding(previousPageKeybind, InputUtil.Type.KEYSYM, -1, category); + nextPage = registerKeyBinding(nextPageKeybind, InputUtil.Type.KEYSYM, -1, category); + focusSearchField = registerKeyBinding(focusSearchFieldKeybind, InputUtil.Type.KEYSYM, -1, category); + copyRecipeIdentifier = registerKeyBinding(copyRecipeIdentifierKeybind, InputUtil.Type.KEYSYM, -1, category); + } + + private KeyBinding registerKeyBinding(Identifier id, InputUtil.Type type, int code, String category) { + return KeyBindingHelper.registerKeyBinding(new KeyBinding("key." + id.getNamespace() + "." + id.getPath(), type, code, category)); } } -- cgit