diff --git a/README.md b/README.md index 7937019..445559c 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ the [release page](https://minecraft.curseforge.com/projects/just-enough-calcula ## Features +- Infinite inputs, outputs and catalysts of recipe - Recipe from NEI recipe handler (recipe gui) - [x] vanilla - [x] gregtech @@ -29,14 +30,12 @@ the [release page](https://minecraft.curseforge.com/projects/just-enough-calcula ## TODO -- Backport the 1.16 feature - - [ ] Disambiguation in picker - - [ ] Infinite recipe inputs, outputs and catalysts +- Handle nei key binding (`R` to open recipe and `U` to open usage) ## Known Issues - [ ] **May crash** if you open the gui immediately after entering the world -- [ ] Client only +- [ ] **Client only** - [ ] Fluid from NEI ItemPanel will be recognized as item - [ ] Some OreDict items renders wrong with overlay (Now removed the overlay) - [ ] GUI will cover the NEI's GUI like tooltip on item panel 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 dda6329..ad2668a 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/ILabel.java +++ b/src/main/java/me/towdium/jecalculation/data/label/ILabel.java @@ -462,9 +462,11 @@ public interface ILabel { @Override public ILabel decreaseAmount() { - if (getAmount() <= getMultiplier()) + if (getAmount() <= 0) { return ILabel.EMPTY; - else { + } if (getAmount() <= getMultiplier()) { + return this; + } else { return setAmount(getAmount() - getMultiplier()); } } 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 ca1615a..f6b8c11 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiCraft.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiCraft.java @@ -15,7 +15,6 @@ import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault; import me.towdium.jecalculation.utils.ItemStackHelper; import me.towdium.jecalculation.utils.Utilities; import me.towdium.jecalculation.utils.wrappers.Pair; -import net.minecraft.client.Minecraft; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import org.lwjgl.input.Mouse; @@ -39,9 +38,9 @@ public class GuiCraft extends WContainer implements IGui { Calculator calculator = null; RecordCraft record; WLabel label = new WLabel(31, 7, 20, 20, true).setLsnrUpdate((i, v) -> refreshLabel(v, false, true)); - WLabelGroup recent = new WLabelGroup(7, 31, 8, 1, false).setLsnrClick( + WLabelGroup recent = new WLabelGroup(7, 31, 8, 1, false).setLsnrLeftClick( (i, v) -> label.setLabel(i.get(v).getLabel().copy(), true)); - WLabelScroll result = new WLabelScroll(7, 87, 8, 4, false).setLsnrClick((i, v) -> { + WLabelScroll result = new WLabelScroll(7, 87, 8, 4, false).setLsnrLeftClick((i, v) -> { Object rep = i.get(v).getLabel().getRepresentation(); NEIPlugin.openRecipeGui(rep, Mouse.getEventButton()); }).setFmtAmount(i -> i.getAmountString(true)).setFmtTooltip((i, j) -> i.getToolTip(j, true)); 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 8e6550d..4502513 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipe.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipe.java @@ -86,11 +86,16 @@ public class GuiRecipe extends WContainer implements IGui { for (IO j : IO.values()) { getWidget(j).setFmtAmount(i -> i.getAmountString(false)) .setFmtTooltip((i, k) -> i.getToolTip(k, true)) - .setLsnrClick((i, v) -> { + .setLsnrLeftClick((i, v) -> { ILabel l = i.get(v).getLabel(); if (l != ILabel.EMPTY) setOverlay(new WAmount(j, v)); }) + .setLsnrRightClick((widget, value) -> { + ILabel l = widget.get(value).getLabel(); + if (l != ILabel.EMPTY) + widget.get(value).setLabel(ILabel.EMPTY, true); + }) .setLsnrUpdate((i, v) -> { refresh(); removeDisamb(j, v); @@ -321,7 +326,7 @@ public class GuiRecipe extends WContainer implements IGui { temp = new WLabel(x - 1, y - 1, 20, 20, false); temp.setLabel(ref.getLabel().copy()); content = new WLabelScroll(x + 8, y - 40, 4, 2, false).setLabels(disamb.get(type).get(idx)) - .setLsnrClick((i, v) -> { + .setLsnrLeftClick((i, v) -> { ref.setLabel( i.get(v).getLabel().copy().multiply(-1), false); diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiSearch.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiSearch.java index 5db12f1..316a929 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiSearch.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiSearch.java @@ -24,7 +24,7 @@ import static me.towdium.jecalculation.gui.Resource.*; public class GuiSearch extends WContainer implements IGui { IdentityHashMap> recipes; WLabelScroll labels = new WLabelScroll(7, 51, 8, 6, false) - .setLsnrClick((i, v) -> { + .setLsnrLeftClick((i, v) -> { ILabel l = i.get(v).getLabel(); if (l != ILabel.EMPTY) setOverlay(new Overlay(i.get(v))); }); diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerPlaceholder.java b/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerPlaceholder.java index 09298ef..c1d4130 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerPlaceholder.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerPlaceholder.java @@ -24,7 +24,7 @@ import static me.towdium.jecalculation.gui.Resource.ICN_TEXT; public class PickerPlaceholder extends IPicker.Impl implements IGui { public PickerPlaceholder() { WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, false) - .setLabels(LPlaceholder.getRecent()).setLsnrClick((i, v) -> notifyLsnr(i.get(v).getLabel())); + .setLabels(LPlaceholder.getRecent()).setLsnrLeftClick((i, v) -> notifyLsnr(i.get(v).getLabel())); WTextField create = new WTextField(26, 7, 69).setListener( i -> i.setColor(i.getText().equals("") ? COLOR_TEXT_RED : COLOR_TEXT_WHITE)); add(new WSearch(26, 45, 90, scroll)); diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerSimple.java b/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerSimple.java index 905eaae..ce59f1c 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerSimple.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerSimple.java @@ -7,7 +7,6 @@ import me.towdium.jecalculation.data.label.labels.LFluidStack; import me.towdium.jecalculation.data.label.labels.LOreDict; import me.towdium.jecalculation.gui.guis.IGui; import me.towdium.jecalculation.gui.widgets.WIcon; -import me.towdium.jecalculation.gui.widgets.WLabel; import me.towdium.jecalculation.gui.widgets.WLabelScroll; import me.towdium.jecalculation.gui.widgets.WSearch; import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault; @@ -34,7 +33,7 @@ public class PickerSimple extends IPicker.Impl implements IGui { */ public PickerSimple(List labels) { WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, false).setLabels(labels) - .setLsnrClick((i, v) -> notifyLsnr(i.get(v).getLabel())); + .setLsnrLeftClick((i, v) -> notifyLsnr(i.get(v).getLabel())); add(new WSearch(26, 7, 90, ls)); add(new WIcon(7, 7, 20, 20, ICN_TEXT, "common.search")); add(ls); 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 1842858..ff2b0ae 100644 --- a/src/main/java/me/towdium/jecalculation/gui/widgets/WLabel.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabel.java @@ -29,7 +29,7 @@ public class WLabel implements IWidget { ILabel label = ILabel.EMPTY; public boolean accept; public ListenerValue update; - public ListenerAction click; + public ListenerAction leftClick, rightClick; Function fmtAmount = i -> ""; BiConsumer> fmtTooltip = (i, j) -> i.getToolTip(j, false); protected Timer timer = new Timer(); @@ -94,18 +94,22 @@ public class WLabel implements IWidget { @Override public boolean onMouseClicked(JecaGui gui, int xMouse, int yMouse, int button) { - if (!mouseIn(xMouse, yMouse) || button == 1) + if (!mouseIn(xMouse, yMouse)) return false; + if(button == 1) { + notifyRightClick(); + return true; + } if (accept) { - if (gui.hand == ILabel.EMPTY && click != null) - notifyClick(); + if (gui.hand == ILabel.EMPTY && leftClick != null) + notifyLeftClick(); else { label = gui.hand; gui.hand = label.EMPTY; notifyUpdate(); } } else - notifyClick(); + notifyLeftClick(); return true; } @@ -114,8 +118,13 @@ public class WLabel implements IWidget { return this; } - public WLabel setLsnrClick(ListenerAction listener) { - click = listener; + public WLabel setLsnrLeftClick(ListenerAction listener) { + leftClick = listener; + return this; + } + + public WLabel setLsnrRightClick(ListenerAction listener) { + rightClick = listener; return this; } @@ -135,9 +144,14 @@ public class WLabel implements IWidget { return xx >= 0 && xx < xSize && yy >= 0 && yy < ySize; } - private void notifyClick() { - if (click != null) - click.invoke(this); + private void notifyLeftClick() { + if (leftClick != null) + leftClick.invoke(this); + } + + private void notifyRightClick() { + if (rightClick != null) + rightClick.invoke(this); } private void notifyUpdate() { diff --git a/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelGroup.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelGroup.java index 236161b..ee00114 100644 --- a/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelGroup.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelGroup.java @@ -23,7 +23,7 @@ import java.util.stream.IntStream; public class WLabelGroup extends WContainer { ArrayList labels = new ArrayList<>(); ListenerValue lsnrUpdate; - ListenerValue lsnrClick; + ListenerValue lsnrLeftClick, lsnrRightClick; public WLabelGroup(int xPos, int yPos, int column, int row, boolean accept) { this(xPos, yPos, column, row, 18, 18, accept); @@ -37,9 +37,12 @@ public class WLabelGroup extends WContainer { (i, v) -> { if (lsnrUpdate != null) lsnrUpdate.invoke(this, r * column + c); - }).setLsnrClick(i -> { - if (lsnrClick != null) - lsnrClick.invoke(this, r * column + c); + }).setLsnrLeftClick(i -> { + if (lsnrLeftClick != null) + lsnrLeftClick.invoke(this, r * column + c); + }).setLsnrRightClick(i -> { + if (lsnrRightClick != null) + lsnrRightClick.invoke(this, r * column + c); }); labels.add(l); add(l); @@ -69,8 +72,13 @@ public class WLabelGroup extends WContainer { return this; } - public WLabelGroup setLsnrClick(ListenerValue listener) { - lsnrClick = listener; + public WLabelGroup setLsnrLeftClick(ListenerValue listener) { + lsnrLeftClick = listener; + return this; + } + + public WLabelGroup setLsnrRightClick(ListenerValue listener) { + lsnrRightClick = listener; return this; } diff --git a/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelScroll.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelScroll.java index 0baeb33..40ee29a 100644 --- a/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelScroll.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelScroll.java @@ -29,7 +29,7 @@ public class WLabelScroll extends WContainer implements ISearchable { protected String filter = ""; protected int xPos, yPos, column, row, current; private ListenerValue lsnrUpdate; - private ListenerValue lsnrClick; + private ListenerValue lsnrLeftClick, lsnrRightClick; protected final boolean accept; public WLabelScroll(int xPos, int yPos, int column, int row, boolean accept) { @@ -39,7 +39,8 @@ public class WLabelScroll extends WContainer implements ISearchable { this.column = column; this.row = row; labelGroup = new WLabelGroup(xPos, yPos, column, row, accept).setLsnrUpdate(this::onUpdate) - .setLsnrClick(this::onClick); + .setLsnrLeftClick(this::onLeftClick) + .setLsnrRightClick(this::onRightClick); scroll = new WScroll(xPos + column * 18 + 4, yPos, row * 18).setListener(i -> update(i.getCurrent())) .setStep(Float.POSITIVE_INFINITY) .setRatio(1); @@ -91,8 +92,13 @@ public class WLabelScroll extends WContainer implements ISearchable { return this; } - public WLabelScroll setLsnrClick(ListenerValue lsnrClick) { - this.lsnrClick = lsnrClick; + public WLabelScroll setLsnrLeftClick(ListenerValue lsnrLeftClick) { + this.lsnrLeftClick = lsnrLeftClick; + return this; + } + + public WLabelScroll setLsnrRightClick(ListenerValue lsnrRightClick) { + this.lsnrRightClick = lsnrRightClick; return this; } @@ -117,9 +123,14 @@ public class WLabelScroll extends WContainer implements ISearchable { } } - protected void onClick(WLabelGroup w, int index) { - if (lsnrClick != null) - lsnrClick.invoke(this, column * current + index); + protected void onLeftClick(WLabelGroup w, int index) { + if (lsnrLeftClick != null) + lsnrLeftClick.invoke(this, column * current + index); + } + + protected void onRightClick(WLabelGroup w, int index) { + if (lsnrRightClick != null) + lsnrRightClick.invoke(this, column * current + index); } public WLabelScroll setFmtAmount(Function f) {