diff --git a/README.md b/README.md index 618418f..67f3e8f 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,25 @@ This mod is focused on calculation, so you might find it powerful and high perfo For all the release files, description or videos, refer to the [release page](https://minecraft.curseforge.com/projects/just-enough-calculation). +## Features + +- Recipe from NEI recipe handler (recipe gui) + - [x] vanilla + - [x] gregtech + - [x] Forestry + - [ ] AE2 + - [ ] Others +- [x] Item from NEI item panel +- [ ] Fluid from NEI item panel (Need to get fluid from labels) +- [x] OreDictionary recognize + + ## Known Issues - [ ] Client Only - [ ] Fluid from NEI ItemPanel will be recognized as item - [ ] **Capability** - [ ] Some OreDict items renders wrong - - [ ] OreDict have many other problems - - [ ] Recent records have problem after reboot game + - [ ] OreDict have many some problems - [ ] GUI will cover the NEI's GUI like tooltip on item panel - [ ] Check the nei version and adapter the old version. - [ ] Fluid from recipe needs lots of adapters, see [Adapter](./src/main/java/me/towdium/jecalculation/nei/Adapter.java). diff --git a/build.gradle b/build.gradle index adeafff..1b2650c 100644 --- a/build.gradle +++ b/build.gradle @@ -86,9 +86,13 @@ dependencies { compile "codechicken:NotEnoughItems:${mc_version}-${nei_version}:universal" compile 'codechicken:CodeChickenLib:1.7.10-1.1.3.138:dev' compile 'codechicken:CodeChickenCore:1.7.10-1.0.7.+:dev' - compile 'forestry:forestry_1.7.10-4.3.1.44' + compile 'org.reflections:reflections:0.9.12' testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0' + + // soft dependencies + compile 'forestry:forestry_1.7.10-4.3.1.44' + compile 'gregtech:gregtech-5.09.34.16' } processResources { diff --git a/libs/gregtech-5.09.34.16.jar b/libs/gregtech-5.09.34.16.jar new file mode 100644 index 0000000..29753bc Binary files /dev/null and b/libs/gregtech-5.09.34.16.jar differ diff --git a/src/main/java/me/towdium/jecalculation/data/Controller.java b/src/main/java/me/towdium/jecalculation/data/Controller.java index 6874bf7..da5cf96 100644 --- a/src/main/java/me/towdium/jecalculation/data/Controller.java +++ b/src/main/java/me/towdium/jecalculation/data/Controller.java @@ -32,29 +32,16 @@ import java.util.stream.Stream; @ParametersAreNonnullByDefault @SideOnly(Side.CLIENT) public class Controller { - public static final String KEY_RECIPES = "recipes"; public static final String KEY_MATH = "math"; public static final String KEY_CRAFT = "craft"; public static final String KEY_PLAYER = "player"; - static RecordPlayer rPlayerServer; static RecordPlayer rPlayerClient; static RecordCraft rCraftClient; static RecordMath rMathClient; - public static void setRecordsServer(RecordPlayer r) { - rPlayerServer = r; - } - - public static boolean isServerActive() { - return rPlayerServer != null; - } - static Recipes getRecipes() { - if (isServerActive()) - return rPlayerServer.recipes; - else - return rPlayerClient.recipes; + return rPlayerClient.recipes; } static Optional getStack() { @@ -72,7 +59,9 @@ public class Controller { JustEnoughCalculation.logger.warn("File " + f.getAbsolutePath() + " contains invalid records."); return nbt == null ? null : new Recipes(nbt); }; - return Arrays.stream(fs).map(i -> new Pair<>(i.getName(), read.apply(i))).filter(i -> i.two != null) + return Arrays.stream(fs) + .map(i -> new Pair<>(i.getName(), read.apply(i))) + .filter(i -> i.two != null) .collect(Collectors.toList()); } @@ -86,8 +75,8 @@ public class Controller { private static void export(String s, Function r) { File f = JecaConfig.getDataFile(s); Utilities.Json.write(r.apply(getRecipes()), f); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation( - "jecalculation.chat.export", f.getAbsolutePath())); + Minecraft.getMinecraft().thePlayer.addChatMessage( + new ChatComponentTranslation("jecalculation.chat.export", f.getAbsolutePath())); } public static void export(String group) { @@ -100,12 +89,11 @@ public class Controller { @Nullable public static String getLast() { - return isServerActive() ? rPlayerServer.last : rPlayerClient.last; + return rPlayerClient.last; } static void setLast(String last) { - if (isServerActive()) rPlayerServer.last = last; - else rPlayerClient.last = last; + rPlayerClient.last = last; } public static List getGroups() { @@ -180,20 +168,11 @@ public class Controller { } private static void setR(T t, Consumer c, String s) { - if (!isServerActive()) c.accept(t); - else { - Optional ois = getStack(); - ois.ifPresent(is -> { - Utilities.getTag(is).setTag(s, t.serialize()); - }); - } + c.accept(t); } public static T getR(T t, String s, Function f) { - if (!isServerActive()) return t; - else return f.apply(getStack() - .map(i -> Utilities.getTag(i).getCompoundTag(s)) - .orElse(new NBTTagCompound())); + return t; } /** @@ -207,8 +186,10 @@ public class Controller { public static boolean hasDuplicate(Recipe r, String group, int index) { Recipes.RecipeIterator ri = recipeIterator(); return ri.stream().anyMatch(i -> { - if (ri.getIndex() == index && ri.getGroup().equals(group)) return false; - else return i.equals(r); + if (ri.getIndex() == index && ri.getGroup().equals(group)) + return false; + else + return i.equals(r); }); } @@ -227,7 +208,9 @@ public class Controller { if (nbt != null) { rCraftClient = new RecordCraft(nbt.getCompoundTag(KEY_CRAFT)); rMathClient = new RecordMath(nbt.getCompoundTag(KEY_MATH)); - rPlayerClient = nbt.hasKey(KEY_PLAYER) ? new RecordPlayer(nbt.getCompoundTag(KEY_PLAYER)) : new RecordPlayer(); + rPlayerClient = nbt.hasKey(KEY_PLAYER) ? + new RecordPlayer(nbt.getCompoundTag(KEY_PLAYER)) : + new RecordPlayer(); } else { rPlayerClient = new RecordPlayer(); rCraftClient = new RecordCraft(new NBTTagCompound()); @@ -254,16 +237,12 @@ public class Controller { } public static void openGuiCraft(boolean scheduled) { - if (!Controller.isServerActive()) JecaGui.displayGui(true, true, scheduled, new GuiCraft()); - else Minecraft.getMinecraft().thePlayer.addChatMessage( - new ChatComponentTranslation("jecalculation.chat.server_mode")); + JecaGui.displayGui(true, true, scheduled, new GuiCraft()); } public static void openGuiMath(boolean scheduled) { - if (!Controller.isServerActive()) JecaGui.displayGui(true, true, scheduled, new GuiMath()); - else Minecraft.getMinecraft().thePlayer.addChatMessage( - new ChatComponentTranslation("jecalculation.chat.server_mode")); + JecaGui.displayGui(true, true, scheduled, new GuiMath()); } diff --git a/src/main/java/me/towdium/jecalculation/data/label/ILabel.java b/src/main/java/me/towdium/jecalculation/data/label/ILabel.java index bf240c5..31ab050 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/ILabel.java +++ b/src/main/java/me/towdium/jecalculation/data/label/ILabel.java @@ -277,7 +277,6 @@ public interface ILabel { } public Pair, List> guess(List labels, @Nullable IRecipeHandler context) { - List ret = new ArrayList<>(); List suggest = new ReversedIterator<>(handlers.get(Priority.SUGGEST)).stream().flatMap( h -> h.convert(labels, context).stream()).collect(Collectors.toList()); List fallback = new ReversedIterator<>(handlers.get(Priority.FALLBACK)).stream().flatMap( diff --git a/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java b/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java index b617201..78dff11 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java +++ b/src/main/java/me/towdium/jecalculation/data/label/labels/LItemStack.java @@ -1,11 +1,13 @@ package me.towdium.jecalculation.data.label.labels; import codechicken.nei.recipe.IRecipeHandler; +import cpw.mods.fml.common.registry.GameData; 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.ItemStackHelper; import me.towdium.jecalculation.utils.Utilities; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -27,38 +29,40 @@ import static net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE; @ParametersAreNonnullByDefault public class LItemStack extends ILabel.Impl { public static final String IDENTIFIER = "itemStack"; - 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_F_META = "fMeta"; - public static final String KEY_F_CAP = "fCap"; - public static final String KEY_F_NBT = "fNbt"; + + private static final String KEY_ITEM = "item"; + private static final String KEY_META = "meta"; + private static final String KEY_NBT = "tag"; // don't modify it + private static final String KEY_F_META = "fMeta"; + private static final String KEY_F_NBT = "fNbt"; Item item; int meta; NBTTagCompound nbt; boolean fMeta; boolean fNbt; - boolean fCap; transient ItemStack temp; // Convert from itemStack public LItemStack(ItemStack is) { super(is.stackSize, false); - init(is.getItem(), is.getItemDamage(), is.getTagCompound(), false, false, false); + init(is.getItem(), is.getItemDamage(), is.getTagCompound(), false, false); } public LItemStack(NBTTagCompound tag) { super(tag); - String id = tag.getString(KEY_ITEM); - Item i = Item.getItemById(tag.getInteger(KEY_ITEM)); - if (i == null) throw new Serializer.SerializationException("Item " + id + " cannot be resolved, ignoring"); - init(i, tag.getInteger(KEY_META), - tag.hasKey(KEY_NBT) ? tag.getCompoundTag(KEY_NBT) : null, - tag.getBoolean(KEY_F_META), - tag.getBoolean(KEY_F_CAP), - tag.getBoolean(KEY_F_NBT) - ); + final String strId = tag.getString(KEY_ITEM); + if(!tag.hasKey("id")) + tag.setShort("id", (short) GameData.getItemRegistry().getId(strId)); + tag.setByte("Count", (byte)1); + tag.setShort("Damage", tag.hasKey(KEY_META) ? (short)tag.getInteger(KEY_META) : 0); + ItemStack stack = ItemStack.loadItemStackFromNBT(tag); + + if (ItemStackHelper.isEmpty(stack)) + throw new Serializer.SerializationException("Item " + strId + " cannot be resolved, ignoring"); + Item i = stack.getItem(); + init(i, tag.getInteger(KEY_META), tag.hasKey(KEY_NBT) ? stack.stackTagCompound : null, + tag.getBoolean(KEY_F_META), tag.getBoolean(KEY_F_NBT)); } private LItemStack(LItemStack lis) { @@ -68,22 +72,15 @@ public class LItemStack extends ILabel.Impl { nbt = lis.nbt; fMeta = lis.fMeta; fNbt = lis.fNbt; - fCap = lis.fCap; temp = lis.temp; } - private void init(@Nullable Item item, - int meta, - @Nullable NBTTagCompound nbt, - boolean fMeta, - boolean fCap, - boolean fNbt) { + private void init(@Nullable Item item, int meta, @Nullable NBTTagCompound nbt, boolean fMeta, boolean fNbt) { Objects.requireNonNull(item); this.item = item; this.meta = fMeta ? 0 : meta; this.nbt = fNbt ? null : nbt; this.fMeta = fMeta; - this.fCap = fCap; this.fNbt = fNbt; temp = new ItemStack(item, 1, this.meta); temp.setTagCompound(this.nbt); @@ -94,12 +91,15 @@ public class LItemStack extends ILabel.Impl { if (a instanceof LItemStack && b instanceof LItemStack) { LItemStack lisA = (LItemStack) a; LItemStack lisB = (LItemStack) b; - if (lisA.meta != lisB.meta && !lisA.fMeta && lisA.meta != WILDCARD_VALUE - && !lisB.fMeta && lisB.meta != WILDCARD_VALUE) return false; + if (lisA.meta != lisB.meta && !lisA.fMeta && lisA.meta != WILDCARD_VALUE && !lisB.fMeta && + lisB.meta != WILDCARD_VALUE) + return false; if (!lisA.fNbt && !lisB.fNbt) { if (lisA.nbt == null) { - if (lisB.nbt != null) return false; - } else if (lisB.nbt == null || !lisA.nbt.equals(lisB.nbt)) return false; + if (lisB.nbt != null) + return false; + } else if (lisB.nbt == null || !lisA.nbt.equals(lisB.nbt)) + return false; } return lisA.item == lisB.item; } @@ -107,21 +107,27 @@ public class LItemStack extends ILabel.Impl { } public static List suggest(List iss, @Nullable IRecipeHandler rl) { - if (iss.size() == 0) return new ArrayList<>(); - for (ILabel i : iss) if (!(i instanceof LItemStack)) return new ArrayList<>(); + if (iss.size() == 0) + return new ArrayList<>(); + for (ILabel i : iss) + if (!(i instanceof LItemStack)) + return new ArrayList<>(); LItemStack lis = (LItemStack) iss.get(0); boolean fMeta = false; boolean fNbt = false; - boolean fCap = false; for (ILabel i : iss) { LItemStack ii = (LItemStack) i; - if (ii.item != lis.item) return new ArrayList<>(); - if (ii.meta != lis.meta || ii.fMeta) fMeta = true; - if (!Objects.equals(ii.nbt, lis.nbt)) fNbt = true; + if (ii.item != lis.item) + return new ArrayList<>(); + if (ii.meta != lis.meta || ii.fMeta) + fMeta = true; + if (!Objects.equals(ii.nbt, lis.nbt)) + fNbt = true; } - if (fMeta || fNbt || fCap) return Collections.singletonList( - lis.copy().setFCap(fCap).setFMeta(fMeta).setFNbt(fNbt)); - else return new ArrayList<>(); + if (fMeta || fNbt) + return Collections.singletonList(lis.copy().setFMeta(fMeta).setFNbt(fNbt)); + else + return new ArrayList<>(); } @@ -129,20 +135,22 @@ public class LItemStack extends ILabel.Impl { List ret = new ArrayList<>(); if (iss.size() == 1) { ILabel label = iss.get(0); - if (!(label instanceof LItemStack)) return ret; + if (!(label instanceof LItemStack)) + return ret; LItemStack lis = (LItemStack) label; - if (lis.fCap || lis.fNbt || lis.fMeta) return new ArrayList<>(); + if (lis.fNbt || lis.fMeta) + return new ArrayList<>(); ret.add(lis.copy().setFMeta(true)); ret.add(lis.copy().setFNbt(true)); - ret.add(lis.copy().setFCap(true)); - ret.add(lis.copy().setFMeta(true).setFNbt(true).setFCap(true)); + ret.add(lis.copy().setFMeta(true).setFNbt(true)); } return ret; } public LItemStack setFMeta(boolean f) { fMeta = f; - if (f) meta = 0; + if (f) + meta = 0; temp = new ItemStack(item, 1, meta); temp.setTagCompound(nbt); return this; @@ -150,14 +158,8 @@ public class LItemStack extends ILabel.Impl { public LItemStack setFNbt(boolean f) { fNbt = f; - if (f) nbt = null; - temp = new ItemStack(item, 1, meta); - temp.setTagCompound(nbt); - return this; - } - - public LItemStack setFCap(boolean f) { - fCap = f; + if (f) + nbt = null; temp = new ItemStack(item, 1, meta); temp.setTagCompound(nbt); return this; @@ -171,9 +173,10 @@ public class LItemStack extends ILabel.Impl { @SideOnly(Side.CLIENT) public void getToolTip(List existing, boolean detailed) { super.getToolTip(existing, detailed); - if (fMeta) existing.add(FORMAT_GREY + Utilities.I18n.get("label.item_stack.fuzzy_meta")); - if (fNbt) existing.add(FORMAT_GREY + Utilities.I18n.get("label.item_stack.fuzzy_nbt")); - if (fCap) existing.add(FORMAT_GREY + Utilities.I18n.get("label.item_stack.fuzzy_cap")); + if (fMeta) + existing.add(FORMAT_GREY + Utilities.I18n.get("label.item_stack.fuzzy_meta")); + if (fNbt) + existing.add(FORMAT_GREY + Utilities.I18n.get("label.item_stack.fuzzy_nbt")); existing.add(FORMAT_BLUE + FORMAT_ITALIC + Utilities.getModName(item)); } @@ -198,7 +201,7 @@ public class LItemStack extends ILabel.Impl { if (l instanceof LItemStack) { LItemStack lis = (LItemStack) l; return (Objects.equals(nbt, lis.nbt)) && meta == lis.meta && item == lis.item && fNbt == lis.fNbt && - super.matches(l) && fCap == lis.fCap && fMeta == lis.fMeta; + super.matches(l) && fMeta == lis.fMeta; } else return false; } @@ -212,19 +215,17 @@ public class LItemStack extends ILabel.Impl { public NBTTagCompound toNbt() { if (item == null) return ILabel.EMPTY.toNbt(); - int id = Item.getIdFromItem(item); + String strId = Item.itemRegistry.getNameForObject(item); NBTTagCompound ret = super.toNbt(); if (meta != 0) ret.setInteger(KEY_META, meta); - ret.setInteger(KEY_ITEM, id); + ret.setString(KEY_ITEM, strId); if (nbt != null) ret.setTag(KEY_NBT, nbt); if (fMeta) ret.setBoolean(KEY_F_META, true); if (fNbt) ret.setBoolean(KEY_F_NBT, true); - if (fCap) - ret.setBoolean(KEY_F_CAP, true); return ret; } @@ -232,10 +233,8 @@ public class LItemStack extends ILabel.Impl { @SideOnly(Side.CLIENT) public void drawLabel(JecaGui gui) { gui.drawItemStack(0, 0, temp, false); - if (fCap || fNbt || fMeta) + if (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) diff --git a/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java b/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java index be04b29..cf12e75 100644 --- a/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java +++ b/src/main/java/me/towdium/jecalculation/data/label/labels/LOreDict.java @@ -23,7 +23,6 @@ import javax.annotation.ParametersAreNonnullByDefault; import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import java.util.function.BiPredicate; import java.util.stream.Collectors; /** @@ -70,9 +69,13 @@ public class LOreDict extends ILabel.Impl { if (a instanceof LOreDict && b instanceof LItemStack) { LOreDict lod = (LOreDict) a; LItemStack lis = (LItemStack) b; - return lod.getAmount() * lis.getAmount() < 0 && - OreDictionary.getOres(lod.name).stream().map(Converter::from) - .anyMatch(i -> LItemStack.merge(i, lis)); + if (lod.getAmount() * lis.getAmount() < 0) { + for (ItemStack ore : OreDictionary.getOres(lod.name)) { + if (LItemStack.merge(Converter.from(ore), lis)) { + return true; + } + } + } } return false; } @@ -110,16 +113,41 @@ public class LOreDict extends ILabel.Impl { return false; Wrapper acceptable = new Wrapper<>(true); - BiPredicate match = (l, o) -> l instanceof LItemStack && - OreDictionary.itemMatches(o, ((LItemStack) l).getRep(), false); - if (biDir) - ores.stream().filter(ore -> labels.stream().noneMatch(label -> match.test(label, ore))).findAny() - .ifPresent(i -> acceptable.value = false); - labels.stream().filter(label -> ores.stream().noneMatch(ore -> match.test(label, ore))).findAny() - .ifPresent(i -> acceptable.value = false); + if (biDir) { + for (ItemStack ore : ores) { + boolean noneMatch = true; + for (ILabel label : labels) { + if (checkMatch(label, ore)) { + noneMatch = false; + break; + } + } + if (noneMatch) { + acceptable.value = false; + break; + } + } + } + for (ILabel label : labels) { + boolean noneMatch = true; + for (ItemStack ore : ores) { + if (checkMatch(label, ore)) { + noneMatch = false; + break; + } + } + if (noneMatch) { + acceptable.value = false; + break; + } + } return acceptable.value; } + private static boolean checkMatch(ILabel l, ItemStack o) { + return l instanceof LItemStack && OreDictionary.itemMatches(o, ((LItemStack) l).getRep(), false); + } + @Override @Nonnull public ItemStack getRepresentation() { diff --git a/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerItemStack.java b/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerItemStack.java index 5a59869..3223df8 100644 --- a/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerItemStack.java +++ b/src/main/java/me/towdium/jecalculation/gui/guis/pickers/PickerItemStack.java @@ -26,8 +26,6 @@ public class PickerItemStack extends IPicker.Impl implements IGui { WButton bConfirm = new WButtonIcon(149, 7, 20, 20, BTN_YES, "item_stack.confirm").setListener(i -> callback.accept(label.getLabel())); WButton bNbtN = new WButtonIcon(49, 7, 20, 20, BTN_NBT_N, "item_stack.nbt_normal").setListener(i -> setFNbt(true)); WButton bNbtF = new WButtonIcon(49, 7, 20, 20, BTN_NBT_F, "item_stack.nbt_fuzzy").setListener(i -> setFNbt(false)); - WButton bCapN = new WButtonIcon(68, 7, 20, 20, BTN_CAP_N, "item_stack.capability_normal").setListener(i -> setFCap(true)); - WButton bCapF = new WButtonIcon(68, 7, 20, 20, BTN_CAP_F, "item_stack.capability_fuzzy").setListener(i -> setFCap(false)); WButton bMetaN = new WButtonIcon(30, 7, 20, 20, BTN_META_N, "item_stack.meta_normal").setListener(i -> setFMeta(true)); WButton bMetaF = new WButtonIcon(30, 7, 20, 20, BTN_META_F, "item_stack.meta_fuzzy").setListener(i -> setFMeta(false)); ILabel raw = ILabel.EMPTY; @@ -40,12 +38,10 @@ public class PickerItemStack extends IPicker.Impl implements IGui { public void update(ILabel l) { raw = l; - setFCap(false); setFMeta(false); setFNbt(false); boolean b = l == ILabel.EMPTY; bNbtN.setDisabled(b); - bCapN.setDisabled(b); bMetaN.setDisabled(b); bConfirm.setDisabled(b); } @@ -58,10 +54,6 @@ public class PickerItemStack extends IPicker.Impl implements IGui { setF(b, bMetaN, bMetaF, () -> fMeta = b); } - private void setFCap(boolean b) { - setF(b, bCapN, bCapF, () -> fCap = b); - } - private void setF(boolean b, WButton be, WButton bd, Runnable r) { remove(be, bd); if (b) add(bd); @@ -69,7 +61,7 @@ public class PickerItemStack extends IPicker.Impl implements IGui { r.run(); if (raw instanceof LItemStack) { LItemStack lis = (LItemStack) raw; - label.setLabel(lis.copy().setFCap(fCap).setFMeta(fMeta).setFNbt(fNbt)); + label.setLabel(lis.copy().setFMeta(fMeta).setFNbt(fNbt)); } } } diff --git a/src/main/java/me/towdium/jecalculation/nei/Adapter.java b/src/main/java/me/towdium/jecalculation/nei/Adapter.java index 7a0b537..058b070 100644 --- a/src/main/java/me/towdium/jecalculation/nei/Adapter.java +++ b/src/main/java/me/towdium/jecalculation/nei/Adapter.java @@ -4,7 +4,9 @@ import codechicken.nei.PositionedStack; import codechicken.nei.recipe.IRecipeHandler; import cpw.mods.fml.common.Loader; import me.towdium.jecalculation.JustEnoughCalculation; +import me.towdium.jecalculation.nei.adapter.AE2; import me.towdium.jecalculation.nei.adapter.Forestry; +import me.towdium.jecalculation.nei.adapter.GregTech; import me.towdium.jecalculation.nei.adapter.IAdapter; import java.util.ArrayList; @@ -18,6 +20,14 @@ public class Adapter { JustEnoughCalculation.logger.info("Forestry is installed"); adapters.add(new Forestry()); } + if (Loader.isModLoaded("appliedenergistics2")) { + JustEnoughCalculation.logger.info("ae2 installed"); + adapters.add(new AE2()); + } + if( Loader.isModLoaded("gregtech")) { + JustEnoughCalculation.logger.info("gregtech installed"); + adapters.add(new GregTech()); + } } public static void handleRecipe(IRecipeHandler recipe, int index, List inputs, List outputs) { diff --git a/src/main/java/me/towdium/jecalculation/nei/NEICalculatorConfig.java b/src/main/java/me/towdium/jecalculation/nei/NEICalculatorConfig.java index dba51e0..3d7d753 100644 --- a/src/main/java/me/towdium/jecalculation/nei/NEICalculatorConfig.java +++ b/src/main/java/me/towdium/jecalculation/nei/NEICalculatorConfig.java @@ -4,23 +4,31 @@ import codechicken.nei.api.API; import codechicken.nei.api.IConfigureNEI; import me.towdium.jecalculation.JustEnoughCalculation; import me.towdium.jecalculation.gui.JecaGui; +import me.towdium.jecalculation.nei.adapter.IAdapter; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; import java.util.stream.Stream; public class NEICalculatorConfig implements IConfigureNEI { @Override public void loadConfig() { - String[] baseOverlayIdentifiers = new String[]{"crafting", "crafting2x2", "smelting", "fuel", "brewing"}; - String[] ae2OverlayIdentifiers = new String[]{"inscriber", "grindstone"}; - /* For the recipeHandlers which extend `TemplateRecipeHandler` without override the `getOverlayIdentifier` function */ - String[] nullOverlayIdentifiers = new String[]{null}; - Stream.of(baseOverlayIdentifiers, ae2OverlayIdentifiers, nullOverlayIdentifiers) - .flatMap(Stream::of) - .forEach(ident -> { - API.registerGuiOverlay(JecaGui.class, ident); - API.registerGuiOverlayHandler(JecaGui.class, new JecaOverlayHandler(), ident); - }); + /* null For the recipeHandlers which extend `TemplateRecipeHandler` without override the `getOverlayIdentifier` function */ + Set baseOverlayIdentifiers = new HashSet<>( + Arrays.asList("crafting", "crafting2x2", "smelting", "fuel", "brewing", null)); + Set adapterIdentifiers = Adapter.adapters.stream() + .map(IAdapter::getAllOverlayIdentifier) + .flatMap(Collection::stream) + .collect(Collectors.toSet()); + + Stream.concat(baseOverlayIdentifiers.stream(), adapterIdentifiers.stream()).forEach(ident -> { + API.registerGuiOverlay(JecaGui.class, ident); + API.registerGuiOverlayHandler(JecaGui.class, new JecaOverlayHandler(), ident); + }); } @Override diff --git a/src/main/java/me/towdium/jecalculation/nei/adapter/AE2.java b/src/main/java/me/towdium/jecalculation/nei/adapter/AE2.java new file mode 100644 index 0000000..fe11482 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/nei/adapter/AE2.java @@ -0,0 +1,20 @@ +package me.towdium.jecalculation.nei.adapter; + +import codechicken.nei.recipe.IRecipeHandler; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class AE2 implements IAdapter{ + @Override + public Set getAllOverlayIdentifier() { + return new HashSet<>(Arrays.asList("inscriber", "grindstone")); + } + + @Override + public void handleRecipe(IRecipeHandler recipe, int index, List inputs, List outputs) { + + } +} diff --git a/src/main/java/me/towdium/jecalculation/nei/adapter/Forestry.java b/src/main/java/me/towdium/jecalculation/nei/adapter/Forestry.java index eeac2c9..338de5d 100644 --- a/src/main/java/me/towdium/jecalculation/nei/adapter/Forestry.java +++ b/src/main/java/me/towdium/jecalculation/nei/adapter/Forestry.java @@ -34,7 +34,7 @@ public class Forestry implements IAdapter { private void bottler(RecipeHandlerBase recipe, int recipeIndex, List inputs) { if (recipe instanceof NEIHandlerBottler) { List> fluids = getFluids(recipe, recipeIndex); - if(fluids.size() >= 1) + if (fluids.size() >= 1) inputs.add(fluids.get(0).toArray()); } } @@ -42,7 +42,7 @@ public class Forestry implements IAdapter { private void carpenter(RecipeHandlerBase recipe, int recipeIndex, List inputs) { if (recipe instanceof NEIHandlerCarpenter) { List> fluids = getFluids(recipe, recipeIndex); - if(fluids.size() >= 1) + if (fluids.size() >= 1) inputs.add(fluids.get(0).toArray()); } } @@ -50,22 +50,20 @@ public class Forestry implements IAdapter { private void centrifuge(RecipeHandlerBase recipe, int recipeIndex, List outputs) { if (recipe instanceof NEIHandlerCentrifuge) { List otherStacks = recipe.getOtherStacks(recipeIndex); - otherStacks.stream() - .map(positionedStack -> positionedStack.items) - .forEach(outputs::add); + otherStacks.stream().map(positionedStack -> positionedStack.items).forEach(outputs::add); } } private void fabricator(RecipeHandlerBase recipe, int recipeIndex, List inputs) { if (recipe instanceof NEIHandlerFabricator) { List> fluids = getFluids(recipe, recipeIndex); - if(fluids.size() >= 1) + if (fluids.size() >= 1) inputs.add(fluids.get(0).toArray()); } } private void fermenter(RecipeHandlerBase recipe, int recipeIndex, List inputs, List outputs) { - if(recipe instanceof NEIHandlerFermenter) { + if (recipe instanceof NEIHandlerFermenter) { List tanks = getTanks(recipe, recipeIndex); tanks.forEach(tank -> { Object[] fluids = Arrays.stream(tank.tanks).map(FluidTank::getFluid).toArray(); @@ -81,14 +79,14 @@ public class Forestry implements IAdapter { } private void moistener(RecipeHandlerBase recipe, int recipeIndex, List inputs, List outputs) { - if(recipe instanceof NEIHandlerMoistener) { + if (recipe instanceof NEIHandlerMoistener) { List> fluids = getFluids(recipe, recipeIndex); - if(fluids.size() >= 1) + if (fluids.size() >= 1) inputs.add(fluids.get(0).toArray()); List otherStacks = recipe.getOtherStacks(recipeIndex); otherStacks.forEach(positionedStack -> { ItemStack[] items = positionedStack.items; - if(positionedStack.relx == 34) { + if (positionedStack.relx == 34) { // item inputs.add(items); } else { @@ -100,18 +98,18 @@ public class Forestry implements IAdapter { } private void squeezer(RecipeHandlerBase recipe, int recipeIndex, List inputs, List outputs) { - if(recipe instanceof NEIHandlerSqueezer) { + if (recipe instanceof NEIHandlerSqueezer) { List> fluids = getFluids(recipe, recipeIndex); - if(fluids.size() >= 1) + if (fluids.size() >= 1) outputs.add(fluids.get(0).toArray()); } } private void still(RecipeHandlerBase recipe, int recipeIndex, List inputs, List outputs) { - if(recipe instanceof NEIHandlerStill) { + if (recipe instanceof NEIHandlerStill) { getTanks(recipe, recipeIndex).forEach(tank -> { Object[] fluids = Arrays.stream(tank.tanks).map(FluidTank::getFluid).toArray(); - if(tank.position.x == 30) { + if (tank.position.x == 30) { // input inputs.add(fluids); } else { diff --git a/src/main/java/me/towdium/jecalculation/nei/adapter/GregTech.java b/src/main/java/me/towdium/jecalculation/nei/adapter/GregTech.java new file mode 100644 index 0000000..f18ede9 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/nei/adapter/GregTech.java @@ -0,0 +1,85 @@ +package me.towdium.jecalculation.nei.adapter; + +import codechicken.nei.NEIServerUtils; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.IRecipeHandler; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.nei.GT_NEI_AssLineHandler; +import gregtech.nei.GT_NEI_DefaultHandler; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +@ParametersAreNonnullByDefault +public class GregTech implements IAdapter { + @Override + public Set getAllOverlayIdentifier() { + return GT_Recipe.GT_Recipe_Map.sMappings.stream() + .map(gt_recipe_map -> gt_recipe_map.mNEIName) + .collect(Collectors.toSet()); + } + + @Override + public void handleRecipe(IRecipeHandler recipe, int index, List inputs, List outputs) { + if (recipe instanceof GT_NEI_DefaultHandler || recipe instanceof GT_NEI_AssLineHandler) { + for (int i = 0; i < inputs.size(); i++) { + Object[] objects = Arrays.stream(inputs.get(i)).map(o -> this.convertFluid((ItemStack) o)).toArray(); + inputs.set(i, objects); + } + List otherStacks = recipe.getOtherStacks(index); + outputs.addAll(otherStacks.stream() + .map(positionedStack -> positionedStack.items) + .map(itemStacks -> Arrays.stream(itemStacks).map(this::convertFluid).toArray()) + .collect(Collectors.toList())); + } + } + + private Object convertFluid(ItemStack itemStack) { + FluidStack fluidStack = GT_Utility.getFluidFromDisplayStack(itemStack); + return fluidStack == null ? itemStack : fluidStack; + } + + /** + * get from `gregtech.nei.GT_NEI_AssLineHandler$CachedDefaultRecipe::Constructor` + * + * @param recipe GT_Recipe + * @param inputs input list + * @param outputs output list + */ + @Deprecated + private void getFromRecipe(GT_Recipe recipe, List inputs, List outputs) { + for (int i = 0; i < recipe.mInputs.length; i++) { + Object obj = recipe instanceof GT_Recipe.GT_Recipe_WithAlt ? + ((GT_Recipe.GT_Recipe_WithAlt) recipe).getAltRepresentativeInput(i) : + recipe.getRepresentativeInput(i); + if (obj != null) { + inputs.add(NEIServerUtils.extractRecipeItems(obj)); + } + } + if (recipe.mSpecialItems != null) { + inputs.add(NEIServerUtils.extractRecipeItems(recipe.mSpecialItems)); + } + + if (recipe.getOutput(0) != null) { + outputs.add(NEIServerUtils.extractRecipeItems(recipe.getOutput(0))); + } + + for (FluidStack mFluidInput : recipe.mFluidInputs) { + if (mFluidInput != null && mFluidInput.getFluid() != null) { + inputs.add(new Object[]{mFluidInput}); + } + } + + for (FluidStack mFluidOutput : recipe.mFluidOutputs) { + if (mFluidOutput != null && mFluidOutput.getFluid() != null) { + outputs.add(new Object[]{mFluidOutput}); + } + } + } +} diff --git a/src/main/java/me/towdium/jecalculation/nei/adapter/IAdapter.java b/src/main/java/me/towdium/jecalculation/nei/adapter/IAdapter.java index a23f2a9..2f2a715 100644 --- a/src/main/java/me/towdium/jecalculation/nei/adapter/IAdapter.java +++ b/src/main/java/me/towdium/jecalculation/nei/adapter/IAdapter.java @@ -3,9 +3,15 @@ package me.towdium.jecalculation.nei.adapter; import codechicken.nei.recipe.IRecipeHandler; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.Collections; import java.util.List; +import java.util.Set; @ParametersAreNonnullByDefault public interface IAdapter { + default Set getAllOverlayIdentifier() { + return Collections.emptySet(); + }; + void handleRecipe(IRecipeHandler recipe, int index, List inputs, List outputs); } diff --git a/src/main/java/me/towdium/jecalculation/polyfill/NBTHelper.java b/src/main/java/me/towdium/jecalculation/polyfill/NBTHelper.java index e63a765..6b56181 100644 --- a/src/main/java/me/towdium/jecalculation/polyfill/NBTHelper.java +++ b/src/main/java/me/towdium/jecalculation/polyfill/NBTHelper.java @@ -8,10 +8,12 @@ import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import javax.annotation.ParametersAreNonnullByDefault; import java.util.List; import java.util.Spliterator; import java.util.Spliterators; +@ParametersAreNonnullByDefault public class NBTHelper { /** * Get an NBTTagCompound from this stack's NBT data. @@ -48,4 +50,10 @@ public class NBTHelper { } } + public static NBTTagCompound serializeNBT(ItemStack stack) { + NBTTagCompound ret = new NBTTagCompound(); + stack.writeToNBT(ret); + return ret; + } + } diff --git a/src/main/java/me/towdium/jecalculation/utils/ItemStackHelper.java b/src/main/java/me/towdium/jecalculation/utils/ItemStackHelper.java index 917ca2d..f7d82a4 100644 --- a/src/main/java/me/towdium/jecalculation/utils/ItemStackHelper.java +++ b/src/main/java/me/towdium/jecalculation/utils/ItemStackHelper.java @@ -12,309 +12,11 @@ import java.util.function.Consumer; import java.util.function.Function; public class ItemStackHelper { - public static final String keyAmount = "amount"; - public static final String keyType = "type"; public static final Item EMPTY_ITEM = null; public static final ItemStack EMPTY_ITEM_STACK = new ItemStack((Item)null); - public enum EnumStackAmountType { - INVALID, NUMBER, PERCENTAGE, FLUID; - - public String getDisplayString(long l) { - switch (this) { - case NUMBER: - if (l < 999) { - return String.valueOf(l); - } else if (l < 9999) { - return String.format("%.2fK", (double) l / 1000); - } else if (l < 99999) { - return String.format("%.1fK", (double) l / 1000); - } else if (l < 999999) { - return String.format("%.0fK", (double) l / 1000); - } else if (l < 9999999) { - return String.format("%.2fM", (double) l / 1000000); - } else if (l < 99999999) { - return String.format("%.1fM", (double) l / 1000000); - } else if (l < 999999999) { - return String.format("%.0fB", (double) l / 1000000); - } else if (l < 9999999999L) { - return String.format("%.2fB", (double) l / 1000000000); - } else if (l < 99999999999L) { - return String.format("%.1fB", (double) l / 1000000000); - } else if (l < 999999999999L) { - return String.format("%.0fT", (double) l / 1000000000); - } else if (l < 9999999999999L) { - return String.format("%.2fT", (double) l / 1000000000000L); - } else if (l < 99999999999999L) { - return String.format("%.1fT", (double) l / 1000000000000L); - } else if (l < 999999999999999L) { - return String.format("%.0fG", (double) l / 1000000000000L); - } else if (l < 9999999999999999L) { - return String.format("%.2fG", (double) l / 1000000000000000L); - } else if (l < 99999999999990999L) { - return String.format("%.1fG", (double) l / 1000000000000000L); - } else { - return String.format("%.0fG", (double) l / 1000000000000000L); - } - case PERCENTAGE: - if (l < 999) { - return String.valueOf(l); - } else if (l < 9999) { - return String.format("≈%.1fK", (double) l / 1000); - } else if (l < 99999) { - return String.format("≈%.0fK", (double) l / 1000); - } else if (l < 999999) { - return String.format("≈%.1fM", (double) l / 1000000); - } else if (l < 9999999) { - return String.format("≈%.1fM", (double) l / 1000000); - } else if (l < 99999999) { - return String.format("≈%.0fM", (double) l / 1000000); - } else if (l < 999999999) { - return String.format("≈%.1fB", (double) l / 1000000000); - } else if (l < 9999999999L) { - return String.format("≈%.1fB", (double) l / 1000000000); - } else if (l < 99999999999L) { - return String.format("≈%.0fB", (double) l / 1000000000); - } else if (l < 999999999999L) { - return String.format("≈%.1fT", (double) l / 1000000000000L); - } else if (l < 9999999999999L) { - return String.format("≈%.1fT", (double) l / 1000000000000L); - } else if (l < 99999999999999L) { - return String.format("≈%.0fT", (double) l / 1000000000000L); - } else if (l < 999999999999999L) { - return String.format("≈%.1fG", (double) l / 1000000000000000L); - } else if (l < 9999999999999999L) { - return String.format("≈%.1fG", (double) l / 1000000000000000L); - } else { - return String.format("≈%.0fG", (double) l / 1000000000000000L); - } - case FLUID: - if (l < 999) { - return l + "mb"; - } else if (l < 9999) { - return String.format("%.2fb", (double) l / 1000); - } else if (l < 99999) { - return String.format("%.1fb", (double) l / 1000); - } else if (l < 999999) { - return String.format("%.0fb", (double) l / 1000); - } else if (l < 9999999) { - return String.format("%.1fKb", (double) l / 1000000); - } else if (l < 99999999) { - return String.format("%.0fKb", (double) l / 1000000); - } else if (l < 999999999) { - return String.format("%.1fMb", (double) l / 1000000000); - } else if (l < 9999999999L) { - return String.format("%.1fMb", (double) l / 1000000000); - } else if (l < 99999999999L) { - return String.format("%.0fMb", (double) l / 1000000000); - } else if (l < 999999999999L) { - return String.format("%.1fBb", (double) l / 1000000000000L); - } else if (l < 9999999999999L) { - return String.format("%.1fBb", (double) l / 1000000000000L); - } else if (l < 99999999999999L) { - return String.format("%.0fBb", (double) l / 1000000000000L); - } else if (l < 999999999999999L) { - return String.format("%.1fTb", (double) l / 1000000000000000L); - } else if (l < 9999999999999999L) { - return String.format("%.1fTb", (double) l / 1000000000000000L); - } else { - return String.format("%.0fTb", (double) l / 1000000000000000L); - } - default: - return "N/A"; - } - } - } - - public static boolean isEmpty(ItemStack stack) { return stack == null || stack == EMPTY_ITEM_STACK || stack.getItem() == EMPTY_ITEM; } - public static boolean isTypeEqual(@Nullable ItemStack one, @Nullable ItemStack two) { - return one != null && two != null && one.getItem() == two.getItem() && getMetadata(one) == getMetadata(two) && - NBT.equalsIgnoreJEC(one.getTagCompound(), two.getTagCompound()); - } - - - @Nullable - public static ItemStack toItemStackJEC(ItemStack itemStack) { - if (itemStack == null) - return null; - NBT.setData(itemStack, EnumStackAmountType.NUMBER, itemStack.stackSize); - itemStack.stackSize = 1; - return itemStack; - } - - public static boolean isItemStackJEC(@Nullable ItemStack itemStack) { - return itemStack != null && itemStack.getTagCompound() != null && - itemStack.getTagCompound().hasKey(JustEnoughCalculation.Reference.MODID); - } - - private static int getMetadata(ItemStack stack) { - return stack.getItemDamage(); - } - - public static class NBT { - public static boolean equalsIgnoreJEC(@Nullable NBTTagCompound a, @Nullable NBTTagCompound b) { - if (a == null && b == null) { - return true; - } else if (a == null || b == null) { - return false; - } else { - NBTTagCompound aNew = ((NBTTagCompound) a.copy()); - aNew.removeTag(JustEnoughCalculation.Reference.MODID); - NBTTagCompound bNew = ((NBTTagCompound) b.copy()); - bNew.removeTag(JustEnoughCalculation.Reference.MODID); - return aNew.equals(bNew); - } - } - - public static ItemStack setAmount(ItemStack itemStack, long amount) { - return setLong(itemStack, true, keyAmount, amount); - } - - public static ItemStack setType(ItemStack itemStack, EnumStackAmountType type) { - return setInteger(itemStack, true, keyType, type.ordinal()); - } - - public static ItemStack setData(ItemStack itemStack, EnumStackAmountType type, long amount) { - setInteger(itemStack, true, keyType, type.ordinal()); - return setLong(itemStack, true, keyAmount, amount); - } - - public static ItemStack setInteger(ItemStack itemStack, boolean isolate, String key, int value) { - return setValue(itemStack, isolate, (nbtTagCompound -> nbtTagCompound.setInteger(key, value))); - } - - public static ItemStack setLong(ItemStack itemStack, boolean isolate, String key, long value) { - return setValue(itemStack, isolate, (nbtTagCompound -> nbtTagCompound.setLong(key, value))); - } - - public static ItemStack setBoolean(ItemStack itemStack, boolean isolate, String key, boolean value) { - return setValue(itemStack, isolate, (nbtTagCompound -> nbtTagCompound.setBoolean(key, value))); - } - - static ItemStack setValue(ItemStack itemStack, boolean isolate, Consumer func) { - NBTTagCompound tagCompound = itemStack.getTagCompound(); - if (tagCompound == null) { - tagCompound = new NBTTagCompound(); - itemStack.setTagCompound(tagCompound); - } - if (isolate) { - if (!tagCompound.hasKey(JustEnoughCalculation.Reference.MODID)) { - tagCompound.setTag(JustEnoughCalculation.Reference.MODID, new NBTTagCompound()); - } - tagCompound = tagCompound.getCompoundTag(JustEnoughCalculation.Reference.MODID); - } - func.accept(tagCompound); - return itemStack; - } - - public static EnumStackAmountType getType(ItemStack itemStack) { - return EnumStackAmountType.values()[getInteger(itemStack, true, keyType)]; - } - - public static long getAmount(ItemStack itemStack) { - return getLong(itemStack, true, keyAmount); - } - - public static long getAmountItem(ItemStack itemStack) { - long amount = getAmount(itemStack); - switch (getType(itemStack)) { - case NUMBER: - return amount; - case PERCENTAGE: - return (amount + 99) % 100; - case FLUID: - return (amount + 999) % 1000; - default: - return 0; - } - } - - public static long getAmountInternal(ItemStack itemStack) { - long amount = getAmount(itemStack); - switch (getType(itemStack)) { - case NUMBER: - return amount * 100; - case PERCENTAGE: - return amount; - case FLUID: - return amount; - default: - return 0; - } - } - - public static int getInteger(ItemStack itemStack, boolean isolate, String key) { - return getTag(itemStack, isolate).getInteger(key); - } - - public static long getLong(ItemStack itemStack, boolean isolate, String key) { - return getTag(itemStack, isolate).getLong(key); - } - - static NBTTagCompound getTag(@Nonnull ItemStack itemStack, boolean isolate) { - if (isolate) { - return NBTHelper.getSubCompound(itemStack, JustEnoughCalculation.Reference.MODID, true); - } else { - if (!itemStack.hasTagCompound()) { - itemStack.setTagCompound(new NBTTagCompound()); - } - return itemStack.getTagCompound(); - } - } - } - - - public static class Click { - @Nullable - public static ItemStack leftClick(@Nullable ItemStack itemStack) { - return getClick(itemStack, (l -> l + 1), (l -> l + 1), (l -> 0L)); - } - - @Nullable - public static ItemStack leftShift(@Nullable ItemStack itemStack) { - return getClick(itemStack, (l -> l == 1 ? 10 : l + 10), (l -> l == 1 ? 10 : l + 10), (l -> 0L)); - } - - @Nullable - public static ItemStack rightClick(@Nullable ItemStack itemStack) { - return getClick(itemStack, (l -> l - 1), (l -> l - 1), (l -> 0L)); - } - - @Nullable - public static ItemStack rightShift(@Nullable ItemStack itemStack) { - return getClick(itemStack, (l -> l == 1 ? 0 : l <= 10 ? 1 : l - 10), - (l -> l == 1 ? 0 : l <= 10 ? 1 : l - 10), (l -> 0L)); - } - - @Nullable - static ItemStack getClick(@Nullable ItemStack itemStack, - Function funcNumber, - Function funcPercentage, - Function funcFluid) { - if (itemStack == null) { - return null; - } else { - long amount = NBT.getAmount(itemStack); - switch (NBT.getType(itemStack)) { - case INVALID: - amount = 0; - break; - case NUMBER: - amount = funcNumber.apply(amount); - break; - case PERCENTAGE: - amount = funcPercentage.apply(amount); - break; - case FLUID: - amount = funcFluid.apply(amount); - break; - } - return amount == 0 ? null : NBT.setAmount(itemStack, amount); - } - } - } } diff --git a/src/main/java/me/towdium/jecalculation/utils/Utilities.java b/src/main/java/me/towdium/jecalculation/utils/Utilities.java index 2d37b11..b77ea25 100644 --- a/src/main/java/me/towdium/jecalculation/utils/Utilities.java +++ b/src/main/java/me/towdium/jecalculation/utils/Utilities.java @@ -20,6 +20,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.IIcon; import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.text.WordUtils; @@ -127,6 +128,8 @@ public class Utilities { } } + + private static IIcon getFluidIcon(Fluid fluid) { IIcon icon = fluid.getFlowingIcon(); if(icon == null) {