mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-18 11:19:30 +00:00
fix: now can work with old version of nei
This commit is contained in:
1 parent
74e43cc883
commit
0a09a18d0a
10 files changed
+188
-39
No files matched your search
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Binary file not shown.
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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<ItemStack> catalysts = Collections.singletonList(catalyst);
|
||||
merge(merged, catalysts, context, Recipe.IO.CATALYST);
|
||||
});
|
||||
@@ -84,4 +88,24 @@ public class JecaOverlayHandler implements IOverlayHandler {
|
||||
});
|
||||
}
|
||||
|
||||
private static Optional<ItemStack> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<Version> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user