From fa3ba7542c7f99f611de8a20145c7bbb99a31ba3 Mon Sep 17 00:00:00 2001 From: Discreater Date: Sat, 1 May 2021 15:38:40 +0800 Subject: [PATCH] feat: clean up --- .../jecalculation/JustEnoughCalculation.java | 16 +- .../jecalculation/command/Commands.java | 25 +-- .../jecalculation/command/ISubCommand.java | 4 + .../jecalculation/command/JecaCommand.java | 11 +- .../commands/{CommandHelp.java => CHelp.java} | 14 +- .../{CommandOreDict.java => COreDict.java} | 8 +- .../{CommandState.java => CState.java} | 6 +- .../commands/{CommandUuid.java => CUuid.java} | 4 +- .../jecalculation/data/Controller.java | 15 +- .../jecalculation/data/label/ILabel.java | 169 +++++++++++------- .../data/label/labels/LFluidStack.java | 20 ++- .../data/label/labels/LItemStack.java | 74 ++++---- .../data/label/labels/LOreDict.java | 80 +++++---- .../data/label/labels/LPlaceholder.java | 12 +- .../structure}/CostList.java | 100 ++++++----- .../jecalculation/data/structure/Recipe.java | 17 +- .../jecalculation/data/structure/Recipes.java | 5 +- .../event/handlers/FMLBusEventHandler.java | 4 +- .../me/towdium/jecalculation/gui/JecaGui.java | 32 ++-- .../towdium/jecalculation/gui/Resource.java | 3 - .../jecalculation/gui/guis/GuiCalculator.java | 99 ++++++---- .../gui/guis/GuiDisambiguation.java | 13 +- .../jecalculation/gui/guis/GuiLabel.java | 9 +- .../jecalculation/gui/guis/GuiRecipe.java | 14 +- .../jecalculation/gui/guis/GuiSearch.java | 36 ++-- .../towdium/jecalculation/gui/guis/IGui.java | 13 ++ .../pickers/IPicker.java} | 13 +- .../gui/guis/pickers/PickerItemStack.java | 10 +- .../gui/guis/pickers/PickerPlaceholder.java | 8 +- .../gui/guis/pickers/PickerSimple.java | 11 +- .../jecalculation/gui/widgets/IContainer.java | 17 ++ .../gui/{ => widgets}/IWidget.java | 4 +- .../gui/{drawables => widgets}/WButton.java | 2 +- .../{drawables => widgets}/WButtonIcon.java | 2 +- .../{drawables => widgets}/WButtonText.java | 3 +- .../{drawables => widgets}/WContainer.java | 5 +- .../gui/{drawables => widgets}/WHelp.java | 13 +- .../gui/{drawables => widgets}/WIcon.java | 2 +- .../gui/{drawables => widgets}/WLabel.java | 80 +++++---- .../{drawables => widgets}/WLabelGroup.java | 13 +- .../{drawables => widgets}/WLabelScroll.java | 4 +- .../gui/{drawables => widgets}/WLine.java | 3 +- .../gui/{drawables => widgets}/WPage.java | 3 +- .../gui/{drawables => widgets}/WPanel.java | 3 +- .../{drawables => widgets}/WRectangle.java | 3 +- .../gui/{drawables => widgets}/WScroll.java | 3 +- .../gui/{drawables => widgets}/WSearch.java | 4 +- .../gui/{drawables => widgets}/WSwitcher.java | 3 +- .../gui/{drawables => widgets}/WText.java | 4 +- .../{drawables => widgets}/WTextField.java | 3 +- .../gui/{drawables => widgets}/WTooltip.java | 3 +- .../jecalculation/utils/ItemStackHelper.java | 4 + .../jecalculation/utils/Utilities.java | 50 +----- .../jecalculation/utils/wrappers/Wrapper.java | 11 ++ .../assets/jecalculation/lang/en_US.lang | 14 +- 55 files changed, 611 insertions(+), 490 deletions(-) rename src/main/java/me/towdium/jecalculation/command/commands/{CommandHelp.java => CHelp.java} (71%) rename src/main/java/me/towdium/jecalculation/command/commands/{CommandOreDict.java => COreDict.java} (72%) rename src/main/java/me/towdium/jecalculation/command/commands/{CommandState.java => CState.java} (76%) rename src/main/java/me/towdium/jecalculation/command/commands/{CommandUuid.java => CUuid.java} (90%) rename src/main/java/me/towdium/jecalculation/{algorithm => data/structure}/CostList.java (57%) create mode 100644 src/main/java/me/towdium/jecalculation/gui/guis/IGui.java rename src/main/java/me/towdium/jecalculation/gui/{IWPicker.java => guis/pickers/IPicker.java} (60%) create mode 100644 src/main/java/me/towdium/jecalculation/gui/widgets/IContainer.java rename src/main/java/me/towdium/jecalculation/gui/{ => widgets}/IWidget.java (85%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WButton.java (98%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WButtonIcon.java (97%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WButtonText.java (92%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WContainer.java (94%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WHelp.java (90%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WIcon.java (97%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WLabel.java (77%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WLabelGroup.java (82%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WLabelScroll.java (94%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WLine.java (86%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WPage.java (95%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WPanel.java (93%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WRectangle.java (88%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WScroll.java (95%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WSearch.java (90%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WSwitcher.java (97%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WText.java (90%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WTextField.java (95%) rename src/main/java/me/towdium/jecalculation/gui/{drawables => widgets}/WTooltip.java (94%) diff --git a/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java b/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java index 3312aed..c01adc8 100644 --- a/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java +++ b/src/main/java/me/towdium/jecalculation/JustEnoughCalculation.java @@ -56,18 +56,10 @@ public class JustEnoughCalculation { public static final String VERSION = "@VERSION@"; } + // Only to use at client side public enum enumSide { - /** - * Running at client side and server not installed. - */ - CLIENT, - /** - * Running at client side and both installed. - */ - BOTH, - /** - * Default unknown. - */ - UNDEFINED + CLIENT, // Running at client side and server not installed + BOTH, // Running at client side and both installed + UNDEFINED // Default unknown } } diff --git a/src/main/java/me/towdium/jecalculation/command/Commands.java b/src/main/java/me/towdium/jecalculation/command/Commands.java index 0f85782..4d7b84c 100644 --- a/src/main/java/me/towdium/jecalculation/command/Commands.java +++ b/src/main/java/me/towdium/jecalculation/command/Commands.java @@ -1,9 +1,9 @@ package me.towdium.jecalculation.command; -import me.towdium.jecalculation.command.commands.CommandHelp; -import me.towdium.jecalculation.command.commands.CommandOreDict; -import me.towdium.jecalculation.command.commands.CommandState; -import me.towdium.jecalculation.command.commands.CommandUuid; +import me.towdium.jecalculation.command.commands.CHelp; +import me.towdium.jecalculation.command.commands.COreDict; +import me.towdium.jecalculation.command.commands.CState; +import me.towdium.jecalculation.command.commands.CUuid; import javax.annotation.ParametersAreNonnullByDefault; import java.util.HashMap; @@ -14,20 +14,13 @@ import java.util.HashMap; */ @ParametersAreNonnullByDefault public class Commands { - public static final HashMap commands; - - public static final CommandHelp commandHelp = new CommandHelp(); - public static final CommandState commandState = new CommandState(); - public static final CommandOreDict commandOreDict = new CommandOreDict(); - public static final CommandUuid commandUuid = new CommandUuid(); + public static final HashMap commands = new HashMap<>(); static { - commands = new HashMap<>(); - - add(commandHelp); - add(commandState); - add(commandOreDict); - add(commandUuid); + add(new CHelp()); + add(new CState()); + add(new COreDict()); + add(new CUuid()); } static void add(ISubCommand c) { diff --git a/src/main/java/me/towdium/jecalculation/command/ISubCommand.java b/src/main/java/me/towdium/jecalculation/command/ISubCommand.java index f552730..ed4bd42 100644 --- a/src/main/java/me/towdium/jecalculation/command/ISubCommand.java +++ b/src/main/java/me/towdium/jecalculation/command/ISubCommand.java @@ -23,4 +23,8 @@ public interface ISubCommand { default List getTabCompletions(ICommandSender sender, String[] args) { return Collections.emptyList(); } + + default String getKey(String key) { + return "jecharacters.command." + getName() + '.' + key; + } } diff --git a/src/main/java/me/towdium/jecalculation/command/JecaCommand.java b/src/main/java/me/towdium/jecalculation/command/JecaCommand.java index b4fefc8..cabc977 100644 --- a/src/main/java/me/towdium/jecalculation/command/JecaCommand.java +++ b/src/main/java/me/towdium/jecalculation/command/JecaCommand.java @@ -1,5 +1,6 @@ package me.towdium.jecalculation.command; +import me.towdium.jecalculation.command.commands.CHelp; import me.towdium.jecalculation.utils.wrappers.Wrapper; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -18,19 +19,19 @@ import java.util.List; public class JecaCommand extends CommandBase { @Override public String getCommandName() { - return "jec"; + return "jeca"; } @Override public String getCommandUsage(ICommandSender sender) { - return "/jec [help]"; + return "/jeca [options]"; } @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (args.length == 0 || args[0].toLowerCase().equals("help")) { - Commands.commandHelp.execute(sender, cut(args)); + if (args.length == 0 || args[0].equalsIgnoreCase("help")) { + Commands.commands.get(CHelp.NAME).execute(sender, cut(args)); } else { ISubCommand cmd = Commands.commands.get(args[0].toLowerCase()); if (cmd != null) { @@ -71,4 +72,6 @@ public class JecaCommand extends CommandBase { : Collections.emptyList(); } } + + } diff --git a/src/main/java/me/towdium/jecalculation/command/commands/CommandHelp.java b/src/main/java/me/towdium/jecalculation/command/commands/CHelp.java similarity index 71% rename from src/main/java/me/towdium/jecalculation/command/commands/CommandHelp.java rename to src/main/java/me/towdium/jecalculation/command/commands/CHelp.java index cf62f7a..1f2a424 100644 --- a/src/main/java/me/towdium/jecalculation/command/commands/CommandHelp.java +++ b/src/main/java/me/towdium/jecalculation/command/commands/CHelp.java @@ -15,25 +15,21 @@ import java.util.Comparator; * Date: 8/10/17. */ @ParametersAreNonnullByDefault -public class CommandHelp implements ISubCommand { +public class CHelp implements ISubCommand { + public static final String NAME = "help"; @Override public String getName() { - return "help"; + return NAME; } @Override public String getUsage(ICommandSender sender) { - return "/jec [help]"; + return "/jeca [help]"; } @Override public void execute(ICommandSender sender, String[] args) { - if (args.length != 0) { - sender.addChatMessage(new ChatComponentTranslation("command.common.unexpected_arg", String.join(" ", args))); - return; - } - - sender.addChatMessage(new ChatComponentTranslation("command.help.list")); + sender.addChatMessage(new ChatComponentTranslation(getKey("list"))); Commands.commands.values().stream().sorted(Comparator.comparing(ISubCommand::getName)) .forEachOrdered(c -> sender.addChatMessage(new ChatComponentText(c.getUsage(sender)))); } diff --git a/src/main/java/me/towdium/jecalculation/command/commands/CommandOreDict.java b/src/main/java/me/towdium/jecalculation/command/commands/COreDict.java similarity index 72% rename from src/main/java/me/towdium/jecalculation/command/commands/CommandOreDict.java rename to src/main/java/me/towdium/jecalculation/command/commands/COreDict.java index b0c44a0..75480a5 100644 --- a/src/main/java/me/towdium/jecalculation/command/commands/CommandOreDict.java +++ b/src/main/java/me/towdium/jecalculation/command/commands/COreDict.java @@ -14,7 +14,7 @@ import java.util.Arrays; * Date: 17-9-11. */ @ParametersAreNonnullByDefault -public class CommandOreDict implements ISubCommand { +public class COreDict implements ISubCommand { @Override public String getName() { return "ore"; @@ -22,13 +22,11 @@ public class CommandOreDict implements ISubCommand { @Override public String getUsage(ICommandSender sender) { - return "/jec ore"; + return "/jeca ore"; } @Override public void execute(ICommandSender sender, String[] args) { - if (args.length == 0) { - Arrays.stream(OreDictionary.getOreNames()).forEach(s -> sender.addChatMessage(new ChatComponentText(s))); - } // TODO error handling + Arrays.stream(OreDictionary.getOreNames()).forEach(s -> sender.addChatMessage(new ChatComponentText(s))); } } diff --git a/src/main/java/me/towdium/jecalculation/command/commands/CommandState.java b/src/main/java/me/towdium/jecalculation/command/commands/CState.java similarity index 76% rename from src/main/java/me/towdium/jecalculation/command/commands/CommandState.java rename to src/main/java/me/towdium/jecalculation/command/commands/CState.java index 27f6cb2..d07d7cd 100644 --- a/src/main/java/me/towdium/jecalculation/command/commands/CommandState.java +++ b/src/main/java/me/towdium/jecalculation/command/commands/CState.java @@ -13,7 +13,7 @@ import javax.annotation.ParametersAreNonnullByDefault; * Date: 8/10/17. */ @ParametersAreNonnullByDefault -public class CommandState implements ISubCommand { +public class CState implements ISubCommand { @Override public String getName() { return "state"; @@ -21,11 +21,11 @@ public class CommandState implements ISubCommand { @Override public String getUsage(ICommandSender sender) { - return "/jec state"; + return "/jeca state"; } @Override public void execute(ICommandSender sender, String[] args) { - sender.addChatMessage(new ChatComponentTranslation("command.state.desc", JustEnoughCalculation.side.toString())); + sender.addChatMessage(new ChatComponentTranslation(getKey("desc"), JustEnoughCalculation.side.toString())); } } diff --git a/src/main/java/me/towdium/jecalculation/command/commands/CommandUuid.java b/src/main/java/me/towdium/jecalculation/command/commands/CUuid.java similarity index 90% rename from src/main/java/me/towdium/jecalculation/command/commands/CommandUuid.java rename to src/main/java/me/towdium/jecalculation/command/commands/CUuid.java index f3f29f6..64110dc 100644 --- a/src/main/java/me/towdium/jecalculation/command/commands/CommandUuid.java +++ b/src/main/java/me/towdium/jecalculation/command/commands/CUuid.java @@ -13,7 +13,7 @@ import javax.annotation.ParametersAreNonnullByDefault; * Date: 17-10-15. */ @ParametersAreNonnullByDefault -public class CommandUuid implements ISubCommand { +public class CUuid implements ISubCommand { @Override public String getName() { return "uuid"; @@ -21,7 +21,7 @@ public class CommandUuid implements ISubCommand { @Override public String getUsage(ICommandSender sender) { - return "/jec uuid"; + return "/jeca uuid"; } diff --git a/src/main/java/me/towdium/jecalculation/data/Controller.java b/src/main/java/me/towdium/jecalculation/data/Controller.java index 3322da3..0047b8b 100644 --- a/src/main/java/me/towdium/jecalculation/data/Controller.java +++ b/src/main/java/me/towdium/jecalculation/data/Controller.java @@ -9,6 +9,9 @@ import me.towdium.jecalculation.data.structure.Recents; import me.towdium.jecalculation.data.structure.Recipe; import me.towdium.jecalculation.data.structure.Recipes; import me.towdium.jecalculation.utils.wrappers.Triple; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -27,7 +30,7 @@ import java.util.stream.Collectors; * Date: 17-10-15. */ @SideOnly(Side.CLIENT) -public class Controller { // TODO record calculate amount +public class Controller { public static final String KEY_RECIPES = "recipes"; public static final String KEY_RECENTS = "recents"; static Recipes recipesClient; @@ -37,6 +40,10 @@ public class Controller { // TODO record calculate amount return recipesClient; } + static Optional getStack() { + return Optional.empty(); + } + public static List getGroups() { Recipes user = getRecord(); if (user.size() != 0) @@ -72,11 +79,11 @@ public class Controller { // TODO record calculate amount return getRecord().getRecipes(group); } - public static Optional getRecipe(ILabel label, Recipe.enumIoType type) { - return getRecord().getRecipe(label, type); + public static Optional getRecipe(ILabel label) { + return getRecord().getRecipe(label); } - public static List getRecent() { // TODO reduce usage of it since it reads nbt again + public static List getRecent() { return recentsClient.getRecords(); } 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 002c2f1..60b8932 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/ILabel.java +++ b/src/main/java/me/towdium/jecalculation/data/label/ILabel.java @@ -7,16 +7,16 @@ import me.towdium.jecalculation.data.label.labels.LFluidStack; import me.towdium.jecalculation.data.label.labels.LItemStack; import me.towdium.jecalculation.data.label.labels.LOreDict; import me.towdium.jecalculation.data.label.labels.LPlaceholder; -import me.towdium.jecalculation.gui.IWPicker; import me.towdium.jecalculation.gui.JecaGui; +import me.towdium.jecalculation.gui.guis.pickers.IPicker; import me.towdium.jecalculation.gui.guis.pickers.PickerItemStack; import me.towdium.jecalculation.gui.guis.pickers.PickerPlaceholder; import me.towdium.jecalculation.gui.guis.pickers.PickerSimple; import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager; import me.towdium.jecalculation.utils.Utilities; -import me.towdium.jecalculation.utils.Utilities.Relation; import me.towdium.jecalculation.utils.Utilities.ReversedIterator; import me.towdium.jecalculation.utils.wrappers.Pair; +import me.towdium.jecalculation.utils.wrappers.Wrapper; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -29,6 +29,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Optional; +import java.util.function.BiFunction; +import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -49,22 +51,23 @@ public interface ILabel { String FORMAT_GREY = "\u00A78"; String FORMAT_ITALIC = "\u00A7o"; + @Nullable + Object getRepresentation(); + ILabel increaseAmount(); ILabel decreaseAmount(); static void initClient() { CONVERTER.register(LOreDict::guess); - EDITOR.register(PickerSimple.FluidStack::new, "fluid_stack", new LFluidStack(1000, FluidRegistry.WATER)); - EDITOR.register(PickerSimple.OreDict::new, "ore_dict", new LOreDict("ingotIron")); + EDITOR.register(PickerSimple.FluidStack::new, "fluid", new LFluidStack(1000, FluidRegistry.WATER)); + EDITOR.register(PickerSimple.OreDict::new, "ore", new LOreDict("ingotIron")); EDITOR.register(PickerPlaceholder::new, "placeholder", new LPlaceholder("example", 1, true)); - EDITOR.register(PickerItemStack::new, "item_stack", - new LItemStack(new ItemStack(Items.iron_pickaxe)).setFMeta(true)); - MERGER.register("itemStack", "itemStack", LItemStack::merge); - MERGER.register("oreDict", "oreDict", LOreDict::merge); - MERGER.register("itemStack", "oreDict", LOreDict::merge); - MERGER.register("fluidStack", "fluidStack", Impl::merge); - MERGER.register("fluidStack", "fluidStack", Impl::merge); + EDITOR.register(PickerItemStack::new, "item", new LItemStack(new ItemStack(Items.iron_pickaxe)).setFMeta(true)); + MERGER.register("itemStack", "itemStack", Impl.form(LItemStack.class, LItemStack.class, LItemStack::merge)); + MERGER.register("oreDict", "oreDict", Impl.form(LOreDict.class, LOreDict.class, LOreDict::mergeSame)); + MERGER.register("oreDict", "itemStack", Impl.form(LOreDict.class, LItemStack.class, LOreDict::mergeFuzzy)); + MERGER.register("fluidStack", "fluidStack", Impl.form(LFluidStack.class, LFluidStack.class, LFluidStack::merge)); } int getAmount(); @@ -77,6 +80,8 @@ public interface ILabel { @SuppressWarnings("UnusedReturnValue") ILabel setPercent(boolean p); + boolean isPercent(); + static void initServer() { SERIALIZER.register(LFluidStack.IDENTIFIER, LFluidStack::new); SERIALIZER.register(LItemStack.IDENTIFIER, LItemStack::new); @@ -85,7 +90,7 @@ public interface ILabel { SERIALIZER.register(LEmpty.IDENTIFIER, i -> EMPTY); } - String getAmountString(); + String getAmountString(boolean round); String getDisplayName(); @@ -110,40 +115,58 @@ public interface ILabel { * Since {@link ILabel} merging is bidirectional, it is redundant to * implement on both side. So this class is created for merging * {@link ILabel label(s)}. - * It uses singleton mode. First registerGuess merge functions, then use - * {@link #merge(ILabel, ILabel, boolean)} to operate the {@link ILabel}. + * It uses singleton mode. First register merge functions, then use + * {@link #merge(ILabel, ILabel)} to operate the {@link ILabel}. * For registering, see {@link Serializer}. */ class Merger { - private Relation functions = new Relation<>(); - + private HashMap, MergerFunction> functions = new HashMap<>(); private Merger() { } public void register(String a, String b, MergerFunction func) { - functions.add(a, b, func); + functions.put(new Pair<>(a, b), func); } - public Optional merge(ILabel a, ILabel b, boolean add) { - Optional ret = functions.get(a.getIdentifier(), b.getIdentifier()) - .orElse((x, y, f) -> Optional.empty()).merge(a, b, add); - if (ret.isPresent() && ret.get() != ILabel.EMPTY && (ret.get() == a || ret.get() == b)) - throw new RuntimeException("Merger should not modify the given label."); - return ret; + /** + * @param a one label + * @param b another label + * @return merge result or empty + * This function will try to merge two labels. + * If both label has same type, just sum up amount + * For different type, the framework will try reversing the order for MergeFunctions to work + * So generally speaking, a and b has no priority in this function + */ + public Optional merge(ILabel a, ILabel b) { + BiFunction get = (c, d) -> { + MergerFunction mf = functions.get(new Pair<>(c.getIdentifier(), d.getIdentifier())); + if (mf != null) return mf.merge(c, d); + else return null; + }; + return new Wrapper(null) + .or(() -> get.apply(a, b)) + .or(() -> get.apply(b, a)) + .ifPresent(i -> { + if (i != ILabel.EMPTY && (i == a || i == b)) + throw new RuntimeException("Merger should not modify the given label."); + }) + .toOptional(); } @FunctionalInterface public interface MergerFunction { /** - * @param a an {@link ILabel} to merge - * @param b another {@link ILabel} to merge - * @param add add together or cancel each other - * @return an optional {@link Pair pair} of {@link ILabel label(s)}. - * If empty, the labels cannot merge, otherwise returns difference and common elements + * @param a requested label + * @param b supplied label + * @return merge result or empty + * This function ensures to generate same type if a and b are from same type + * If a is fuzzy, b is explicit, generates a is amount is negative, else generates b + * Normally, explicit type cannot request fuzzy type */ - Optional merge(ILabel a, ILabel b, boolean add); + @Nullable + ILabel merge(ILabel a, ILabel b); } } @@ -181,7 +204,8 @@ public interface ILabel { public ILabel deserialize(NBTTagCompound nbt) { String s = nbt.getString(KEY_IDENTIFIER); Function func = idToData.get(s); - if (func != null) return func.apply(nbt.getCompoundTag(KEY_CONTENT)); + if (func != null) + return func.apply(nbt.getCompoundTag(KEY_CONTENT)); else { JustEnoughCalculation.logger.warn("Unrecognized type identifier \"" + s + "\", use empty instead."); return ILabel.EMPTY; @@ -219,11 +243,13 @@ public interface ILabel { handlers.add(handler); } + // get most possible guess from labels public ILabel first(List labels) { List guess = guess(labels); return guess.isEmpty() ? labels.get(0) : guess.get(0); } + // to test if the labels can be converted to other labels (like oreDict) public List guess(List labels) { return new ReversedIterator<>(handlers).stream().flatMap(h -> h.apply(labels).stream()) .collect(Collectors.toList()); @@ -237,7 +263,7 @@ public interface ILabel { private RegistryEditor() { } - public void register(Supplier editor, String unlocalizedName, ILabel representation) { + public void register(Supplier editor, String unlocalizedName, ILabel representation) { records.add(new Record(editor, "common.label." + unlocalizedName, representation)); } @@ -247,11 +273,11 @@ public interface ILabel { } public static class Record { - public Supplier editor; + public Supplier editor; public String localizeKey; public ILabel representation; - public Record(Supplier editor, String localizeKey, ILabel representation) { + public Record(Supplier editor, String localizeKey, ILabel representation) { this.editor = editor; this.localizeKey = localizeKey; this.representation = representation; @@ -270,6 +296,12 @@ public interface ILabel { private LEmpty() { } + @Nullable + @Override + public Object getRepresentation() { + return null; + } + @Override public ILabel increaseAmount() { return this; @@ -295,6 +327,11 @@ public interface ILabel { throw new UnsupportedOperationException(); } + @Override + public boolean isPercent() { + return false; + } + @Override public int getAmount() { return 0; @@ -306,7 +343,7 @@ public interface ILabel { } @Override - public String getAmountString() { + public String getAmountString(boolean round) { return ""; } @@ -350,9 +387,9 @@ public interface ILabel { return getDisplayName() + 'x' + getAmount(); } - public Impl(int amount) { + public Impl(int amount, boolean percent) { this.amount = amount; - percent = false; + this.percent = percent; } public Impl(Impl lsa) { @@ -399,32 +436,27 @@ public interface ILabel { return this; } + protected static Merger.MergerFunction form(Class a, Class b, BiPredicate p) { + return (c, d) -> { + if (c == EMPTY || d == EMPTY) return null; + if (a.isInstance(c) && b.isInstance(d) && p.test(c, d)) { + int amountC = c.isPercent() ? c.getAmount() : c.getAmount() * 100; + int amountD = d.isPercent() ? d.getAmount() : d.getAmount() * 100; + int amount = amountC + amountD; + int amountI = (amount > 0 ? amount + 99 : amount - 99) / 100; + if (amount == 0) return EMPTY; + else if (amount > 0) return d.copy().setAmount(d.isPercent() ? amount : amountI); + else return c.copy().setAmount(c.isPercent() ? amount : amountI); + } else return null; + }; + } + @Override @SideOnly(Side.CLIENT) public void getToolTip(List existing, boolean detailed) { if (detailed) - existing.add(FORMAT_GREY + Utilities.I18n.format("label.common.tooltip.amount", getAmountString())); - } - - public static Optional merge(ILabel a, ILabel b, boolean add) { - if (a instanceof Impl && b instanceof Impl && a.matches(b)) return mergeUnchecked((Impl) a, (Impl) b, add); - else return Optional.empty(); - } - - protected static Optional mergeUnchecked(Impl a, Impl b, boolean add) { - Impl ret = a.copy(); - boolean p = a.percent || b.percent; - int amountA = a.amount; - int amountB = b.amount; - if (p) { - if (!a.percent) - amountA *= 100; - if (!b.percent) - amountB *= 100; - } - ret.amount = add ? amountA + amountB : amountA - amountB; - ret.percent = p; - return Optional.of(ret.amount == 0 ? ILabel.EMPTY : ret); + existing.add( + FORMAT_GREY + Utilities.I18n.format("label.common.tooltip.amount", getAmountString(false))); } @Override @@ -454,7 +486,7 @@ public interface ILabel { } public ILabel setPercent(boolean p) { - if (!acceptPercent()) + if (p && !acceptPercent()) throw new UnsupportedOperationException(); if (p && !percent) { amount *= 100; @@ -466,6 +498,11 @@ public interface ILabel { return this; } + @Override + public boolean isPercent() { + return percent; + } + @Override public boolean equals(Object obj) { return obj instanceof Impl && amount == ((Impl) obj).amount && matches(obj); @@ -473,10 +510,16 @@ public interface ILabel { @Override @SideOnly(Side.CLIENT) - public String getAmountString() { - return getAmount() == 0 ? - "" : - (percent ? Utilities.cutNumber(getAmount(), 4) + "%" : Utilities.cutNumber(getAmount(), 5)); + @SuppressWarnings("IntegerDivisionInFloatingPointContext") + public String getAmountString(boolean round) { + if (getAmount() == 0) + return ""; + else if (!percent) + return Utilities.cutNumber(getAmount(), 5); + else if (round) + return Utilities.cutNumber((getAmount() + 99) / 100, 5); + else + return Utilities.cutNumber(getAmount(), 4) + "%"; } @Override diff --git a/src/main/java/me/towdium/jecalculation/data/label/labels/LFluidStack.java b/src/main/java/me/towdium/jecalculation/data/label/labels/LFluidStack.java index 0218d03..b1eff7b 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/labels/LFluidStack.java +++ b/src/main/java/me/towdium/jecalculation/data/label/labels/LFluidStack.java @@ -30,6 +30,12 @@ public class LFluidStack extends ILabel.Impl { NBTTagCompound nbt; FluidStack temp; + + @Override + public FluidStack getRepresentation() { + return temp; + } + @Override public boolean acceptPercent() { return false; @@ -44,7 +50,7 @@ public class LFluidStack extends ILabel.Impl { } public LFluidStack(int amount, Fluid fluid, @Nullable NBTTagCompound nbt) { - super(amount); + super(amount, false); this.fluid = fluid; this.nbt = nbt; temp = new FluidStack(fluid, amount, nbt); @@ -68,11 +74,12 @@ public class LFluidStack extends ILabel.Impl { } @Override - public String getAmountString() { + public String getAmountString(boolean round) { return amount >= 1000 ? Utilities.cutNumber(amount / 1000f, 4) + "B" - : Integer.toString(amount) + "mB"; + : amount + "mB"; } + @Override @SideOnly(Side.CLIENT) public String getDisplayName() { @@ -88,7 +95,7 @@ public class LFluidStack extends ILabel.Impl { public boolean matches(Object l) { if (l instanceof LFluidStack) { LFluidStack lfs = (LFluidStack) l; - return (nbt == null ? lfs.nbt == null : nbt.equals(lfs.nbt)) && fluid == lfs.fluid; + return (Objects.equals(nbt, lfs.nbt)) && fluid == lfs.fluid; } else return false; } @@ -125,4 +132,9 @@ public class LFluidStack extends ILabel.Impl { public int hashCode() { return fluid.getUnlocalizedName().hashCode() ^ amount ^ (nbt == null ? 0 : nbt.hashCode()); } + + public static boolean merge(ILabel a, ILabel b) { + if (a instanceof LFluidStack && b instanceof LFluidStack) return a.matches(b); + else return false; + } } diff --git a/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java b/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java index 25c32aa..ea2c4e0 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java +++ b/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java @@ -41,8 +41,8 @@ public class LItemStack extends ILabel.Impl { boolean fCap; transient ItemStack temp; - public LItemStack(int amount, Item item, int meta, @Nullable NBTTagCompound nbt) { - super(amount); + public LItemStack(int amount, Item item, int meta, @Nullable NBTTagCompound nbt, boolean percent) { + super(amount, percent); this.item = item; this.meta = meta; this.nbt = nbt == null ? null : (NBTTagCompound) nbt.copy(); @@ -52,13 +52,20 @@ public class LItemStack extends ILabel.Impl { // Convert from itemStack public LItemStack(ItemStack is) { - this(is.stackSize, is.getItem(), is.getItemDamage(), is.getTagCompound()); + this(is.stackSize, is.getItem(), is.getItemDamage(), is.getTagCompound(), false); } - public LItemStack(NBTTagCompound nbt) { - this(nbt.getInteger(KEY_AMOUNT), Objects.requireNonNull(Item.getItemById(nbt.getInteger(KEY_ITEM))), - nbt.getInteger(KEY_META), nbt.hasKey(KEY_NBT) ? nbt.getCompoundTag(KEY_NBT) : null); - fromFuzzy(nbt.getByte(KEY_FUZZY)); + public LItemStack(NBTTagCompound tag) { + super(tag); + item = Item.getItemById(tag.getInteger(KEY_ITEM)); + meta = tag.getInteger(KEY_META); + nbt = tag.hasKey(KEY_NBT) ? tag.getCompoundTag(KEY_NBT) : null; + byte fuzzy = tag.getByte(KEY_FUZZY); + fMeta = (fuzzy & FUZZY_META) != 0; + fCap = (fuzzy & FUZZY_CAP) != 0; + fNbt = (fuzzy & FUZZY_NBT) != 0; + temp = new ItemStack(item, 1, meta); + temp.setTagCompound(tag); } private LItemStack(LItemStack lis) { @@ -66,36 +73,31 @@ public class LItemStack extends ILabel.Impl { item = lis.item; meta = lis.meta; nbt = lis.nbt; + fMeta = lis.fMeta; + fNbt = lis.fNbt; + fCap = lis.fCap; temp = new ItemStack(item, 1, meta); temp.setTagCompound(nbt); } - public static Optional merge(ILabel a, ILabel b, boolean add) { + public static boolean merge(ILabel a, ILabel b) { if (a instanceof LItemStack && b instanceof LItemStack) { LItemStack lisA = (LItemStack) a; LItemStack lisB = (LItemStack) b; - - // check meta - int resultMeta = 0; - boolean checkedMeta = true; - if (lisA.meta == WILDCARD_VALUE || lisB.meta == WILDCARD_VALUE) - resultMeta = WILDCARD_VALUE; - else if (lisA.fMeta || lisB.fMeta || lisA.meta == lisB.meta) - resultMeta = lisA.meta; - else - checkedMeta = false; - - // check nbt and cap - boolean checkedNbt = (Objects.equals(lisA.nbt, lisB.nbt)) || lisA.fNbt || lisB.fNbt; - - if (lisA.item == lisB.item && checkedMeta && checkedNbt) { - LItemStack is = lisA.copy(); - is.meta = resultMeta; - return Impl.mergeUnchecked(is, lisB, add); + if (lisA.meta != WILDCARD_VALUE && lisB.meta == WILDCARD_VALUE) return false; + if (!lisA.fNbt) { + if (lisB.fNbt) return false; + else if (lisA.nbt == null) { + if (lisB.nbt != null) return false; + } else if (lisB.nbt == null || !lisA.nbt.equals(lisB.nbt)) return false; } + if (!lisA.fCap) { + if (lisB.fCap) return false; + } + return lisA.item == lisB.item; } - return Optional.empty(); + return false; } public ILabel setFMeta(boolean f) { @@ -124,6 +126,11 @@ public class LItemStack extends ILabel.Impl { existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(item)); } + @Override + public ItemStack getRepresentation() { + return temp; + } + @Override @SideOnly(Side.CLIENT) public String getDisplayName() { @@ -161,20 +168,11 @@ public class LItemStack extends ILabel.Impl { ret.setInteger(KEY_ITEM, id); if (nbt != null) ret.setTag(KEY_NBT, nbt); - ret.setByte(KEY_FUZZY, toFuzzy()); + int fuzzy = (fMeta ? FUZZY_META : 0) | (fCap ? FUZZY_CAP : 0) | (fNbt ? FUZZY_NBT : 0); + ret.setByte(KEY_FUZZY, (byte) fuzzy); return ret; } - private byte toFuzzy() { - return (byte) ((fMeta ? FUZZY_META : 0) | (fCap ? FUZZY_CAP : 0) | (fNbt ? FUZZY_NBT : 0)); - } - - private void fromFuzzy(byte i) { - fMeta = (i & FUZZY_META) != 0; - fCap = (i & FUZZY_CAP) != 0; - fNbt = (i & FUZZY_NBT) != 0; - } - @Override @SideOnly(Side.CLIENT) public void drawLabel(JecaGui gui) { diff --git a/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java b/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java index 4790311..c3d8480 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java +++ b/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java @@ -3,10 +3,9 @@ package me.towdium.jecalculation.data.label.labels; 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.JecaGui; import me.towdium.jecalculation.gui.Resource; -import me.towdium.jecalculation.data.label.ILabel; -import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager; import me.towdium.jecalculation.polyfill.mc.util.NonNullList; import me.towdium.jecalculation.utils.Utilities; import net.minecraft.creativetab.CreativeTabs; @@ -14,6 +13,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.oredict.OreDictionary; +import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import java.util.ArrayList; import java.util.HashSet; @@ -30,7 +30,7 @@ public class LOreDict extends ILabel.Impl { public static final String IDENTIFIER = "oreDict"; public static final String KEY_NAME = "name"; public static final String KEY_AMOUNT = "amount"; - public static final boolean MODE_FORCE = true; + public static final boolean MODE_FORCE = false; protected String name; @@ -39,7 +39,7 @@ public class LOreDict extends ILabel.Impl { } public LOreDict(String name, int amount) { - super(amount); + super(amount, false); this.name = name; } @@ -53,35 +53,45 @@ public class LOreDict extends ILabel.Impl { name = nbt.getString(KEY_NAME); } + @Override + @Nonnull + public ItemStack getRepresentation() { + NonNullList list = NonNullList.create(); + OreDictionary.getOres(name).forEach(is -> { + if (is.getItemDamage() == OreDictionary.WILDCARD_VALUE) { + is.getItem().getSubItems(is.getItem(), CreativeTabs.tabAllSearch, list); + } else + list.add(is); + }); + long index = System.currentTimeMillis() / 1500; + return list.get((int) (index % list.size())); + } + @Override @SideOnly(Side.CLIENT) public String getDisplayName() { return Utilities.I18n.format("label.ore_dict.name", name); } - public static Optional merge(ILabel a, ILabel b, boolean add) { + public static boolean mergeSame(ILabel a, ILabel b) { if (a instanceof LOreDict && b instanceof LOreDict) { LOreDict lodA = (LOreDict) a; LOreDict lodB = (LOreDict) b; - if (lodA.getName().equals(lodB.getName())) { - return Impl.mergeUnchecked(lodA, lodB, add); - } - } else if ((a instanceof LOreDict && b instanceof LItemStack) - || a instanceof LItemStack && b instanceof LOreDict) { - LItemStack lis; - LOreDict lor; - if (a instanceof LOreDict) { - lis = (LItemStack) b; - lor = (LOreDict) a; - } else { - lis = (LItemStack) a; - lor = (LOreDict) b; - } - return OreDictionary.getOres(lor.name).stream().map(o -> Converter.from(o).multiply(lor.amount)) - .map(i -> LItemStack.merge(i, lis, add)).filter(Optional::isPresent) - .findAny().flatMap(i -> i); + return lodA.getName().equals(lodB.getName()); + } else return false; + } + + public static boolean mergeFuzzy(ILabel a, ILabel b) { + if (a instanceof LOreDict && b instanceof LItemStack) { + LOreDict lod = (LOreDict) a; + LItemStack lis = (LItemStack) b; + if (lod.getAmount() > 0) + return false; + return OreDictionary.getOres(lod.name).stream() + .map(Converter::from) + .anyMatch(i -> LItemStack.merge(i, lis)); } - return Optional.empty(); + return false; } public static List guess(List iss) { @@ -89,24 +99,24 @@ public class LOreDict extends ILabel.Impl { HashSet ids = new HashSet<>(); int amount = l.getAmount(); for (int i : OreDictionary.getOreIDs(((LItemStack) l).getRep())) - if (check(i, iss)) ids.add(i); - return ids.stream().map(i -> new LOreDict(OreDictionary.getOreName(i), amount)) - .collect(Collectors.toList()); + if (check(i, iss)) + ids.add(i); + return ids.stream().map(i -> new LOreDict(OreDictionary.getOreName(i), amount)).collect(Collectors.toList()); } // check labels in the list suitable for the ore id private static boolean check(int id, List labels) { ArrayList ores = OreDictionary.getOres(OreDictionary.getOreName(id)); - if (labels.size() == 1 && ores.size() == 1 - && (ores.get(0).getItemDamage() == OreDictionary.WILDCARD_VALUE || !MODE_FORCE)) + if (labels.size() == 1 && ores.size() == 1 && + (ores.get(0).getItemDamage() == OreDictionary.WILDCARD_VALUE || !MODE_FORCE)) return false; boolean acceptable = true; for (ItemStack ore : ores) { boolean found = false; for (ILabel label : labels) { - if (label instanceof LItemStack && OreDictionary.itemMatches( - ore, ((LItemStack) label).getRep(), false)) { + if (label instanceof LItemStack && + OreDictionary.itemMatches(ore, ((LItemStack) label).getRep(), false)) { found = true; break; } @@ -119,8 +129,8 @@ public class LOreDict extends ILabel.Impl { for (ILabel label : labels) { boolean found = false; for (ItemStack ore : ores) { - if (label instanceof LItemStack && OreDictionary.itemMatches( - ore, ((LItemStack) label).getRep(), false)) { + if (label instanceof LItemStack && + OreDictionary.itemMatches(ore, ((LItemStack) label).getRep(), false)) { found = true; break; } @@ -155,9 +165,11 @@ public class LOreDict extends ILabel.Impl { OreDictionary.getOres(name).forEach(is -> { if (is.getItemDamage() == OreDictionary.WILDCARD_VALUE) { is.getItem().getSubItems(is.getItem(), CreativeTabs.tabAllSearch, list); - } else list.add(is); + } else + list.add(is); }); - if(list.isEmpty()) return; + if (list.isEmpty()) + return; long index = System.currentTimeMillis() / 1500; //GlStateManager.pushMatrix(); //GlStateManager.translate(1, 1, 0); diff --git a/src/main/java/me/towdium/jecalculation/data/label/labels/LPlaceholder.java b/src/main/java/me/towdium/jecalculation/data/label/labels/LPlaceholder.java index a83b509..5a74765 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/labels/LPlaceholder.java +++ b/src/main/java/me/towdium/jecalculation/data/label/labels/LPlaceholder.java @@ -9,6 +9,7 @@ import me.towdium.jecalculation.gui.Resource; import me.towdium.jecalculation.utils.Utilities; import net.minecraft.nbt.NBTTagCompound; +import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; import java.util.List; import java.util.stream.Collectors; @@ -27,7 +28,8 @@ public class LPlaceholder extends ILabel.Impl { String name; public LPlaceholder(NBTTagCompound tag) { - this(tag.getString(KEY_NAME), tag.getInteger(KEY_AMOUNT)); + super(tag); + name = tag.getString(KEY_NAME); } public LPlaceholder(String name, int amount) { @@ -35,7 +37,7 @@ public class LPlaceholder extends ILabel.Impl { } public LPlaceholder(String name, int amount, boolean silent) { - super(amount); + super(amount, false); this.name = name; if (!silent) getRecord().push(new LPlaceholder(name, 1, true)); } @@ -82,6 +84,12 @@ public class LPlaceholder extends ILabel.Impl { return name.hashCode() ^ amount; } + @Nullable + @Override + public Object getRepresentation() { + return null; + } + @Override @SideOnly(Side.CLIENT) public String getDisplayName() { diff --git a/src/main/java/me/towdium/jecalculation/algorithm/CostList.java b/src/main/java/me/towdium/jecalculation/data/structure/CostList.java similarity index 57% rename from src/main/java/me/towdium/jecalculation/algorithm/CostList.java rename to src/main/java/me/towdium/jecalculation/data/structure/CostList.java index 85f8341..9f33840 100644 --- a/src/main/java/me/towdium/jecalculation/algorithm/CostList.java +++ b/src/main/java/me/towdium/jecalculation/data/structure/CostList.java @@ -1,15 +1,16 @@ -package me.towdium.jecalculation.algorithm; +package me.towdium.jecalculation.data.structure; import me.towdium.jecalculation.data.Controller; import me.towdium.jecalculation.data.label.ILabel; -import me.towdium.jecalculation.data.structure.Recipe; import me.towdium.jecalculation.utils.wrappers.Pair; import java.util.*; import java.util.stream.Collectors; +import static me.towdium.jecalculation.data.structure.Recipe.enumIoType.INPUT; import static me.towdium.jecalculation.data.structure.Recipe.enumIoType.OUTPUT; +// positive => generate; negative => require public class CostList { List labels; @@ -22,65 +23,61 @@ public class CostList { } public CostList(List labels) { - this.labels = labels.stream().map(i -> i.copy().multiply(-1)).collect(Collectors.toList()); + this.labels = labels.stream() + .filter(i -> i != ILabel.EMPTY) + .map(i -> i.copy().multiply(-1)) + .collect(Collectors.toList()); } public CostList(List positive, List negative) { - labels = positive.stream().map(ILabel::copy).collect(Collectors.toList()); - negative.forEach(i -> { - ILabel l = i.copy(); - labels.add(l.multiply(-1)); - }); + this(positive); + multiply(-1); + merge(new CostList(negative), false, true); } + public CostList(Recipe recipe) { this(Arrays.stream(recipe.getLabel(OUTPUT)).filter(i -> i != ILabel.EMPTY).collect(Collectors.toList()), - Arrays.stream(recipe.getLabel(Recipe.enumIoType.INPUT)).filter(i -> i != ILabel.EMPTY) - .collect(Collectors.toList())); + Arrays.stream(recipe.getLabel(INPUT)).filter(i -> i != ILabel.EMPTY).collect(Collectors.toList())); } @SuppressWarnings("UnusedReturnValue") - public CostList merge(CostList costList, boolean add, boolean strict) { - CostList ret = copy(); - costList.labels.forEach(i -> ret.labels.add(add ? i.copy() : i.copy().multiply(-1))); - ret.cancel(strict); - return ret; - } - - public void multiply(int i) { - labels = labels.stream().map(j -> j.multiply(i)).collect(Collectors.toList()); - } - - private void cancel(boolean strict) { - for (int i = 0; i < labels.size(); i++) { - for (int j = 0; j < labels.size(); j++) { - if (i == j) - continue; + public CostList merge(CostList costList, boolean strict, boolean inplace) { + CostList ret = inplace ? this : copy(); + costList.labels.forEach(i -> ret.labels.add(i.copy())); + for (int i = 0; i < ret.labels.size(); i++) { + for (int j = i + 1; j < ret.labels.size(); j++) { if (strict) { - ILabel a = labels.get(i); - ILabel b = labels.get(j); + ILabel a = ret.labels.get(i); + ILabel b = ret.labels.get(j); if (a.matches(b)) { - labels.set(i, a.setAmount(a.getAmount() + b.getAmount())); - labels.set(j, ILabel.EMPTY); + ret.labels.set(i, a.setAmount(a.getAmount() + b.getAmount())); + ret.labels.set(j, ILabel.EMPTY); } } else { - Optional l = ILabel.MERGER.merge(labels.get(i), labels.get(j), true); + Optional l = ILabel.MERGER.merge(ret.labels.get(i), ret.labels.get(j)); if (l.isPresent()) { - labels.set(i, l.get()); - labels.set(j, ILabel.EMPTY); + ret.labels.set(i, l.get()); + ret.labels.set(j, ILabel.EMPTY); } } } } - labels = labels.stream().filter(i -> i != ILabel.EMPTY).collect(Collectors.toList()); + ret.labels = ret.labels.stream().filter(i -> i != ILabel.EMPTY).collect(Collectors.toList()); + return ret; + } + + public CostList multiply(int i) { + labels = labels.stream().map(j -> j.multiply(i)).collect(Collectors.toList()); + return this; } @Override public boolean equals(Object obj) { if (obj instanceof CostList) { CostList c = (CostList) obj; - CostList m = c.copy(); - return m.merge(this, false, true).labels.isEmpty(); + CostList m = c.copy().multiply(-1); + return merge(m, true, false).labels.isEmpty(); } else return false; } @@ -126,7 +123,7 @@ public class CostList { CostList original = getCurrent(); CostList difference = new CostList(next.one); difference.multiply(next.two); - CostList result = original.merge(difference, true, false); + CostList result = original.merge(difference, false, false); if (set.contains(result)) next = find(false); else { @@ -146,9 +143,8 @@ public class CostList { ILabel label = labels.get(index); if (label.getAmount() >= 0) continue; - Optional recipe = Controller.getRecipe(label, OUTPUT); - if (recipe.isPresent()) - return new Pair<>(recipe.get(), recipe.get().multiplier(label, OUTPUT)); + Optional recipe = Controller.getRecipe(label); + if (recipe.isPresent()) return new Pair<>(recipe.get(), recipe.get().multiplier(label)); } return null; } @@ -178,5 +174,29 @@ public class CostList { return getCurrent().labels.stream().filter(i -> i.getAmount() < 0).map(i -> i.copy().multiply(-1)) .collect(Collectors.toList()); } + + public List getOutputs(List ignore) { + return getCurrent().labels.stream() + .map(i -> i.copy().multiply(-1)) + .map(i -> { + for (ILabel j : ignore) { + Optional merged = ILabel.MERGER.merge(i, j); + if (merged.isPresent()) i = merged.get(); + } + return i; + }) + .filter(i -> i != ILabel.EMPTY && i.getAmount() < 0) + .map(i -> i.multiply(-1)) + .collect(Collectors.toList()); + } + + public List getSteps() { + //noinspection OptionalGetWithoutIsPresent + List ret = procedure.stream() + .map(i -> i.two.labels.stream().filter(l -> l.getAmount() > 0).findFirst().get()) + .collect(Collectors.toList()); + Collections.reverse(ret); + return ret; + } } } diff --git a/src/main/java/me/towdium/jecalculation/data/structure/Recipe.java b/src/main/java/me/towdium/jecalculation/data/structure/Recipe.java index feda68d..434233b 100644 --- a/src/main/java/me/towdium/jecalculation/data/structure/Recipe.java +++ b/src/main/java/me/towdium/jecalculation/data/structure/Recipe.java @@ -105,15 +105,20 @@ public class Recipe { return ret; } - public boolean matches(ILabel label, enumIoType type) { - return Arrays.stream(getLabel(type)).anyMatch(i -> ILabel.MERGER.merge(label, i, true).isPresent()); + public boolean matches(ILabel label) { + return Arrays.stream(output).anyMatch(i -> ILabel.MERGER.merge(label, i).isPresent()); } - public int multiplier(ILabel label, enumIoType type) { - return Arrays.stream(getLabel(type)).filter(i -> ILabel.MERGER.merge(label, i, true).isPresent()).findAny() - .map(i -> (i.getAmount() + Math.abs(label.getAmount()) - 1) / i.getAmount()).orElse(0); + public int multiplier(ILabel label) { + return Arrays.stream(output).filter(i -> ILabel.MERGER.merge(label, i).isPresent()).findAny() + .map(i -> { + int amountA = label.getAmount(); + if (!label.isPercent()) amountA *= 100; + int amountB = i.getAmount(); + if (!i.isPercent()) amountB *= 100; + return (amountB + Math.abs(amountA) - 1) / amountB; + }).orElse(0); } - public enum enumIoType { INPUT, OUTPUT, CATALYST; diff --git a/src/main/java/me/towdium/jecalculation/data/structure/Recipes.java b/src/main/java/me/towdium/jecalculation/data/structure/Recipes.java index a6dbe10..1de00e5 100644 --- a/src/main/java/me/towdium/jecalculation/data/structure/Recipes.java +++ b/src/main/java/me/towdium/jecalculation/data/structure/Recipes.java @@ -95,10 +95,9 @@ public class Recipes { return flatStream(group).collect(Collectors.toCollection(ArrayList::new)); } - public Optional getRecipe(ILabel label, Recipe.enumIoType type) { - return flatStream().map(i -> i.one).filter(i -> i.matches(label, type)).findFirst(); + public Optional getRecipe(ILabel label) { + return flatStream().map(i -> i.one).filter(i -> i.matches(label)).findFirst(); } - public void forEach(BiConsumer> consumer) { records.forEach(consumer); } diff --git a/src/main/java/me/towdium/jecalculation/event/handlers/FMLBusEventHandler.java b/src/main/java/me/towdium/jecalculation/event/handlers/FMLBusEventHandler.java index 728a6de..bf0d62b 100644 --- a/src/main/java/me/towdium/jecalculation/event/handlers/FMLBusEventHandler.java +++ b/src/main/java/me/towdium/jecalculation/event/handlers/FMLBusEventHandler.java @@ -25,7 +25,7 @@ public class FMLBusEventHandler { public void onKey(InputEvent.KeyInputEvent event) { if (ClientHandler.keyOpenGui.isPressed()) { if (JustEnoughCalculation.side == JustEnoughCalculation.enumSide.CLIENT) - JecaGui.displayGui(new GuiCalculator()); + JecaGui.displayGui(true, true, new GuiCalculator()); else Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation("chat.server_mode")); } @@ -34,7 +34,7 @@ public class FMLBusEventHandler { @SubscribeEvent public void onLogout(PlayerEvent.PlayerLoggedOutEvent event) { JustEnoughCalculation.logger.info("on log out event"); - Controller.writeToLocal();; + Controller.writeToLocal(); LPlaceholder.onLogOut(); } } diff --git a/src/main/java/me/towdium/jecalculation/gui/JecaGui.java b/src/main/java/me/towdium/jecalculation/gui/JecaGui.java index 8db55e0..ab79b6e 100644 --- a/src/main/java/me/towdium/jecalculation/gui/JecaGui.java +++ b/src/main/java/me/towdium/jecalculation/gui/JecaGui.java @@ -5,7 +5,8 @@ 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.drawables.WContainer; +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; @@ -25,10 +26,7 @@ import org.lwjgl.input.Mouse; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; +import java.util.*; /** * Author: towdium @@ -43,14 +41,15 @@ public class JecaGui extends GuiContainer { public static final int COLOR_TEXT_WHITE = 0xFFFFFF; public static final boolean ALWAYS_TOOLTIP = false; public ILabel hand = ILabel.EMPTY; - public WContainer root; + protected static JecaGui last; protected JecaGui parent; + public IGui root; - public JecaGui(@Nullable JecaGui parent, WContainer root) { + public JecaGui(@Nullable JecaGui parent, IGui root) { this(parent, false, root); } - public JecaGui(@Nullable JecaGui parent, boolean acceptsTransfer, WContainer root) { + public JecaGui(@Nullable JecaGui parent, boolean acceptsTransfer, IGui root) { super(acceptsTransfer ? new ContainerTransfer() : new ContainerNonTransfer()); this.parent = parent; this.root = root; @@ -62,11 +61,11 @@ public class JecaGui extends GuiContainer { return xMouse > xPos && yMouse > yPos && xMouse <= xPos + xSize && yMouse <= yPos + ySize; } - public static void displayGui(WContainer root) { + public static void displayGui(IGui root) { displayGui(true, false, root); } - public static void displayGui(boolean updateParent, boolean acceptsTransfer, WContainer root) { + public static void displayGui(boolean updateParent, boolean acceptsTransfer, IGui root) { // isCallingFromMinecraftThread if (Minecraft.getMinecraft().func_152345_ab()) displayGuiUnsafe(updateParent, acceptsTransfer, root); @@ -86,25 +85,30 @@ public class JecaGui extends GuiContainer { - private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, WContainer root) { + private static void displayGuiUnsafe(boolean updateParent, boolean acceptsTransfer, IGui root) { Minecraft mc = Minecraft.getMinecraft(); JecaGui parent; if (mc.currentScreen == null) parent = null; else if (!(mc.currentScreen instanceof JecaGui)) - parent = getCurrent(); + parent = last; else if (updateParent) parent = (JecaGui) mc.currentScreen; else parent = ((JecaGui) mc.currentScreen).parent; JecaGui toShow = new JecaGui(parent, acceptsTransfer, root); + root.onVisible(toShow); + last = toShow; mc.displayGuiScreen(toShow); } public static void displayParent() { // isCallingFromMinecraftThread if (Minecraft.getMinecraft().func_152345_ab()) { - Minecraft.getMinecraft().displayGuiScreen(getCurrent().parent); + JecaGui gui = getCurrent().parent; + gui.root.onVisible(gui); + last = gui; + Minecraft.getMinecraft().displayGuiScreen(gui); } } @@ -389,7 +393,7 @@ public class JecaGui extends GuiContainer { } public void drawHoveringText(String text, int x, int y) { - super.drawHoveringText(Arrays.asList(text), x, y, fontRendererObj); + super.drawHoveringText(Collections.singletonList(text), x, y, fontRendererObj); } public void drawHoveringText(List textLines, int x, int y) { diff --git a/src/main/java/me/towdium/jecalculation/gui/Resource.java b/src/main/java/me/towdium/jecalculation/gui/Resource.java index 6196ea7..4ec4cde 100644 --- a/src/main/java/me/towdium/jecalculation/gui/Resource.java +++ b/src/main/java/me/towdium/jecalculation/gui/Resource.java @@ -141,10 +141,7 @@ public class Resource { public static final ResourceGroup ICN_CATALYST = new ResourceGroup(ICN_CATALYST_N, ICN_CATALYST_F); public static final ResourceGroup ICN_LIST = new ResourceGroup(ICN_LIST_N, ICN_LIST_F); public static final ResourceGroup ICN_LABEL = new ResourceGroup(ICN_LABEL_N, ICN_LABEL_F); - public static final ResourceGroup ICN_HELP = new ResourceGroup(ICN_HELP_N, ICN_HELP_F); - public static final ResourceGroup ICN_STACK = new ResourceGroup(ICN_STACK_N, ICN_STACK_F); public static final ResourceGroup ICN_TEXT = new ResourceGroup(ICN_TEXT_N, ICN_TEXT_F); - public static final ResourceGroup ICN_MULTI = new ResourceGroup(ICN_MULTI_N, ICN_MULTI_F); protected int xPos, yPos, xSize, ySize; protected ResourceLocation rl; diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java index 2dc4e7a..3e8df1b 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiCalculator.java @@ -2,16 +2,24 @@ package me.towdium.jecalculation.gui.guis; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.algorithm.CostList; +import me.towdium.jecalculation.data.Controller; +import me.towdium.jecalculation.data.label.ILabel; +import me.towdium.jecalculation.data.structure.CostList; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; -import me.towdium.jecalculation.gui.drawables.*; -import me.towdium.jecalculation.data.label.ILabel; -import me.towdium.jecalculation.data.Controller; +import me.towdium.jecalculation.gui.widgets.*; +import me.towdium.jecalculation.utils.ItemStackHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; import javax.annotation.ParametersAreNonnullByDefault; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Stream; /** * Author: towdium @@ -19,30 +27,30 @@ import java.util.List; */ @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) -public class GuiCalculator extends WContainer { +public class GuiCalculator extends WContainer implements IGui { enumMode mode = enumMode.INPUT; CostList.Calculator calculator = null; - WLabelGroup lgRecent = new WLabelGroup(7, 31, 8, 1, WLabel.enumMode.PICKER); - WLabel lLabel = new WLabel(31, 7, 20, 20, WLabel.enumMode.SELECTOR); - WLabelScroll lsResult = new WLabelScroll(7, 87, 8, 4, WLabel.enumMode.RESULT, true); - WButton btnSteps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST, "calculator.step") - .setLsnrLeft(() -> setMode(enumMode.STEPS)); - WButton btnCatalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "calculator.catalyst") - .setLsnrLeft(() -> setMode(enumMode.CATALYST)); - WButton btnOutput = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT, "calculator.output") - .setLsnrLeft(() -> setMode(enumMode.OUTPUT)); - WButton btnInput = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN, "calculator.input") + WLabelGroup recent = new WLabelGroup(7, 31, 8, 1, WLabel.enumMode.PICKER); + WLabel label = new WLabel(31, 7, 20, 20, WLabel.enumMode.SELECTOR); + WLabelScroll result = new WLabelScroll(7, 87, 8, 4, WLabel.enumMode.RESULT, true); + WButton input = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN, "calculator.input") .setLsnrLeft(() -> setMode(enumMode.INPUT)); - WTextField tfAmount = new WTextField(60, 7, 65); + WButton output = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT, "calculator.output") + .setLsnrLeft(() -> setMode(enumMode.OUTPUT)); + WButton catalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "calculator.catalyst") + .setLsnrLeft(() -> setMode(enumMode.CATALYST)); + WButton steps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST, "calculator.step") + .setLsnrLeft(() -> setMode(enumMode.STEPS)); + WTextField amount = new WTextField(60, 7, 65); public GuiCalculator() { - lLabel.setLsnrUpdate(() -> { - Controller.setRecent(lLabel.label); + label.setLsnrUpdate(() -> { + Controller.setRecent(label.label); refreshRecent(); refreshCalculator(); }); - lgRecent.setLsnrUpdate(l -> JecaGui.getCurrent().hand = lgRecent.getLabelAt(l)); - tfAmount.setLsnrText(s -> refreshCalculator()); + recent.setLsnrUpdate(l -> JecaGui.getCurrent().hand = recent.getLabelAt(l)); + amount.setLsnrText(s -> refreshCalculator()); add(new WHelp("calculator")); add(new WPanel()); add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL, "calculator.label") @@ -57,56 +65,73 @@ public class GuiCalculator extends WContainer { add(new WText(53, 13, JecaGui.Font.PLAIN, "x")); add(new WLine(55)); add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT, "calculator.history")); - addAll(lgRecent, lLabel, btnInput, btnOutput, btnCatalyst, btnSteps, lsResult, tfAmount); + addAll(recent, label, input, output, catalyst, steps, result, amount); refreshRecent(); setMode(enumMode.INPUT); + } + + @Override + public void onVisible(JecaGui gui) { refreshCalculator(); } void setMode(enumMode mode) { this.mode = mode; - btnInput.setDisabled(mode == enumMode.INPUT); - btnOutput.setDisabled(mode == enumMode.OUTPUT); - btnCatalyst.setDisabled(mode == enumMode.CATALYST); - btnSteps.setDisabled(mode == enumMode.STEPS); + input.setDisabled(mode == enumMode.INPUT); + output.setDisabled(mode == enumMode.OUTPUT); + catalyst.setDisabled(mode == enumMode.CATALYST); + steps.setDisabled(mode == enumMode.STEPS); refreshResult(); } void refreshRecent() { List recent = Controller.getRecent(); - if (!recent.isEmpty()) lLabel.setLabel(recent.get(0)); - if (recent.size() > 1) lgRecent.setLabel(recent.subList(1, recent.size()), 0); + if (!recent.isEmpty()) label.setLabel(recent.get(0)); + if (recent.size() > 1) this.recent.setLabel(recent.subList(1, recent.size()), 0); } void refreshCalculator() { try { - String s = tfAmount.getText(); - int i = s.isEmpty() ? 1 : Integer.parseInt(tfAmount.getText()); - tfAmount.setColor(JecaGui.COLOR_TEXT_WHITE); - calculator = new CostList(lLabel.getLabel().copy().setAmount(i)).calculate(); + String s = amount.getText(); + int i = s.isEmpty() ? 1 : Integer.parseInt(amount.getText()); + amount.setColor(JecaGui.COLOR_TEXT_WHITE); + List dest = Collections.singletonList(label.getLabel().copy().setAmount(i)); + calculator = new CostList(getInventory(), dest).calculate(); } catch (NumberFormatException e) { - tfAmount.setColor(JecaGui.COLOR_TEXT_RED); + amount.setColor(JecaGui.COLOR_TEXT_RED); calculator = null; } refreshResult(); } + List getInventory() { + InventoryPlayer inv = Minecraft.getMinecraft().thePlayer.inventory; + ArrayList labels = new ArrayList<>(); + Consumer> add = i -> i + .filter(j -> !ItemStackHelper.isEmpty(j)) + .forEach(j -> labels.add(ILabel.Converter.from(j))); + add.accept(Arrays.stream(inv.armorInventory)); + add.accept(Arrays.stream(inv.mainInventory)); + return labels; + } + + void refreshResult() { if (calculator == null) { - lsResult.setLabels(new ArrayList<>()); + result.setLabels(new ArrayList<>()); } else { switch (mode) { case INPUT: - lsResult.setLabels(calculator.getInputs()); + result.setLabels(calculator.getInputs()); break; case OUTPUT: - lsResult.setLabels(new ArrayList<>()); + result.setLabels(calculator.getOutputs(getInventory())); break; case CATALYST: - lsResult.setLabels(calculator.getCatalysts()); + result.setLabels(calculator.getCatalysts()); break; case STEPS: - lsResult.setLabels(new ArrayList<>()); + result.setLabels(calculator.getSteps()); break; } } diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiDisambiguation.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiDisambiguation.java index 2d537cb..c01c271 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiDisambiguation.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiDisambiguation.java @@ -2,9 +2,9 @@ package me.towdium.jecalculation.gui.guis; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.IWPicker; +import me.towdium.jecalculation.gui.guis.pickers.IPicker; import me.towdium.jecalculation.gui.Resource; -import me.towdium.jecalculation.gui.drawables.*; +import me.towdium.jecalculation.gui.widgets.*; import me.towdium.jecalculation.data.label.ILabel; import javax.annotation.ParametersAreNonnullByDefault; @@ -16,7 +16,7 @@ import java.util.List; */ @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) -public class GuiDisambiguation extends IWPicker.Impl { +public class GuiDisambiguation extends IPicker.Impl implements IGui { protected WLabelScroll lsUp; protected WLabelScroll lsDown; protected WSwitcher switcher; @@ -31,20 +31,17 @@ public class GuiDisambiguation extends IWPicker.Impl { add(new WPanel()); add(switcher); - add(new WIcon(149, 24, 20, 20, Resource.ICN_HELP, "disambiguation.help")); add(new WIcon(7, 48, 18, 54, Resource.ICN_LIST, "disambiguation.list")); add(new WIcon(7, 105, 18, 54, Resource.ICN_LABEL, "disambiguation.label")); add(new WSearch(i -> { - if (callback != null) callback.accept(i.copy().increaseAmount()); + if (callback != null) callback.accept(i.copy().multiply(-1)); }, tf, lsUp, lsDown)); setPage(0); } - protected void setPage(int n) { // TODO + protected void setPage(int n) { lsUp.setLabels(record.get(n)); lsDown.setLabels(ILabel.CONVERTER.guess(record.get(n))); - //lsUp.setLabels(record.get(n).stream().map(ILabel.CONVERTER_ITEM::toLabel).collect(Collectors.toList())); - //lsDown.setLabels(ILabel.CONVERTER_ITEM.toLabel(record.get(n))); } } diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/GuiLabel.java b/src/main/java/me/towdium/jecalculation/gui/guis/GuiLabel.java index af3ff60..ab4b52c 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiLabel.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiLabel.java @@ -6,10 +6,7 @@ import com.google.common.cache.LoadingCache; import com.google.common.cache.Weigher; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.IWidget; -import me.towdium.jecalculation.gui.drawables.WContainer; -import me.towdium.jecalculation.gui.drawables.WPage; -import me.towdium.jecalculation.gui.drawables.WPanel; +import me.towdium.jecalculation.gui.widgets.*; import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.utils.wrappers.Wrapper; @@ -22,7 +19,7 @@ import java.util.function.Consumer; */ @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) -public class GuiLabel extends WContainer { +public class GuiLabel extends WContainer implements IGui { WContainer container = new WContainer(); Consumer callback; LoadingCache cache = CacheBuilder.newBuilder().concurrencyLevel(1) @@ -43,7 +40,7 @@ public class GuiLabel extends WContainer { add(new WPage(i, r, false).setListener(() -> refresh(i))); index.value += 1; }); - add(new WPanel()); + addAll(new WHelp("label"), new WPanel()); add(container); refresh(0); } 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 4d7c8a6..5100594 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipe.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiRecipe.java @@ -1,13 +1,13 @@ package me.towdium.jecalculation.gui.guis; import codechicken.nei.recipe.IRecipeHandler; -import me.towdium.jecalculation.algorithm.CostList; +import me.towdium.jecalculation.data.structure.CostList; import me.towdium.jecalculation.data.Controller; import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.data.structure.Recipe; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; -import me.towdium.jecalculation.gui.drawables.*; +import me.towdium.jecalculation.gui.widgets.*; import me.towdium.jecalculation.nei.NEIPlugin; import me.towdium.jecalculation.utils.Utilities; import me.towdium.jecalculation.utils.wrappers.Pair; @@ -22,7 +22,7 @@ import java.util.stream.Stream; * Author: towdium * Date: 17-9-8. */ -public class GuiRecipe extends WContainer { +public class GuiRecipe extends WContainer implements IGui { Pair dest; HashMap> disambiguation = new HashMap<>(); WSwitcher switcherGroup = new WSwitcher(7, 7, 162, Controller.getGroups()); @@ -88,10 +88,12 @@ public class GuiRecipe extends WContainer { Recipe r = Controller.getRecipe(group, index); fromRecipe(r); switcherGroup.setIndex(Controller.getGroups().indexOf(group)); + buttonCopy.setDisabled(false); + buttonDel.setDisabled(false); } public GuiRecipe() { - add(new WPanel()); + addAll(new WHelp("recipe"), new WPanel()); add(new WIcon(7, 63, 21, 20, Resource.ICN_OUTPUT, "recipe.output")); add(new WIcon(7, 87, 21, 20, Resource.ICN_CATALYST, "recipe.catalyst")); add(new WIcon(7, 111, 21, 40, Resource.ICN_INPUT, "recipe.input")); @@ -151,8 +153,8 @@ public class GuiRecipe extends WContainer { dst.stream().filter(p -> { CostList cl = new CostList(list); if (p.three.equals(cl)) { - ILabel.MERGER.merge(p.one, ILabel.CONVERTER.first(list), true).ifPresent(i -> p.one = i); - p.two = p.two.merge(cl, true, true); + ILabel.MERGER.merge(p.one, ILabel.CONVERTER.first(list)).ifPresent(i -> p.one = i); + p.two = p.two.merge(cl, true, false); return true; } else return 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 9e5be5d..e32983b 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/GuiSearch.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/GuiSearch.java @@ -1,10 +1,10 @@ package me.towdium.jecalculation.gui.guis; -import me.towdium.jecalculation.data.structure.Recipe; import me.towdium.jecalculation.data.Controller; +import me.towdium.jecalculation.data.structure.Recipe; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; -import me.towdium.jecalculation.gui.drawables.*; +import me.towdium.jecalculation.gui.widgets.*; import me.towdium.jecalculation.utils.Utilities; import me.towdium.jecalculation.utils.wrappers.Triple; @@ -12,29 +12,39 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -public class GuiSearch extends WContainer { +public class GuiSearch extends WContainer implements IGui { List> content; WSwitcher switcherGroup; WLabelScroll labelScroll; public GuiSearch() { - ArrayList groups = new ArrayList<>(); - groups.add(Utilities.I18n.format("gui.search.all")); - groups.addAll(Controller.getGroups()); - switcherGroup = new WSwitcher(7, 7, 162, groups).setListener(this::refresh); labelScroll = new WLabelScroll(7, 51, 8, 6, WLabel.enumMode.PICKER, true); add(new WPanel()); - add(switcherGroup); - add(new WSearch(i -> content.stream().filter(j -> j.one.getRep() == i).findFirst().ifPresent(j -> - JecaGui.displayGui(false, true, new GuiRecipe(j.two, j.three))), new WTextField(25, 27, 90), labelScroll)); - add(new WIcon(149, 27, 20, 20, Resource.ICN_HELP, "search.help")); + add(new WSearch(i -> content.stream().filter(j -> j.one.getRep() == i).findFirst() + .ifPresent(j -> JecaGui.displayGui(true, true, new GuiRecipe(j.two, j.three))), + new WTextField(25, 27, 90), labelScroll)); add(new WIcon(7, 27, 20, 20, Resource.ICN_TEXT, "search.text")); - refresh(); } public void refresh() { int iGroup = switcherGroup.getIndex(); content = iGroup == 0 ? Controller.getRecipes() : Controller.getRecipes(switcherGroup.getText()); - labelScroll.setLabels(content.stream().map(i -> i.one.getRep()).collect(Collectors.toCollection(ArrayList::new))); + labelScroll + .setLabels(content.stream().map(i -> i.one.getRep()).collect(Collectors.toCollection(ArrayList::new))); + } + + @Override + public void onVisible(JecaGui gui) { + remove(switcherGroup); + ArrayList groups = new ArrayList<>(); + groups.add(Utilities.I18n.format("gui.search.all")); + groups.addAll(Controller.getGroups()); + int index = switcherGroup == null ? 0 : switcherGroup.getIndex(); + if (index >= groups.size()) + index = groups.size() - 1; + switcherGroup = new WSwitcher(7, 7, 162, groups).setListener(this::refresh); + switcherGroup.setIndex(index); + add(switcherGroup); + refresh(); } } diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/IGui.java b/src/main/java/me/towdium/jecalculation/gui/guis/IGui.java new file mode 100644 index 0000000..0e9a7d8 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/gui/guis/IGui.java @@ -0,0 +1,13 @@ +package me.towdium.jecalculation.gui.guis; + +import me.towdium.jecalculation.gui.JecaGui; +import me.towdium.jecalculation.gui.widgets.IContainer; + +/** + * Author: Towdium + * Date: 18-9-25 + */ +public interface IGui extends IContainer { + default void onVisible(JecaGui gui) { + } +} diff --git a/src/main/java/me/towdium/jecalculation/gui/IWPicker.java b/src/main/java/me/towdium/jecalculation/gui/guis/pickers/IPicker.java similarity index 60% rename from src/main/java/me/towdium/jecalculation/gui/IWPicker.java rename to src/main/java/me/towdium/jecalculation/gui/guis/pickers/IPicker.java index 66f1aeb..013cc04 100644 --- a/src/main/java/me/towdium/jecalculation/gui/IWPicker.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/pickers/IPicker.java @@ -1,10 +1,11 @@ -package me.towdium.jecalculation.gui; +package me.towdium.jecalculation.gui.guis.pickers; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.drawables.WContainer; +import me.towdium.jecalculation.gui.guis.IGui; +import me.towdium.jecalculation.gui.widgets.IWidget; +import me.towdium.jecalculation.gui.widgets.WContainer; import me.towdium.jecalculation.data.label.ILabel; -import me.towdium.jecalculation.utils.wrappers.Wrapper; import javax.annotation.ParametersAreNonnullByDefault; import java.util.function.Consumer; @@ -15,10 +16,10 @@ import java.util.function.Consumer; */ @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) -public interface IWPicker extends IWidget { - IWPicker setCallback(Consumer callback); +public interface IPicker extends IGui { + IPicker setCallback(Consumer callback); - class Impl extends WContainer implements IWPicker { + class Impl extends WContainer implements IPicker { protected Consumer callback; @Override diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerItemStack.java b/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerItemStack.java index 5c95985..89913ab 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerItemStack.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerItemStack.java @@ -4,11 +4,11 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.data.label.labels.LItemStack; -import me.towdium.jecalculation.gui.IWPicker; import me.towdium.jecalculation.gui.Resource; -import me.towdium.jecalculation.gui.drawables.WButton; -import me.towdium.jecalculation.gui.drawables.WButtonIcon; -import me.towdium.jecalculation.gui.drawables.WLabel; +import me.towdium.jecalculation.gui.guis.IGui; +import me.towdium.jecalculation.gui.widgets.WButton; +import me.towdium.jecalculation.gui.widgets.WButtonIcon; +import me.towdium.jecalculation.gui.widgets.WLabel; import javax.annotation.ParametersAreNonnullByDefault; import java.util.function.Consumer; @@ -19,7 +19,7 @@ import java.util.function.Consumer; */ @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) -public class PickerItemStack extends IWPicker.Impl { +public class PickerItemStack extends IPicker.Impl implements IGui { WLabel label = new WLabel(7, 7, 20, 20, WLabel.enumMode.SELECTOR).setLsnrUpdate(this::update); WButton bConfirm = new WButtonIcon(149, 7, 20, 20, Resource.BTN_YES).setLsnrLeft(() -> callback.accept(label.getLabel())); WButton bNbtF = new WButtonIcon(49, 7, 20, 20, Resource.BTN_NBT_F).setLsnrLeft(() -> setFNbt(false)); 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 423ed53..6e762b6 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 @@ -3,10 +3,10 @@ package me.towdium.jecalculation.gui.guis.pickers; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.data.label.labels.LPlaceholder; -import me.towdium.jecalculation.gui.IWPicker; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; -import me.towdium.jecalculation.gui.drawables.*; +import me.towdium.jecalculation.gui.guis.IGui; +import me.towdium.jecalculation.gui.widgets.*; import javax.annotation.ParametersAreNonnullByDefault; @@ -16,7 +16,7 @@ import javax.annotation.ParametersAreNonnullByDefault; */ @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) -public class PickerPlaceholder extends IWPicker.Impl { +public class PickerPlaceholder extends IPicker.Impl implements IGui { public PickerPlaceholder() { WLabelScroll scroll = new WLabelScroll(7, 69, 8, 5, WLabel.enumMode.PICKER, true) .setLabels(LPlaceholder.getRecent()); @@ -24,8 +24,6 @@ public class PickerPlaceholder extends IWPicker.Impl { WTextField create = new WTextField(26, 7, 69); create.setLsnrText(s -> create.setColor(s.equals("") ? JecaGui.COLOR_TEXT_RED : JecaGui.COLOR_TEXT_WHITE)); add(new WSearch(l -> callback.accept(l), search, scroll)); - add(new WIcon(149, 45, 20, 20, Resource.ICN_HELP, "picker_placeholder.help_search")); - add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP, "picker_placeholder.help_create")); add(new WIcon(7, 45, 20, 20, Resource.ICN_TEXT, "picker_placeholder.text_search")); add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT, "picker_placeholder.text_create")); add(new WLine(36)); 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 6bf1ab5..ecb4040 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 @@ -2,9 +2,9 @@ package me.towdium.jecalculation.gui.guis.pickers; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.IWPicker; import me.towdium.jecalculation.gui.Resource; -import me.towdium.jecalculation.gui.drawables.*; +import me.towdium.jecalculation.gui.guis.IGui; +import me.towdium.jecalculation.gui.widgets.*; import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.data.label.labels.LFluidStack; import me.towdium.jecalculation.data.label.labels.LOreDict; @@ -22,7 +22,7 @@ import java.util.stream.Collectors; */ @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) -public class PickerSimple extends IWPicker.Impl { +public class PickerSimple extends IPicker.Impl implements IGui { /** * @param labels label to be displayed for selection * @param l18nKey localization key for help string, @@ -32,15 +32,14 @@ public class PickerSimple extends IWPicker.Impl { WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, WLabel.enumMode.PICKER, true).setLabels(labels); WTextField tf = new WTextField(26, 7, 90); add(new WSearch(l -> callback.accept(l), tf, ls)); - add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP, l18nKey + ".help")); add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT, l18nKey + ".text")); } public static class FluidStack extends PickerSimple { public FluidStack() { - super(FluidRegistry.getRegisteredFluids().entrySet().stream() - .map(e -> new LFluidStack(1000, e.getValue())).collect(Collectors.toList()), + super(FluidRegistry.getRegisteredFluids().values().stream() + .map(fluid -> new LFluidStack(1000, fluid)).collect(Collectors.toList()), "picker_fluid_stack"); } } diff --git a/src/main/java/me/towdium/jecalculation/gui/widgets/IContainer.java b/src/main/java/me/towdium/jecalculation/gui/widgets/IContainer.java new file mode 100644 index 0000000..481b03f --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/IContainer.java @@ -0,0 +1,17 @@ +package me.towdium.jecalculation.gui.widgets; + +/** + * Author: Towdium + * Date: 18-9-25 + */ +public interface IContainer extends IWidget { + void add(IWidget w); + + void addAll(IWidget... w); + + void remove(IWidget w); + + void removeAll(IWidget... w); + + void clear(); +} diff --git a/src/main/java/me/towdium/jecalculation/gui/IWidget.java b/src/main/java/me/towdium/jecalculation/gui/widgets/IWidget.java similarity index 85% rename from src/main/java/me/towdium/jecalculation/gui/IWidget.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/IWidget.java index 79518b3..bed0f5c 100644 --- a/src/main/java/me/towdium/jecalculation/gui/IWidget.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/IWidget.java @@ -1,4 +1,6 @@ -package me.towdium.jecalculation.gui; +package me.towdium.jecalculation.gui.widgets; + +import me.towdium.jecalculation.gui.JecaGui; import java.util.List; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WButton.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WButton.java similarity index 98% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WButton.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WButton.java index f212030..09c46ca 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WButton.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WButton.java @@ -1,4 +1,4 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WButtonIcon.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WButtonIcon.java similarity index 97% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WButtonIcon.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WButtonIcon.java index ab85903..5e19118 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WButtonIcon.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WButtonIcon.java @@ -1,4 +1,4 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WButtonText.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WButtonText.java similarity index 92% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WButtonText.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WButtonText.java index 727fec9..ce1767a 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WButtonText.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WButtonText.java @@ -1,9 +1,8 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.gui.JecaGui; -import me.towdium.jecalculation.utils.Utilities; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WContainer.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WContainer.java similarity index 94% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WContainer.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WContainer.java index 805f79a..548fd35 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WContainer.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WContainer.java @@ -1,9 +1,8 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.gui.JecaGui; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.utils.Utilities; import javax.annotation.ParametersAreNonnullByDefault; @@ -16,7 +15,7 @@ import java.util.List; */ @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) -public class WContainer implements IWidget { +public class WContainer implements IContainer { protected List widgets = new ArrayList<>(); public void add(IWidget w) { diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WHelp.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WHelp.java similarity index 90% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WHelp.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WHelp.java index baf3dc3..2c58a0d 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WHelp.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WHelp.java @@ -1,6 +1,5 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; import me.towdium.jecalculation.utils.Utilities.I18n; @@ -31,7 +30,7 @@ public class WHelp extends WTooltip { @Override public boolean mouseIn(int xMouse, int yMouse) { - return JecaGui.mouseIn(-17, 0, 20, 20, xMouse, yMouse); + return JecaGui.mouseIn(-21, 0, 24, 24, xMouse, yMouse); } @Override @@ -50,6 +49,12 @@ public class WHelp extends WTooltip { addAll(new WPanel(), new Icon(), tTitle, tContent, sPage); } + @Override + public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) { + if (!super.onClicked(gui, xMouse, yMouse, button)) gui.root.remove(this); + return true; + } + public class Text implements IWidget { List> pages = new ArrayList<>(); int page; @@ -111,7 +116,7 @@ public class WHelp extends WTooltip { @Override public boolean mouseIn(int xMouse, int yMouse) { - return JecaGui.mouseIn(-17, 0, 20, 20, xMouse, yMouse); + return JecaGui.mouseIn(-21, 0, 24, 24, xMouse, yMouse); } @Override diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WIcon.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WIcon.java similarity index 97% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WIcon.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WIcon.java index ea4f62b..abfcc1d 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WIcon.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WIcon.java @@ -1,4 +1,4 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WLabel.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabel.java similarity index 77% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WLabel.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WLabel.java index 5d1b30a..0841a7f 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WLabel.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabel.java @@ -1,9 +1,10 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; +import codechicken.nei.recipe.GuiCraftingRecipe; +import codechicken.nei.recipe.GuiUsageRecipe; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.data.label.ILabel; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; import me.towdium.jecalculation.utils.IllegalPositionException; @@ -51,7 +52,7 @@ public class WLabel implements IWidget { gui.drawResourceContinuous(Resource.WGT_SLOT, xPos, yPos, xSize, ySize, 3, 3, 3, 3); label.drawLabel(gui, xPos + xSize / 2, yPos + ySize / 2, true); if (mode == enumMode.RESULT || mode == enumMode.EDITOR) { - String s = label.getAmountString(); + String s = label.getAmountString(mode == enumMode.RESULT); gui.drawText(xPos + xSize / 2.0f + 8 - HALF.getTextWidth(s), yPos + ySize / 2.0f + 8.5f - HALF.getTextHeight(), HALF, s); } @@ -60,12 +61,14 @@ public class WLabel implements IWidget { 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); } - if (mouseIn(xMouse, yMouse)) gui.drawRectangle(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF); + if (mouseIn(xMouse, yMouse)) + gui.drawRectangle(xPos + 1, yPos + 1, xSize - 2, ySize - 2, 0x80FFFFFF); } @Override public boolean onTooltip(JecaGui gui, int xMouse, int yMouse, List tooltip) { - if (!mouseIn(xMouse, yMouse)) return false; + if (!mouseIn(xMouse, yMouse)) + return false; if (label != ILabel.EMPTY) { tooltip.add(label.getDisplayName()); label.getToolTip(tooltip, mode == enumMode.EDITOR || mode == enumMode.RESULT); @@ -87,7 +90,8 @@ public class WLabel implements IWidget { @Override public boolean onClicked(JecaGui gui, int xMouse, int yMouse, int button) { - if (!mouseIn(xMouse, yMouse)) return false; + if (!mouseIn(xMouse, yMouse)) + return false; switch (mode) { case EDITOR: if (gui.hand != label.EMPTY) { @@ -98,14 +102,27 @@ public class WLabel implements IWidget { } else if (label != label.EMPTY) { gui.root.add(new WAmount()); return true; - } else return false; + } else + return false; case RESULT: + // open NEI + Object item = label.getRepresentation(); + if (item != null) { + if (button == 0) { + GuiCraftingRecipe.openRecipeGui("item", item); + return true; + } else if (button == 1) { + GuiUsageRecipe.openRecipeGui("item", item); + return true; + } + } return false; case PICKER: if (label != label.EMPTY) { notifyLsnr(); return true; - } else return false; + } else + return false; case SELECTOR: label = gui.hand; gui.hand = label.EMPTY; @@ -134,24 +151,13 @@ public class WLabel implements IWidget { public enum enumMode { - /** - * Slots in editor gui. Can use to edit amount. Exact amount displayed. - */ - EDITOR, - /** - * Slots to display calculate/getRecipes result. Rounded amount displayed. - */ - RESULT, - /** - * Slots that can pick items from. No amount displayed. - */ - PICKER, - /** - * Slots to put labels into. No amount displayed. - */ - SELECTOR + EDITOR, // Slots in editor gui. Can use to edit amount. Exact amount displayed. + RESULT, // Slots to display calculate/getRecipes result. Rounded amount displayed. + PICKER, // Slots that can pick items from. No amount displayed. + SELECTOR // Slots to put labels into. No amount displayed. } + class WAmount extends WContainer { WLabel wl = new WLabel(xPos, yPos, xSize, ySize, enumMode.SELECTOR).setLsnrUpdate(this::update); WTextField wtf = new WTextField(xPos + xSize + 10, yPos + ySize / 2 - WTextField.HEIGHT / 2, 50); @@ -160,8 +166,7 @@ public class WLabel implements IWidget { WButton bAmount = new WButtonText(xPos + xSize + 60, yPos, 20, 20, "general.to_percent", "#") .setLsnrLeft(() -> setPercent(true)); WButton bYes = new WButtonIcon(xPos + xSize + 83, yPos, 20, 20, Resource.BTN_YES).setLsnrLeft(() -> { - setLabel(wl.getLabel().setAmount( - wtf.getText().isEmpty() ? 0 : Integer.parseInt(wtf.getText()))); + setLabel(wl.getLabel().setAmount(wtf.getText().isEmpty() ? 0 : Integer.parseInt(wtf.getText()))); JecaGui.getCurrent().root.remove(this); }); WButton bNo = new WButtonIcon(xPos + xSize + 102, yPos, 20, 20, Resource.BTN_NO).setLsnrLeft(() -> { @@ -170,8 +175,10 @@ public class WLabel implements IWidget { }); public WAmount() { - wl.setLabel(getLabel()); - wtf.setText(Integer.toString(getLabel().getAmount())); + wl.setLabel(label); + add(new WPanel(xPos - 5, yPos - 5, xSize + 133, ySize + 10)); + add(new WText(xPos + xSize + 3, yPos + 5, JecaGui.Font.PLAIN, "x")); + addAll(wl, wtf, bYes, bNo); wtf.setLsnrText(i -> { try { Integer.parseInt(wtf.getText()); @@ -183,15 +190,13 @@ public class WLabel implements IWidget { bYes.setDisabled(!acceptable); } }); - add(new WPanel(xPos - 5, yPos - 5, xSize + 133, ySize + 10)); - add(new WText(xPos + xSize + 3, yPos + 5, JecaGui.Font.PLAIN, "x")); - addAll(wl, wtf, bYes, bNo); update(); } private void update() { - bYes.setDisabled(!wl.getLabel().acceptPercent()); - setPercent(false); + label = wl.getLabel(); + bAmount.setDisabled(!wl.label.acceptPercent()); + setPercent(label.isPercent()); } private void setPercent(boolean b) { @@ -202,16 +207,19 @@ public class WLabel implements IWidget { remove(bPercent); add(bAmount); } - wl.getLabel().setPercent(b); + wl.label.setPercent(b); + wtf.setText(Integer.toString(wl.label.getAmount())); } @Override public boolean onKey(JecaGui gui, char ch, int code) { - if (super.onKey(gui, ch, code)) return true; + if (super.onKey(gui, ch, code)) + return true; if (code == Keyboard.KEY_ESCAPE) { gui.root.remove(this); return true; - } else return false; + } else + return false; } } } diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WLabelGroup.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelGroup.java similarity index 82% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WLabelGroup.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WLabelGroup.java index 5981916..a403d59 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WLabelGroup.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelGroup.java @@ -1,8 +1,7 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.utils.wrappers.Wrapper; @@ -38,13 +37,6 @@ public class WLabelGroup extends WContainer { })); } - @Override - public void remove(IWidget w) { - super.remove(w); - if (w instanceof WLabel) - labels.remove(w); - } - public ILabel getLabelAt(int index) { return labels.get(index).getLabel(); } @@ -62,8 +54,7 @@ public class WLabelGroup extends WContainer { } public void setLabel(List labels, int start) { - Wrapper i = new Wrapper<>(start); // TODO simplify - this.labels.forEach(l -> l.setLabel(i.value < labels.size() ? labels.get(i.value++) : ILabel.EMPTY)); + for (WLabel label : this.labels) label.setLabel(start < labels.size() ? labels.get(start++) : ILabel.EMPTY); } public WLabelGroup setLsnrUpdate(Consumer listener) { diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WLabelScroll.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelScroll.java similarity index 94% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WLabelScroll.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WLabelScroll.java index a4fc571..b7bf7d9 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WLabelScroll.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WLabelScroll.java @@ -1,4 +1,4 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -74,7 +74,7 @@ public class WLabelScroll extends WContainer { public boolean setFilter(String str) { filter = str; - filtered = labels.stream().filter(l -> Utilities.contains(l.getDisplayName().toLowerCase(), str.toLowerCase())) + filtered = labels.stream().filter(l -> Utilities.I18n.contains(l.getDisplayName().toLowerCase(), str.toLowerCase())) .collect(Collectors.toList()); scroll.setCurrent(0); update(0); diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WLine.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WLine.java similarity index 86% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WLine.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WLine.java index 7218e6c..ecb0106 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WLine.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WLine.java @@ -1,8 +1,7 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WPage.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WPage.java similarity index 95% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WPage.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WPage.java index fa03575..84b4894 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WPage.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WPage.java @@ -1,10 +1,9 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.data.label.ILabel.RegistryEditor.Record; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; import me.towdium.jecalculation.utils.Utilities; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WPanel.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WPanel.java similarity index 93% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WPanel.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WPanel.java index ddba8f5..e36c0d0 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WPanel.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WPanel.java @@ -1,8 +1,7 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WRectangle.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WRectangle.java similarity index 88% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WRectangle.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WRectangle.java index 81a1d69..816a11f 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WRectangle.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WRectangle.java @@ -1,8 +1,7 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WScroll.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WScroll.java similarity index 95% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WScroll.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WScroll.java index 0361e23..51214b0 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WScroll.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WScroll.java @@ -1,8 +1,7 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.gui.Resource; import org.lwjgl.input.Mouse; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WSearch.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WSearch.java similarity index 90% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WSearch.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WSearch.java index af7209e..17c7825 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WSearch.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WSearch.java @@ -1,4 +1,4 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -6,8 +6,6 @@ import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.data.label.ILabel; import javax.annotation.ParametersAreNonnullByDefault; -import java.util.Arrays; -import java.util.List; import java.util.function.Consumer; /** diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WSwitcher.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WSwitcher.java similarity index 97% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WSwitcher.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WSwitcher.java index b7123ab..a8b9439 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WSwitcher.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WSwitcher.java @@ -1,4 +1,4 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -9,7 +9,6 @@ import me.towdium.jecalculation.utils.Utilities.Circulator; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; import java.util.List; -import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.IntStream; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WText.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WText.java similarity index 90% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WText.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WText.java index d38f4be..42b052c 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WText.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WText.java @@ -1,12 +1,10 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import javax.annotation.ParametersAreNonnullByDefault; -import java.util.function.Supplier; /** * Author: towdium diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WTextField.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WTextField.java similarity index 95% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WTextField.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WTextField.java index 4c6e87e..8a70cbd 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WTextField.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WTextField.java @@ -1,9 +1,8 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.gui.JecaGui; -import me.towdium.jecalculation.gui.IWidget; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiTextField; diff --git a/src/main/java/me/towdium/jecalculation/gui/drawables/WTooltip.java b/src/main/java/me/towdium/jecalculation/gui/widgets/WTooltip.java similarity index 94% rename from src/main/java/me/towdium/jecalculation/gui/drawables/WTooltip.java rename to src/main/java/me/towdium/jecalculation/gui/widgets/WTooltip.java index fc58875..03a469e 100644 --- a/src/main/java/me/towdium/jecalculation/gui/drawables/WTooltip.java +++ b/src/main/java/me/towdium/jecalculation/gui/widgets/WTooltip.java @@ -1,8 +1,7 @@ -package me.towdium.jecalculation.gui.drawables; +package me.towdium.jecalculation.gui.widgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import me.towdium.jecalculation.gui.IWidget; import me.towdium.jecalculation.gui.JecaGui; import me.towdium.jecalculation.utils.Utilities; diff --git a/src/main/java/me/towdium/jecalculation/utils/ItemStackHelper.java b/src/main/java/me/towdium/jecalculation/utils/ItemStackHelper.java index 408fe8e..917ca2d 100644 --- a/src/main/java/me/towdium/jecalculation/utils/ItemStackHelper.java +++ b/src/main/java/me/towdium/jecalculation/utils/ItemStackHelper.java @@ -127,6 +127,10 @@ public class ItemStackHelper { } + public static boolean isEmpty(ItemStack stack) { + return stack == null || stack == EMPTY_ITEM_STACK || stack.getItem() == EMPTY_ITEM; + } + public static boolean isTypeEqual(@Nullable ItemStack one, @Nullable ItemStack two) { return one != null && two != null && one.getItem() == two.getItem() && getMetadata(one) == getMetadata(two) && NBT.equalsIgnoreJEC(one.getTagCompound(), two.getTagCompound()); diff --git a/src/main/java/me/towdium/jecalculation/utils/Utilities.java b/src/main/java/me/towdium/jecalculation/utils/Utilities.java index fae1106..13f5929 100644 --- a/src/main/java/me/towdium/jecalculation/utils/Utilities.java +++ b/src/main/java/me/towdium/jecalculation/utils/Utilities.java @@ -82,31 +82,6 @@ public class Utilities { return NBTHelper.getOrCreateSubCompound(is, JustEnoughCalculation.Reference.MODID); } - public static boolean contains(String s1, String s2) { - return s1.contains(s2); - } - - // public static Recipes getRecipes(EntityPlayer player) { - // IExtendedEntityProperties properties = player - // .getExtendedProperties(JecaCapabilityProvider.PROPERTIES_NAME); - // if(properties instanceof JecaCapabilityProvider) { - // return ((JecaCapabilityProvider) properties).record; - // } else { - // JustEnoughCalculation.logger.info("getExtendedProperties error: " + properties.toString()); - // return new Recipes(); - // } - // } - - - // // get calculator item in player inventory - // public static Optional getStack() { - // InventoryPlayer inv = Minecraft.getMinecraft().thePlayer.inventory; - // ItemStack is = inv.getCurrentItem(); - // if (is.getItem() instanceof ItemCalculator) - // return Optional.of(is); - // return Optional.empty(); - // } - public static class Timer { long time = System.currentTimeMillis(); boolean running = false; @@ -202,27 +177,12 @@ public class Utilities { } } - public static class Relation { - HashMap, R> data = new HashMap<>(); - - public void add(T a, T b, R relation) { - data.put(a.hashCode() < b.hashCode() ? new Pair<>(a, b) : new Pair<>(b, a), relation); - } - - public Optional get(T a, T b) { - int ah = a.hashCode(); - int bh = b.hashCode(); - Wrapper ret = new Wrapper<>(null); - if (ah == bh) - ret.push(data.get(new Pair<>(a, b))).push(data.get(new Pair<>(b, a))); - else - ret.push(data.get(ah < bh ? new Pair<>(a, b) : new Pair<>(b, a))); - return Optional.ofNullable(ret.value); - } - } - @SideOnly(Side.CLIENT) public static class I18n { + public static boolean contains(String s1, String s2) { + return s1.contains(s2); + } + public static Pair search(String translateKey, Object... parameters) { Pair ret = new Pair<>(null, null); translateKey = "jecharacters." + translateKey; @@ -332,7 +292,7 @@ public class Utilities { } public static Locale getLocaleFromString(String languageCode) { - String parts[] = languageCode.split("_", -1); + String[] parts = languageCode.split("_", -1); if (parts.length == 1) return new Locale(parts[0]); else if (parts.length == 2 || (parts.length == 3 && parts[2].startsWith("#"))) diff --git a/src/main/java/me/towdium/jecalculation/utils/wrappers/Wrapper.java b/src/main/java/me/towdium/jecalculation/utils/wrappers/Wrapper.java index 0f1539a..1e84be2 100644 --- a/src/main/java/me/towdium/jecalculation/utils/wrappers/Wrapper.java +++ b/src/main/java/me/towdium/jecalculation/utils/wrappers/Wrapper.java @@ -1,8 +1,10 @@ package me.towdium.jecalculation.utils.wrappers; import javax.annotation.Nullable; +import java.util.Optional; import java.util.function.Consumer; import java.util.function.Predicate; +import java.util.function.Supplier; /** * Author: Towdium @@ -22,6 +24,15 @@ public class Wrapper { return this; } + public Wrapper or(Supplier s) { + if (value == null) value = s.get(); + return this; + } + + public Optional toOptional() { + return Optional.ofNullable(value); + } + public Wrapper ifPresent(Consumer c) { if (value != null) c.accept(value); diff --git a/src/main/resources/assets/jecalculation/lang/en_US.lang b/src/main/resources/assets/jecalculation/lang/en_US.lang index 3eaf941..f6b686c 100644 --- a/src/main/resources/assets/jecalculation/lang/en_US.lang +++ b/src/main/resources/assets/jecalculation/lang/en_US.lang @@ -1,10 +1,9 @@ -jecharacters.command.common.not_found=Invalid option: %s -jecharacters.command.common.unexpected_arg=Unexpected arg: %s jecharacters.command.help.list=Here is the list of all commands available: jecharacters.command.state.desc=The mod is working on state: %s +jecharacters.command.reload.done=Reloading finished jecharacters.chat.server_mode=The mod is not working in client mode. Key binding will not work. jecharacters.gui.calculator.recipe.active=New recipe -jecharacters.gui.calculator.help=Welcome to the main interface of the mod. The first thing suggested to do is to use the two button at upper right to input the recipes, which allows you to create and edit recipes. All the calculation requires recipes to be recorded.\fTo calculate the cost of item, simply pick an item from JEI item list then put to the slot at upper left of the interface with all the recipes used recorded. The result will then be displayed in lower slots in the interface. The four button provide options to display input, output, catalyst and crafting steps.\fThe button in upper left allows you to to edit and get a lable. Labels are very important part of the mod. They are basiclly things can be put into a slot, including ItemStack, FluidStack, OreDict entry, or simply a placeholder. Lables are used in the calculation process. Most of time they are quite clever as long as you config them properly. +jecharacters.gui.calculator.help=Welcome to the main interface of the mod. The first thing suggested to do is to use the two button at upper right to input the recipes, which allows you to create and edit recipes. All the calculation requires recipes to be recorded.\fTo calculate the cost of item, simply pick an item from JEI item list then put to the slot at upper left of the interface with all the recipes to use recorded. The result will then be displayed in lower slots in the interface. The four button provide options to display input, output, catalyst and crafting steps.\fThe button in upper left allows you to to edit and get a lable. Labels are very important part of the mod. They are basiclly things can be put into a slot, including ItemStack, FluidStack, OreDict entry, or simply a placeholder. Lables are used in the calculation process. Most of time they are quite clever as long as you config them properly. jecharacters.gui.calculator.title=Crafting Calculator jecharacters.gui.recipe.save.active=Save jecharacters.gui.recipe.copy.active=Save as new recipe @@ -16,13 +15,18 @@ jecharacters.gui.recipe.disamb.disabled=Disambiguate settings not available\nbec jecharacters.gui.recipe.new.active=New group jecharacters.gui.recipe.cancel.active=Cancel jecharacters.gui.recipe.confirm.active=Confirm +jecharacters.gui.recipe.title=Recipe Editing +jecharacters.gui.recipe.help=This interface allows you to create or edit recipes. To create one recipe, you can pick items from JEI item list, then put into slots. When finished, simply click save button. You can also fast transer recipes from JEI by clicking "+" when openning recipe view.\fTo edit one label, you can simply click it, then a toolbar will pop up to help you, where you can switch between amount and percentage mode, type the amount, or remove the label. In addition, you can use mouse scroll to quickly change the amount. Clicking "Clear" button will remove all the labels.\fUsing recipe fast transfer, some labels will automatically setup for you, like oreDict labels. If you do not want this behavoir, simply use "Disambiguous" button to select manually. You can also add labels by ckicking "Add label" button. By the way, normally you shouldn't put fuzzy labels as output.\fYou can easily manage recipes using groups. Click "New group" button, type the group name and hit the tick, you are done. The new group name will show in the top bar. If you already have groups set up and you want to use an existing one, you can use arrows to select between them.\fWhen you are editing an existing recipe, you will have two extra buttons, "Save as" and "Delete". "Save as" allows you to save the current recipe as a new recipe, without changing the existing one. "Delete" simply allows you to delete the recipe. +jecharacters.gui.label.title=Label Editing +jecharacters.gui.label.help=This interface allows you to create labels. This mod provides 4 types of labels: fluid, oreDict, placeholder and item. To create fluid and oreDict label, you can just search and pick. Item labels represent an item stack, but with fuzzy options for meta, nbt and capalibity.\fAs is indicated by name, Placeholder labels do not hold any content. It is just a string to connect recipes. You can use it for anything, like structure or event energy. To create one, simply type in the name, then hit the tick. You can also search and pick existing ones. jecharacters.gui.search.all=All jecharacters.gui.search.input=Input jecharacters.gui.search.output=Output jecharacters.gui.search.catalyst=Catalyst -jecharacters.gui.common.label.ore_dict=OreDict -jecharacters.gui.common.label.fluid_stack=Fluid +jecharacters.gui.common.label.ore=OreDict +jecharacters.gui.common.label.fluid=Fluid jecharacters.gui.common.label.placeholder=Placeholder +jecharacters.gui.common.label.item=Item jecharacters.config.force_client=Force Client jecharacters.label.ore_dict.name=Ore: %s jecharacters.label.placeholder.name=Placeholder: %s