diff --git a/.shelf/Uncommitted_changes_before_Update_at_04_11_2022_1_47_[Default_Changelist]/22.png b/.shelf/Uncommitted_changes_before_Update_at_04_11_2022_1_47_[Default_Changelist]/22.png deleted file mode 100644 index 635ffe299..000000000 Binary files a/.shelf/Uncommitted_changes_before_Update_at_04_11_2022_1_47_[Default_Changelist]/22.png and /dev/null differ diff --git a/build.gradle b/build.gradle index e606294b2..21505c1ac 100644 --- a/build.gradle +++ b/build.gradle @@ -110,6 +110,11 @@ dependencies { processResources { + def propertiesFile = file "src/main/resources/version.properties" + def properties = new Properties() + properties.setProperty("version", project.version) + propertiesFile.withWriter { properties.store(it, null) } + // this will ensure that this task is redone when the versions change. inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version diff --git a/src/main/java/idealindustrial/II_Core.java b/src/main/java/idealindustrial/II_Core.java index 5e1658567..3ddf461d6 100644 --- a/src/main/java/idealindustrial/II_Core.java +++ b/src/main/java/idealindustrial/II_Core.java @@ -1,27 +1,51 @@ package idealindustrial; +import com.google.gson.Gson; +import com.google.gson.JsonArray; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; -import cpw.mods.fml.common.event.*; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerAboutToStartEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.common.event.FMLServerStoppingEvent; +import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import idealindustrial.commands.CommandFixMaterials; import idealindustrial.commands.CommandFixQuests; import idealindustrial.commands.DimTPCommand; import idealindustrial.commands.ReloadRecipesCommand; import idealindustrial.integration.ingameinfo.InGameInfoLoader; +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.crash.CrashReport; import net.minecraft.util.ReportedException; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.world.WorldEvent; - -import java.io.File; -import java.io.IOException; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; @Mod(modid = "iicore", name = "II_Core", version = "MC1710", useMetadata = false, dependencies = "after:gregtech") public class II_Core { - private static final String version = "1.17.1"; + + private static final String PACKAGES_URL = "https://api.github.com/orgs/IdealIndustrial/packages/maven/idealindustrial.gt-ii-edition/versions"; + private static final String ANY_TOKEN = "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"; //just any public token without write access + private static final String version = "1.19.2"; + private String auto_version = "Dev_version"; + private String auto_last_version = null; public II_Core() { FMLCommonHandler.instance().bus().register(this); @@ -60,32 +84,66 @@ public void onServerStopping(FMLServerStoppingEvent event) { } + @SubscribeEvent(priority = EventPriority.LOWEST) + public void openGui(GuiOpenEvent event) { + if (auto_last_version != null || !(event.gui instanceof net.minecraft.client.gui.GuiMainMenu || event.gui.getClass().getSimpleName().equals("GuiCustom"))) { + return; + } + + try { + Properties p = new Properties(); + InputStream is = getClass().getResourceAsStream("/version.properties"); + if (is != null) { + p.load(is); + auto_version = p.getProperty("version", auto_version).replace("-SNAPSHOT", ""); + } + + //get the latest vesrion from github: + HttpGet get = new HttpGet(PACKAGES_URL); + HttpClient client = new DefaultHttpClient(); + get.setHeader("Authorization", "Bearer " + ANY_TOKEN); + HttpResponse response = client.execute(get); + String s = IOUtils.toString(response.getEntity().getContent()); + JsonArray root = new Gson().fromJson(s, JsonArray.class); + auto_last_version = root.get(0).getAsJsonObject().get("name").getAsString().replace("-SNAPSHOT", ""); + } catch (Exception e) { + auto_last_version = auto_version; + } + auto_version = "Current version: " + auto_version; + auto_last_version = "Latest version: " + auto_last_version; + } + + @SubscribeEvent(priority = EventPriority.LOW) + public void renderScreenPost(GuiScreenEvent.DrawScreenEvent.Post event) throws IOException { + if (event.gui instanceof net.minecraft.client.gui.GuiMainMenu || event.gui.getClass().getSimpleName().equals("GuiCustom")) { + FontRenderer fr = Minecraft.getMinecraft().fontRenderer; + event.gui.drawString(fr, auto_version, event.gui.width - fr.getStringWidth(auto_version), 0, Color.ORANGE.getRGB()); + event.gui.drawString(fr, auto_last_version, event.gui.width - fr.getStringWidth(auto_last_version), fr.FONT_HEIGHT + 2, Color.ORANGE.getRGB()); + } + } + private static boolean checkEnvironment() { try { Class.forName("thermos.Thermos"); - } - catch (ClassNotFoundException e) { + } catch (ClassNotFoundException e) { return true; } try { Class.forName("betterquesting.core.BetterQuesting"); - } - catch (ClassNotFoundException e){ + } catch (ClassNotFoundException e) { return true; } - + try { Class.forName("a.b.c.gambiarra.Plugin"); - } - catch (ClassNotFoundException e) { - - try { - Class.forName("com.juanmuscaria.playercontainerfix.FMLCoreMod"); - } - catch (ClassNotFoundException f) { - return false; - } - } + } catch (ClassNotFoundException e) { + + try { + Class.forName("com.juanmuscaria.playercontainerfix.FMLCoreMod"); + } catch (ClassNotFoundException f) { + return false; + } + } return true; } @@ -96,7 +154,6 @@ public void onServerStarting(FMLServerStartingEvent aEvent) { aEvent.registerServerCommand(new ReloadRecipesCommand()); // aEvent.registerServerCommand(new CommandFixMaterials()); - } @Mod.EventHandler diff --git a/src/main/java/idealindustrial/hooks/II_GameTitlePatch.java b/src/main/java/idealindustrial/hooks/II_GameTitlePatch.java index 9e3aa43a9..7dadb1811 100644 --- a/src/main/java/idealindustrial/hooks/II_GameTitlePatch.java +++ b/src/main/java/idealindustrial/hooks/II_GameTitlePatch.java @@ -2,16 +2,15 @@ import gloomyfolken.hooklib.asm.Hook; import gregtech.GT_Mod; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.ForgeHooksClient; -import org.lwjgl.opengl.Display; - -import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import javax.imageio.ImageIO; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.ForgeHooksClient; +import org.lwjgl.opengl.Display; public class II_GameTitlePatch { @@ -24,7 +23,6 @@ public static void createDisplay(ForgeHooksClient mc) { InputStream inputstream = GT_Mod.class.getResourceAsStream("/assets/" + icon.getResourceDomain() + "/" + icon.getResourcePath()); Display.setIcon(new ByteBuffer[]{call(inputstream)}); } catch (IOException ignore) { - } }