mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-14 01:04:06 +00:00
feat: gui recipe
This commit is contained in:
1 parent
cce76168c0
commit
8ee76a5f8a
58 files changed
+925
-486
No files matched your search
@@ -5,13 +5,10 @@ import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import cpw.mods.fml.common.network.NetworkCheckHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.command.JecaCommand;
|
||||
import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.network.IProxy;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package me.towdium.jecalculation.algorithm;
|
||||
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CostList {
|
||||
ArrayList<ILabel> labels;
|
||||
|
||||
public CostList() {
|
||||
labels = new ArrayList<>();
|
||||
}
|
||||
|
||||
public CostList(List<ILabel> labels) {
|
||||
this.labels = new ArrayList<>(labels);
|
||||
}
|
||||
|
||||
public CostList(List<ILabel> positive, List<ILabel> negative) {
|
||||
labels = new ArrayList<>(positive);
|
||||
negative.forEach(i -> {
|
||||
ILabel l = i.copy();
|
||||
labels.add(l.invertAmount());
|
||||
});
|
||||
}
|
||||
|
||||
public CostList merge(CostList costList, boolean add) {
|
||||
costList.labels.forEach(i -> labels.add(add ? i.copy() : i.copy().invertAmount()));
|
||||
return cancel();
|
||||
}
|
||||
|
||||
private CostList cancel() {
|
||||
ArrayList<ILabel> cancelled = new ArrayList<>();
|
||||
for (int i = 0; i < labels.size(); i++) {
|
||||
for (int j = i + 1; j < labels.size(); j++) {
|
||||
Optional<Pair<ILabel, ILabel>> l = ILabel.MERGER.merge(labels.get(i), labels.get(j), true);
|
||||
if (l.isPresent()) {
|
||||
labels.set(i, l.get().one);
|
||||
labels.set(j, ILabel.EMPTY);
|
||||
cancelled.add(l.get().two);
|
||||
}
|
||||
}
|
||||
}
|
||||
labels = labels.stream().filter(i -> i != ILabel.EMPTY).collect(Collectors.toCollection(ArrayList::new));
|
||||
return new CostList(cancelled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof CostList) {
|
||||
CostList c = (CostList) obj;
|
||||
CostList m = c.copy();
|
||||
m.merge(this, false);
|
||||
return m.labels.isEmpty();
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public CostList copy() {
|
||||
CostList ret = new CostList();
|
||||
ret.labels = labels.stream().map(ILabel::copy).collect(Collectors.toCollection(ArrayList::new));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return labels.isEmpty();
|
||||
}
|
||||
|
||||
public ArrayList<ILabel> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package me.towdium.jecalculation.client.gui.guis;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.data.structure.User;
|
||||
import me.towdium.jecalculation.event.handlers.ControllerClient;
|
||||
import me.towdium.jecalculation.item.ItemCalculator;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static me.towdium.jecalculation.client.gui.drawables.WLabel.enumMode.*;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/14/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiCalculator extends WContainer {
|
||||
WLabelGroup wRecent = new WLabelGroup(7, 31, 8, 1, PICKER);
|
||||
User.Recent recent;
|
||||
|
||||
|
||||
public GuiCalculator() {
|
||||
add(new WPanel());
|
||||
add(new WTextField(61, 7, 64));
|
||||
add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "calculator.label")
|
||||
.setListenerLeft(() -> JecGui.displayGui(new GuiLabel(l -> {
|
||||
JecGui.displayParent();
|
||||
JecGui.getCurrent().hand = l;
|
||||
}))));
|
||||
add(new WButtonIcon(130, 7, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "calculator.recipe")
|
||||
.setListenerLeft(() -> JecGui.displayGui(true, true, new GuiRecipe())));
|
||||
add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH_N, Resource.BTN_SEARCH_F, "calculator.search"));
|
||||
add(new WLabelGroup(7, 87, 9, 4, RESULT));
|
||||
add(wRecent);
|
||||
add(new WLabel(31, 7, 20, 20, SELECTOR).setLsnrUpdate(this::setRecent));
|
||||
add(new WLine(52));
|
||||
add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT_N, Resource.ICN_RECENT_F, "calculator.history"));
|
||||
add(new WSwitcher(7, 56, 162, 5));
|
||||
Optional<ItemStack> ois = getStack();
|
||||
recent = ois.map(is -> new User.Recent(Utilities.getTag(is).getTagList(User.Recent.IDENTIFIER, 9)))
|
||||
.orElseGet(ControllerClient::getRecent);
|
||||
}
|
||||
|
||||
void setRecent(ILabel label) {
|
||||
recent.push(label);
|
||||
Optional<ItemStack> ois = getStack();
|
||||
ois.ifPresent(is -> Utilities.getTag(is).setTag(User.Recent.IDENTIFIER, recent.serialize()));
|
||||
wRecent.setLabel(recent.getRecords().subList(1, recent.getRecords().size()), 0);
|
||||
}
|
||||
|
||||
Optional<ItemStack> getStack() {
|
||||
ItemStack is = Minecraft.getMinecraft().thePlayer.inventory.getCurrentItem();
|
||||
return Optional.ofNullable(is.getItem() instanceof ItemCalculator ? is : null);
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package me.towdium.jecalculation.client.gui.guis;
|
||||
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static me.towdium.jecalculation.client.gui.drawables.WLabel.enumMode.EDITOR;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-8.
|
||||
*/
|
||||
public class GuiRecipe extends WContainer {
|
||||
List<List<ItemStack>> disambiguation;
|
||||
WButton buttonSave = new WButtonIcon(26, 33, 20, 20, Resource.BTN_SAVE_N, Resource.BTN_SAVE_F, "recipe.save");
|
||||
WButton buttonCopy = new WButtonIcon(83, 33, 20, 20, Resource.BTN_COPY_N, Resource.BTN_COPY_F, Resource.BTN_COPY_D,
|
||||
"recipe.copy").setDisabled(true);
|
||||
WButton buttonDel = new WButtonIcon(64, 33, 20, 20, Resource.BTN_DEL_N, Resource.BTN_DEL_F, "recipe.clear");
|
||||
WButton buttonLabel = new WButtonIcon(45, 33, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "recipe.label")
|
||||
.setListenerLeft(() -> JecGui.displayGui(new GuiLabel((l) -> {
|
||||
JecGui.displayParent();
|
||||
JecGui.getCurrent().hand = l;
|
||||
})));
|
||||
WButton buttonDisamb = new WButtonIcon(102, 33, 20, 20, Resource.BTN_DISAMB_N,
|
||||
Resource.BTN_DISAMB_F, Resource.BTN_DISAMB_D, "recipe.disamb").setDisabled(true).setListenerLeft(() -> {
|
||||
if (disambiguation != null) JecGui.displayGui(new GuiDisambiguation(disambiguation).setCallback(l -> {
|
||||
JecGui.displayParent();
|
||||
JecGui.getCurrent().hand = l;
|
||||
}));
|
||||
});
|
||||
WButton buttonYes = new WButtonIcon(7, 33, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F, "recipe.confirm");
|
||||
WButton buttonNo = new WButtonIcon(26, 33, 20, 20, Resource.BTN_NO_N, Resource.BTN_NO_F, "recipe.abort");
|
||||
WLabelGroup groupInput = new WLabelGroup(28, 111, 7, 2, 20, 20, EDITOR);
|
||||
WLabelGroup groupCatalyst = new WLabelGroup(28, 87, 7, 1, 20, 20, EDITOR);
|
||||
WLabelGroup groupOutput = new WLabelGroup(28, 63, 7, 1, 20, 20, EDITOR);
|
||||
WTextField textField = new WTextField(49, 33, 119);
|
||||
WButton buttonNew = new WButtonIcon(7, 33, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "recipe.new")
|
||||
.setListenerLeft(() -> setModeNewGroup(true));
|
||||
|
||||
public GuiRecipe() {
|
||||
add(new WPanel());
|
||||
add(new WSwitcher(7, 7, 162, 1));
|
||||
add(new WIcon(7, 63, 21, 20, Resource.ICN_OUTPUT_N, Resource.ICN_OUTPUT_F, "recipe.output"));
|
||||
add(new WIcon(7, 87, 21, 20, Resource.ICN_CATALYST_N, Resource.ICN_CATALYST_F, "recipe.catalyst"));
|
||||
add(new WIcon(7, 111, 21, 40, Resource.ICN_INPUT_N, Resource.ICN_INPUT_F, "recipe.input"));
|
||||
add(new WLine(57));
|
||||
addAll(groupInput, groupCatalyst, groupOutput);
|
||||
setModeNewGroup(false);
|
||||
}
|
||||
|
||||
public void setModeNewGroup(boolean b) {
|
||||
if (b) {
|
||||
removeAll(buttonNew, buttonLabel, buttonDel, buttonCopy, buttonSave, buttonDisamb);
|
||||
addAll(buttonYes, buttonNo, textField);
|
||||
} else {
|
||||
addAll(buttonNew, buttonLabel, buttonDel, buttonCopy, buttonSave, buttonDisamb);
|
||||
removeAll(buttonYes, buttonNo, textField);
|
||||
}
|
||||
}
|
||||
|
||||
public void transfer(IRecipeHandler recipe, int recipeIndex) {
|
||||
ArrayList<List<ItemStack>> buf = new ArrayList<>();
|
||||
ArrayList<ILabel> input = new ArrayList<>();
|
||||
ArrayList<ILabel> output = new ArrayList<>();
|
||||
|
||||
BiConsumer<ArrayList<ILabel>, ILabel> merge = (list, label) -> IntStream.range(0, list.size()).filter(i -> {
|
||||
Optional<ILabel> l = ILabel.MERGER.merge(list.get(i), label, true);
|
||||
boolean ret = l.isPresent();
|
||||
if (ret) list.set(i, l.get());
|
||||
return ret;
|
||||
}).findAny().orElseGet(() -> {
|
||||
list.add(label);
|
||||
return -1;
|
||||
});
|
||||
|
||||
|
||||
List<ILabel> raw = new ArrayList<>();
|
||||
|
||||
// input
|
||||
List<ItemStack> itemStacks = recipe.getIngredientStacks(recipeIndex).stream()
|
||||
.map((positionedStack) -> positionedStack.item).collect(Collectors.toList());
|
||||
|
||||
itemStacks.forEach((itemStack) -> {
|
||||
raw.add(ILabel.CONVERTER_ITEM.toLabel(itemStack));
|
||||
});
|
||||
List<ILabel> guessed = ILabel.CONVERTER_ITEM.toLabel(itemStacks);
|
||||
merge.accept(input, guessed.isEmpty() ? ILabel.CONVERTER_ITEM.toLabel(itemStacks.get(0)) : guessed.get(0));
|
||||
|
||||
buf.add(itemStacks);
|
||||
|
||||
// output
|
||||
ItemStack outputStack = recipe.getResultStack(recipeIndex).item;
|
||||
merge.accept(output, ILabel.CONVERTER_ITEM.toLabel(outputStack));
|
||||
buf.add(Collections.singletonList(outputStack));
|
||||
|
||||
groupInput.setLabel(input, 0);
|
||||
groupOutput.setLabel(output, 0);
|
||||
disambiguation = buf;
|
||||
buttonDisamb.setDisabled(buf.isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.towdium.jecalculation.command;
|
||||
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import me.towdium.jecalculation.utils.wrappers.Wrapper;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
@@ -64,7 +64,7 @@ public class JecaCommand extends CommandBase {
|
||||
if (args.length == 1) {
|
||||
return getListOfStringsFromIterableMatchingLastWord(args, Commands.commands.keySet());
|
||||
} else {
|
||||
Single<ISubCommand> sub = new Single<>(null);
|
||||
Wrapper<ISubCommand> sub = new Wrapper<>(null);
|
||||
Commands.commands.values().stream().filter(c -> c.getName().equals(cmd))
|
||||
.findFirst().ifPresent(sub::push);
|
||||
return sub.value != null ? sub.value.getTabCompletions(sender, cut(args))
|
||||
|
||||
@@ -2,10 +2,10 @@ package me.towdium.jecalculation.data.label;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWPicker;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.guis.pickers.PickerSimple;
|
||||
import me.towdium.jecalculation.client.gui.guis.pickers.PickerUniversal;
|
||||
import me.towdium.jecalculation.gui.IWPicker;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.guis.pickers.PickerSimple;
|
||||
import me.towdium.jecalculation.gui.guis.pickers.PickerUniversal;
|
||||
import me.towdium.jecalculation.data.label.labels.LFluidStack;
|
||||
import me.towdium.jecalculation.data.label.labels.LItemStack;
|
||||
import me.towdium.jecalculation.data.label.labels.LOreDict;
|
||||
@@ -14,10 +14,13 @@ import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.ItemStackHelper;
|
||||
import me.towdium.jecalculation.utils.Utilities.Relation;
|
||||
import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
@@ -30,10 +33,9 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface ILabel {
|
||||
RegistryMerger MERGER = new RegistryMerger();
|
||||
RegistrySerializer DESERIALIZER = new RegistrySerializer();
|
||||
RegistryConverterItem CONVERTER_ITEM = new RegistryConverterItem();
|
||||
RegistryConverterFluid CONVERTER_FLUID = new RegistryConverterFluid();
|
||||
Merger MERGER = new Merger();
|
||||
Serializer DESERIALIZER = new Serializer();
|
||||
Converter CONVERTER = new Converter();
|
||||
RegistryEditor EDITOR = new RegistryEditor();
|
||||
ILabel EMPTY = new LItemStack(ItemStackHelper.EMPTY_ITEM_STACK, 0);
|
||||
|
||||
@@ -49,6 +51,8 @@ public interface ILabel {
|
||||
|
||||
ILabel decreaseAmountLarge();
|
||||
|
||||
ILabel invertAmount();
|
||||
|
||||
String getAmountString();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -68,12 +72,12 @@ public interface ILabel {
|
||||
NBTTagCompound toNBTTagCompound();
|
||||
|
||||
static void initClient() {
|
||||
CONVERTER_ITEM.register(LOreDict::guess);
|
||||
CONVERTER.register(LOreDict::guess);
|
||||
EDITOR.register(PickerSimple.FluidStack::new, "fluid_stack", new LFluidStack(FluidRegistry.WATER, 1000));
|
||||
EDITOR.register(PickerSimple.OreDict::new, "ore_dict", new LOreDict("ingotIron"));
|
||||
EDITOR.register(PickerUniversal::new, "string", new LString("example", 1));
|
||||
MERGER.register("itemStack", "itemStack", ILabel.RegistryMerger::mergeItemStackNItemStack);
|
||||
MERGER.register("oreDict", "oreDict", ILabel.RegistryMerger::mergeOreDictNOreDict);
|
||||
MERGER.register("itemStack", "itemStack", Merger::mergeItemStackNItemStack);
|
||||
MERGER.register("oreDict", "oreDict", Merger::mergeOreDictNOreDict);
|
||||
}
|
||||
|
||||
String getIdentifier();
|
||||
@@ -94,13 +98,13 @@ public interface ILabel {
|
||||
* {@link ILabel label(s)}.
|
||||
* It uses singleton mode. First registerGuess merge functions, then use
|
||||
* {@link #merge(ILabel, ILabel, boolean)} to operate the {@link ILabel}.
|
||||
* For registering, see {@link RegistrySerializer}.
|
||||
* For registering, see {@link Serializer}.
|
||||
*/
|
||||
class RegistryMerger {
|
||||
class Merger {
|
||||
private Relation<String, MergerFunction> functions = new Relation<>();
|
||||
|
||||
|
||||
private RegistryMerger() {
|
||||
private Merger() {
|
||||
}
|
||||
|
||||
public void register(String a, String b, MergerFunction func) {
|
||||
@@ -108,7 +112,7 @@ public interface ILabel {
|
||||
}
|
||||
|
||||
static Optional<ILabel> mergeItemStackNItemStack(ILabel a, ILabel b, boolean add) {
|
||||
if (a instanceof LItemStack && b instanceof LItemStack) {
|
||||
if (a instanceof LItemStack && b instanceof LItemStack && a != ILabel.EMPTY && b != ILabel.EMPTY) {
|
||||
LItemStack lisA = (LItemStack) a;
|
||||
LItemStack lisB = (LItemStack) b;
|
||||
ItemStack isA = lisA.getItemStack();
|
||||
@@ -118,7 +122,7 @@ public interface ILabel {
|
||||
isA.getTagCompound().equals(isB.getTagCompound()))) {
|
||||
LItemStack ret = new LItemStack(lisA.getItemStack(),
|
||||
add ? lisA.getAmount() + lisB.getAmount() : lisA.getAmount() - lisB.getAmount());
|
||||
return Optional.of(ret);
|
||||
return Optional.of(ret.getAmount() == 0 ? ILabel.EMPTY : ret);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
@@ -135,22 +139,22 @@ public interface ILabel {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<ILabel> merge(ILabel a, ILabel b, boolean add) {
|
||||
public Optional<Pair<ILabel, ILabel>> merge(ILabel a, ILabel b, boolean add) {
|
||||
Optional<ILabel> ret = functions.get(a.getIdentifier(), b.getIdentifier())
|
||||
.orElse((x, y, f) -> Optional.empty()).merge(a, b, add);
|
||||
if (ret.isPresent() && (ret.get() == a || ret.get() == b))
|
||||
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;
|
||||
return ret.map(i -> new Pair<>(i, add ? b.copy().invertAmount() : b.copy()));
|
||||
}
|
||||
|
||||
|
||||
@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 merged {@link ILabel label(s)} if not changed (no matter order), they cannot merge.
|
||||
* @return an optional {@link Pair pair} of {@link ILabel label(s)}.
|
||||
* If empty, the labels cannot merge, otherwise returns difference and common elements
|
||||
*/
|
||||
Optional<ILabel> merge(ILabel a, ILabel b, boolean add);
|
||||
}
|
||||
@@ -159,15 +163,15 @@ public interface ILabel {
|
||||
/**
|
||||
* This class is used to registerGuess an {@link ILabel} type.
|
||||
* Here you can find the identifier and deserializer of one type.
|
||||
* For {@link ILabel} operations, see {@link RegistryMerger}
|
||||
* For {@link ILabel} operations, see {@link Merger}
|
||||
*/
|
||||
class RegistrySerializer {
|
||||
class Serializer {
|
||||
public static final String KEY_IDENTIFIER = "identifier";
|
||||
public static final String KEY_CONTENT = "content";
|
||||
|
||||
private HashMap<String, Function<NBTTagCompound, ILabel>> idToData = new HashMap<>();
|
||||
|
||||
private RegistrySerializer() {
|
||||
private Serializer() {
|
||||
}
|
||||
|
||||
public void register(String identifier, Function<NBTTagCompound, ILabel> deserializer) {
|
||||
@@ -202,50 +206,28 @@ public interface ILabel {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class RegistryConverter<T> {
|
||||
List<Function<List<T>, List<ILabel>>> handlers = new ArrayList<>();
|
||||
class Converter {
|
||||
ArrayList<Function<List<ILabel>, List<ILabel>>> handlers = new ArrayList<>();
|
||||
|
||||
private RegistryConverter() {
|
||||
public static ILabel from(@Nullable Object o) {
|
||||
if (o == null) return ILabel.EMPTY;
|
||||
else if (o instanceof ItemStack) return new LItemStack((ItemStack) o);
|
||||
else if (o instanceof FluidStack) return new LFluidStack((FluidStack) o);
|
||||
else throw new RuntimeException("Unrecognized ingredient type: " + o.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ingredient the ingredient, possibly itemStack or FluidStack
|
||||
* @return the identical representation
|
||||
*/
|
||||
public abstract ILabel toLabel(T ingredient);
|
||||
|
||||
/**
|
||||
* @param ingredients the list of ingredient, possibly itemStack or FluidStack
|
||||
* @return list of guessed representation, sorted by possibility
|
||||
*/
|
||||
public List<ILabel> toLabel(List<T> ingredients) {
|
||||
return new ReversedIterator<>(handlers).stream().flatMap(h -> h.apply(ingredients).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void register(Function<List<T>, List<ILabel>> handler) {
|
||||
public void register(Function<List<ILabel>, List<ILabel>> handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
}
|
||||
|
||||
class RegistryConverterItem extends RegistryConverter<ItemStack> {
|
||||
private RegistryConverterItem() {
|
||||
public ILabel first(List<ILabel> labels) {
|
||||
List<ILabel> guess = guess(labels);
|
||||
return guess.isEmpty() ? labels.get(0) : guess.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel toLabel(ItemStack ingredient) {
|
||||
return new LItemStack(ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
class RegistryConverterFluid extends RegistryConverter<net.minecraftforge.fluids.FluidStack> {
|
||||
|
||||
private RegistryConverterFluid() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel toLabel(net.minecraftforge.fluids.FluidStack ingredient) {
|
||||
return new LFluidStack(new net.minecraftforge.fluids.FluidStack(ingredient.getFluid(), 1000), ingredient.amount);
|
||||
public List<ILabel> guess(List<ILabel> labels) {
|
||||
return new ReversedIterator<>(handlers).stream().flatMap(h -> h.apply(labels).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package me.towdium.jecalculation.data.label.labels;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -21,23 +21,19 @@ import java.util.List;
|
||||
public class LFluidStack implements ILabel {
|
||||
public static final String IDENTIFIER = "fluidStack";
|
||||
public static final String KEY_FLUID = "name";
|
||||
public static final String KEY_AMOUNT = "amount";
|
||||
|
||||
FluidStack fluid;
|
||||
int amount;
|
||||
|
||||
public LFluidStack(FluidStack fluid, int amount) {
|
||||
public LFluidStack(FluidStack fluid) {
|
||||
this.fluid = fluid;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public LFluidStack(Fluid fluid, int amount) {
|
||||
this(new FluidStack(fluid, 1000), amount);
|
||||
this.fluid = new FluidStack(fluid, amount);
|
||||
}
|
||||
|
||||
public LFluidStack(NBTTagCompound nbt) {
|
||||
fluid = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag(KEY_FLUID));
|
||||
amount = nbt.getInteger(KEY_AMOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,9 +56,16 @@ public class LFluidStack implements ILabel {
|
||||
return ILabel.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel invertAmount() {
|
||||
fluid.amount *= -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAmountString() {
|
||||
return amount >= 1000 ? Utilities.cutNumber(amount / 1000f, 4) + "B" : Integer.toString(amount) + "mB";
|
||||
return fluid.amount >= 1000 ? Utilities.cutNumber(fluid.amount / 1000f, 4) + "B"
|
||||
: Integer.toString(fluid.amount) + "mB";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,14 +81,13 @@ public class LFluidStack implements ILabel {
|
||||
|
||||
@Override
|
||||
public ILabel copy() {
|
||||
return new LFluidStack(fluid, amount);
|
||||
return new LFluidStack(fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound toNBTTagCompound() {
|
||||
NBTTagCompound ret = new NBTTagCompound();
|
||||
ret.setTag(KEY_FLUID, fluid.writeToNBT(new NBTTagCompound())); // TODO check
|
||||
ret.setInteger(KEY_AMOUNT, amount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -105,12 +107,11 @@ public class LFluidStack implements ILabel {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof LFluidStack
|
||||
&& fluid.equals(((LFluidStack) obj).fluid) && amount == ((LFluidStack) obj).amount;
|
||||
return obj instanceof LFluidStack && fluid.equals(((LFluidStack) obj).fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return fluid.hashCode() ^ amount;
|
||||
return fluid.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package me.towdium.jecalculation.data.label.labels;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -3,8 +3,8 @@ 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.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
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;
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -28,6 +29,8 @@ public class LOreDict extends LabelSimpleAmount {
|
||||
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 = false;
|
||||
|
||||
|
||||
static {
|
||||
|
||||
@@ -57,17 +60,34 @@ public class LOreDict extends LabelSimpleAmount {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getDisplayName() {
|
||||
return Utilities.L18n.format("label.ore_dict.name", name);
|
||||
return Utilities.I18n.format("label.ore_dict.name", name);
|
||||
}
|
||||
|
||||
public static List<ILabel> guess(List<ItemStack> iss) {
|
||||
HashSet<Integer> ids = new HashSet<>();
|
||||
for (int i : OreDictionary.getOreIDs(iss.get(0))) ids.add(i);
|
||||
iss.forEach(is -> {
|
||||
for (int i : OreDictionary.getOreIDs(is))
|
||||
if (!ids.contains(i)) ids.remove(i);
|
||||
});
|
||||
return ids.stream().map(i -> new LOreDict(OreDictionary.getOreName(i))).collect(Collectors.toList());
|
||||
public static List<ILabel> guess(List<ILabel> iss) {
|
||||
ILabel l = iss.get(0);
|
||||
if ((MODE_FORCE || iss.size() > 1) && l instanceof LItemStack) {
|
||||
HashSet<Integer> ids = new HashSet<>();
|
||||
int amount = ((LItemStack) l).getAmount();
|
||||
for (int i : OreDictionary.getOreIDs(((LItemStack) l).itemStack))
|
||||
if (check(i, iss)) ids.add(i);
|
||||
return ids.stream().map(i -> new LOreDict(OreDictionary.getOreName(i), amount))
|
||||
.collect(Collectors.toList());
|
||||
} else return new ArrayList<>();
|
||||
}
|
||||
|
||||
// check labels in the list suitable for the ore id
|
||||
private static boolean check(int id, List<ILabel> labels) {
|
||||
List<ItemStack> ores = OreDictionary.getOres(OreDictionary.getOreName(id));
|
||||
for (ItemStack ore : ores) if (!check(ore, labels)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// check the recorded ore item is in the list
|
||||
private static boolean check(ItemStack ore, List<ILabel> labels) {
|
||||
for (ILabel label : labels)
|
||||
if (label instanceof LItemStack && OreDictionary.itemMatches(ore, ((LItemStack) label).itemStack, false))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,8 +2,8 @@ package me.towdium.jecalculation.data.label.labels;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -31,15 +31,15 @@ public class LString extends LabelSimpleAmount {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public LString(LString lu) {
|
||||
super(lu);
|
||||
name = lu.name;
|
||||
public LString(LString label) {
|
||||
super(label);
|
||||
name = label.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getDisplayName() {
|
||||
return Utilities.L18n.format("label.universal.name", name);
|
||||
return Utilities.I18n.format("label.universal.name", name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -61,11 +61,17 @@ public abstract class LabelSimpleAmount implements ILabel {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabel invertAmount() {
|
||||
amount *= -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<String> getToolTip(List<String> existing, boolean detailed) {
|
||||
if (detailed) existing.add(FORMAT_GREY +
|
||||
Utilities.L18n.format("label.common.tooltip.amount", Integer.toString(amount)));
|
||||
Utilities.I18n.format("label.common.tooltip.amount", Integer.toString(amount)));
|
||||
return existing;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package me.towdium.jecalculation.data.structure;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.polyfill.NBTHelper;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import me.towdium.jecalculation.utils.wrappers.Wrapper;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
@@ -44,14 +44,15 @@ public class Recipe {
|
||||
BiFunction<ILabel[], Integer, ILabel[]> convert = (ls, i) -> {
|
||||
ILabel[] ret = new ILabel[i];
|
||||
if (ls.length > i) throw new RuntimeException("Too many labels");
|
||||
System.arraycopy(ls, 0, this.input, 0, Math.min(i, ls.length));
|
||||
System.arraycopy(ls, 0, ret, 0, ls.length);
|
||||
for (int j = ls.length; j < i; j++) ret[j] = ILabel.EMPTY;
|
||||
return ret;
|
||||
};
|
||||
this.input = convert.apply(input, 16);
|
||||
this.catalyst = convert.apply(catalyst, 8);
|
||||
this.output = convert.apply(output, 8);
|
||||
this.input = convert.apply(input, 14);
|
||||
this.catalyst = convert.apply(catalyst, 7);
|
||||
this.output = convert.apply(output, 7);
|
||||
|
||||
Single<Integer> hash = new Single<>(0);
|
||||
Wrapper<Integer> hash = new Wrapper<>(0);
|
||||
Consumer<ILabel[]> hasher = (ls) -> Arrays.stream(ls)
|
||||
.filter(Objects::nonNull).forEach(i -> hash.value ^= i.hashCode());
|
||||
hasher.accept(input);
|
||||
|
||||
@@ -3,6 +3,7 @@ package me.towdium.jecalculation.data.structure;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.polyfill.NBTHelper;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
@@ -13,6 +14,7 @@ import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
@@ -78,6 +80,14 @@ public class User {
|
||||
}).set(index, recipe);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return records.size();
|
||||
}
|
||||
|
||||
public Stream<Pair<String, List<Recipe>>> stream() {
|
||||
return records.stream();
|
||||
}
|
||||
|
||||
public void remove(String group, int index) {
|
||||
records.get(group).orElseGet(() -> {
|
||||
throw new RuntimeException("Group not found: " + group + ".");
|
||||
|
||||
@@ -4,13 +4,22 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
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.data.structure.Recipe;
|
||||
import me.towdium.jecalculation.data.structure.User;
|
||||
import me.towdium.jecalculation.network.packets.PCalculator;
|
||||
import me.towdium.jecalculation.network.packets.PRecipe;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
@@ -19,25 +28,31 @@ import java.util.List;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ControllerClient {
|
||||
static User recordWorld;
|
||||
static User recordClient;
|
||||
static User recordClient = new User();
|
||||
|
||||
static User getRecord() {
|
||||
return recordWorld == null ? recordClient : recordWorld;
|
||||
}
|
||||
|
||||
public static List<String> getGroups() {
|
||||
User user = getRecord();
|
||||
if (user.recipes.size() != 0) return user.recipes.stream().map(p -> p.one).collect(Collectors.toList());
|
||||
else return Collections.singletonList(Utilities.I18n.format("common.default"));
|
||||
}
|
||||
|
||||
public static void addRecipe(String group, Recipe recipe) {
|
||||
getRecord().recipes.add(group, recipe);
|
||||
// TODO sync
|
||||
JustEnoughCalculation.network.sendToServer(new PRecipe(group, -1, recipe));
|
||||
}
|
||||
|
||||
public static void setRecipe(String group, int index, Recipe recipe) {
|
||||
getRecord().recipes.set(group, index, recipe);
|
||||
// TODO sync
|
||||
JustEnoughCalculation.network.sendToServer(new PRecipe(group, index, recipe));
|
||||
}
|
||||
|
||||
public static void removeRecipe(String group, int index) {
|
||||
getRecord().recipes.remove(group, index);
|
||||
// TODO sync
|
||||
JustEnoughCalculation.network.sendToServer(new PRecipe(group, index, null));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,11 +74,40 @@ public class ControllerClient {
|
||||
return getRecord().recipes.search(group, label, type);
|
||||
}
|
||||
|
||||
public static User.Recent getRecent() {
|
||||
return getRecord().recent;
|
||||
public static List<ILabel> getRecent() {
|
||||
if (recordWorld == null) return recordClient.recent.getRecords();
|
||||
else {
|
||||
ArrayList<ILabel> ret = new ArrayList<>();
|
||||
Optional<ItemStack> ois = Utilities.getStack();
|
||||
ois.ifPresent(is -> {
|
||||
User.Recent recent = new User.Recent(Utilities.getTag(is).getTagList(User.Recent.IDENTIFIER, 10));
|
||||
ret.addAll(recent.getRecords());
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
public static void setRecent(ILabel label) {
|
||||
if (recordWorld == null) recordClient.recent.push(label);
|
||||
else {
|
||||
Optional<ItemStack> ois = Utilities.getStack();
|
||||
ois.ifPresent(is -> {
|
||||
User.Recent recent = new User.Recent(Utilities.getTag(is).getTagList(User.Recent.IDENTIFIER, 10));
|
||||
recent.push(label);
|
||||
Utilities.getTag(is).setTag(User.Recent.IDENTIFIER, recent.serialize());
|
||||
JustEnoughCalculation.network.sendToServer(new PCalculator(is));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void setRecent(ILabel label) {
|
||||
getRecord().recent.push(label); // no need to sync because client only
|
||||
public static void syncFromServer(User u) {
|
||||
recordWorld = u;
|
||||
}
|
||||
|
||||
public static void loadFromLocal() {
|
||||
recordClient = new User(); // TODO
|
||||
}
|
||||
|
||||
public static void writeToLocal() {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,18 @@ package me.towdium.jecalculation.event.handlers;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.data.structure.Recipe;
|
||||
import me.towdium.jecalculation.data.structure.User;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import me.towdium.jecalculation.network.packets.PRecord;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent.LoadFromFile;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent.SaveToFile;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -18,29 +24,59 @@ import java.util.UUID;
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class ControllerServer {
|
||||
static HashMap<UUID, Pair<Boolean, User>> records;
|
||||
static HashMap<UUID, User> records = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @param uuid User UUID
|
||||
* @param group Recipe group, crate when not exist
|
||||
* @param index Recipe group, -1 for add
|
||||
* @param recipe Recipe content, null for remove
|
||||
*/
|
||||
public static void modify(UUID uuid, String group, int index, @Nullable Recipe recipe) {
|
||||
User.Recipes rs = records.get(uuid).recipes;
|
||||
if (recipe == null) rs.remove(group, index);
|
||||
else if (index == -1) rs.add(group, recipe);
|
||||
else rs.set(group, index, recipe);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onJoin(PlayerEvent.PlayerLoggedInEvent e) {
|
||||
JustEnoughCalculation.logger.info(String.format("Player join, name: %s, remote: %b, uuid: %s",
|
||||
e.player.getDisplayName(), e.player.worldObj.isRemote, e.player.getUniqueID()));
|
||||
JustEnoughCalculation.network.sendTo(new PRecord(records.get(e.player.getUniqueID())),
|
||||
(EntityPlayerMP) e.player);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onQuit(PlayerEvent.PlayerLoggedOutEvent e) {
|
||||
JustEnoughCalculation.logger.info(String.format("Player quit, name: %s, remote: %b",
|
||||
e.player.getDisplayName(), e.player.worldObj.isRemote));
|
||||
records.remove(e.player.getUniqueID());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onLoad(LoadFromFile e) {
|
||||
JustEnoughCalculation.logger.info(String.format("Player load, name: %s, remote: %b",
|
||||
e.entityPlayer.getDisplayName(), e.entityPlayer.worldObj.isRemote));
|
||||
try {
|
||||
FileInputStream stream = new FileInputStream(e.getPlayerFile("jeca"));
|
||||
NBTTagCompound tag = CompressedStreamTools.readCompressed(stream);
|
||||
records.put(UUID.fromString(e.playerUUID), new User(tag));
|
||||
} catch (FileNotFoundException ex) {
|
||||
JustEnoughCalculation.logger.info("Record not found for "
|
||||
+ e.entityPlayer.getDisplayName());
|
||||
records.put(UUID.fromString(e.playerUUID), new User());
|
||||
} catch (IOException | IllegalArgumentException ex) {
|
||||
JustEnoughCalculation.logger.warn("Fail to load records for "
|
||||
+ e.entityPlayer.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSave(SaveToFile e) {
|
||||
JustEnoughCalculation.logger.info(String.format("Player save, name: %s, remote: %b",
|
||||
e.entityPlayer.getDisplayName(), e.entityPlayer.worldObj.isRemote));
|
||||
try {
|
||||
File file = e.getPlayerFile("jeca");
|
||||
User user = records.get(UUID.fromString(e.playerUUID));
|
||||
NBTTagCompound tag = user.serialize();
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
CompressedStreamTools.writeCompressed(tag, fos);
|
||||
} catch (Exception ex) {
|
||||
JustEnoughCalculation.logger.warn("Fail to save records for "
|
||||
+ e.entityPlayer.getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.guis.GuiCalculator;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.guis.GuiCalculator;
|
||||
import me.towdium.jecalculation.network.ProxyClient;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
package me.towdium.jecalculation.client.gui;
|
||||
package me.towdium.jecalculation.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WContainer;
|
||||
import me.towdium.jecalculation.gui.drawables.WContainer;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import me.towdium.jecalculation.utils.wrappers.Wrapper;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.function.Consumer;
|
||||
@@ -19,7 +19,7 @@ public interface IWPicker extends IWidget {
|
||||
IWPicker setCallback(Consumer<ILabel> callback);
|
||||
|
||||
class Simple extends WContainer implements IWPicker {
|
||||
protected Single<Consumer<ILabel>> callback = new Single<>(null);
|
||||
protected Wrapper<Consumer<ILabel>> callback = new Wrapper<>(null);
|
||||
|
||||
@Override
|
||||
public IWPicker setCallback(Consumer<ILabel> callback) {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.towdium.jecalculation.client.gui;
|
||||
package me.towdium.jecalculation.gui;
|
||||
|
||||
public interface IWidget {
|
||||
void onDraw(JecGui gui, int xMouse, int yMouse);
|
||||
+31
-31
@@ -1,4 +1,4 @@
|
||||
package me.towdium.jecalculation.client.gui;
|
||||
package me.towdium.jecalculation.gui;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiUtils;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -8,7 +8,7 @@ import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import me.towdium.jecalculation.utils.wrappers.Wrapper;
|
||||
import me.towdium.jecalculation.utils.wrappers.Triple;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
@@ -45,10 +45,9 @@ public class JecGui extends GuiContainer {
|
||||
public static final int COLOR_TEXT_RED = 0xFF0000;
|
||||
public static final int COLOR_TEXT_WHITE = 0xFFFFFF;
|
||||
public static final boolean ALWAYS_TOOLTIP = false;
|
||||
|
||||
protected JecGui parent;
|
||||
public ILabel hand = ILabel.EMPTY;
|
||||
public IWidget root;
|
||||
protected JecGui parent;
|
||||
protected List<Triple<Integer, Integer, List<String>>> tooltipBuffer = new ArrayList<>();
|
||||
|
||||
public JecGui(@Nullable JecGui parent, IWidget root) {
|
||||
@@ -111,6 +110,10 @@ public class JecGui extends GuiContainer {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isShiftDown() {
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
@@ -312,7 +315,7 @@ public class JecGui extends GuiContainer {
|
||||
}
|
||||
|
||||
private void drawText(float xPos, float yPos, Font f, Function<String, Integer> indenter, String... text) {
|
||||
Single<Integer> y = new Single<>(0);
|
||||
Wrapper<Integer> y = new Wrapper<>(0);
|
||||
boolean unicode = fontRendererObj.getUnicodeFlag();
|
||||
if (!f.unicode)
|
||||
fontRendererObj.setUnicodeFlag(false);
|
||||
@@ -392,6 +395,29 @@ public class JecGui extends GuiContainer {
|
||||
GlStateManager.disableDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
boolean inGui = root.onClicked(this, mouseX - guiLeft, mouseY - guiTop, mouseButton);
|
||||
if (!inGui) {
|
||||
this.handleMouseEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
if (!root.onKey(this, typedChar, keyCode)) {
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
if (hand != ILabel.EMPTY)
|
||||
hand = ILabel.EMPTY;
|
||||
else if (parent != null)
|
||||
Minecraft.getMinecraft().displayGuiScreen(parent);
|
||||
else
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Font {
|
||||
public static final Font DEFAULT_SHADOW = new Font(0xFFFFFF, true, true, false, 1, enumAlign.AUTO);
|
||||
public static final Font DEFAULT_NO_SHADOW = new Font(0x404040, false, true, false, 1, enumAlign.AUTO);
|
||||
@@ -425,32 +451,6 @@ public class JecGui extends GuiContainer {
|
||||
public enum enumAlign {LEFT, CENTRE, RIGHT, AUTO}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
boolean inGui = root.onClicked(this, mouseX - guiLeft, mouseY - guiTop, mouseButton);
|
||||
if (!inGui) {
|
||||
this.handleMouseEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
if (!root.onKey(this, typedChar, keyCode)) {
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
if (hand != ILabel.EMPTY)
|
||||
hand = ILabel.EMPTY;
|
||||
else if (parent != null)
|
||||
Minecraft.getMinecraft().displayGuiScreen(parent);
|
||||
else
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isShiftDown() {
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
}
|
||||
|
||||
public static class JecContainer extends Container {
|
||||
JecGui gui;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.towdium.jecalculation.client.gui;
|
||||
package me.towdium.jecalculation.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.utils.ClientUtils;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -22,7 +22,7 @@ public class WButtonText extends WButton {
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
super.onDraw(gui, xMouse, yMouse);
|
||||
int textColor = mouseIn(xMouse, yMouse) ? 16777120 : 0;
|
||||
String text = Utilities.L18n.format(String.join(".", "gui", name, "text"));
|
||||
String text = Utilities.I18n.format(String.join(".", "gui", name, "text"));
|
||||
int strWidth = gui.getFontRenderer().getStringWidth(text);
|
||||
int ellipsisWidth = gui.getFontRenderer().getStringWidth("...");
|
||||
String str = text;
|
||||
+8
-8
@@ -1,9 +1,9 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
@@ -63,12 +63,12 @@ public class WContainer implements IWidget {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*public Optional<DLabel> getEntryAt(int xMouse, int yMouse) {
|
||||
/*public Optional<WLabel> getLabelAt(int xMouse, int yMouse) {
|
||||
return drawables.stream().map(w -> {
|
||||
if (w instanceof DLabelGroup) return ((DLabelGroup) w).getEntryAt(xMouse, yMouse);
|
||||
else if (w instanceof DLabel) return Optional.ofNullable(
|
||||
((DLabel) w).mouseIn(xMouse, yMouse) ? ((DLabel) w) : null);
|
||||
else return Optional.<DLabel>empty();
|
||||
if (w instanceof WLabelGroup) return ((WLabelGroup) w).getLabelAt(xMouse, yMouse);
|
||||
else if (w instanceof WLabel) return Optional.ofNullable(
|
||||
((WLabel) w).mouseIn(xMouse, yMouse) ? ((WLabel) w) : null);
|
||||
else return Optional.<WLabel>empty();
|
||||
}).filter(Optional::isPresent).findFirst().orElse(Optional.empty());
|
||||
}*/
|
||||
}
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
+8
-8
@@ -1,17 +1,16 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
@@ -31,7 +30,7 @@ public class WLabel implements IWidget {
|
||||
public int xPos, yPos, xSize, ySize;
|
||||
public ILabel label;
|
||||
public enumMode mode;
|
||||
public Consumer<ILabel> lsnrUpdate;
|
||||
public Runnable lsnrUpdate;
|
||||
protected Utilities.Timer timer = new Utilities.Timer();
|
||||
|
||||
public WLabel(int xPos, int yPos, int xSize, int ySize, enumMode mode) {
|
||||
@@ -136,7 +135,7 @@ public class WLabel implements IWidget {
|
||||
return false;
|
||||
}
|
||||
|
||||
public WLabel setLsnrUpdate(Consumer<ILabel> lsnr) {
|
||||
public WLabel setLsnrUpdate(Runnable lsnr) {
|
||||
lsnrUpdate = lsnr;
|
||||
return this;
|
||||
}
|
||||
@@ -148,9 +147,10 @@ public class WLabel implements IWidget {
|
||||
}
|
||||
|
||||
void notifyLsnr() {
|
||||
if (lsnrUpdate != null) lsnrUpdate.accept(label);
|
||||
if (lsnrUpdate != null) lsnrUpdate.run();
|
||||
}
|
||||
|
||||
|
||||
public enum enumMode {
|
||||
/**
|
||||
* Slots in editor gui. Can use to edit amount. Exact amount displayed.
|
||||
+21
-6
@@ -1,15 +1,17 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import me.towdium.jecalculation.utils.wrappers.Wrapper;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
@@ -20,6 +22,7 @@ import java.util.stream.IntStream;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class WLabelGroup extends WContainer {
|
||||
ArrayList<WLabel> labels = new ArrayList<>();
|
||||
Consumer<Integer> lsnrUpdate;
|
||||
|
||||
public WLabelGroup(int xPos, int yPos, int column, int row, WLabel.enumMode mode) {
|
||||
this(xPos, yPos, column, row, 18, 18, mode);
|
||||
@@ -27,7 +30,9 @@ public class WLabelGroup extends WContainer {
|
||||
|
||||
public WLabelGroup(int xPos, int yPos, int column, int row, int xSize, int ySize, WLabel.enumMode mode) {
|
||||
IntStream.range(0, row).forEach(r -> IntStream.range(0, column).forEach(c -> {
|
||||
WLabel l = new WLabel(xPos + c * xSize, yPos + r * ySize, xSize, ySize, mode);
|
||||
WLabel l = new WLabel(xPos + c * xSize, yPos + r * ySize, xSize, ySize, mode).setLsnrUpdate(() -> {
|
||||
if (lsnrUpdate != null) lsnrUpdate.accept(r * column + c);
|
||||
});
|
||||
labels.add(l);
|
||||
add(l);
|
||||
}));
|
||||
@@ -36,15 +41,25 @@ public class WLabelGroup extends WContainer {
|
||||
@Override
|
||||
public void remove(IWidget w) {
|
||||
super.remove(w);
|
||||
if (w instanceof WLabel) labels.remove(w);
|
||||
if (w instanceof WLabel)
|
||||
labels.remove(w);
|
||||
}
|
||||
|
||||
public Optional<WLabel> getLabelAt(int xMouse, int yMouse) {
|
||||
return labels.stream().filter(w -> w.mouseIn(xMouse, yMouse)).findFirst();
|
||||
}
|
||||
|
||||
public List<ILabel> getLabels() {
|
||||
return labels.stream().map(WLabel::getLabel).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void setLabel(List<ILabel> labels, int start) {
|
||||
Single<Integer> i = new Single<>(start);
|
||||
Wrapper<Integer> i = new Wrapper<>(start);
|
||||
this.labels.forEach(l -> l.setLabel(i.value < labels.size() ? labels.get(i.value++) : ILabel.EMPTY));
|
||||
}
|
||||
|
||||
public WLabelGroup setLsnrUpdate(Consumer<Integer> listener) {
|
||||
lsnrUpdate = listener;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
+5
-5
@@ -1,10 +1,10 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class WPage implements IWidget {
|
||||
record.representation.drawLabel(gui, index * 24 + 4, -17, false);
|
||||
timer.setState(JecGui.mouseIn(index * 24, -21, 24, 21, xMouse, yMouse));
|
||||
if (timer.getTime() > 1000)
|
||||
gui.drawTooltip(xMouse, yMouse, Utilities.L18n.format("gui." + record.localizeKey));
|
||||
gui.drawTooltip(xMouse, yMouse, Utilities.I18n.format("gui." + record.localizeKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
+5
-4
@@ -1,16 +1,17 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-15.
|
||||
* Base panel of GUIs
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
+5
-4
@@ -1,10 +1,10 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -13,6 +13,7 @@ import java.util.function.Consumer;
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-19.
|
||||
* Scroll bar
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
+42
-23
@@ -1,10 +1,9 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.utils.Utilities.Circulator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -13,30 +12,28 @@ import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-8-19.
|
||||
* Widget to select page with button for left and right
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class WSwitcher extends WContainer {
|
||||
public static final int SIZE = 13;
|
||||
|
||||
public Consumer<Integer> listener;
|
||||
protected int xPos, xSize, yPos;
|
||||
protected WButton left, right;
|
||||
protected WRectangle wRect;
|
||||
protected WText wText;
|
||||
protected List<String> keys;
|
||||
protected Circulator index;
|
||||
@Nullable
|
||||
protected String temp;
|
||||
public Consumer<Integer> listener;
|
||||
|
||||
public WSwitcher(int xPos, int yPos, int xSize, int total) {
|
||||
this(xPos, yPos, xSize, IntStream.rangeClosed(1, total)
|
||||
.mapToObj(i -> i + "/" + total).collect(Collectors.toList()));
|
||||
this(xPos, yPos, xSize,
|
||||
IntStream.rangeClosed(1, total).mapToObj(i -> i + "/" + total).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public WSwitcher(int xPos, int yPos, int xSize, List<String> keys) {
|
||||
@@ -44,28 +41,38 @@ public class WSwitcher extends WContainer {
|
||||
this.xSize = xSize;
|
||||
this.yPos = yPos;
|
||||
this.keys = keys;
|
||||
left = new WButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WGT_ARR_L_N, Resource.WGT_ARR_L_F,
|
||||
Resource.WGT_ARR_L_D).setListenerLeft(() -> move(false));
|
||||
left = new WButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WGT_ARR_L_N, Resource.WGT_ARR_L_F, Resource.WGT_ARR_L_D)
|
||||
.setListenerLeft(() -> {
|
||||
if (temp == null)
|
||||
move(false);
|
||||
else
|
||||
setTemp(null);
|
||||
});
|
||||
right = new WButtonIcon(xPos + xSize - SIZE, yPos, SIZE, SIZE, Resource.WGT_ARR_R_N, Resource.WGT_ARR_R_F,
|
||||
Resource.WGT_ARR_R_D).setListenerLeft(() -> move(true));
|
||||
Resource.WGT_ARR_R_D).setListenerLeft(() -> {
|
||||
if (temp == null)
|
||||
move(true);
|
||||
else
|
||||
setTemp(null);
|
||||
});
|
||||
wRect = new WRectangle(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.COLOR_GUI_GREY);
|
||||
wText = new WText(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.Font.DEFAULT_SHADOW,
|
||||
() -> temp == null ? keys.get(index.current()) : temp);
|
||||
index = new Circulator(keys.size());
|
||||
if (keys.size() == 1) {
|
||||
left.setDisabled(true);
|
||||
right.setDisabled(true);
|
||||
}
|
||||
refresh();
|
||||
addAll(left, right, wRect, wText);
|
||||
}
|
||||
|
||||
|
||||
protected void move(boolean forward) {
|
||||
if (temp == null) {
|
||||
if (forward) index.move(1);
|
||||
else index.move(-1);
|
||||
} else temp = null;
|
||||
|
||||
if (listener != null) listener.accept(getIndex());
|
||||
if (forward)
|
||||
index.move(1);
|
||||
else
|
||||
index.move(-1);
|
||||
} else
|
||||
temp = null;
|
||||
notifyLsnr();
|
||||
}
|
||||
|
||||
public WSwitcher setListener(Consumer<Integer> listener) {
|
||||
@@ -75,7 +82,8 @@ public class WSwitcher extends WContainer {
|
||||
|
||||
public void setTemp(@Nullable String temp) {
|
||||
this.temp = temp;
|
||||
if (listener != null) listener.accept(getIndex());
|
||||
notifyLsnr();
|
||||
refresh();
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
@@ -85,4 +93,15 @@ public class WSwitcher extends WContainer {
|
||||
public String getText() {
|
||||
return temp == null ? keys.get(index.current()) : temp;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
boolean b = temp == null && keys.size() < 2;
|
||||
left.setDisabled(b);
|
||||
right.setDisabled(b);
|
||||
}
|
||||
|
||||
public void notifyLsnr() {
|
||||
if (listener != null)
|
||||
listener.accept(getIndex());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.function.Supplier;
|
||||
+14
-5
@@ -1,9 +1,9 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
@@ -17,9 +17,9 @@ import java.util.function.Consumer;
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class WTextField implements IWidget {
|
||||
public Consumer<String> lsnrText;
|
||||
protected int xPos, yPos, xSize;
|
||||
GuiTextField textField;
|
||||
public Consumer<String> lsnrText;
|
||||
|
||||
public WTextField(int xPos, int yPos, int xSize) {
|
||||
this.xPos = xPos;
|
||||
@@ -44,7 +44,7 @@ public class WTextField implements IWidget {
|
||||
@Override
|
||||
public boolean onKey(JecGui gui, char ch, int code) {
|
||||
boolean ret = textField.textboxKeyTyped(ch, code);
|
||||
if (ret && lsnrText != null) lsnrText.accept(textField.getText());
|
||||
if (ret) notifyLsnr();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,11 @@ public class WTextField implements IWidget {
|
||||
return textField.getText();
|
||||
}
|
||||
|
||||
public void setText(String s) {
|
||||
textField.setText(s);
|
||||
notifyLsnr();
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public WTextField setLsnrText(Consumer<String> lsnrText) {
|
||||
this.lsnrText = lsnrText;
|
||||
@@ -62,4 +67,8 @@ public class WTextField implements IWidget {
|
||||
textField.setTextColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
void notifyLsnr() {
|
||||
if (lsnrText != null) lsnrText.accept(textField.getText());
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -1,11 +1,10 @@
|
||||
package me.towdium.jecalculation.client.gui.drawables;
|
||||
package me.towdium.jecalculation.gui.drawables;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.IWidget;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -32,7 +31,7 @@ public abstract class WTooltip implements IWidget {
|
||||
if (name != null) {
|
||||
timer.setState(mouseIn(xMouse, yMouse));
|
||||
if (timer.getTime() > 500) {
|
||||
String str = getSuffix().stream().map(s -> Utilities.L18n.search(String.join(".", "gui", name, s)))
|
||||
String str = getSuffix().stream().map(s -> Utilities.I18n.search(String.join(".", "gui", name, s)))
|
||||
.filter(p -> p.two).findFirst().map(p -> p.one)
|
||||
.orElse(JecGui.ALWAYS_TOOLTIP ? String.join(".", "gui", name, getSuffix().get(0)) : null);
|
||||
if (str != null) gui.drawTooltip(xMouse, yMouse, str);
|
||||
@@ -0,0 +1,56 @@
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.drawables.*;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.event.handlers.ControllerClient;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/14/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiCalculator extends WContainer {
|
||||
WLabelGroup wRecent = new WLabelGroup(7, 31, 8, 1, WLabel.enumMode.PICKER);
|
||||
WLabel wLabel = new WLabel(31, 7, 20, 20, WLabel.enumMode.SELECTOR);
|
||||
|
||||
public GuiCalculator() {
|
||||
add(new WPanel());
|
||||
add(new WTextField(61, 7, 64));
|
||||
add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "calculator.label")
|
||||
.setListenerLeft(() -> JecGui.displayGui(new GuiLabel(l -> {
|
||||
JecGui.displayParent();
|
||||
JecGui.getCurrent().hand = l;
|
||||
}))));
|
||||
add(new WButtonIcon(130, 7, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "calculator.recipe")
|
||||
.setListenerLeft(() -> JecGui.displayGui(true, true, new GuiRecipe())));
|
||||
add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH_N, Resource.BTN_SEARCH_F, "calculator.search"));
|
||||
add(new WLabelGroup(7, 87, 9, 4, WLabel.enumMode.RESULT));
|
||||
add(wRecent);
|
||||
add(wLabel);
|
||||
add(new WLine(52));
|
||||
add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT_N, Resource.ICN_RECENT_F, "calculator.history"));
|
||||
add(new WSwitcher(7, 56, 162, 5));
|
||||
refresh();
|
||||
List<ILabel> recent = ControllerClient.getRecent();
|
||||
if (recent.size() > 0)
|
||||
wLabel.setLabel(ControllerClient.getRecent().get(0));
|
||||
wLabel.setLsnrUpdate(() -> {
|
||||
ControllerClient.setRecent(wLabel.label);
|
||||
refresh();
|
||||
});
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
List<ILabel> recent = ControllerClient.getRecent();
|
||||
if (recent.size() > 1)
|
||||
wRecent.setLabel(recent.subList(1, recent.size()), 0);
|
||||
}
|
||||
}
|
||||
+12
-13
@@ -1,16 +1,14 @@
|
||||
package me.towdium.jecalculation.client.gui.guis;
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWPicker;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
import me.towdium.jecalculation.gui.IWPicker;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.drawables.*;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
@@ -21,13 +19,12 @@ import java.util.stream.Collectors;
|
||||
public class GuiDisambiguation extends IWPicker.Simple {
|
||||
protected WLabelScroll lsUp;
|
||||
protected WLabelScroll lsDown;
|
||||
protected List<List<ItemStack>> record;
|
||||
protected List<List<ILabel>> record;
|
||||
|
||||
public GuiDisambiguation(List<List<ItemStack>> record) {
|
||||
public GuiDisambiguation(List<List<ILabel>> record) {
|
||||
lsUp = new WLabelScroll(25, 48, 7, 3, WLabel.enumMode.PICKER, true);
|
||||
lsDown = new WLabelScroll(25, 105, 7, 3, WLabel.enumMode.PICKER, true);
|
||||
this.record = record.stream().filter(iss -> !ILabel.CONVERTER_ITEM.toLabel(iss).isEmpty()).distinct()
|
||||
.collect(Collectors.toList());
|
||||
this.record = record;
|
||||
WTextField tf = new WTextField(25, 24, 90);
|
||||
|
||||
add(new WPanel());
|
||||
@@ -40,8 +37,10 @@ public class GuiDisambiguation extends IWPicker.Simple {
|
||||
setPage(0);
|
||||
}
|
||||
|
||||
protected void setPage(int n) {
|
||||
lsUp.setLabels(record.get(n).stream().map(ILabel.CONVERTER_ITEM::toLabel).collect(Collectors.toList()));
|
||||
lsDown.setLabels(ILabel.CONVERTER_ITEM.toLabel(record.get(n)));
|
||||
protected void setPage(int n) { // TODO
|
||||
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)));
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
package me.towdium.jecalculation.client.gui.guis;
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
@@ -6,12 +6,12 @@ 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.client.gui.IWidget;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WContainer;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WPage;
|
||||
import me.towdium.jecalculation.client.gui.drawables.WPanel;
|
||||
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.data.label.ILabel;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import me.towdium.jecalculation.utils.wrappers.Wrapper;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.function.Consumer;
|
||||
@@ -37,7 +37,7 @@ public class GuiLabel extends WContainer {
|
||||
|
||||
public GuiLabel(Consumer<ILabel> callback) {
|
||||
this.callback = callback;
|
||||
Single<Integer> index = new Single<>(0);
|
||||
Wrapper<Integer> index = new Wrapper<>(0);
|
||||
ILabel.EDITOR.getRecords().forEach(r -> {
|
||||
int i = index.value;
|
||||
add(new WPage(i, r, false).setListener(() -> refresh(i)));
|
||||
@@ -0,0 +1,166 @@
|
||||
package me.towdium.jecalculation.gui.guis;
|
||||
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import me.towdium.jecalculation.algorithm.CostList;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.data.structure.Recipe;
|
||||
import me.towdium.jecalculation.event.handlers.ControllerClient;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.drawables.*;
|
||||
import me.towdium.jecalculation.utils.wrappers.Triple;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-8.
|
||||
*/
|
||||
public class GuiRecipe extends WContainer {
|
||||
HashMap<Integer, List<ILabel>> disambiguation = new HashMap<>();
|
||||
WSwitcher switcherGroup = new WSwitcher(7, 7, 162, ControllerClient.getGroups());
|
||||
WButton buttonCopy = new WButtonIcon(83, 33, 20, 20, Resource.BTN_COPY_N, Resource.BTN_COPY_F, Resource.BTN_COPY_D,
|
||||
"recipe.copy").setDisabled(true);
|
||||
WLabelGroup groupCatalyst = new WLabelGroup(28, 87, 7, 1, 20, 20, WLabel.enumMode.EDITOR);
|
||||
WButton buttonDisamb = new WButtonIcon(102, 33, 20, 20, Resource.BTN_DISAMB_N, Resource.BTN_DISAMB_F,
|
||||
Resource.BTN_DISAMB_D, "recipe.disamb").setDisabled(true)
|
||||
.setListenerLeft(() -> {
|
||||
if (disambiguation != null)
|
||||
JecGui.displayGui(
|
||||
new GuiDisambiguation(
|
||||
new ArrayList<>(
|
||||
disambiguation
|
||||
.values()))
|
||||
.setCallback(
|
||||
l -> {
|
||||
JecGui.displayParent();
|
||||
JecGui.getCurrent().hand = l;
|
||||
}));
|
||||
});
|
||||
WLabelGroup groupInput = new WLabelGroup(28, 111, 7, 2, 20, 20, WLabel.enumMode.EDITOR).setLsnrUpdate(i -> {
|
||||
disambiguation.remove(i);
|
||||
refresh();
|
||||
});
|
||||
WLabelGroup groupOutput = new WLabelGroup(28, 63, 7, 1, 20, 20, WLabel.enumMode.EDITOR).setLsnrUpdate(i -> {
|
||||
disambiguation.remove(i + 14);
|
||||
refresh();
|
||||
});
|
||||
WButton buttonClear = new WButtonIcon(64, 33, 20, 20, Resource.BTN_DEL_N, Resource.BTN_DEL_F, "recipe.clear")
|
||||
.setListenerLeft(this::clear);
|
||||
WButton buttonLabel = new WButtonIcon(45, 33, 20, 20, Resource.BTN_LABEL_N, Resource.BTN_LABEL_F, "recipe.label")
|
||||
.setListenerLeft(() -> JecGui.displayGui(new GuiLabel((l) -> {
|
||||
JecGui.displayParent();
|
||||
JecGui.getCurrent().hand = l;
|
||||
})));
|
||||
WButton buttonSave = new WButtonIcon(26, 33, 20, 20, Resource.BTN_SAVE_N, Resource.BTN_SAVE_F, "recipe.save")
|
||||
.setListenerLeft(() -> {
|
||||
ControllerClient.addRecipe(switcherGroup.getText(), toRecipe());
|
||||
JecGui.displayParent();
|
||||
});
|
||||
WTextField textField = new WTextField(49, 33, 119);
|
||||
WButton buttonNew = new WButtonIcon(7, 33, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "recipe.new")
|
||||
.setListenerLeft(() -> setModeNewGroup(true));
|
||||
WButton buttonYes = new WButtonIcon(7, 33, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F, "recipe.confirm")
|
||||
.setListenerLeft(() -> {
|
||||
switcherGroup.setTemp(textField.getText());
|
||||
textField.setText("");
|
||||
setModeNewGroup(false);
|
||||
});
|
||||
WButton buttonNo = new WButtonIcon(26, 33, 20, 20, Resource.BTN_NO_N, Resource.BTN_NO_F, "recipe.cancel")
|
||||
.setListenerLeft(() -> setModeNewGroup(false));
|
||||
|
||||
public GuiRecipe() {
|
||||
add(new WPanel());
|
||||
add(new WIcon(7, 63, 21, 20, Resource.ICN_OUTPUT_N, Resource.ICN_OUTPUT_F, "recipe.output"));
|
||||
add(new WIcon(7, 87, 21, 20, Resource.ICN_CATALYST_N, Resource.ICN_CATALYST_F, "recipe.catalyst"));
|
||||
add(new WIcon(7, 111, 21, 40, Resource.ICN_INPUT_N, Resource.ICN_INPUT_F, "recipe.input"));
|
||||
add(new WLine(57));
|
||||
addAll(groupInput, groupCatalyst, groupOutput, switcherGroup);
|
||||
setModeNewGroup(false);
|
||||
}
|
||||
|
||||
public void setModeNewGroup(boolean b) {
|
||||
if (b) {
|
||||
removeAll(buttonNew, buttonLabel, buttonClear, buttonCopy, buttonSave, buttonDisamb);
|
||||
addAll(buttonYes, buttonNo, textField);
|
||||
} else {
|
||||
addAll(buttonNew, buttonLabel, buttonClear, buttonCopy, buttonSave, buttonDisamb);
|
||||
removeAll(buttonYes, buttonNo, textField);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
groupInput.setLabel(Collections.nCopies(14, ILabel.EMPTY), 0);
|
||||
groupCatalyst.setLabel(Collections.nCopies(7, ILabel.EMPTY), 0);
|
||||
groupOutput.setLabel(Collections.nCopies(7, ILabel.EMPTY), 0);
|
||||
}
|
||||
|
||||
public void transfer(IRecipeHandler recipe, int recipeIndex) {
|
||||
// item disamb raw
|
||||
ArrayList<Triple<ILabel, CostList, CostList>> input = new ArrayList<>();
|
||||
ArrayList<Triple<ILabel, CostList, CostList>> output = new ArrayList<>();
|
||||
HashMap<Integer, List<ILabel>> disamb = new HashMap<>();
|
||||
|
||||
BiConsumer<ArrayList<Triple<ILabel, CostList, CostList>>, List<ILabel>> merge = (dst, list) -> {
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
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.one);
|
||||
p.two.merge(cl, true);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}).findAny().orElseGet(() -> {
|
||||
Triple<ILabel, CostList, CostList> ret = new Triple<>(ILabel.CONVERTER.first(list), new CostList(list),
|
||||
new CostList(list));
|
||||
dst.add(ret);
|
||||
return ret;
|
||||
});
|
||||
};
|
||||
|
||||
BiFunction<ArrayList<Triple<ILabel, CostList, CostList>>, Integer, ArrayList<ILabel>> sort = (src, offset) -> {
|
||||
ArrayList<ILabel> ret = new ArrayList<>();
|
||||
for (int i = 0; i < src.size(); i++) {
|
||||
Triple<ILabel, CostList, CostList> p = src.get(i);
|
||||
ret.add(p.one);
|
||||
if (!ILabel.CONVERTER.guess(p.three.getLabels()).isEmpty())
|
||||
disamb.put(i + offset, p.two.getLabels());
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
// input
|
||||
List<ItemStack> itemStacks = recipe.getIngredientStacks(recipeIndex).stream()
|
||||
.map((positionedStack) -> positionedStack.item).collect(Collectors.toList());
|
||||
|
||||
|
||||
merge.accept(input, itemStacks.stream().map(ILabel.Converter::from).collect(Collectors.toList()));
|
||||
|
||||
// output
|
||||
ItemStack outputStack = recipe.getResultStack(recipeIndex).item;
|
||||
merge.accept(output, Stream.of(outputStack).map(ILabel.Converter::from).collect(Collectors.toList()));
|
||||
|
||||
groupInput.setLabel(sort.apply(input, 0), 0);
|
||||
groupOutput.setLabel(sort.apply(output, 14), 0);
|
||||
disambiguation = disamb;
|
||||
refresh();
|
||||
}
|
||||
|
||||
Recipe toRecipe() {
|
||||
return new Recipe(groupInput.getLabels(), groupCatalyst.getLabels(), groupOutput.getLabels());
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
buttonDisamb.setDisabled(disambiguation.isEmpty());
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
package me.towdium.jecalculation.client.gui.guis.pickers;
|
||||
package me.towdium.jecalculation.gui.guis.pickers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWPicker;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
import me.towdium.jecalculation.gui.IWPicker;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.drawables.*;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.data.label.labels.LFluidStack;
|
||||
import me.towdium.jecalculation.data.label.labels.LOreDict;
|
||||
+5
-5
@@ -1,11 +1,11 @@
|
||||
package me.towdium.jecalculation.client.gui.guis.pickers;
|
||||
package me.towdium.jecalculation.gui.guis.pickers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.client.gui.IWPicker;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.Resource;
|
||||
import me.towdium.jecalculation.client.gui.drawables.*;
|
||||
import me.towdium.jecalculation.gui.IWPicker;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.Resource;
|
||||
import me.towdium.jecalculation.gui.drawables.*;
|
||||
import me.towdium.jecalculation.data.label.labels.LString;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -5,8 +5,8 @@ import codechicken.nei.recipe.IRecipeHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.guis.GuiRecipe;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.guis.GuiRecipe;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.towdium.jecalculation.nei;
|
||||
|
||||
import codechicken.nei.guihook.IContainerTooltipHandler;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package me.towdium.jecalculation.nei;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
|
||||
public class NEICalculatorConfig implements IConfigureNEI {
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ public class NEIPlugin {
|
||||
|
||||
public static ILabel getLabelUnderMouse() {
|
||||
if (NEIPlugin.currentItemStack == null) return ILabel.EMPTY;
|
||||
else return ILabel.CONVERTER_ITEM.toLabel(NEIPlugin.currentItemStack);
|
||||
// else if (o instanceof FluidStack) return ILabel.CONVERTER_FLUID.toLabel(((FluidStack) o));
|
||||
return ILabel.Converter.from(NEIPlugin.currentItemStack);
|
||||
}
|
||||
|
||||
public static void setLabelUnderMouse(ItemStack itemStack) {
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
package me.towdium.jecalculation.network;
|
||||
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.gui.guis.GuiCalculator;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.guis.GuiCalculator;
|
||||
import me.towdium.jecalculation.command.JecaCommand;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.event.Handlers;
|
||||
import me.towdium.jecalculation.item.ItemCalculator;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraftforge.client.ClientCommandHandler;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.towdium.jecalculation.network;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.gui.JecGui;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.event.Handlers;
|
||||
import me.towdium.jecalculation.item.ItemCalculator;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package me.towdium.jecalculation.network.packets;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import me.towdium.jecalculation.item.ItemCalculator;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class PCalculator implements IMessage, IMessageHandler<PCalculator, IMessage> {
|
||||
ItemStack stack;
|
||||
|
||||
public PCalculator() {
|
||||
}
|
||||
|
||||
public PCalculator(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
stack = ByteBufUtils.readItemStack(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PCalculator message, MessageContext ctx) {
|
||||
InventoryPlayer inventory = ctx.getServerHandler().playerEntity.inventory;
|
||||
ItemStack calculator = inventory.getCurrentItem();
|
||||
if (calculator != null && calculator.getItem() instanceof ItemCalculator) {
|
||||
inventory.setInventorySlotContents(inventory.currentItem, message.stack);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package me.towdium.jecalculation.network.packets;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import me.towdium.jecalculation.data.structure.Recipe;
|
||||
import me.towdium.jecalculation.event.handlers.ControllerServer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PRecipe implements IMessage, IMessageHandler<PRecipe, IMessage> {
|
||||
static final String KEY_GROUP = "group";
|
||||
static final String KEY_INDEX = "index";
|
||||
static final String KEY_RECIPE = "recipe";
|
||||
|
||||
String group;
|
||||
int index;
|
||||
Recipe recipe;
|
||||
|
||||
public PRecipe() {
|
||||
}
|
||||
|
||||
public PRecipe(String group, int index, Recipe recipe) {
|
||||
this.group = group;
|
||||
this.index = index;
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
NBTTagCompound tag = ByteBufUtils.readTag(buf);
|
||||
tag = tag == null ? new NBTTagCompound() : tag;
|
||||
group = tag.getString(KEY_GROUP);
|
||||
index = tag.getInteger(KEY_INDEX);
|
||||
recipe = tag.hasKey(KEY_RECIPE) ? new Recipe(tag.getCompoundTag(KEY_RECIPE)) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setString(KEY_GROUP, group);
|
||||
tag.setInteger(KEY_INDEX, index);
|
||||
if (recipe != null) tag.setTag(KEY_RECIPE, recipe.serialize());
|
||||
ByteBufUtils.writeTag(buf, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PRecipe message, MessageContext ctx) {
|
||||
UUID uuid = ctx.getServerHandler().playerEntity.getUniqueID();
|
||||
ControllerServer.modify(uuid, message.group, message.index, message.recipe);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package me.towdium.jecalculation.network.packets;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import me.towdium.jecalculation.data.structure.User;
|
||||
import me.towdium.jecalculation.event.handlers.ControllerClient;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class PRecord implements IMessage, IMessageHandler<PRecord, IMessage> {
|
||||
User user;
|
||||
|
||||
public PRecord(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public PRecord() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
NBTTagCompound tag = ByteBufUtils.readTag(buf);
|
||||
user = new User(tag == null ? new NBTTagCompound() : tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeTag(buf, user.serialize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PRecord message, MessageContext ctx) {
|
||||
ControllerClient.syncFromServer(message.user);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
package me.towdium.jecalculation.utils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.item.ItemCalculator;
|
||||
import me.towdium.jecalculation.polyfill.NBTHelper;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import me.towdium.jecalculation.utils.wrappers.Wrapper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -44,6 +45,12 @@ public class Utilities {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean stackEqual(ItemStack a, ItemStack b) {
|
||||
return a.getItem() == b.getItem() && a.getItemDamage() == b.getItemDamage() &&
|
||||
((a.getTagCompound() == null && b.getTagCompound() == null) ||
|
||||
(a.getTagCompound() != null && a.getTagCompound().equals(b.getTagCompound())));
|
||||
}
|
||||
|
||||
// FLOAT FORMATTING
|
||||
public static String cutNumber(float f, int size) {
|
||||
BiFunction<Float, Integer, String> form = (fl, len) -> {
|
||||
@@ -99,6 +106,17 @@ public class Utilities {
|
||||
return s1.contains(s2);
|
||||
}
|
||||
|
||||
public static Optional<ItemStack> 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 void setStack(ItemStack is) {
|
||||
|
||||
}
|
||||
|
||||
public static class Timer {
|
||||
long time = System.currentTimeMillis();
|
||||
boolean running = false;
|
||||
@@ -204,7 +222,7 @@ public class Utilities {
|
||||
public Optional<R> get(T a, T b) {
|
||||
int ah = a.hashCode();
|
||||
int bh = b.hashCode();
|
||||
Single<R> ret = new Single<>(null);
|
||||
Wrapper<R> ret = new Wrapper<>(null);
|
||||
if (ah == bh)
|
||||
ret.push(data.get(new Pair<>(a, b))).push(data.get(new Pair<>(b, a)));
|
||||
else
|
||||
@@ -214,10 +232,10 @@ public class Utilities {
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static class L18n {
|
||||
public static class I18n {
|
||||
public static Pair<String, Boolean> search(String translateKey, Object... parameters) {
|
||||
Pair<String, Boolean> ret = new Pair<>(null, null);
|
||||
String buffer = I18n.format(translateKey, parameters);
|
||||
String buffer = net.minecraft.client.resources.I18n.format(translateKey, parameters);
|
||||
ret.two = !buffer.equals(translateKey);
|
||||
buffer = StringEscapeUtils.unescapeJava(buffer);
|
||||
ret.one = buffer.replace("\t", " ");
|
||||
@@ -255,7 +273,7 @@ public class Utilities {
|
||||
return (List<T>) data.clone();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class OrderedHashMap<K, V> {
|
||||
public HashMap<K, Integer> index = new HashMap<>();
|
||||
public List<Pair<K, V>> value = new ArrayList<>();
|
||||
@@ -291,5 +309,13 @@ public class Utilities {
|
||||
public void forEach(BiConsumer<K, V> func) {
|
||||
value.forEach(p -> func.accept(p.one, p.two));
|
||||
}
|
||||
|
||||
public Stream<Pair<K, V>> stream() {
|
||||
return value.stream();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return value.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -8,27 +8,27 @@ import java.util.function.Predicate;
|
||||
* Author: Towdium
|
||||
* Date: 2016/7/1.
|
||||
*/
|
||||
public class Single<T> {
|
||||
public class Wrapper<T> {
|
||||
public T value;
|
||||
public Predicate<T> predicate = t -> true;
|
||||
|
||||
public Single(T value) {
|
||||
public Wrapper(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Single<T> push(@Nullable T value) {
|
||||
public Wrapper<T> push(@Nullable T value) {
|
||||
if (value != null && predicate.test(value))
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Single<T> ifPresent(Consumer<T> c) {
|
||||
public Wrapper<T> ifPresent(Consumer<T> c) {
|
||||
if (value != null)
|
||||
c.accept(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Single<T> ifPresentNot(Runnable r) {
|
||||
public Wrapper<T> ifPresentNot(Runnable r) {
|
||||
if (value == null)
|
||||
r.run();
|
||||
return this;
|
||||
Reference in new issue
Block a user