diff --git a/build.gradle b/build.gradle index 31e150c..16ba5f4 100644 --- a/build.gradle +++ b/build.gradle @@ -10,35 +10,53 @@ buildscript { apply plugin: 'net.minecraftforge.gradle.forge' //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. +ext.modid = "titlechanger" +ext.modname = "Title Changer" +ext.moddescription = "Changes the Minecraft window title." +ext.modauthors = "maxwell-lt" +ext.modversion = "1.1.0" +ext.modpackage = "maxwell_lt.titlechanger" +ext.modarchive = "titlechanger" -version = "1.0" -group = "maxwell_lt.titlechanger" // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = "titlechanger" +ext.url = "https://www.github.com/Maxwell-lt/TitleChanger" +ext.updatejson = "https://raw.githubusercontent.com/Maxwell-lt/TitleChanger/master/update.json" -sourceCompatibility = targetCompatibility = "1.6" // Need this here so eclipse task generates correctly. +ext.mcversion = "1.11.2" +ext.forgeversion = "13.20.0.2206" +ext.mcpmappings = "snapshot_20161220" + + +version = modversion +group = modpackage // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = modarchive + +sourceCompatibility = targetCompatibility = "1.8" // Need this here so eclipse task generates correctly. compileJava { - sourceCompatibility = targetCompatibility = "1.6" + sourceCompatibility = targetCompatibility = "1.8" } minecraft { - version = "1.11.2-13.20.0.2206" + version = mcversion + '-' + forgeversion runDir = "run" - + // the mappings can be changed at any time, and must be in the following format. // snapshot_YYYYMMDD snapshot are built nightly. // stable_# stables are built at the discretion of the MCP team. // Use non-default mappings at your own risk. they may not always work. // simply re-run your setup task after changing the mappings to update your workspace. - mappings = "snapshot_20161220" - // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. + mappings = mcpmappings + makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. } + dependencies { + + // you may put jars on which you depend on in ./libs // or you may define them like so.. //compile "some.group:artifact:version:classifier" //compile "some.group:artifact:version" - + // real examples //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env @@ -65,13 +83,13 @@ processResources { // replace stuff in mcmod.info, nothing else from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' - + // replace version and mcversion - expand 'version':project.version, 'mcversion':project.minecraft.version + expand 'modid':modid, 'name':modname, 'description':moddescription, 'authors':modauthors, 'version':modversion, 'url':url, 'updatejson':updatejson } - + // copy everything else except the mcmod.info from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } -} +} \ No newline at end of file diff --git a/releases/titlechanger-1.1.0.jar b/releases/titlechanger-1.1.0.jar new file mode 100644 index 0000000..0435c16 Binary files /dev/null and b/releases/titlechanger-1.1.0.jar differ diff --git a/src/main/java/maxwell_lt/titlechanger/ClientProxy.java b/src/main/java/maxwell_lt/titlechanger/ClientProxy.java index 4165058..0664ea1 100644 --- a/src/main/java/maxwell_lt/titlechanger/ClientProxy.java +++ b/src/main/java/maxwell_lt/titlechanger/ClientProxy.java @@ -1,7 +1,6 @@ package maxwell_lt.titlechanger; -import org.lwjgl.opengl.Display; - +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; public class ClientProxy extends CommonProxy { @@ -9,8 +8,10 @@ public class ClientProxy extends CommonProxy { @Override public void preInit(FMLPreInitializationEvent e) { super.preInit(e); - - if (Config.windowTitle != "") Display.setTitle(Config.windowTitle); + + MinecraftForge.EVENT_BUS.register(new ReplaceTitle()); + + ReplaceTitle.Replace(); } } diff --git a/src/main/java/maxwell_lt/titlechanger/Config.java b/src/main/java/maxwell_lt/titlechanger/Config.java index e837b12..e326c17 100644 --- a/src/main/java/maxwell_lt/titlechanger/Config.java +++ b/src/main/java/maxwell_lt/titlechanger/Config.java @@ -8,6 +8,7 @@ public class Config { private static final String CATEGORY_GENERAL = "general"; public static String windowTitle = ""; + public static String timeFormat = "h:mm a"; public static void readConfig() { Configuration cfg = CommonProxy.config; @@ -25,7 +26,8 @@ public static void readConfig() { private static void initGeneralConfig(Configuration cfg) { cfg.addCustomCategoryComment(CATEGORY_GENERAL, "General configuration"); - windowTitle = cfg.getString("windowtitle", CATEGORY_GENERAL, "", "The title of the Minecraft window. Leave blank to keep the default window title for your version of Minecraft."); + windowTitle = cfg.getString("windowtitle", CATEGORY_GENERAL, "", "The title of the Minecraft window. Leave blank to keep the default window title for your version of Minecraft.\nSome special values that will be inserted at runtime:\n%mcver% -> The current Minecraft version\n%modcount% -> Number of loaded mods\n%time% -> Current system time\n"); + timeFormat = cfg.getString("timeformat", CATEGORY_GENERAL, "h:mm a", "Format to display time in. See http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns"); } } diff --git a/src/main/java/maxwell_lt/titlechanger/ReplaceTitle.java b/src/main/java/maxwell_lt/titlechanger/ReplaceTitle.java new file mode 100644 index 0000000..638bd63 --- /dev/null +++ b/src/main/java/maxwell_lt/titlechanger/ReplaceTitle.java @@ -0,0 +1,36 @@ +package maxwell_lt.titlechanger; + +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.lwjgl.opengl.Display; +import java.text.SimpleDateFormat; +import java.util.Date; + + +public class ReplaceTitle { + + @SubscribeEvent(priority = EventPriority.LOWEST) + public void clientTick(TickEvent.ClientTickEvent e) { + Replace(); + } + + public static void Replace() { + if (Config.windowTitle != "") { + Display.setTitle(processText(Config.windowTitle)); + } + } + + public static String processText(String formatString) { + String mcVersion = Loader.instance().getMinecraftModContainer().getVersion(); + String modCount = Integer.toString(Loader.instance().getModList().size()); + String time = new SimpleDateFormat(Config.timeFormat).format(new Date()).toString(); + + formatString = formatString.replaceAll("%mcver%", mcVersion); + formatString = formatString.replaceAll("%modcount%", modCount); + formatString = formatString.replaceAll("%time%", time); + + return formatString; + } +} \ No newline at end of file diff --git a/src/main/java/maxwell_lt/titlechanger/TitleChanger.java b/src/main/java/maxwell_lt/titlechanger/TitleChanger.java index da28338..5de9416 100644 --- a/src/main/java/maxwell_lt/titlechanger/TitleChanger.java +++ b/src/main/java/maxwell_lt/titlechanger/TitleChanger.java @@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -@Mod(modid = TitleChanger.MODID, version = TitleChanger.VERSION, name = TitleChanger.MODNAME, useMetadata = true, acceptedMinecraftVersions = "[1.10,1.11.2]") +@Mod(modid = TitleChanger.MODID, version = TitleChanger.VERSION, name = TitleChanger.MODNAME, useMetadata = true, acceptedMinecraftVersions = "[1.10,1.11.2]", updateJSON = "https://raw.githubusercontent.com/Maxwell-lt/TitleChanger/master/update.json") public class TitleChanger { public static final String MODID = "titlechanger"; diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 467a31f..8ad753a 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,16 +1,16 @@ [ -{ - "modid": "titlechanger", - "name": "Title Changer", - "description": "Changes the Minecraft window title.", - "version": "1.0", - "mcversion": "1.11.2", - "url": "https://github.com/Maxwell-lt/TitleChanger", - "updateJson": "https://raw.githubusercontent.com/Maxwell-lt/TitleChanger/master/update.json", - "authorList": ["maxwell-lt"], - "credits": "", - "logoFile": "", - "screenshots": [], - "dependencies": [] -} -] + { + "modid": "${modid}", + "name": "${name}", + "description": "${description}", + "version": "${version}", + "mcversion": "1.11.2", + "url": "${url}", + "updateUrl": "${updatejson}", + "authorList": ["${authors}"], + "credits": "", + "logoFile": "", + "screenshots": [], + "dependencies": [] + } +] \ No newline at end of file diff --git a/update.json b/update.json index becbb18..268bb33 100644 --- a/update.json +++ b/update.json @@ -1,13 +1,15 @@ { "homepage": "https://github.com/Maxwell-lt/TitleChanger/", "1.10.2": { + "1.1.0": "Added runtime replacements", "1.0": "First version" }, "1.11.2": { + "1.1.0": "Added runtime replacements", "1.0": "First version" }, "promos": { - "1.10.2-latest": "1.0", - "1.11.2-latest": "1.0" + "1.10.2-latest": "1.1.0", + "1.11.2-latest": "1.1.0" } }