Skip to content

Commit

Permalink
Add NEI Version Check (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
glowredman authored Feb 5, 2025
1 parent 1e5903b commit 5628efe
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ curseForgeRelations =
# This can be useful if you e.g. only want to allow versions in the form of '1.1.xxx'.
# The check is ONLY performed if the version is a git tag.
# Note: the specified string must be escaped, so e.g. 1\\.1\\.\\d+ instead of 1\.1\.\d+
# versionPattern =
versionPattern = d+\\.d+\\.d+(-pre|-snapshot)?

# Uncomment to prevent the source code from being published.
# noPublishedSources = true
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.31'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.32'
}


5 changes: 5 additions & 0 deletions src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import com.gtnewhorizon.gtnhlib.commands.ItemInHandCommand;
import com.gtnewhorizon.gtnhlib.compat.FalseTweaks;
import com.gtnewhorizon.gtnhlib.compat.Mods;
import com.gtnewhorizon.gtnhlib.compat.NotEnoughItemsVersionChecker;
import com.gtnewhorizon.gtnhlib.eventbus.EventBusSubscriber;
import com.gtnewhorizon.gtnhlib.util.AboveHotbarHUD;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
Expand Down Expand Up @@ -45,6 +47,9 @@ public void postInit(FMLPostInitializationEvent event) {
GTNHLib.info("FalseTweaks threaded rendering is enabled - disabling GTNHLib's thread safety checks");
}
}
if (Mods.NEI) {
FMLCommonHandler.instance().bus().register(new NotEnoughItemsVersionChecker());
}

if (shouldLoadModels()) {
Minecraft.getMinecraft().refreshResources();
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/gtnewhorizon/gtnhlib/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.util.IChatComponent;
import net.minecraftforge.common.util.FakePlayer;

import com.gtnewhorizon.gtnhlib.config.ConfigException;
import com.gtnewhorizon.gtnhlib.config.ConfigurationManager;
import com.gtnewhorizon.gtnhlib.eventbus.AutoEventBus;
import com.gtnewhorizon.gtnhlib.eventbus.Phase;
Expand All @@ -29,6 +30,11 @@ public void construct(FMLConstructionEvent event) {
public void preInit(FMLPreInitializationEvent event) {
AutoEventBus.executePhase(Phase.PRE);
GTNHLib.info("GTNHLib version " + Tags.VERSION + " loaded.");
try {
ConfigurationManager.registerConfig(GTNHLibConfig.class);
} catch (ConfigException e) {
GTNHLib.LOG.error("Failed to register GTNHLib config!", e);
}
}

public void init(FMLInitializationEvent event) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/gtnewhorizon/gtnhlib/GTNHLibConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.gtnewhorizon.gtnhlib;

import com.gtnewhorizon.gtnhlib.config.Config;

@Config(modid = GTNHLib.MODID)
public class GTNHLibConfig {

@Config.Comment("Set to true to no longer check if the NEI version is new enough to support RenderTooltipEvents")
@Config.DefaultBoolean(false)
public static boolean ignoreNEIVersion;

}
1 change: 1 addition & 0 deletions src/main/java/com/gtnewhorizon/gtnhlib/compat/Mods.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
public class Mods {

public static final boolean FALSETWEAKS = Loader.isModLoaded("falsetweaks");
public static final boolean NEI = Loader.isModLoaded("NotEnoughItems");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.gtnewhorizon.gtnhlib.compat;

import java.util.Locale;

import com.gtnewhorizon.gtnhlib.GTNHLib;
import com.gtnewhorizon.gtnhlib.GTNHLibConfig;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
import cpw.mods.fml.common.versioning.ArtifactVersion;
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;

public class NotEnoughItemsVersionChecker {

@SubscribeEvent
public void checkNEIVersion(ClientTickEvent event) {
if (FMLClientHandler.instance().getClient().thePlayer == null) {
return;
}

FMLCommonHandler.instance().bus().unregister(this);

if (GTNHLibConfig.ignoreNEIVersion) {
return;
}

ArtifactVersion neiVersion = Loader.instance().getIndexedModList().get("NotEnoughItems").getProcessedVersion();
if (neiVersion.compareTo(new DefaultArtifactVersion("2.7.8-GTNH")) >= 0) {
return; // NEI is at least version 2.7.8-GTNH
}
GTNHLib.proxy.addWarnToChat(
String.format(
Locale.ROOT,
"Installed NEI version is to old to support RenderTooltipEvents! This may cause problems. Installed NEI version: %s (2.7.8-GTNH and newer support RenderTooltipEvents)",
neiVersion.getVersionString()));
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/gtnewhorizon/gtnhlib/util/FilesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import java.io.IOException;
import java.net.URI;

import net.minecraft.util.Util;

import org.lwjgl.Sys;

import com.gtnewhorizon.gtnhlib.GTNHLib;

public class FilesUtil {

public static void openUri(URI uri) {
switch (net.minecraft.util.Util.getOSType()) {
switch (Util.getOSType()) {
case OSX -> {
try {
Runtime.getRuntime().exec(new String[] { "/usr/bin/open", uri.toString() });
Expand Down

0 comments on commit 5628efe

Please sign in to comment.