From 3a5d0940638588ea6b2beb62a55e4c0e2d8b8abc Mon Sep 17 00:00:00 2001 From: Discreater Date: Sun, 2 May 2021 04:17:58 +0800 Subject: [PATCH] feat: almost done --- README.md | 49 ++++++++----- .../jecalculation/data/label/ILabel.java | 13 +--- .../me/towdium/jecalculation/gui/JecaGui.java | 73 ++++++++++++++----- .../towdium/jecalculation/gui/Resource.java | 8 +- .../jecalculation/gui/guis/GuiRecipe.java | 17 +++-- .../jecalculation/gui/widgets/WLabel.java | 35 +++++---- 6 files changed, 117 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index af4a48b..1737b5e 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,35 @@ -## Just Enough Calculation Mod +[![][1]][3] [![][2]][3] [![][4]][5] -Hey, this is a small add on to JEI (Just 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 a example: -you want to know how many wood log do you need to craft 40 stairs, simply -choose the recipe you want to use and hit "Calculate!". 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! +# Just Enough Calculation Mod -#### Achieved features +Hey, this is a small add on to [NEI-GTNH-2.1](https://github.com/GTNewHorizons/NotEnoughItems) (Not Enough Items), in +order to help you calculate the amount of resources to craft a specific amount of item. . -* Recursive calculation -* Repeated recipe support -* Shift - left click for quick input of recipe -* Personal preference record -* Support for percentage in recipes -* Check Player's inventory for missed gradients -* View the crafting procedure -* Recent records +This might be a little confusing, here's a example: -#### Planed features +- you want to know how many wood log 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. -* Liquid support +This mod is focused on calculation so you might find it powerful and high performance in some complicated cases. Have fun! + +For all the release files, description or videos, refer to +the [release page](https://minecraft.curseforge.com/projects/just-enough-calculation). + +## Known Issues + +- [ ] 无法覆盖NEI默认点击行为 +- [ ] OreDict 渲染存在问题 +- [ ] capability +- [ ] 带 nbt 的物品存储到本地存在问题 +- [ ] 主界面合成表转移存在问题 + +[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/data/label/ILabel.java b/src/main/java/me/towdium/jecalculation/data/label/ILabel.java index a565245..bf240c5 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/ILabel.java +++ b/src/main/java/me/towdium/jecalculation/data/label/ILabel.java @@ -451,8 +451,7 @@ public interface ILabel { @Override public ILabel increaseAmount() { - setAmount(getAmount() + getMultiplier()); - return this; + return setAmount(getAmount() + getMultiplier()); } @Override @@ -460,8 +459,7 @@ public interface ILabel { if (getAmount() <= getMultiplier()) return ILabel.EMPTY; else { - setAmount(getAmount() - getMultiplier()); - return this; + return setAmount(getAmount() - getMultiplier()); } } @@ -496,13 +494,10 @@ public interface ILabel { @Override public ILabel multiply(float i) { float amount = i * getAmount(); - if (amount > Long.MAX_VALUE) - throw new ArithmeticException("Multiply overflow"); - setAmount((long) amount); - return this; + if (amount > Long.MAX_VALUE) throw new ArithmeticException("Multiply overflow"); + return setAmount((long) amount); } - @Override @SideOnly(Side.CLIENT) public void getToolTip(List existing, boolean detailed) { diff --git a/src/main/java/me/towdium/jecalculation/gui/JecaGui.java b/src/main/java/me/towdium/jecalculation/gui/JecaGui.java index 2001aa3..db5dfa6 100644 --- a/src/main/java/me/towdium/jecalculation/gui/JecaGui.java +++ b/src/main/java/me/towdium/jecalculation/gui/JecaGui.java @@ -1,12 +1,12 @@ package me.towdium.jecalculation.gui; +import codechicken.nei.guihook.GuiContainerManager; import cpw.mods.fml.client.config.GuiUtils; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.JustEnoughCalculation; import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.gui.guis.IGui; -import me.towdium.jecalculation.gui.widgets.WContainer; import me.towdium.jecalculation.nei.NEIPlugin; import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager; import me.towdium.jecalculation.utils.Utilities; @@ -27,7 +27,12 @@ import org.lwjgl.input.Mouse; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import static codechicken.lib.gui.GuiDraw.renderEngine; /** * Author: towdium @@ -98,7 +103,8 @@ public class JecaGui extends GuiContainer { if (scheduled) { JecaGui.scheduled = r; JecaGui.timeout = 2; - } else r.run(); + } else + r.run(); } /** @@ -114,7 +120,6 @@ public class JecaGui extends GuiContainer { } - private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, IGui root) { Minecraft mc = Minecraft.getMinecraft(); JecaGui parent; @@ -148,7 +153,8 @@ public class JecaGui extends GuiContainer { Runnable r = scheduled; scheduled = null; r.run(); - } else timeout--; + } else + timeout--; } } @@ -198,13 +204,16 @@ public class JecaGui extends GuiContainer { int i = 0; for (String s : textLines) { int j = this.fontRendererObj.getStringWidth(s); - if (j > i) i = j; + if (j > i) + i = j; } int l1 = x + 12; int i2 = y - 12; int k = 8 + (textLines.size() - 1) * 10; - if (l1 + i > this.width) l1 -= 28 + i; - if (i2 + k + 6 > this.height) i2 = this.height - k - 6; + if (l1 + i > this.width) + l1 -= 28 + i; + if (i2 + k + 6 > this.height) + i2 = this.height - k - 6; zLevel = 300.0F; itemRender.zLevel = 300.0F; drawGradientRect(l1 - 3, i2 - 4, l1 + i + 3, i2 - 3, -267386864, -267386864); @@ -288,11 +297,18 @@ public class JecaGui extends GuiContainer { drawResourceContinuous(r, xPos, yPos, xSize, ySize, border, border, border, border); } - public void drawResourceContinuous( - Resource r, int xPos, int yPos, int xSize, int ySize, - int borderTop, int borderBottom, int borderLeft, int borderRight) { + public void drawResourceContinuous(Resource r, + int xPos, + int yPos, + int xSize, + int ySize, + int borderTop, + int borderBottom, + int borderLeft, + int borderRight) { GuiUtils.drawContinuousTexturedBox(r.getResourceLocation(), xPos, yPos, r.getXPos(), r.getYPos(), xSize, ySize, - r.getXSize(), r.getYSize(), borderTop, borderBottom, borderLeft, borderRight, zLevel); + r.getXSize(), r.getYSize(), borderTop, borderBottom, borderLeft, borderRight, + zLevel); } private void setColor(int color) { @@ -332,6 +348,16 @@ public class JecaGui extends GuiContainer { GlStateManager.enableTexture2D(); } + public void drawOverRectangle(int xPos, int yPos, int xSize, int ySize, int color) { + GlStateManager.disableLighting(); + GlStateManager.disableDepth(); + GlStateManager.colorMask(true, true, true, false); + this.drawGradientRect(xPos, yPos, xPos + xSize, yPos + ySize, color, color); + GlStateManager.colorMask(true, true, true, true); + GlStateManager.enableLighting(); + GlStateManager.enableDepth(); + } + public int getStringWidth(String s) { return fontRendererObj.getStringWidth(s); } @@ -371,10 +397,12 @@ public class JecaGui extends GuiContainer { private void drawText(float xPos, float yPos, Font f, Runnable r) { boolean unicode = fontRendererObj.getUnicodeFlag(); - if (f.raw) fontRendererObj.setUnicodeFlag(false); + if (f.raw) + fontRendererObj.setUnicodeFlag(false); GlStateManager.pushMatrix(); GlStateManager.translate(xPos, yPos, 0); - if (f.half) GlStateManager.scale(0.5, 0.5, 1); + if (f.half) + GlStateManager.scale(0.5, 0.5, 1); r.run(); GlStateManager.popMatrix(); fontRendererObj.setUnicodeFlag(unicode); @@ -388,11 +416,14 @@ public class JecaGui extends GuiContainer { xPos -= 8; yPos -= 8; } + float zLevel = itemRender.zLevel += 100F; GlStateManager.enableDepth(); RenderHelper.enableGUIStandardItemLighting(); - itemRender.renderItemIntoGUI(fontRendererObj, mc.getTextureManager(), is, xPos, yPos); + itemRender.renderItemAndEffectIntoGUI(fontRendererObj, renderEngine, is, xPos, yPos); + itemRender.renderItemOverlayIntoGUI(fontRendererObj, renderEngine, is, xPos, yPos); RenderHelper.disableStandardItemLighting(); GlStateManager.disableDepth(); + itemRender.zLevel = zLevel - 100F; } @Override @@ -407,10 +438,13 @@ public class JecaGui extends GuiContainer { @Override protected void keyTyped(char typedChar, int keyCode) { - if (keyCode == Keyboard.KEY_ESCAPE && hand != ILabel.EMPTY) hand = ILabel.EMPTY; + if (keyCode == Keyboard.KEY_ESCAPE && hand != ILabel.EMPTY) + hand = ILabel.EMPTY; else if (!root.onKey(this, typedChar, keyCode)) { - if (keyCode == Keyboard.KEY_ESCAPE && parent != null) displayParent(); - else super.keyTyped(typedChar, keyCode); + if (keyCode == Keyboard.KEY_ESCAPE && parent != null) + displayParent(); + else + super.keyTyped(typedChar, keyCode); } } @@ -434,7 +468,8 @@ public class JecaGui extends GuiContainer { public int getTextWidth(String s) { FontRenderer fr = getCurrent().fontRendererObj; boolean flag = fr.getUnicodeFlag(); - if (raw) fr.setUnicodeFlag(false); + if (raw) + fr.setUnicodeFlag(false); int ret = (int) Math.ceil(fr.getStringWidth(s) * (half ? 0.5f : 1)); fr.setUnicodeFlag(flag); return ret; diff --git a/src/main/java/me/towdium/jecalculation/gui/Resource.java b/src/main/java/me/towdium/jecalculation/gui/Resource.java index ad569e3..8edf798 100644 --- a/src/main/java/me/towdium/jecalculation/gui/Resource.java +++ b/src/main/java/me/towdium/jecalculation/gui/Resource.java @@ -247,14 +247,14 @@ public class Resource { return new Resource(x * 14, y * 14, 14, 14); } - private static Resource getLabel(int x) { - return new Resource(x * 16, 132, 16, 16); - } - private static Resource getWidget(int x) { return new Resource(x * 20, 112, 20, 20); } + private static Resource getLabel(int x) { + return new Resource(x * 16, 132, 16, 16); + } + public static class ResourceGroup { public Resource normal; public Resource focused; diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipe.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipe.java index 93c2307..f3b7ba6 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipe.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipe.java @@ -147,19 +147,20 @@ public class GuiRecipe extends WContainer implements IGui { disambCache = new HashMap<>(); // input - List inputItemStacks = recipe.getIngredientStacks(recipeIndex).stream() - .map((positionedStack) -> positionedStack.item) - .collect(Collectors.toList()); - List outputItemStacks = Collections.singletonList(recipe.getResultStack(recipeIndex).item); + recipe.getIngredientStacks(recipeIndex).stream() + .map((positionedStack) -> positionedStack.items) + .forEach(i -> merge(input, Arrays.asList(i), recipe)); + // output + merge(output, Arrays.asList(recipe.getResultStack(recipeIndex).items), recipe); - merge(input, inputItemStacks, recipe); - merge(output, outputItemStacks, recipe); - - // catalyst ignore multiple catalyst + // catalyst. Ignore multiple catalyst NEIPlugin.getCatalyst(recipe).map(ILabel.Converter::from).ifPresent(catalyst -> { this.catalyst.setLabel(catalyst, 0); }); + // other. Unused. For example fuel in furnaces. + recipe.getOtherStacks(recipeIndex).stream(); + this.input.setLabel(sort(input, 0), 0); this.output.setLabel(sort(output, 21), 0); refresh(); diff --git a/src/main/java/me/towdium/jecalculation/gui/widgets/WLabel.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabel.java index ee98fcc..9080258 100644 --- a/src/main/java/me/towdium/jecalculation/gui/widgets/WLabel.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabel.java @@ -1,5 +1,6 @@ package me.towdium.jecalculation.gui.widgets; +import codechicken.lib.gui.GuiDraw; import codechicken.nei.recipe.GuiCraftingRecipe; import codechicken.nei.recipe.GuiUsageRecipe; import cpw.mods.fml.relauncher.Side; @@ -9,12 +10,10 @@ import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; import me.towdium.jecalculation.utils.IllegalPositionException; import me.towdium.jecalculation.utils.Utilities; -import org.lwjgl.input.Keyboard; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; import java.util.List; -import java.util.stream.IntStream; import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_RED; import static me.towdium.jecalculation.gui.JecaGui.COLOR_TEXT_WHITE; @@ -66,10 +65,10 @@ public class WLabel implements IWidget { if (mode == Mode.EDITOR || mode == Mode.SELECTOR) { timer.setState(gui.hand != ILabel.EMPTY); int color = 0xFFFFFF + (int) ((-Math.cos(timer.getTime() * Math.PI / 1500) + 1) * 0x40) * 0x1000000; - gui.drawRectangle(xPos + 1, yPos + 1, xSize - 2, ySize - 2, color); + GuiDraw.drawRect(xPos + 1, yPos + 1, xSize - 2, ySize - 2, color); } if (mouseIn(xMouse, yMouse)) - gui.drawRectangle(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF); + GuiDraw.drawRect(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF); } @Override @@ -92,7 +91,8 @@ public class WLabel implements IWidget { notifyLsnr(); } return true; - } else return false; + } else + return false; } @Nullable @@ -158,7 +158,8 @@ public class WLabel implements IWidget { } void notifyLsnr() { - if (listener != null) listener.invoke(this, label); + if (listener != null) + listener.invoke(this, label); } @@ -172,17 +173,15 @@ public class WLabel implements IWidget { class WAmount extends WOverlay { WLabel temp = new WLabel(xPos, yPos, xSize, ySize, Mode.PICKER).setListener((i, v) -> update()); - WButton number = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "#", "general.to_percent") - .setListener(i -> { - temp.label.setPercent(true); - update(); - }); + WButton number = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "#", "general.to_percent").setListener(i -> { + temp.label.setPercent(true); + update(); + }); WTextField text = new WTextField(xPos + xSize + 10, yPos + ySize / 2 - WTextField.HEIGHT / 2, 50); - WButton percent = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "%", "general.to_percent") - .setListener(i -> { - temp.label.setPercent(false); - update(); - }); + WButton percent = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "%", "general.to_percent").setListener(i -> { + temp.label.setPercent(false); + update(); + }); WButton pick = new WButtonIcon(xPos + xSize + 83, yPos, 20, 20, BTN_PICK, "label.pick").setListener(i -> { JecaGui.getCurrent().hand = temp.label; setLabel(ILabel.EMPTY); @@ -200,7 +199,6 @@ public class WLabel implements IWidget { JecaGui.getCurrent().root.remove(this); }); - public WAmount() { temp.setLabel(label.copy()); add(new WPanel(xPos - 5, yPos - 5, xSize + 152, ySize + 10)); @@ -212,7 +210,8 @@ public class WLabel implements IWidget { try { amount = Long.parseLong(text.getText()); acceptable = amount > 0; - if (!acceptable) amount = 1; + if (!acceptable) + amount = 1; } catch (NumberFormatException e) { acceptable = text.getText().isEmpty(); amount = 1;