chore: refactor

This commit is contained in:
Discreater committed 2021-05-01 02:29:28 +08:00
1 parent 85ba97338c
commit b05011cace
25 files changed
+659 -338

No files matched your search

@@ -8,6 +8,8 @@ import me.towdium.jecalculation.utils.wrappers.Pair;
import java.util.*;
import java.util.stream.Collectors;
import static me.towdium.jecalculation.data.structure.Recipe.enumIoType.OUTPUT;
public class CostList {
List<ILabel> labels;
@@ -15,31 +17,40 @@ public class CostList {
labels = new ArrayList<>();
}
public CostList(ILabel label) {
labels = Collections.singletonList(label.copy().multiply(-1));
}
public CostList(List<ILabel> labels) {
this.labels = labels.stream().map(ILabel::copy).collect(Collectors.toList());
this.labels = labels.stream().map(i -> i.copy().multiply(-1)).collect(Collectors.toList());
}
public CostList(List<ILabel> positive, List<ILabel> negative) {
labels = positive.stream().map(ILabel::copy).collect(Collectors.toList());
negative.forEach(i -> {
ILabel l = i.copy();
labels.add(l.invertAmount());
labels.add(l.multiply(-1));
});
}
public CostList(Recipe recipe) {
this(Arrays.asList(recipe.getLabel(Recipe.enumIoType.OUTPUT)),
Arrays.asList(recipe.getLabel(Recipe.enumIoType.INPUT)));
this(Arrays.stream(recipe.getLabel(OUTPUT)).filter(i -> i != ILabel.EMPTY).collect(Collectors.toList()),
Arrays.stream(recipe.getLabel(Recipe.enumIoType.INPUT)).filter(i -> i != ILabel.EMPTY)
.collect(Collectors.toList()));
}
@SuppressWarnings("UnusedReturnValue")
public CostList merge(CostList costList, boolean add, boolean strict) {
CostList ret = copy();
costList.labels.forEach(i -> ret.labels.add(add ? i.copy() : i.copy().invertAmount()));
costList.labels.forEach(i -> ret.labels.add(add ? i.copy() : i.copy().multiply(-1)));
ret.cancel(strict);
return ret;
}
public void multiply(int i) {
labels = labels.stream().map(j -> j.multiply(i)).collect(Collectors.toList());
}
private void cancel(boolean strict) {
for (int i = 0; i < labels.size(); i++) {
for (int j = 0; j < labels.size(); j++) {
@@ -70,7 +81,8 @@ public class CostList {
CostList c = (CostList) obj;
CostList m = c.copy();
return m.merge(this, false, true).labels.isEmpty();
} else return false;
} else
return false;
}
public CostList copy() {
@@ -90,7 +102,7 @@ public class CostList {
public Calculator calculate() {
return new Calculator(this);
return new Calculator();
}
@Override
@@ -101,33 +113,32 @@ public class CostList {
return hash;
}
public static class Calculator {
CostList start;
ArrayList<Pair<CostList, CostList>> procedure;
List<ILabel> catalysts;
public class Calculator {
ArrayList<Pair<CostList, CostList>> procedure = new ArrayList<>();
ArrayList<ILabel> catalysts = new ArrayList<>();
private int index;
public Calculator(CostList cl) {
public Calculator() {
HashSet<CostList> set = new HashSet<>();
start = cl;
set.add(start);
Recipe next = find(true);
set.add(CostList.this);
Pair<Recipe, Integer> next = find(true);
while (next != null) {
CostList original = getCurrent();
CostList difference = new CostList(next);
CostList result = original.merge(difference, false, false);
CostList difference = new CostList(next.one);
difference.multiply(next.two);
CostList result = original.merge(difference, true, false);
if (set.contains(result))
next = find(false);
else {
set.add(result);
procedure.add(new Pair<>(result, difference));
addCatalyst(next.getLabel(Recipe.enumIoType.CATALYST));
addCatalyst(next.one.getLabel(Recipe.enumIoType.CATALYST));
next = find(true);
}
}
}
private Recipe find(boolean reset) {
private Pair<Recipe, Integer> find(boolean reset) {
if (reset)
index = 0;
List<ILabel> labels = getCurrent().labels;
@@ -135,9 +146,9 @@ public class CostList {
ILabel label = labels.get(index);
if (label.getAmount() >= 0)
continue;
Optional<Recipe> recipe = Controller.getRecipe(label, Recipe.enumIoType.OUTPUT);
Optional<Recipe> recipe = Controller.getRecipe(label, OUTPUT);
if (recipe.isPresent())
return recipe.get();
return new Pair<>(recipe.get(), recipe.get().multiplier(label, OUTPUT));
}
return null;
}
@@ -147,7 +158,7 @@ public class CostList {
for (ILabel i : labels) {
for (ILabel j : catalysts) {
if (j.matches(i)) {
j.setAmount(j.getAmount() + i.getAmount());
j.setAmount(Math.max(i.getAmount(), j.getAmount()));
continue LOOP;
}
}
@@ -156,7 +167,16 @@ public class CostList {
}
private CostList getCurrent() {
return procedure.isEmpty() ? start : procedure.get(procedure.size() - 1).one;
return procedure.isEmpty() ? CostList.this : procedure.get(procedure.size() - 1).one;
}
public List<ILabel> getCatalysts() {
return catalysts;
}
public List<ILabel> getInputs() {
return getCurrent().labels.stream().filter(i -> i.getAmount() < 0).map(i -> i.copy().multiply(-1))
.collect(Collectors.toList());
}
}
}
@@ -27,7 +27,7 @@ import java.util.stream.Collectors;
* Date: 17-10-15.
*/
@SideOnly(Side.CLIENT)
public class Controller {
public class Controller { // TODO record calculate amount
public static final String KEY_RECIPES = "recipes";
public static final String KEY_RECENTS = "recents";
static Recipes recipesClient;
@@ -2,16 +2,21 @@ package me.towdium.jecalculation.data.label;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.labels.*;
import me.towdium.jecalculation.data.label.labels.LFluidStack;
import me.towdium.jecalculation.data.label.labels.LItemStack;
import me.towdium.jecalculation.data.label.labels.LOreDict;
import me.towdium.jecalculation.data.label.labels.LPlaceholder;
import me.towdium.jecalculation.gui.IWPicker;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.guis.pickers.PickerSimple;
import me.towdium.jecalculation.gui.guis.pickers.PickerItemStack;
import me.towdium.jecalculation.gui.guis.pickers.PickerPlaceholder;
import me.towdium.jecalculation.gui.guis.pickers.PickerSimple;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.Utilities.Relation;
import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
import me.towdium.jecalculation.utils.wrappers.Pair;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidRegistry;
@@ -19,7 +24,10 @@ import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -44,19 +52,26 @@ public interface ILabel {
ILabel decreaseAmount();
ILabel invertAmount();
int getAmount();
static void initClient() {
CONVERTER.register(LOreDict::guess);
EDITOR.register(PickerSimple.FluidStack::new, "fluid_stack", new LFluidStack(1000, FluidRegistry.WATER));
EDITOR.register(PickerSimple.OreDict::new, "ore_dict", new LOreDict("ingotIron"));
EDITOR.register(PickerPlaceholder::new, "placeholder", new LPlaceholder("example", 1, true));
EDITOR.register(PickerItemStack::new, "item_stack",
new LItemStack(new ItemStack(Items.iron_pickaxe)).setFMeta(true));
MERGER.register("itemStack", "itemStack", LItemStack::merge);
MERGER.register("oreDict", "oreDict", LOreDict::mergeOreDict);
MERGER.register("oreDict", "oreDict", LOreDict::merge);
MERGER.register("itemStack", "oreDict", LOreDict::merge);
}
int getAmount();
ILabel multiply(int i);
boolean acceptPercent();
ILabel setPercent(boolean p);
static void initServer() {
DESERIALIZER.register(LFluidStack.IDENTIFIER, LFluidStack::new);
DESERIALIZER.register(LItemStack.IDENTIFIER, LItemStack::new);
@@ -79,6 +94,7 @@ public interface ILabel {
ILabel setAmount(int amount);
// test two labels are exactly same except amount
boolean matches(Object l);
@SideOnly(Side.CLIENT)
@@ -170,14 +186,23 @@ public interface ILabel {
}
}
/**
* Provides support to convert between different types of labels.
* For example, guess oreDict from list of labels.
* It can also convert ItemStack or FluidStack to ILabel
*/
class Converter {
ArrayList<Function<List<ILabel>, List<ILabel>>> handlers = new ArrayList<>();
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());
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());
}
public void register(Function<List<ILabel>, List<ILabel>> handler) {
@@ -246,10 +271,20 @@ public interface ILabel {
}
@Override
public ILabel invertAmount() {
public ILabel multiply(int i) {
return this;
}
@Override
public boolean acceptPercent() {
return false;
}
@Override
public ILabel setPercent(boolean p) {
throw new UnsupportedOperationException();
}
@Override
public int getAmount() {
return 0;
@@ -296,7 +331,9 @@ public interface ILabel {
abstract class Impl implements ILabel {
public static final String KEY_AMOUNT = "amount";
public static final String KEY_PERCENT = "percent";
protected int amount;
protected boolean percent;
@Override
public String toString() {
@@ -305,14 +342,17 @@ public interface ILabel {
public Impl(int amount) {
this.amount = amount;
percent = false;
}
public Impl(Impl lsa) {
this(lsa.amount);
amount = lsa.amount;
percent = lsa.percent;
}
public Impl(NBTTagCompound nbt) {
amount = nbt.getInteger(KEY_AMOUNT);
percent = nbt.getBoolean(KEY_PERCENT);
}
protected int getMultiplier() {
@@ -335,7 +375,8 @@ public interface ILabel {
@Override
public ILabel decreaseAmount() {
if (getAmount() <= getMultiplier()) return ILabel.EMPTY;
if (getAmount() <= getMultiplier())
return ILabel.EMPTY;
else {
setAmount(getAmount() - getMultiplier());
return this;
@@ -343,23 +384,32 @@ public interface ILabel {
}
@Override
public ILabel invertAmount() {
setAmount(-getAmount());
public ILabel multiply(int i) {
setAmount(i * getAmount());
return this;
}
@Override
@SideOnly(Side.CLIENT)
public void getToolTip(List<String> existing, boolean detailed) {
if (detailed) existing.add(FORMAT_GREY +
Utilities.I18n.format("label.common.tooltip.amount", getAmountString()));
if (detailed)
existing.add(FORMAT_GREY + Utilities.I18n.format("label.common.tooltip.amount", getAmountString()));
}
@Override
public NBTTagCompound toNBTTagCompound() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger(KEY_AMOUNT, amount);
return nbt;
protected static Optional<ILabel> merge(Impl a, Impl b, boolean add) {
Impl ret = a.copy();
boolean p = a.percent || b.percent;
int amountA = a.amount;
int amountB = b.amount;
if (p) {
if (!a.percent)
amountA *= 100;
if (!b.percent)
amountB *= 100;
}
ret.amount = add ? amountA + amountB : amountA - amountB;
ret.percent = p;
return Optional.of(ret.amount == 0 ? ILabel.EMPTY : ret);
}
@Override
@@ -369,15 +419,36 @@ public interface ILabel {
@Override
public ILabel setAmount(int amount) {
if (amount == 0) return ILabel.EMPTY;
if (amount == 0)
return ILabel.EMPTY;
this.amount = amount;
return this;
}
@Override
@SideOnly(Side.CLIENT)
public String getAmountString() {
return getAmount() == 0 ? "" : Utilities.cutNumber(getAmount(), 5);
public NBTTagCompound toNBTTagCompound() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger(KEY_AMOUNT, amount);
nbt.setBoolean(KEY_PERCENT, percent);
return nbt;
}
@Override
public boolean acceptPercent() {
return true;
}
public ILabel setPercent(boolean p) {
if (!acceptPercent())
throw new UnsupportedOperationException();
if (p && !percent) {
amount *= 100;
percent = true;
} else if (!p && percent) {
amount = (amount + 99) / 100;
percent = false;
}
return this;
}
@Override
@@ -385,6 +456,22 @@ public interface ILabel {
return obj instanceof Impl && amount == ((Impl) obj).amount && matches(obj);
}
@Override
@SideOnly(Side.CLIENT)
public String getAmountString() {
return getAmount() == 0 ?
"" :
(percent ? Utilities.cutNumber(getAmount(), 4) + "%" : Utilities.cutNumber(getAmount(), 5));
}
@Override
abstract public Impl copy();
@Override
public boolean matches(Object l) {
return l instanceof Impl && percent == ((Impl) l).percent;
}
abstract protected void drawLabel(JecaGui gui);
}
}
@@ -30,6 +30,11 @@ public class LFluidStack extends ILabel.Impl {
NBTTagCompound nbt;
FluidStack temp;
@Override
public boolean acceptPercent() {
return false;
}
public LFluidStack(FluidStack fs) {
this(fs.amount, fs.getFluid(), fs.tag);
}
@@ -88,7 +93,7 @@ public class LFluidStack extends ILabel.Impl {
}
@Override
public ILabel copy() {
public LFluidStack copy() {
return new LFluidStack(this);
}
@@ -4,11 +4,11 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -16,6 +16,8 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE;
/**
* Author: towdium
* Date: 8/11/17.
@@ -26,10 +28,17 @@ public class LItemStack extends ILabel.Impl {
public static final String KEY_ITEM = "item";
public static final String KEY_META = "meta";
public static final String KEY_NBT = "nbt";
public static final String KEY_FUZZY = "fuzzy";
public static final byte FUZZY_META = 0x1;
public static final byte FUZZY_CAP = 0x2;
public static final byte FUZZY_NBT = 0x4;
Item item;
int meta;
NBTTagCompound nbt;
boolean fMeta;
boolean fNbt;
boolean fCap;
transient ItemStack temp;
public LItemStack(int amount, Item item, int meta, @Nullable NBTTagCompound nbt) {
@@ -49,6 +58,7 @@ public class LItemStack extends ILabel.Impl {
public LItemStack(NBTTagCompound nbt) {
this(nbt.getInteger(KEY_AMOUNT), Objects.requireNonNull(Item.getItemById(nbt.getInteger(KEY_ITEM))),
nbt.getInteger(KEY_META), nbt.hasKey(KEY_NBT) ? nbt.getCompoundTag(KEY_NBT) : null);
fromFuzzy(nbt.getByte(KEY_FUZZY));
}
private LItemStack(LItemStack lis) {
@@ -65,18 +75,44 @@ public class LItemStack extends ILabel.Impl {
if (a instanceof LItemStack && b instanceof LItemStack) {
LItemStack lisA = (LItemStack) a;
LItemStack lisB = (LItemStack) b;
boolean wildcard = lisA.meta == OreDictionary.WILDCARD_VALUE || lisB.meta == OreDictionary.WILDCARD_VALUE;
if ((Objects.equals(lisA.nbt, lisB.nbt)) && (lisA.meta == lisB.meta || wildcard)) {
LItemStack ret = new LItemStack(lisA);
if (wildcard)
ret.meta = OreDictionary.WILDCARD_VALUE;
ret.amount = add ? lisA.amount + lisB.amount : lisA.amount - lisB.amount;
return Optional.of(ret.amount == 0 ? ILabel.EMPTY : ret);
// check meta
int resultMeta = 0;
boolean checkedMeta = true;
if (lisA.meta == WILDCARD_VALUE || lisB.meta == WILDCARD_VALUE)
resultMeta = WILDCARD_VALUE;
else if (lisA.fMeta || lisB.fMeta || lisA.meta == lisB.meta)
resultMeta = lisA.meta;
else
checkedMeta = false;
// check nbt and cap
boolean checkedNbt = (Objects.equals(lisA.nbt, lisB.nbt)) || lisA.fNbt || lisB.fNbt;
if (lisA.item == lisB.item && checkedMeta && checkedNbt) {
LItemStack is = lisA.copy();
is.meta = resultMeta;
return Impl.merge(is, lisB, add);
}
}
return Optional.empty();
}
public ILabel setFMeta(boolean f) {
fMeta = f;
return this;
}
public ILabel setFNbt(boolean f) {
fNbt = f;
return this;
}
public ILabel setFCap(boolean f) {
fCap = f;
return this;
}
public ItemStack getRep() {
return temp;
}
@@ -103,13 +139,15 @@ public class LItemStack extends ILabel.Impl {
public boolean matches(Object l) {
if (l instanceof LItemStack) {
LItemStack lis = (LItemStack) l;
return (Objects.equals(nbt, lis.nbt)) && meta == lis.meta && item == lis.item;
return (Objects.equals(nbt, lis.nbt)) && meta == lis.meta && item == lis.item
&& fNbt == lis.fNbt && super.matches(l)
&& fCap == lis.fCap && fMeta == lis.fMeta;
} else
return false;
}
@Override
public ILabel copy() {
public LItemStack copy() {
return new LItemStack(this);
}
@@ -123,13 +161,28 @@ public class LItemStack extends ILabel.Impl {
ret.setInteger(KEY_ITEM, id);
if (nbt != null)
ret.setTag(KEY_NBT, nbt);
ret.setByte(KEY_FUZZY, toFuzzy());
return ret;
}
private byte toFuzzy() {
return (byte) ((fMeta ? FUZZY_META : 0) | (fCap ? FUZZY_CAP : 0) | (fNbt ? FUZZY_NBT : 0));
}
private void fromFuzzy(byte i) {
fMeta = (i & FUZZY_META) != 0;
fCap = (i & FUZZY_CAP) != 0;
fNbt = (i & FUZZY_NBT) != 0;
}
@Override
@SideOnly(Side.CLIENT)
public void drawLabel(JecaGui gui) {
gui.drawItemStack(0, 0, temp, false);
if (fCap || fNbt || fMeta) gui.drawResource(Resource.LBL_FRAME, 0, 0);
if (fCap) gui.drawResource(Resource.LBL_FR_LL, 0, 0);
if (fNbt) gui.drawResource(Resource.LBL_FR_UL, 0, 0);
if (fMeta) gui.drawResource(Resource.LBL_FR_UR, 0, 0);
}
@Override
@@ -59,13 +59,27 @@ public class LOreDict extends ILabel.Impl {
return Utilities.I18n.format("label.ore_dict.name", name);
}
public static Optional<ILabel> mergeOreDict(ILabel a, ILabel b, boolean add) {
public static Optional<ILabel> merge(ILabel a, ILabel b, boolean add) {
if (a instanceof LOreDict && b instanceof LOreDict) {
LOreDict lodA = (LOreDict) a;
LOreDict lodB = (LOreDict) b;
if (lodA.getName().equals(lodB.getName()))
return Optional.of(new LOreDict(lodA.getName(),
add ? lodA.getAmount() + lodB.getAmount() : lodA.getAmount() - lodB.getAmount()));
if (lodA.getName().equals(lodB.getName())) {
return Impl.merge(lodA, lodB, add);
}
} else if ((a instanceof LOreDict && b instanceof LItemStack)
|| a instanceof LItemStack && b instanceof LOreDict) {
LItemStack lis;
LOreDict lor;
if (a instanceof LOreDict) {
lis = (LItemStack) b;
lor = (LOreDict) a;
} else {
lis = (LItemStack) a;
lor = (LOreDict) b;
}
return OreDictionary.getOres(lor.name).stream().map(o -> Converter.from(o).multiply(lor.amount))
.map(i -> LItemStack.merge(i, lis, add)).filter(Optional::isPresent)
.findAny().flatMap(i -> i);
}
return Optional.empty();
}
@@ -126,7 +140,7 @@ public class LOreDict extends ILabel.Impl {
@Override
public boolean matches(Object l) {
return l instanceof LOreDict && name.equals(((LOreDict) l).name);
return l instanceof LOreDict && name.equals(((LOreDict) l).name) && super.matches(l);
}
@Override
@@ -145,7 +159,7 @@ public class LOreDict extends ILabel.Impl {
});
if(list.isEmpty()) return;
long index = System.currentTimeMillis() / 1500;
gui.drawResource(Resource.LBL_ORE_DICT, 0, 0);
gui.drawResource(Resource.LBL_FRAME, 0, 0);
GlStateManager.pushMatrix();
GlStateManager.translate(1, 1, 0);
GlStateManager.scale(14f / 16, 14f / 16, 1);
@@ -90,11 +90,11 @@ public class LPlaceholder extends ILabel.Impl {
@Override
public boolean matches(Object l) {
return l instanceof LPlaceholder && name.equals(((LPlaceholder) l).name);
return l instanceof LPlaceholder && name.equals(((LPlaceholder) l).name) && super.matches(l);
}
@Override
public ILabel copy() {
public LPlaceholder copy() {
return new LPlaceholder(this);
}
@@ -1,78 +0,0 @@
package me.towdium.jecalculation.data.label.labels;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-9-28.
*/
@ParametersAreNonnullByDefault
public class LString extends ILabel.Impl {
public static final String KEY_NAME = "name";
public static final String IDENTIFIER = "string";
String name;
public LString(NBTTagCompound tag) {
super(tag);
this.name = tag.getString(KEY_NAME);
}
public LString(String name, int amount) {
super(amount);
this.name = name;
}
public LString(LString label) {
super(label);
name = label.name;
}
@Override
@SideOnly(Side.CLIENT)
public String getDisplayName() {
return Utilities.I18n.format("label.universal.name", name);
}
@Override
public String getIdentifier() {
return "string";
}
@Override
public boolean matches(Object l) {
return l instanceof LString && name.equals(((LString) l).name);
}
@Override
public ILabel copy() {
return new LString(this);
}
@Override
public NBTTagCompound toNBTTagCompound() {
NBTTagCompound nbt = super.toNBTTagCompound();
nbt.setString(KEY_NAME, name);
return nbt;
}
@Override
@SideOnly(Side.CLIENT)
public void drawLabel(JecaGui gui) {
gui.drawResource(Resource.LBL_UNIV_B, 0, 0);
gui.drawResource(Resource.LBL_UNIV_F, 0, 0, (name.hashCode() * 0x131723) & 0xFFFFFF);
}
@Override
public int hashCode() {
return name.hashCode() ^ amount;
}
}
@@ -109,6 +109,11 @@ public class Recipe {
return Arrays.stream(getLabel(type)).anyMatch(i -> ILabel.MERGER.merge(label, i, true).isPresent());
}
public int multiplier(ILabel label, enumIoType type) {
return Arrays.stream(getLabel(type)).filter(i -> ILabel.MERGER.merge(label, i, true).isPresent()).findAny()
.map(i -> (i.getAmount() + Math.abs(label.getAmount()) - 1) / i.getAmount()).orElse(0);
}
public enum enumIoType {
INPUT, OUTPUT, CATALYST;
@@ -16,40 +16,57 @@ import javax.annotation.ParametersAreNonnullByDefault;
public class Resource {
public static final ResourceLocation location = new ResourceLocation(
JustEnoughCalculation.Reference.MODID, "textures/gui/resources.png");
public static final Resource BTN_LABEL_N = new Resource(0, 14, 14, 14);
public static final Resource BTN_LABEL_F = new Resource(0, 0, 14, 14);
public static final Resource BTN_NEW_N = new Resource(14, 14, 14, 14);
public static final Resource BTN_NEW_F = new Resource(14, 0, 14, 14);
public static final Resource BTN_SEARCH_N = new Resource(28, 14, 14, 14);
public static final Resource BTN_SEARCH_F = new Resource(28, 0, 14, 14);
public static final Resource BTN_SAVE_N = new Resource(42, 14, 14, 14);
public static final Resource BTN_SAVE_F = new Resource(42, 0, 14, 14);
public static final Resource BTN_COPY_N = new Resource(56, 14, 14, 14);
public static final Resource BTN_COPY_F = new Resource(56, 0, 14, 14);
public static final Resource BTN_COPY_D = new Resource(242, 14, 14, 14);
public static final Resource BTN_DEL_N = new Resource(70, 14, 14, 14);
public static final Resource BTN_DEL_F = new Resource(70, 0, 14, 14);
public static final Resource BTN_YES_N = new Resource(84, 14, 14, 14);
public static final Resource BTN_YES_F = new Resource(84, 0, 14, 14);
public static final Resource BTN_YES_D = new Resource(228, 14, 14, 14);
public static final Resource BTN_NO_N = new Resource(98, 14, 14, 14);
public static final Resource BTN_NO_F = new Resource(98, 0, 14, 14);
public static final Resource BTN_NO_D = new Resource(228, 0, 14, 14);
public static final Resource BTN_DISAMB_N = new Resource(112, 14, 14, 14);
public static final Resource BTN_DISAMB_F = new Resource(112, 0, 14, 14);
public static final Resource BTN_DISAMB_D = new Resource(242, 0, 14, 14);
public static final Resource BTN_IN_N = new Resource(126, 14, 14, 14);
public static final Resource BTN_IN_F = new Resource(126, 0, 14, 14);
public static final Resource BTN_IN_D = new Resource(200, 0, 14, 14);
public static final Resource BTN_OUT_N = new Resource(140, 14, 14, 14);
public static final Resource BTN_OUT_F = new Resource(140, 0, 14, 14);
public static final Resource BTN_OUT_D = new Resource(214, 0, 14, 14);
public static final Resource BTN_CAT_N = new Resource(154, 14, 14, 14);
public static final Resource BTN_CAT_F = new Resource(154, 0, 14, 14);
public static final Resource BTN_CAT_D = new Resource(200, 14, 14, 14);
public static final Resource BTN_LIST_N = new Resource(168, 14, 14, 14);
public static final Resource BTN_LIST_F = new Resource(168, 0, 14, 14);
public static final Resource BTN_LIST_D = new Resource(214, 14, 14, 14);
// letters abbr for button & icon: N - normal, F - focused, D - disabled
// letters abbr for fuzzy related: N - normal, F - fuzzy
public static final Resource BTN_LABEL_N = getIcon(0, 1);
public static final Resource BTN_LABEL_F = getIcon(0, 0);
public static final Resource BTN_NEW_N = getIcon(1, 1);
public static final Resource BTN_NEW_F = getIcon(1, 0);
public static final Resource BTN_SEARCH_N = getIcon(2, 1);
public static final Resource BTN_SEARCH_F = getIcon(2, 0);
public static final Resource BTN_SAVE_N = getIcon(3, 1);
public static final Resource BTN_SAVE_F = getIcon(3, 0);
public static final Resource BTN_COPY_N = getIcon(4, 1);
public static final Resource BTN_COPY_F = getIcon(4, 0);
public static final Resource BTN_COPY_D = getIcon(4, 2);
public static final Resource BTN_DEL_N = getIcon(5, 1);
public static final Resource BTN_DEL_F = getIcon(5, 0);
public static final Resource BTN_YES_N = getIcon(6, 1);
public static final Resource BTN_YES_F = getIcon(6, 0);
public static final Resource BTN_YES_D = getIcon(6, 2);
public static final Resource BTN_NO_N = getIcon(7, 1);
public static final Resource BTN_NO_F = getIcon(7, 0);
public static final Resource BTN_NO_D = getIcon(7, 2);
public static final Resource BTN_DISAMB_N = getIcon(8, 1);
public static final Resource BTN_DISAMB_F = getIcon(8, 0);
public static final Resource BTN_DISAMB_D = getIcon(8, 2);
public static final Resource BTN_IN_N = getIcon(9, 1);
public static final Resource BTN_IN_F = getIcon(9, 0);
public static final Resource BTN_IN_D = getIcon(9, 2);
public static final Resource BTN_OUT_N = getIcon(10, 1);
public static final Resource BTN_OUT_F = getIcon(10, 0);
public static final Resource BTN_OUT_D = getIcon(10, 2);
public static final Resource BTN_CAT_N = getIcon(11, 1);
public static final Resource BTN_CAT_F = getIcon(11, 0);
public static final Resource BTN_CAT_D = getIcon(11, 2);
public static final Resource BTN_LIST_N = getIcon(12, 1);
public static final Resource BTN_LIST_F = getIcon(12, 0);
public static final Resource BTN_LIST_D = getIcon(12, 2);
public static final Resource BTN_META_N_N = getIcon(14, 0);
public static final Resource BTN_META_N_F = getIcon(13, 0);
public static final Resource BTN_META_F_N = getIcon(16, 0);
public static final Resource BTN_META_F_F = getIcon(15, 0);
public static final Resource BTN_META_D = getIcon(17, 0);
public static final Resource BTN_NBT_N_N = getIcon(14, 1);
public static final Resource BTN_NBT_N_F = getIcon(13, 1);
public static final Resource BTN_NBT_F_N = getIcon(16, 1);
public static final Resource BTN_NBT_F_F = getIcon(15, 1);
public static final Resource BTN_NBT_D = getIcon(17, 1);
public static final Resource BTN_CAP_N_N = getIcon(14, 2);
public static final Resource BTN_CAP_N_F = getIcon(13, 2);
public static final Resource BTN_CAP_F_N = getIcon(16, 2);
public static final Resource BTN_CAP_F_F = getIcon(15, 2);
public static final Resource BTN_CAP_D = getIcon(17, 2);
public static final Resource WGT_BUTTON_N = new Resource(40, 232, 20, 20);
public static final Resource WGT_BUTTON_F = new Resource(60, 232, 20, 20);
public static final Resource WGT_BUTTON_D = new Resource(80, 232, 20, 20);
@@ -66,30 +83,66 @@ public class Resource {
public static final Resource WGT_ARR_R_N = new Resource(167, 242, 7, 9);
public static final Resource WGT_ARR_R_D = new Resource(174, 242, 7, 9);
public static final Resource WGT_SCROLL = new Resource(181, 232, 12, 15);
public static final Resource ICN_RECENT_N = new Resource(0, 42, 14, 14);
public static final Resource ICN_RECENT_F = new Resource(0, 28, 14, 14);
public static final Resource ICN_INPUT_N = new Resource(14, 42, 14, 14);
public static final Resource ICN_INPUT_F = new Resource(14, 28, 14, 14);
public static final Resource ICN_OUTPUT_N = new Resource(28, 42, 14, 14);
public static final Resource ICN_OUTPUT_F = new Resource(28, 28, 14, 14);
public static final Resource ICN_CATALYST_N = new Resource(42, 42, 14, 14);
public static final Resource ICN_CATALYST_F = new Resource(42, 28, 14, 14);
public static final Resource ICN_LIST_N = new Resource(56, 42, 14, 14);
public static final Resource ICN_LIST_F = new Resource(56, 28, 14, 14);
public static final Resource ICN_LABEL_N = new Resource(70, 42, 14, 14);
public static final Resource ICN_LABEL_F = new Resource(70, 28, 14, 14);
public static final Resource ICN_HELP_N = new Resource(84, 42, 14, 14);
public static final Resource ICN_HELP_F = new Resource(84, 28, 14, 14);
public static final Resource ICN_STACK_N = new Resource(98, 42, 14, 14);
public static final Resource ICN_STACK_F = new Resource(98, 28, 14, 14);
public static final Resource ICN_TEXT_N = new Resource(112, 42, 14, 14);
public static final Resource ICN_TEXT_F = new Resource(112, 28, 14, 14);
public static final Resource ICN_MULTI_N = new Resource(126, 42, 14, 14);
public static final Resource ICN_MULTI_F = new Resource(126, 28, 14, 14);
public static final Resource LBL_ORE_DICT = new Resource(0, 56, 16, 16);
public static final Resource LBL_FLUID = new Resource(16, 56, 16, 16);
public static final Resource LBL_UNIV_B = new Resource(32, 56, 16, 16);
public static final Resource LBL_UNIV_F = new Resource(48, 56, 16, 16);
public static final Resource ICN_RECENT_N = getIcon(0, 4);
public static final Resource ICN_RECENT_F = getIcon(0, 3);
public static final Resource ICN_INPUT_N = getIcon(1, 4);
public static final Resource ICN_INPUT_F = getIcon(1, 3);
public static final Resource ICN_OUTPUT_N = getIcon(2, 4);
public static final Resource ICN_OUTPUT_F = getIcon(2, 3);
public static final Resource ICN_CATALYST_N = getIcon(3, 4);
public static final Resource ICN_CATALYST_F = getIcon(3, 3);
public static final Resource ICN_LIST_N = getIcon(4, 4);
public static final Resource ICN_LIST_F = getIcon(4, 3);
public static final Resource ICN_LABEL_N = getIcon(5, 4);
public static final Resource ICN_LABEL_F = getIcon(5, 3);
public static final Resource ICN_HELP_N = getIcon(6, 4);
public static final Resource ICN_HELP_F = getIcon(6, 3);
public static final Resource ICN_STACK_N = getIcon(7, 4);
public static final Resource ICN_STACK_F = getIcon(7, 3);
public static final Resource ICN_TEXT_N = getIcon(8, 4);
public static final Resource ICN_TEXT_F = getIcon(8, 3);
public static final Resource ICN_MULTI_N = getIcon(9, 4);
public static final Resource ICN_MULTI_F = getIcon(9, 3);
public static final Resource LBL_FRAME = getLabel(0);
public static final Resource LBL_FLUID = getLabel(1);
public static final Resource LBL_UNIV_B = getLabel(2);
public static final Resource LBL_UNIV_F = getLabel(3);
public static final Resource LBL_FR_UL = getLabel(4);
public static final Resource LBL_FR_UR = getLabel(5);
public static final Resource LBL_FR_LL = getLabel(6);
public static final ResourceGroup BTN_LABEL = new ResourceGroup(BTN_LABEL_N, BTN_LABEL_F);
public static final ResourceGroup BTN_NEW = new ResourceGroup(BTN_NEW_N, BTN_NEW_F);
public static final ResourceGroup BTN_SEARCH = new ResourceGroup(BTN_SEARCH_N, BTN_SEARCH_F);
public static final ResourceGroup BTN_SAVE = new ResourceGroup(BTN_SAVE_N, BTN_SAVE_F);
public static final ResourceGroup BTN_COPY = new ResourceGroup(BTN_COPY_N, BTN_COPY_F, BTN_COPY_D);
public static final ResourceGroup BTN_DEL = new ResourceGroup(BTN_DEL_N, BTN_DEL_F);
public static final ResourceGroup BTN_YES = new ResourceGroup(BTN_YES_N, BTN_YES_F, BTN_YES_D);
public static final ResourceGroup BTN_NO = new ResourceGroup(BTN_NO_N, BTN_NO_F, BTN_NO_D);
public static final ResourceGroup BTN_DISAMB = new ResourceGroup(BTN_DISAMB_N, BTN_DISAMB_F, BTN_DISAMB_D);
public static final ResourceGroup BTN_IN = new ResourceGroup(BTN_IN_N, BTN_IN_F, BTN_IN_D);
public static final ResourceGroup BTN_OUT = new ResourceGroup(BTN_OUT_N, BTN_OUT_F, BTN_OUT_D);
public static final ResourceGroup BTN_CAT = new ResourceGroup(BTN_CAT_N, BTN_CAT_F, BTN_CAT_D);
public static final ResourceGroup BTN_LIST = new ResourceGroup(BTN_LIST_N, BTN_LIST_F, BTN_LIST_D);
public static final ResourceGroup BTN_META_N = new ResourceGroup(BTN_META_N_N, BTN_META_N_F, BTN_META_D);
public static final ResourceGroup BTN_CAP_N = new ResourceGroup(BTN_CAP_N_N, BTN_CAP_N_F, BTN_CAP_D);
public static final ResourceGroup BTN_NBT_N = new ResourceGroup(BTN_NBT_N_N, BTN_NBT_N_F, BTN_NBT_D);
public static final ResourceGroup BTN_META_F = new ResourceGroup(BTN_META_F_N, BTN_META_F_F, BTN_META_D);
public static final ResourceGroup BTN_CAP_F = new ResourceGroup(BTN_CAP_F_N, BTN_CAP_F_F, BTN_CAP_D);
public static final ResourceGroup BTN_NBT_F = new ResourceGroup(BTN_NBT_F_N, BTN_NBT_F_F, BTN_NBT_D);
public static final ResourceGroup WGT_ARR_L = new ResourceGroup(WGT_ARR_L_N, WGT_ARR_L_F, WGT_ARR_L_D);
public static final ResourceGroup WGT_ARR_R = new ResourceGroup(WGT_ARR_R_N, WGT_ARR_R_F, WGT_ARR_R_D);
public static final ResourceGroup ICN_RECENT = new ResourceGroup(ICN_RECENT_N, ICN_RECENT_F);
public static final ResourceGroup ICN_INPUT = new ResourceGroup(ICN_INPUT_N, ICN_INPUT_F);
public static final ResourceGroup ICN_OUTPUT = new ResourceGroup(ICN_OUTPUT_N, ICN_OUTPUT_F);
public static final ResourceGroup ICN_CATALYST = new ResourceGroup(ICN_CATALYST_N, ICN_CATALYST_F);
public static final ResourceGroup ICN_LIST = new ResourceGroup(ICN_LIST_N, ICN_LIST_F);
public static final ResourceGroup ICN_LABEL = new ResourceGroup(ICN_LABEL_N, ICN_LABEL_F);
public static final ResourceGroup ICN_HELP = new ResourceGroup(ICN_HELP_N, ICN_HELP_F);
public static final ResourceGroup ICN_STACK = new ResourceGroup(ICN_STACK_N, ICN_STACK_F);
public static final ResourceGroup ICN_TEXT = new ResourceGroup(ICN_TEXT_N, ICN_TEXT_F);
public static final ResourceGroup ICN_MULTI = new ResourceGroup(ICN_MULTI_N, ICN_MULTI_F);
protected int xPos, yPos, xSize, ySize;
protected ResourceLocation rl;
@@ -124,4 +177,29 @@ public class Resource {
public ResourceLocation getResourceLocation() {
return rl;
}
private static Resource getIcon(int x, int y) {
return new Resource(x * 14, y * 14, 14, 14);
}
private static Resource getLabel(int x) {
return new Resource(x * 16, 70, 16, 16);
}
public static class ResourceGroup {
public Resource normal;
public Resource focused;
public Resource disabled;
public ResourceGroup(Resource normal, Resource focused, Resource disabled) {
this.normal = normal;
this.focused = focused;
this.disabled = disabled;
}
public ResourceGroup(Resource normal, Resource focused) {
this.normal = normal;
this.focused = focused;
}
}
}
@@ -30,12 +30,12 @@ public abstract class WButton extends WTooltip {
this.ySize = ySize;
}
public WButton setListenerLeft(Runnable r) {
public WButton setLsnrLeft(Runnable r) {
lsnrLeft = r;
return this;
}
public WButton setListenerRight(Runnable r) {
public WButton setLsnrRight(Runnable r) {
lsnrRight = r;
return this;
}
@@ -20,20 +20,16 @@ import java.util.List;
public class WButtonIcon extends WButton {
protected Resource rNormal, rFocused, rDisabled;
public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
this(xPos, yPos, xSize, ySize, normal, focused, null, null);
public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource.ResourceGroup res, String name) {
this(xPos, yPos, xSize, ySize, res.normal, res.focused, res.disabled, name);
}
public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused, String name) {
this(xPos, yPos, xSize, ySize, normal, focused, null, name);
public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource.ResourceGroup res) {
this(xPos, yPos, xSize, ySize, res.normal, res.focused, res.disabled, null);
}
public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused, Resource disabled) {
this(xPos, yPos, xSize, ySize, normal, focused, disabled, null);
}
public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused,
@Nullable Resource disabled, @Nullable String name) {
private WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused,
@Nullable Resource disabled, @Nullable String name) {
super(xPos, yPos, xSize, ySize, name);
this.rNormal = normal;
this.rFocused = focused;
@@ -19,12 +19,16 @@ public class WIcon extends WTooltip {
public int xPos, yPos, xSize, ySize;
public Resource normal, focused;
public WIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
this(xPos, yPos, xSize, ySize, normal, focused, null);
public WIcon(int xPos, int yPos, int xSize, int ySize, Resource.ResourceGroup res) {
this(xPos, yPos, xSize, ySize, res.normal, res.focused, null);
}
public WIcon(int xPos, int yPos, int xSize, int ySize,
Resource normal, Resource focused, @Nullable String name) {
public WIcon(int xPos, int yPos, int xSize, int ySize, Resource.ResourceGroup res, String name) {
this(xPos, yPos, xSize, ySize, res.normal, res.focused, name);
}
private WIcon(int xPos, int yPos, int xSize, int ySize,
Resource normal, Resource focused, @Nullable String name) {
super(name);
this.xPos = xPos;
this.yPos = yPos;
@@ -49,8 +49,6 @@ public class WLabel implements IWidget {
public void setLabel(ILabel label) {
this.label = label;
// if (mode == enumMode.EDITOR || mode == enumMode.SELECTOR)
// notifyLsnr();
}
@Override
@@ -185,17 +183,15 @@ public class WLabel implements IWidget {
WLabel wl = new WLabel(w.xPos, w.yPos, w.xSize, w.ySize, enumMode.SELECTOR);
wl.setLabel(w.getLabel());
WTextField wtf = new WTextField(xAlign + 10, w.yPos + w.ySize / 2 - WTextField.HEIGHT / 2, 50);
WButton wby = new WButtonIcon(xAlign + 60, w.yPos, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F,
Resource.BTN_YES_D).setListenerLeft(() -> {
WButton wby = new WButtonIcon(xAlign + 60, w.yPos, 20, 20, Resource.BTN_YES).setLsnrLeft(() -> {
w.setLabel(wl.getLabel().setAmount(
wtf.getText().isEmpty() ? 0 : Integer.parseInt(wtf.getText())));
JecaGui.getCurrent().root.remove(this);
});
WButton wbn = new WButtonIcon(xAlign + 79, w.yPos, 20, 20, Resource.BTN_NO_N, Resource.BTN_NO_F)
.setListenerLeft(() -> {
w.setLabel(ILabel.EMPTY);
JecaGui.getCurrent().root.remove(this);
});
WButton wbn = new WButtonIcon(xAlign + 79, w.yPos, 20, 20, Resource.BTN_NO).setLsnrLeft(() -> {
w.setLabel(ILabel.EMPTY);
JecaGui.getCurrent().root.remove(this);
});
wtf.setText(Integer.toString(w.getLabel().getAmount()));
wtf.setLsnrText(i -> {
try {
@@ -57,8 +57,12 @@ public class WLabelGroup extends WContainer {
return labels.stream().map(WLabel::getLabel).collect(Collectors.toList());
}
public void setLabel(ILabel label, int index) {
labels.get(index).setLabel(label);
}
public void setLabel(List<ILabel> labels, int start) {
Wrapper<Integer> i = new Wrapper<>(start);
Wrapper<Integer> i = new Wrapper<>(start); // TODO simplify
this.labels.forEach(l -> l.setLabel(i.value < labels.size() ? labels.get(i.value++) : ILabel.EMPTY));
}
@@ -41,19 +41,13 @@ 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(() -> {
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(() -> {
if (temp == null)
move(true);
else
setTemp(null);
left = new WButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WGT_ARR_L).setLsnrLeft(() -> {
if (temp == null) move(false);
else setTemp(null);
});
right = new WButtonIcon(xPos + xSize - SIZE, yPos, SIZE, SIZE, Resource.WGT_ARR_R).setLsnrLeft(() -> {
if (temp == null) move(true);
else setTemp(null);
});
wRect = new WRectangle(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecaGui.COLOR_GUI_GREY);
wText = new WText(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecaGui.Font.DEFAULT_SHADOW,
@@ -2,6 +2,7 @@ package me.towdium.jecalculation.gui.guis;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.algorithm.CostList;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.gui.drawables.*;
@@ -9,6 +10,7 @@ import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.Controller;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
/**
@@ -18,52 +20,95 @@ import java.util.List;
@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);
WButton btnSteps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST_N, Resource.BTN_LIST_F,
Resource.BTN_LIST_D, "calculator.step").setListenerLeft(() -> setMode(enumMode.STEPS));
WButton btnCatalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT_N, Resource.BTN_CAT_F,
Resource.BTN_CAT_D, "calculator.catalyst").setListenerLeft(() -> setMode(enumMode.CATALYST));
WButton btnOutput = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT_N, Resource.BTN_OUT_F,
Resource.BTN_OUT_D, "calculator.output").setListenerLeft(() -> setMode(enumMode.OUTPUT));
WButton btnInput = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN_N, Resource.BTN_IN_F,
Resource.BTN_IN_D, "calculator.input").setListenerLeft(() -> setMode(enumMode.INPUT));
enumMode mode = enumMode.INPUT;
CostList.Calculator calculator = null;
WLabelGroup lgRecent = new WLabelGroup(7, 31, 8, 1, WLabel.enumMode.PICKER);
WLabel lLabel = new WLabel(31, 7, 20, 20, WLabel.enumMode.SELECTOR);
WLabelScroll lsResult = new WLabelScroll(7, 87, 8, 4, WLabel.enumMode.RESULT, true);
WButton btnSteps = new WButtonIcon(64, 62, 20, 20, Resource.BTN_LIST, "calculator.step")
.setLsnrLeft(() -> setMode(enumMode.STEPS));
WButton btnCatalyst = new WButtonIcon(45, 62, 20, 20, Resource.BTN_CAT, "calculator.catalyst")
.setLsnrLeft(() -> setMode(enumMode.CATALYST));
WButton btnOutput = new WButtonIcon(26, 62, 20, 20, Resource.BTN_OUT, "calculator.output")
.setLsnrLeft(() -> setMode(enumMode.OUTPUT));
WButton btnInput = new WButtonIcon(7, 62, 20, 20, Resource.BTN_IN, "calculator.input")
.setLsnrLeft(() -> setMode(enumMode.INPUT));
WTextField tfAmount = new WTextField(60, 7, 65);
public GuiCalculator() {
wLabel.setLsnrUpdate(() -> {
Controller.setRecent(wLabel.label);
lLabel.setLsnrUpdate(() -> {
Controller.setRecent(lLabel.label);
refreshRecent();
refreshCalculator();
});
wRecent.setLsnrUpdate(l -> JecaGui.getCurrent().hand = wRecent.getLabelAt(l));
lgRecent.setLsnrUpdate(l -> JecaGui.getCurrent().hand = lgRecent.getLabelAt(l));
tfAmount.setLsnrText(s -> refreshCalculator());
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(() -> JecaGui.displayGui(new GuiLabel(l -> {
add(new WButtonIcon(7, 7, 20, 20, Resource.BTN_LABEL, "calculator.label")
.setLsnrLeft(() -> JecaGui.displayGui(new GuiLabel(l -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
}))));
add(new WButtonIcon(130, 7, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "calculator.recipe")
.setListenerLeft(() -> JecaGui.displayGui(true, true, new GuiRecipe())));
add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH_N, Resource.BTN_SEARCH_F, "calculator.search")
.setListenerLeft(() -> JecaGui.displayGui(new GuiSearch())));
add(new WButtonIcon(130, 7, 20, 20, Resource.BTN_NEW, "calculator.recipe")
.setLsnrLeft(() -> JecaGui.displayGui(true, true, new GuiRecipe())));
add(new WButtonIcon(149, 7, 20, 20, Resource.BTN_SEARCH, "calculator.search")
.setLsnrLeft(() -> JecaGui.displayGui(new GuiSearch())));
add(new WText(53, 13, JecaGui.Font.DEFAULT_NO_SHADOW, "x"));
add(new WLine(55));
add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT_N, Resource.ICN_RECENT_F, "calculator.history"));
add(new WLabelScroll(7, 87, 8, 4, WLabel.enumMode.RESULT, true));
addAll(wRecent, wLabel, btnInput, btnOutput, btnCatalyst, btnSteps);
add(new WIcon(151, 31, 18, 18, Resource.ICN_RECENT, "calculator.history"));
addAll(lgRecent, lLabel, btnInput, btnOutput, btnCatalyst, btnSteps, lsResult, tfAmount);
refreshRecent();
setMode(enumMode.INPUT);
refreshCalculator();
}
void setMode(enumMode mode) {
this.mode = mode;
btnInput.setDisabled(mode == enumMode.INPUT);
btnOutput.setDisabled(mode == enumMode.OUTPUT);
btnCatalyst.setDisabled(mode == enumMode.CATALYST);
btnSteps.setDisabled(mode == enumMode.STEPS);
refreshResult();
}
void refreshRecent() {
List<ILabel> recent = Controller.getRecent();
if (recent.size() > 1) wRecent.setLabel(recent.subList(1, recent.size()), 0);
if (!recent.isEmpty()) lLabel.setLabel(recent.get(0));
if (recent.size() > 1) lgRecent.setLabel(recent.subList(1, recent.size()), 0);
}
void refreshCalculator() {
try {
String s = tfAmount.getText();
int i = s.isEmpty() ? 1 : Integer.parseInt(tfAmount.getText());
tfAmount.setColor(JecaGui.COLOR_TEXT_WHITE);
calculator = new CostList(lLabel.getLabel().copy().setAmount(i)).calculate();
} catch (NumberFormatException e) {
tfAmount.setColor(JecaGui.COLOR_TEXT_RED);
calculator = null;
}
refreshResult();
}
void refreshResult() {
if (calculator == null) {
lsResult.setLabels(new ArrayList<>());
} else {
switch (mode) {
case INPUT:
lsResult.setLabels(calculator.getInputs());
break;
case OUTPUT:
lsResult.setLabels(new ArrayList<>());
break;
case CATALYST:
lsResult.setLabels(calculator.getCatalysts());
break;
case STEPS:
lsResult.setLabels(new ArrayList<>());
break;
}
}
}
enum enumMode {
@@ -31,11 +31,11 @@ public class GuiDisambiguation extends IWPicker.Impl {
add(new WPanel());
add(switcher);
add(new WIcon(149, 24, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "disambiguation.help"));
add(new WIcon(7, 48, 18, 54, Resource.ICN_LIST_N, Resource.ICN_LIST_F, "disambiguation.list"));
add(new WIcon(7, 105, 18, 54, Resource.ICN_LABEL_N, Resource.ICN_LABEL_F, "disambiguation.label"));
add(new WIcon(149, 24, 20, 20, Resource.ICN_HELP, "disambiguation.help"));
add(new WIcon(7, 48, 18, 54, Resource.ICN_LIST, "disambiguation.list"));
add(new WIcon(7, 105, 18, 54, Resource.ICN_LABEL, "disambiguation.label"));
add(new WSearch(i -> {
if (callback != null) callback.accept(i);
if (callback != null) callback.accept(i.copy().increaseAmount());
}, tf, lsUp, lsDown));
setPage(0);
@@ -8,14 +8,13 @@ import me.towdium.jecalculation.data.structure.Recipe;
import me.towdium.jecalculation.gui.JecaGui;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.gui.drawables.*;
import me.towdium.jecalculation.nei.NEIPlugin;
import me.towdium.jecalculation.utils.Utilities;
import me.towdium.jecalculation.utils.wrappers.Pair;
import me.towdium.jecalculation.utils.wrappers.Triple;
import net.minecraft.item.ItemStack;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -28,66 +27,59 @@ public class GuiRecipe extends WContainer {
HashMap<Integer, List<ILabel>> disambiguation = new HashMap<>();
WSwitcher switcherGroup = new WSwitcher(7, 7, 162, Controller.getGroups());
WTextField textField = new WTextField(49, 33, 119);
WButton buttonCopy = new WButtonIcon(83, 33, 20, 20, Resource.BTN_COPY_N, Resource.BTN_COPY_F,
Resource.BTN_COPY_D, "recipe.copy").setDisabled(true).setListenerLeft(() -> {
WButton buttonCopy = new WButtonIcon(83, 33, 20, 20, Resource.BTN_COPY, "recipe.copy").setLsnrLeft(() -> {
Controller.addRecipe(switcherGroup.getText(), toRecipe());
JecaGui.displayParent();
});
WLabelGroup groupCatalyst = new WLabelGroup(28, 87, 7, 1, 20, 20, WLabel.enumMode.EDITOR);
WButton buttonDisamb = new WButtonIcon(121, 33, 20, 20, Resource.BTN_DISAMB_N,
Resource.BTN_DISAMB_F, Resource.BTN_DISAMB_D, "recipe.disamb").setDisabled(true).setListenerLeft(() -> {
WButton buttonDisamb = new WButtonIcon(121, 33, 20, 20, Resource.BTN_DISAMB, "recipe.disamb").setLsnrLeft(() -> {
if (disambiguation != null) JecaGui.displayGui(new GuiDisambiguation(new ArrayList<>(disambiguation.values()))
.setCallback(l -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
}));
});
WLabelGroup groupInput = new WLabelGroup(28, 111, 7, 2, 20, 20, WLabel.enumMode.EDITOR).setLsnrUpdate(i -> {
}); 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);
disambiguation.remove(i + 21);
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(() -> JecaGui.displayGui(new GuiLabel((l) -> {
WButton buttonClear = new WButtonIcon(64, 33, 20, 20, Resource.BTN_DEL, "recipe.clear").setLsnrLeft(this::clear);
WButton buttonLabel = new WButtonIcon(45, 33, 20, 20, Resource.BTN_LABEL, "recipe.label")
.setLsnrLeft(() -> JecaGui.displayGui(new GuiLabel((l) -> {
JecaGui.displayParent();
JecaGui.getCurrent().hand = l;
})));
WButton buttonSave = new WButtonIcon(26, 33, 20, 20, Resource.BTN_SAVE_N, Resource.BTN_SAVE_F, "recipe.save")
.setListenerLeft(() -> {
if (dest == null)
Controller.addRecipe(switcherGroup.getText(), toRecipe());
else {
if (textField.getText().equals(dest.one))
Controller.setRecipe(dest.one, dest.two, toRecipe());
else {
Controller.removeRecipe(dest.one, dest.two);
Controller.addRecipe(switcherGroup.getText(), toRecipe());
}
}
JecaGui.displayParent();
});
WButton buttonSave = new WButtonIcon(26, 33, 20, 20, Resource.BTN_SAVE, "recipe.save").setLsnrLeft(() -> {
if (dest == null)
Controller.addRecipe(switcherGroup.getText(), toRecipe());
else {
if (textField.getText().equals(dest.one))
Controller.setRecipe(dest.one, dest.two, toRecipe());
else {
Controller.removeRecipe(dest.one, dest.two);
Controller.addRecipe(switcherGroup.getText(), toRecipe());
}
}
JecaGui.displayParent();
});
WButton buttonNew = new WButtonIcon(7, 33, 20, 20, Resource.BTN_NEW_N, Resource.BTN_NEW_F, "recipe.new")
.setListenerLeft(() -> setModeNewGroup(true));
WButton buttonDel = new WButtonIcon(102, 33, 20, 20, Resource.BTN_NO_N, Resource.BTN_NO_F, Resource.BTN_NO_D,
"recipe.delete").setDisabled(true).setListenerLeft(() -> {
WButton buttonDel = new WButtonIcon(102, 33, 20, 20, Resource.BTN_NO, "recipe.delete").setLsnrLeft(() -> {
Controller.removeRecipe(dest.one, dest.two);
JecaGui.displayParent();
});
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));
WButton buttonNew = new WButtonIcon(7, 33, 20, 20, Resource.BTN_NEW, "recipe.new")
.setLsnrLeft(() -> setModeNewGroup(true));
WButton buttonYes = new WButtonIcon(7, 33, 20, 20, Resource.BTN_YES, "recipe.confirm").setLsnrLeft(() -> {
switcherGroup.setTemp(textField.getText());
textField.setText("");
setModeNewGroup(false);
});
WButton buttonNo = new WButtonIcon(26, 33, 20, 20, Resource.BTN_NO, "recipe.cancel")
.setLsnrLeft(() -> setModeNewGroup(false));
public GuiRecipe(String group, int index) {
@@ -96,19 +88,20 @@ public class GuiRecipe extends WContainer {
Recipe r = Controller.getRecipe(group, index);
fromRecipe(r);
switcherGroup.setIndex(Controller.getGroups().indexOf(group));
buttonCopy.setDisabled(false);
buttonDel.setDisabled(false);
}
public GuiRecipe() {
add(new WPanel());
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 WIcon(7, 63, 21, 20, Resource.ICN_OUTPUT, "recipe.output"));
add(new WIcon(7, 87, 21, 20, Resource.ICN_CATALYST, "recipe.catalyst"));
add(new WIcon(7, 111, 21, 40, Resource.ICN_INPUT, "recipe.input"));
add(new WLine(57));
addAll(groupInput, groupCatalyst, groupOutput, switcherGroup);
if (switcherGroup.getTexts().isEmpty()) switcherGroup.setTemp(Utilities.I18n.format("common.default"));
setModeNewGroup(false);
buttonCopy.setDisabled(true);
buttonDel.setDisabled(true);
buttonDisamb.setDisabled(true);
}
public void setModeNewGroup(boolean b) {
@@ -142,23 +135,30 @@ public class GuiRecipe extends WContainer {
ItemStack outputStack = recipe.getResultStack(recipeIndex).item;
merge(output, Stream.of(outputStack).map(ILabel.Converter::from).collect(Collectors.toList()));
// catalyst ignore multiple catalyst
NEIPlugin.getCatalyst(recipe).map(ILabel.Converter::from).ifPresent(catalyst -> {
groupCatalyst.setLabel(catalyst, 0);
});
groupInput.setLabel(sort(input, 0, true), 0);
groupOutput.setLabel(sort(output, 14, false), 0);
groupOutput.setLabel(sort(output, 21, false), 0);
refresh();
}
private void merge(ArrayList<Triple<ILabel, CostList, CostList>> dst, List<ILabel> list) {
if (list.isEmpty()) return;
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);
p.two = p.two.merge(cl, true, true);
return true;
} else return false;
} else
return false;
}).findAny().orElseGet(() -> {
Triple<ILabel, CostList, CostList> ret = new Triple<>(
ILabel.CONVERTER.first(list), new CostList(list), new CostList(list));
Triple<ILabel, CostList, CostList> ret = new Triple<>(ILabel.CONVERTER.first(list), new CostList(list),
new CostList(list));
dst.add(ret);
return ret;
});
@@ -180,12 +180,13 @@ public class GuiRecipe extends WContainer {
}
void fromRecipe(Recipe r) {
groupInput.setLabel(Arrays.stream(r.getLabel(Recipe.enumIoType.INPUT))
.map(ILabel::copy).collect(Collectors.toList()), 0);
groupCatalyst.setLabel(Arrays.stream(r.getLabel(Recipe.enumIoType.CATALYST))
.map(ILabel::copy).collect(Collectors.toList()), 0);
groupOutput.setLabel(Arrays.stream(r.getLabel(Recipe.enumIoType.OUTPUT))
.map(ILabel::copy).collect(Collectors.toList()), 0);
groupInput.setLabel(
Arrays.stream(r.getLabel(Recipe.enumIoType.INPUT)).map(ILabel::copy).collect(Collectors.toList()), 0);
groupCatalyst.setLabel(
Arrays.stream(r.getLabel(Recipe.enumIoType.CATALYST)).map(ILabel::copy).collect(Collectors.toList()),
0);
groupOutput.setLabel(
Arrays.stream(r.getLabel(Recipe.enumIoType.OUTPUT)).map(ILabel::copy).collect(Collectors.toList()), 0);
}
@@ -27,8 +27,8 @@ public class GuiSearch extends WContainer {
add(switcherGroup);
add(new WSearch(i -> content.stream().filter(j -> j.one.getRep() == i).findFirst().ifPresent(j ->
JecaGui.displayGui(false, true, new GuiRecipe(j.two, j.three))), new WTextField(25, 27, 90), labelScroll));
add(new WIcon(149, 27, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "search.help"));
add(new WIcon(7, 27, 20, 20, Resource.ICN_TEXT_N, Resource.ICN_TEXT_F, "search.text"));
add(new WIcon(149, 27, 20, 20, Resource.ICN_HELP, "search.help"));
add(new WIcon(7, 27, 20, 20, Resource.ICN_TEXT, "search.text"));
refresh();
}
@@ -0,0 +1,72 @@
package me.towdium.jecalculation.gui.guis.pickers;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.data.label.ILabel;
import me.towdium.jecalculation.data.label.labels.LItemStack;
import me.towdium.jecalculation.gui.IWPicker;
import me.towdium.jecalculation.gui.Resource;
import me.towdium.jecalculation.gui.drawables.WButton;
import me.towdium.jecalculation.gui.drawables.WButtonIcon;
import me.towdium.jecalculation.gui.drawables.WLabel;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;
/**
* Author: Towdium
* Date: 18-9-18
*/
@ParametersAreNonnullByDefault
@SideOnly(Side.CLIENT)
public class PickerItemStack extends IWPicker.Impl {
WLabel label = new WLabel(7, 7, 20, 20, WLabel.enumMode.SELECTOR).setLsnrUpdate(this::update);
WButton bConfirm = new WButtonIcon(149, 7, 20, 20, Resource.BTN_YES).setLsnrLeft(() -> callback.accept(label.getLabel()));
WButton bNbtF = new WButtonIcon(49, 7, 20, 20, Resource.BTN_NBT_F).setLsnrLeft(() -> setFNbt(false));
WButton bBbtN = new WButtonIcon(49, 7, 20, 20, Resource.BTN_NBT_N).setLsnrLeft(() -> setFNbt(true));
WButton bCapF = new WButtonIcon(68, 7, 20, 20, Resource.BTN_CAP_F).setLsnrLeft(() -> setFCap(false));
WButton bCapN = new WButtonIcon(68, 7, 20, 20, Resource.BTN_CAP_N).setLsnrLeft(() -> setFCap(true));
WButton bMetaF = new WButtonIcon(30, 7, 20, 20, Resource.BTN_META_F).setLsnrLeft(() -> setFMeta(false));
WButton bMetaN = new WButtonIcon(30, 7, 20, 20, Resource.BTN_META_N).setLsnrLeft(() -> setFMeta(true));
public PickerItemStack() {
addAll(label, bConfirm);
add(bConfirm);
update();
}
public void update() {
setFCap(false);
setFMeta(false);
setFNbt(false);
boolean b = label.getLabel() == ILabel.EMPTY;
bBbtN.setDisabled(b);
bCapN.setDisabled(b);
bMetaN.setDisabled(b);
bConfirm.setDisabled(b);
}
private void setFNbt(boolean b) {
setF(b, bBbtN, bNbtF, i -> i.setFNbt(b));
}
private void setFMeta(boolean b) {
setF(b, bMetaN, bMetaF, i -> i.setFMeta(b));
}
private void setFCap(boolean b) {
setF(b, bCapN, bCapF, i -> i.setFCap(b));
}
private void setF(boolean b, WButton be, WButton bd, Consumer<LItemStack> c) {
if (b) {
remove(be);
add(bd);
} else {
remove(bd);
add(be);
}
ILabel l = this.label.getLabel();
if (l instanceof LItemStack) c.accept((LItemStack) l);
}
}
@@ -24,12 +24,12 @@ public class PickerPlaceholder extends IWPicker.Impl {
WTextField create = new WTextField(26, 7, 69);
create.setLsnrText(s -> create.setColor(s.equals("") ? JecaGui.COLOR_TEXT_RED : JecaGui.COLOR_TEXT_WHITE));
add(new WSearch(l -> callback.accept(l), search, scroll));
add(new WIcon(149, 45, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "picker_placeholder.help_search"));
add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, "picker_placeholder.help_create"));
add(new WIcon(7, 45, 20, 20, Resource.ICN_TEXT_N, Resource.ICN_TEXT_F, "picker_placeholder.text_search"));
add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT_N, Resource.ICN_TEXT_F, "picker_placeholder.text_create"));
add(new WIcon(149, 45, 20, 20, Resource.ICN_HELP, "picker_placeholder.help_search"));
add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP, "picker_placeholder.help_create"));
add(new WIcon(7, 45, 20, 20, Resource.ICN_TEXT, "picker_placeholder.text_search"));
add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT, "picker_placeholder.text_create"));
add(new WLine(36));
add(new WButtonIcon(95, 7, 20, 20, Resource.BTN_YES_N, Resource.BTN_YES_F).setListenerLeft(() -> {
add(new WButtonIcon(95, 7, 20, 20, Resource.BTN_YES).setLsnrLeft(() -> {
if (!create.getText().equals("")) callback.accept(new LPlaceholder(create.getText(), 1));
}));
add(create);
@@ -32,8 +32,8 @@ public class PickerSimple extends IWPicker.Impl {
WLabelScroll ls = new WLabelScroll(7, 33, 8, 7, WLabel.enumMode.PICKER, true).setLabels(labels);
WTextField tf = new WTextField(26, 7, 90);
add(new WSearch(l -> callback.accept(l), tf, ls));
add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP_N, Resource.ICN_HELP_F, l18nKey + ".help"));
add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT_N, Resource.ICN_TEXT_F, l18nKey + ".text"));
add(new WIcon(149, 7, 20, 20, Resource.ICN_HELP, l18nKey + ".help"));
add(new WIcon(7, 7, 20, 20, Resource.ICN_TEXT, l18nKey + ".text"));
}
@@ -1,8 +1,16 @@
package me.towdium.jecalculation.nei;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.HandlerInfo;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import me.towdium.jecalculation.data.label.ILabel;
import net.minecraft.item.ItemStack;
import scala.tools.cmd.Opt;
import javax.annotation.Nonnull;
import java.util.Optional;
public class NEIPlugin {
@@ -20,4 +28,21 @@ public class NEIPlugin {
public static void setLabelUnderMouse(ItemStack itemStack) {
NEIPlugin.currentItemStack = itemStack;
}
public static Optional<ItemStack> getCatalyst(@Nonnull IRecipeHandler handler) {
final String handlerName = handler.toString().split("@")[0];
final String handlerID;
if(handler instanceof TemplateRecipeHandler) {
handlerID = (((TemplateRecipeHandler)handler).getOverlayIdentifier());
} else {
handlerID = null;
}
HandlerInfo info = GuiRecipeTab.getHandlerInfo(handlerName, handlerID);
if(info == null) {
return Optional.empty();
}
ItemStack itemStack = info.getItemStack();
return Optional.ofNullable(itemStack);
}
}