From f2aa21f61631ed13789f4857bca34e06aa970408 Mon Sep 17 00:00:00 2001 From: Discreater Date: Sat, 8 May 2021 19:17:08 +0800 Subject: [PATCH] feat: add support for nei keybinding --- README.md | 5 +- README_CN.md | 55 +++++++++++++++++++ .../event/handlers/NEIEventHandler.java | 29 +++++++++- .../me/towdium/jecalculation/gui/JecaGui.java | 21 ++++--- .../jecalculation/gui/guis/GuiCraft.java | 6 +- .../towdium/jecalculation/nei/NEIPlugin.java | 12 ++-- src/main/resources/mcmod.info | 2 +- 7 files changed, 108 insertions(+), 22 deletions(-) create mode 100644 README_CN.md diff --git a/README.md b/README.md index a720813..45acd52 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ [![][1]][3] [![][2]][3] [![][4]][5] +[中文](README_CN.md) + # Just Enough Calculation Mod Hey, this is a small add-on to **NEI** (Not Enough Items), in @@ -19,7 +21,7 @@ the [release page](https://minecraft.curseforge.com/projects/just-enough-calcula - Support get catalyst in [NEI-GTNH-2.1](https://github.com/GTNewHorizons/NotEnoughItems) - Infinite inputs, outputs and catalysts of recipe -- Recipe from NEI recipe handler (recipe gui) +- Recipe can transferred from NEI recipe handler (recipe gui) - [x] vanilla - [x] gregtech - [x] Forestry @@ -42,7 +44,6 @@ the [release page](https://minecraft.curseforge.com/projects/just-enough-calcula - [ ] GUI will cover the NEI's GUI like tooltip on item panel - [ ] Fluid from recipe needs lots of adapters, see [Adapter](./src/main/java/me/towdium/jecalculation/nei/Adapter.java). - ## Development For run `gradle runClient`, you need copy the mods from `dev-mods/` to `run/mods`. diff --git a/README_CN.md b/README_CN.md new file mode 100644 index 0000000..29791a3 --- /dev/null +++ b/README_CN.md @@ -0,0 +1,55 @@ +[![][1]][3] [![][2]][3] [![][4]][5] + +# Just Enough Calculation Mod + +Hey, this is a small add-on to **NEI** (Not Enough Items), in +order to help you calculate the amount of resources to craft a specific amount of item. . + +This might be a little confusing, here's an example: + +- you want to know how many wood logs do you need to craft 40 stairs, simply load the recipe you want to use, and it will +tell you 13 logs should be enough, that's all. + +This mod is focused on calculation, so you might find it powerful and high performance in some complicated cases. Have fun! + +--- + +查看所有的 Release 文件, 描述或者视频, 请查看 [release 页面](https://minecraft.curseforge.com/projects/just-enough-calculation). + +## 功能 + +- 支持 [NEI-GTNH-2.1](https://github.com/GTNewHorizons/NotEnoughItems) 的催化剂(不消耗的合成参与者,如工作台,各种机器之类的) +- 合成表的输入、输出和催化剂 无数量限制 +- 可以从 NEI 合成表 gui 页面直接获取合成表 + - [x] 原生MC + - [x] gregtech + - [x] Forestry + - [ ] AE2(目前没办法,需要 AE2 作者支持 + - [ ] 其它 +- [x] 从 NEI 物品列表抓取物品 +- [ ] 从 NEI 物品列表抓取流体 (暂未实现,目前请从 计算器内部流体标签 抓取流体) +- [x] 矿物词典支持 + +## 已知问题 + +- [ ] 如果在进入是世界后立刻打开计算器 gui,游戏可能会 **崩溃 (强烈建议进入世界后等 3~4 秒)** +- [ ] **仅客户端(大概)** +- [ ] 从 NEI 物品列表抓取的 流体 会被识别为 物体 +- [ ] 矿物词典标签的渲染存在问题,目前暂时不显示覆盖的标识 +- [ ] 计算器 gui 会覆盖 NEI 的 tooltip +- [ ] 流体需要针对 mod 进行适配, 开发人员可以查看 [Adapter](./src/main/java/me/towdium/jecalculation/nei/Adapter.java). + +## 开发 + +如果要运行 `gradle runClient`, 需要将 `dev-mods/` 文件夹中的全部模组复制到 `run/mods`(运行一次 `runClient` 后生成)文件夹中. + +[1]: http://cf.way2muchnoise.eu/full_just-enough-calculation_downloads.svg + +[2]: http://cf.way2muchnoise.eu/versions/just-enough-calculation.svg + +[3]: https://minecraft.curseforge.com/projects/just-enough-calculation + +[4]: https://img.shields.io/discord/517485644163973120.svg?logo=discord + +[5]: https://discord.gg/M3fNfTW + diff --git a/src/main/java/me/towdium/jecalculation/event/handlers/NEIEventHandler.java b/src/main/java/me/towdium/jecalculation/event/handlers/NEIEventHandler.java index fbb9a80..9720888 100644 --- a/src/main/java/me/towdium/jecalculation/event/handlers/NEIEventHandler.java +++ b/src/main/java/me/towdium/jecalculation/event/handlers/NEIEventHandler.java @@ -1,22 +1,47 @@ package me.towdium.jecalculation.event.handlers; +import codechicken.nei.NEIClientConfig; +import codechicken.nei.NEIClientUtils; import codechicken.nei.guihook.IContainerInputHandler; +import me.towdium.jecalculation.JustEnoughCalculation; +import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.gui.JecaGui; +import me.towdium.jecalculation.nei.NEIPlugin; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; public class NEIEventHandler implements IContainerInputHandler { @Override public boolean keyTyped(GuiContainer guiContainer, char c, int i) { + JustEnoughCalculation.logger.info("nei key typed"); return false; } @Override public void onKeyTyped(GuiContainer guiContainer, char c, int i) { - + JustEnoughCalculation.logger.info("nei on key typed"); } @Override - public boolean lastKeyTyped(GuiContainer guiContainer, char c, int i) { + public boolean lastKeyTyped(GuiContainer guiContainer, char keyChar, int keyCode) { + if (guiContainer == Minecraft.getMinecraft().currentScreen && guiContainer instanceof JecaGui) { + JecaGui gui = (JecaGui) guiContainer; + ILabel label = gui.getLabelUnderMouse(); + if (label == null) + return false; + Object stack = label.getRepresentation(); + + if (keyCode == NEIClientConfig.getKeyBinding("gui.usage") || + (keyCode == NEIClientConfig.getKeyBinding("gui.recipe") && NEIClientUtils.shiftKey())) { + return NEIPlugin.openRecipeGui(stack, true); + } + if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) { + return NEIPlugin.openRecipeGui(stack, false); + } + + return false; + } + return false; } diff --git a/src/main/java/me/towdium/jecalculation/gui/JecaGui.java b/src/main/java/me/towdium/jecalculation/gui/JecaGui.java index ade0f6a..583a27a 100644 --- a/src/main/java/me/towdium/jecalculation/gui/JecaGui.java +++ b/src/main/java/me/towdium/jecalculation/gui/JecaGui.java @@ -120,7 +120,7 @@ public class JecaGui extends GuiContainer { } return false; } - + public static void onMouseReleased() { Optional optionalJecaGui = currentJecaGui(); if (!optionalJecaGui.isPresent()) @@ -133,15 +133,14 @@ public class JecaGui extends GuiContainer { } - - @Nullable public Slot getSlotUnderMouse() { IInventory i = new InventoryBasic("", false, 1); Slot s = new Slot(i, 0, 0, 0); ILabel l = getLabelUnderMouse(); Object rep = l == null ? null : l.getRepresentation(); - if (rep instanceof ItemStack) s.putStack((ItemStack) rep); + if (rep instanceof ItemStack) + s.putStack((ItemStack) rep); return s; } @@ -221,7 +220,10 @@ public class JecaGui extends GuiContainer { } /** - * called by {@link me.towdium.jecalculation.event.handlers.FMLBusEventHandler} + * Called by {@link me.towdium.jecalculation.event.handlers.FMLBusEventHandler}. + * This event happened only when not in gui. + * For nei keybinding event, see {@link me.towdium.jecalculation.event.handlers.NEIEventHandler#lastKeyTyped(GuiContainer, char, int)} + * I think they won't conflict */ public static void onKey() { if (keyOpenGuiCraft.isPressed()) @@ -300,10 +302,12 @@ public class JecaGui extends GuiContainer { if (j > i) i = j; //noinspection StringEquality - if (s == JecaGui.SEPARATOR) separators++; + if (s == JecaGui.SEPARATOR) + separators++; } //noinspection StringEquality - if (textLines.get(textLines.size() - 1) == SEPARATOR) separators--; + if (textLines.get(textLines.size() - 1) == SEPARATOR) + separators--; int l1 = x + 12; int i2 = y - 12; int k = 8 + (textLines.size() - separators - 1) * 10 + 2 * separators; @@ -324,7 +328,8 @@ public class JecaGui extends GuiContainer { drawGradientRect(l1 - 3, i2 + k + 2, l1 + i + 3, i2 + k + 3, 1344798847, 1344798847); for (String s1 : textLines) { //noinspection StringEquality - if (s1 == SEPARATOR) i2 += 2; + if (s1 == SEPARATOR) + i2 += 2; else { font.drawStringWithShadow(s1, l1, i2, -1); i2 += 10; diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiCraft.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiCraft.java index f6b8c11..6474555 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiCraft.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiCraft.java @@ -17,7 +17,6 @@ import me.towdium.jecalculation.utils.Utilities; import me.towdium.jecalculation.utils.wrappers.Pair; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; -import org.lwjgl.input.Mouse; import javax.annotation.ParametersAreNonnullByDefault; import java.util.*; @@ -42,7 +41,10 @@ public class GuiCraft extends WContainer implements IGui { (i, v) -> label.setLabel(i.get(v).getLabel().copy(), true)); WLabelScroll result = new WLabelScroll(7, 87, 8, 4, false).setLsnrLeftClick((i, v) -> { Object rep = i.get(v).getLabel().getRepresentation(); - NEIPlugin.openRecipeGui(rep, Mouse.getEventButton()); + NEIPlugin.openRecipeGui(rep, false); + }).setLsnrRightClick((widget, value) -> { + Object rep = widget.get(value).getLabel().getRepresentation(); + NEIPlugin.openRecipeGui(rep, true); }).setFmtAmount(i -> i.getAmountString(true)).setFmtTooltip((i, j) -> i.getToolTip(j, true)); WButton steps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST, "craft.step").setListener(i -> setMode(STEPS)); WButton catalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "common.catalyst").setListener( diff --git a/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java b/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java index d0f4410..ccb7fb2 100644 --- a/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java +++ b/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java @@ -46,19 +46,17 @@ public class NEIPlugin { NEIPlugin.currentItemStack = itemStack; } - public static void openRecipeGui(Object rep, int button) { + public static boolean openRecipeGui(Object rep, boolean usage) { if ((rep instanceof ItemStack || rep instanceof FluidStack)) { String id = rep instanceof ItemStack ? "item" : "liquid"; - if (button == 0) { - GuiCraftingRecipe.openRecipeGui(id, rep); - } else if (button == 1) { - GuiUsageRecipe.openRecipeGui(id, rep); + if (!usage) { + return GuiCraftingRecipe.openRecipeGui(id, rep); } else { - // TODO check - JustEnoughCalculation.logger.warn("unknown button " + button); + return GuiUsageRecipe.openRecipeGui(id, rep); } } else if (rep != null) { JustEnoughCalculation.logger.warn("unknown label representation " + rep); } + return false; } } diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 8aefe96..152442f 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -7,7 +7,7 @@ "mcversion": "${mcversion}", "url": "https://github.com/Towdium/JustEnoughCalculation", "updateUrl": "http://minecratft.curseforge.com/projects/just-enough-calculation", - "authorList": ["Towdium"], + "authorList": ["Towdium", "Discreater"], "logoFile": "", "screenshots": [], "dependencies": ["NotEnoughItems"],