diff --git a/README.md b/README.md index 445559c..a720813 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Just Enough Calculation Mod -Hey, this is a small add-on to [NEI-GTNH-2.1](https://github.com/GTNewHorizons/NotEnoughItems) (Not Enough Items), in +Hey, this is a small add-on to **NEI** (Not Enough Items), in order to help you calculate the amount of resources to craft a specific amount of item. . This might be a little confusing, here's an example: @@ -17,6 +17,7 @@ the [release page](https://minecraft.curseforge.com/projects/just-enough-calcula ## Features +- Support get catalyst in [NEI-GTNH-2.1](https://github.com/GTNewHorizons/NotEnoughItems) - Infinite inputs, outputs and catalysts of recipe - Recipe from NEI recipe handler (recipe gui) - [x] vanilla @@ -25,7 +26,7 @@ the [release page](https://minecraft.curseforge.com/projects/just-enough-calcula - [ ] AE2 - [ ] Others - [x] Item from NEI item panel -- [ ] Fluid from NEI item panel (Need to get fluid from labels) +- [ ] Fluid from NEI item panel (Now need to get fluid from labels picker) - [x] OreDictionary recognize ## TODO @@ -39,10 +40,13 @@ the [release page](https://minecraft.curseforge.com/projects/just-enough-calcula - [ ] Fluid from NEI ItemPanel will be recognized as item - [ ] Some OreDict items renders wrong with overlay (Now removed the overlay) - [ ] GUI will cover the NEI's GUI like tooltip on item panel -- [ ] 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). +## Development + +For run `gradle runClient`, you need copy the mods from `dev-mods/` to `run/mods`. + [1]: http://cf.way2muchnoise.eu/full_just-enough-calculation_downloads.svg [2]: http://cf.way2muchnoise.eu/versions/just-enough-calculation.svg diff --git a/build.gradle b/build.gradle index 1b2650c..3de53aa 100644 --- a/build.gradle +++ b/build.gradle @@ -112,6 +112,9 @@ processResources { from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } + + // Move access transformer to META-INF + rename '(.+_at.cfg)', 'META-INF/$1' } tasks.withType(JavaCompile) { diff --git a/dev-mods/industrialcraft-2-2.2.828a-experimental.jar b/dev-mods/industrialcraft-2-2.2.828a-experimental.jar new file mode 100644 index 0000000..d2d45a3 Binary files /dev/null and b/dev-mods/industrialcraft-2-2.2.828a-experimental.jar differ diff --git a/src/main/java/me/towdium/jecalculation/nei/Adapter.java b/src/main/java/me/towdium/jecalculation/nei/Adapter.java index 058b070..6309ea3 100644 --- a/src/main/java/me/towdium/jecalculation/nei/Adapter.java +++ b/src/main/java/me/towdium/jecalculation/nei/Adapter.java @@ -17,14 +17,14 @@ public class Adapter { public static void init() { if (Loader.isModLoaded("Forestry")) { - JustEnoughCalculation.logger.info("Forestry is installed"); + JustEnoughCalculation.logger.info("Forestry installed"); adapters.add(new Forestry()); } if (Loader.isModLoaded("appliedenergistics2")) { JustEnoughCalculation.logger.info("ae2 installed"); adapters.add(new AE2()); } - if( Loader.isModLoaded("gregtech")) { + if (Loader.isModLoaded("gregtech")) { JustEnoughCalculation.logger.info("gregtech installed"); adapters.add(new GregTech()); } diff --git a/src/main/java/me/towdium/jecalculation/nei/JecaOverlayHandler.java b/src/main/java/me/towdium/jecalculation/nei/JecaOverlayHandler.java index ce463c2..72b1faf 100644 --- a/src/main/java/me/towdium/jecalculation/nei/JecaOverlayHandler.java +++ b/src/main/java/me/towdium/jecalculation/nei/JecaOverlayHandler.java @@ -1,7 +1,10 @@ package me.towdium.jecalculation.nei; import codechicken.nei.api.IOverlayHandler; +import codechicken.nei.recipe.GuiRecipeTab; +import codechicken.nei.recipe.HandlerInfo; import codechicken.nei.recipe.IRecipeHandler; +import codechicken.nei.recipe.TemplateRecipeHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import me.towdium.jecalculation.data.label.ILabel; @@ -13,6 +16,7 @@ import me.towdium.jecalculation.utils.wrappers.Trio; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; import java.util.*; import java.util.stream.Collectors; @@ -49,7 +53,7 @@ public class JecaOverlayHandler implements IOverlayHandler { // output recipeOutputs.forEach(o -> merge(merged, Arrays.asList(o), context, Recipe.IO.OUTPUT)); - NEIPlugin.getCatalyst(recipe).ifPresent(catalyst -> { + JecaOverlayHandler.getCatalyst(recipe).ifPresent(catalyst -> { List catalysts = Collections.singletonList(catalyst); merge(merged, catalysts, context, Recipe.IO.CATALYST); }); @@ -84,4 +88,24 @@ public class JecaOverlayHandler implements IOverlayHandler { }); } + private static Optional getCatalyst(@Nonnull IRecipeHandler handler) { + if (!NEIPlugin.isCatalystEnabled()) { + return Optional.empty(); + } + 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); + } + } diff --git a/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java b/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java index 08aa322..d0f4410 100644 --- a/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java +++ b/src/main/java/me/towdium/jecalculation/nei/NEIPlugin.java @@ -2,23 +2,40 @@ package me.towdium.jecalculation.nei; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.recipe.*; +import cpw.mods.fml.common.Loader; import me.towdium.jecalculation.JustEnoughCalculation; import me.towdium.jecalculation.data.label.ILabel; +import me.towdium.jecalculation.utils.Version; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -import javax.annotation.Nonnull; -import java.util.Optional; - public class NEIPlugin { + private static boolean catalystEnabled = false; + + private static final Version CATALYST_NEI_VERSION = new Version("2.1.0-GTNH"); + public static void init() { GuiContainerManager.addTooltipHandler(new JecaTooltipHandler()); Adapter.init(); + // nei version check + String neiVersion = Loader.instance().getIndexedModList().get("NotEnoughItems").getVersion(); + JustEnoughCalculation.logger.info("NEI version: " + neiVersion); + Version version = new Version(neiVersion); + if (version.isSuccess() && version.compareTo(CATALYST_NEI_VERSION) > 0) { + NEIPlugin.catalystEnabled = true; + JustEnoughCalculation.logger.info("catalyst enabled"); + } else { + JustEnoughCalculation.logger.info("catalyst disabled"); + } } private static ItemStack currentItemStack; + public static boolean isCatalystEnabled() { + return catalystEnabled; + } + public static ILabel getLabelUnderMouse() { if (NEIPlugin.currentItemStack == null) return ILabel.EMPTY; @@ -29,23 +46,6 @@ public class NEIPlugin { NEIPlugin.currentItemStack = itemStack; } - public static Optional 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); - } - public static void openRecipeGui(Object rep, int button) { if ((rep instanceof ItemStack || rep instanceof FluidStack)) { String id = rep instanceof ItemStack ? "item" : "liquid"; @@ -61,6 +61,4 @@ public class NEIPlugin { JustEnoughCalculation.logger.warn("unknown label representation " + rep); } } - - } diff --git a/src/main/java/me/towdium/jecalculation/network/ClientHandler.java b/src/main/java/me/towdium/jecalculation/network/ClientHandler.java index a82b176..0ecfb84 100644 --- a/src/main/java/me/towdium/jecalculation/network/ClientHandler.java +++ b/src/main/java/me/towdium/jecalculation/network/ClientHandler.java @@ -5,15 +5,10 @@ import me.towdium.jecalculation.command.JecaCommand; import me.towdium.jecalculation.data.Controller; import me.towdium.jecalculation.data.label.ILabel; import me.towdium.jecalculation.event.Handlers; -import net.minecraft.client.Minecraft; -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.client.ClientCommandHandler; -import org.lwjgl.input.Keyboard; import static me.towdium.jecalculation.gui.JecaGui.keyOpenGuiCraft; import static me.towdium.jecalculation.gui.JecaGui.keyOpenGuiMath; -import static org.lwjgl.input.Keyboard.KEY_NONE; public class ClientHandler { @@ -32,9 +27,4 @@ public class ClientHandler { ClientRegistry.registerKeyBinding(keyOpenGuiCraft); ClientRegistry.registerKeyBinding(keyOpenGuiMath); } - - - public EntityPlayer getPlayer() { - return Minecraft.getMinecraft().thePlayer; - } } diff --git a/src/main/java/me/towdium/jecalculation/utils/Version.java b/src/main/java/me/towdium/jecalculation/utils/Version.java new file mode 100644 index 0000000..829ff51 --- /dev/null +++ b/src/main/java/me/towdium/jecalculation/utils/Version.java @@ -0,0 +1,78 @@ +package me.towdium.jecalculation.utils; + + +import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class Version implements Comparable { + private int major = 0, minor = 0, patch = 0; + private String preRelease = ""; + private final boolean success; + + private static final String PRE_RELEASE_PREFIX = "-"; + + public Version(int major, int minor, int patch, String preRelease) { + this.major = major; + this.minor = minor; + this.patch = patch; + this.preRelease = preRelease; + this.success = true; + } + + public Version(String version) { + String[] split = version.split(PRE_RELEASE_PREFIX); + if (split.length == 0) { + success = false; + } else { + String[] versions = split[0].split("\\."); + if (versions.length != 3) + success = false; + else { + major = Integer.parseInt(versions[0]); + minor = Integer.parseInt(versions[1]); + patch = Integer.parseInt(versions[2]); + success = true; + } + } + + if (split.length > 1) { + preRelease = split[1]; + } + } + + @Override + public int compareTo(Version o) { + assert this.isSuccess(); + assert o.isSuccess(); + if (this.getMajor() != o.getMajor()) + return this.getMajor() < o.getMajor() ? -1 : 1; + if (this.getMinor() != o.getMinor()) + return this.getMinor() < o.getMinor() ? -1 : 1; + if (this.getPatch() != o.getPatch()) + return this.getPatch() < o.getPatch() ? -1 : 1; + return 0; + } + + public int getMajor() { + return major; + } + + public int getMinor() { + return minor; + } + + public int getPatch() { + return patch; + } + + public String getPreRelease() { + return preRelease; + } + + public boolean isSuccess() { + return success; + } +} diff --git a/src/main/resources/nei_at.cfg b/src/main/resources/nei_at.cfg index d422228..f9b27a0 100644 --- a/src/main/resources/nei_at.cfg +++ b/src/main/resources/nei_at.cfg @@ -1,4 +1,3 @@ # NEI Access Transformer configuration file -public net.minecraft.client.Minecraft func_152345_ab #isCallingFromMinecraftThread public net.minecraft.nbt.NBTTagCompound field_74784_a #tagMap public net.minecraft.nbt.NBTTagList field_74747_a #taglist diff --git a/src/test/java/me/towdium/jecalculation/utils/VersionTest.java b/src/test/java/me/towdium/jecalculation/utils/VersionTest.java new file mode 100644 index 0000000..38a6043 --- /dev/null +++ b/src/test/java/me/towdium/jecalculation/utils/VersionTest.java @@ -0,0 +1,53 @@ +package me.towdium.jecalculation.utils; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +/** + * Please use IDEA test instead Gradle. (In settings 'Gradle -> Run Tests Using') + */ +class VersionTest { + + @Test + void newInstance_withTwoDotRelease_isParsedCorrectly() { + final Version version = new Version("2.12.24"); + assertTrue(version.isSuccess()); + assertEquals(version.getMajor(), 2); + assertEquals(version.getMinor(), 12); + assertEquals(version.getPatch(), 24); + } + + @Test + void newInstance_withTwoDotReleaseAndPreReleaseName_isParsedCorrectly() { + final Version version = new Version("1.26.2-DEBUG"); + assertTrue(version.isSuccess()); + assertEquals(version.getMajor(), 1); + assertEquals(version.getMinor(), 26); + assertEquals(version.getPatch(), 2); + assertEquals(version.getPreRelease(), "DEBUG"); + } + + @Test + void compareTo_withEarlierVersion_isGreaterThan() { + assertEquals(new Version("2.0.0").compareTo(new Version("1.0.0")), 1); + } + + + @Test + void compareTo_withSameVersion_isEqual() { + assertEquals(new Version("2.0.0").compareTo(new Version("2.0.0")), 0); + } + + @Test + void compareTo_withLaterVersion_isLessThan() { + assertEquals(new Version("1.0.0").compareTo(new Version("2.0.0")), -1); + } + + @Test + void compareTo_withPreReleaseName_isGreaterThan() { + assertEquals(new Version("2.1.2-GTNH").compareTo(new Version("2.0.1-GTHN")), 1); + } +} \ No newline at end of file