Skip to content

Commit

Permalink
+ auto update of current and latest version of iis at main menu page
Browse files Browse the repository at this point in the history
  • Loading branch information
WiseProjects committed Jun 19, 2024
1 parent 56b738c commit 83b2c5d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 27 deletions.
Binary file not shown.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
99 changes: 78 additions & 21 deletions src/main/java/idealindustrial/II_Core.java
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -96,7 +154,6 @@ public void onServerStarting(FMLServerStartingEvent aEvent) {
aEvent.registerServerCommand(new ReloadRecipesCommand());

// aEvent.registerServerCommand(new CommandFixMaterials());

}

@Mod.EventHandler
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/idealindustrial/hooks/II_GameTitlePatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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) {

}
}

Expand Down

0 comments on commit 83b2c5d

Please sign in to comment.