mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-14 01:04:06 +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
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user