diff --git a/README.md b/README.md index 55373b1..00352af 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ -Source Code for the Custom Main Menu Minecraft Mod -================ \ No newline at end of file +# Patched Main Menu +### Fork of [Custom Main Menu](https://github.com/lumien231/Custom-Main-Menu) +This is a simple set of critical patches collected during the use of this mod: +* Uploading all file types in UTF-8 format. + (Previously, the standard system encoding was used) +* There will no longer be an LF ending at the end of lines that are loaded from the WEB \ No newline at end of file diff --git a/build.gradle b/build.gradle index 534c5f3..c728df0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,81 +1,66 @@ buildscript { repositories { - jcenter() - maven { url = "https://files.minecraftforge.net/maven" } + maven { url = 'https://maven.minecraftforge.net/' } + mavenCentral() } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' + classpath 'net.minecraftforge.gradle:ForgeGradle:3.+' } } -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. +apply plugin: 'net.minecraftforge.gradle' +apply plugin: 'maven-publish' -version = "2.0.9" -group = "lumien.custommainmenu" // http://maven.apache.org/guides/mini/guide-naming-conventions.html +version = '1.0' +group = 'lumien.custommainmenu' +archivesBaseName = 'custommainmenu' -sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. -compileJava { - sourceCompatibility = targetCompatibility = '1.8' -} +sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' minecraft { - version = "1.12.2-14.23.5.2847" - runDir = "run" - - replaceIn "CustomMainMenu.java" - replace "@VERSION@",project.version - - // 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_20171003" - // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. + mappings channel: 'snapshot', version: '20171003-1.12' + runs { + client { + workingDirectory project.file('run') + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + property 'forge.logging.console.level', 'debug' + } + server { + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + property 'forge.logging.console.level', 'debug' + } + } } -archivesBaseName = "CustomMainMenu-MC" + minecraft.version - 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 - - // the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. - //provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' - - // the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided, - // except that these dependencies get remapped to your current MCP mappings - //deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev' - //deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev' - - // for more info... - // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html - // http://www.gradle.org/docs/current/userguide/dependency_management.html + minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2860' + compile fileTree(dir: 'libs', include: '*.jar') +} +jar { + manifest { + attributes(["Specification-Title" : "custommainmenu", + "Specification-Vendor" : "examplemodsareus", + "Specification-Version" : "1", + "Implementation-Title" : project.name, + "Implementation-Version" : version, + "Implementation-Vendor" : "examplemodsareus", + "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")]) + } } -processResources { - // this will ensure that this task is redone when the versions change. - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version +jar.finalizedBy('reobfJar') - // 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 +publishing { + publications { + mavenJava(MavenPublication) { + artifact jar + } } - - // copy everything else except the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' + repositories { + maven { + url "file:///${project.projectDir}/mcmodsrepo" + } } + } diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index e9b9fd5..0000000 --- a/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -# Sets default memory used for gradle commands. Can be overridden by user or command line properties. -# This is required to provide enough memory for the Minecraft decompilation process. -org.gradle.jvmargs=-Xmx3G diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e18cba7..f5095af 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip diff --git a/libs/japng-0.5.1.jar b/libs/japng-0.5.1.jar new file mode 100644 index 0000000..3e25074 Binary files /dev/null and b/libs/japng-0.5.1.jar differ diff --git a/src/main/java/lumien/custommainmenu/CustomMainMenu.java b/src/main/java/lumien/custommainmenu/CustomMainMenu.java index 15b987f..999eade 100644 --- a/src/main/java/lumien/custommainmenu/CustomMainMenu.java +++ b/src/main/java/lumien/custommainmenu/CustomMainMenu.java @@ -25,7 +25,7 @@ public class CustomMainMenu { public static final String MOD_ID = "custommainmenu"; public static final String MOD_NAME = "Custom Main Menu"; - public static final String MOD_VERSION = "@VERSION@"; + public static final String MOD_VERSION = "1.0"; @Instance(value = MOD_ID) public static CustomMainMenu INSTANCE; diff --git a/src/main/java/lumien/custommainmenu/configuration/ConfigurationLoader.java b/src/main/java/lumien/custommainmenu/configuration/ConfigurationLoader.java index b049449..f0861bb 100644 --- a/src/main/java/lumien/custommainmenu/configuration/ConfigurationLoader.java +++ b/src/main/java/lumien/custommainmenu/configuration/ConfigurationLoader.java @@ -1,172 +1,69 @@ package lumien.custommainmenu.configuration; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import lumien.custommainmenu.CustomMainMenu; -import lumien.custommainmenu.gui.GuiCustom; - -import org.apache.commons.io.IOUtils; - -import com.google.common.io.ByteStreams; -import com.google.common.io.Files; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.stream.JsonReader; +import lumien.custommainmenu.CustomMainMenu; +import lumien.custommainmenu.gui.GuiCustom; +import org.apache.commons.io.IOUtils; -public class ConfigurationLoader -{ - Config config; - - public ConfigurationLoader(Config config) - { - this.config = config; - } - - public void load() throws Exception - { - JsonParser jsonParser = new JsonParser(); - - File configFolder = new File(CustomMainMenu.INSTANCE.configFolder, "CustomMainMenu"); - if (!configFolder.exists()) - { - configFolder.mkdir(); - } - - File mainmenuConfig = new File(configFolder, "mainmenu.json"); - if (!mainmenuConfig.exists()) - { - InputStream input = null; - - OutputStream output = null; - try - { - output = new FileOutputStream(mainmenuConfig); - input = getClass().getResourceAsStream("/assets/custommainmenu/mainmenu_default.json"); - ByteStreams.copy(input, output); - } - catch (FileNotFoundException e1) - { - e1.printStackTrace(); - } - catch (IOException e) - { - e.printStackTrace(); - } - finally - { - IOUtils.closeQuietly(output); - IOUtils.closeQuietly(input); - } - } - - File[] jsonFiles = configFolder.listFiles(); - - - // Preload Main Menu so that other menus can rely on it - - for (File guiFile : jsonFiles) - { - if (guiFile.getName().equals("mainmenu.json")) - { - GuiConfig guiConfig = new GuiConfig(); - String name = guiFile.getName().replace(".json", ""); - - JsonReader reader = null; - try - { - reader = new JsonReader(new FileReader(guiFile)); - } - catch (FileNotFoundException e) - { - e.printStackTrace(); - } - try - { - JsonElement jsonElement = jsonParser.parse(reader); - JsonObject jsonObject = jsonElement.getAsJsonObject(); - - guiConfig.load(name, jsonObject); - } - catch (Exception e) - { - try - { - reader.close(); - } - catch (IOException io) - { - io.printStackTrace(); - } - throw e; - } - - try - { - reader.close(); - } - catch (IOException io) - { - io.printStackTrace(); - } - - this.config.addGui(guiConfig.name, new GuiCustom(guiConfig)); - } - } - - for (File guiFile : jsonFiles) - { - if (!guiFile.getName().equals("mainmenu.json") && guiFile.getName().endsWith(".json")) - { - GuiConfig guiConfig = new GuiConfig(); - String name = guiFile.getName().replace(".json", ""); - - JsonReader reader = null; - try - { - reader = new JsonReader(new FileReader(guiFile)); - } - catch (FileNotFoundException e) - { - e.printStackTrace(); - } - try - { - JsonElement jsonElement = jsonParser.parse(reader); - JsonObject jsonObject = jsonElement.getAsJsonObject(); - - guiConfig.load(name, jsonObject); - } - catch (Exception e) - { - try - { - reader.close(); - } - catch (IOException io) - { - io.printStackTrace(); - } - throw e; - } - - try - { - reader.close(); - } - catch (IOException io) - { - io.printStackTrace(); - } - - this.config.addGui(guiConfig.name, new GuiCustom(guiConfig)); - } - } - } +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; + +public class ConfigurationLoader { + Config config; + + public ConfigurationLoader(Config config) { + this.config = config; + } + + public void load() { + JsonParser jsonParser = new JsonParser(); + + File configFolder = new File(CustomMainMenu.INSTANCE.configFolder, "CustomMainMenu"); + if (!configFolder.exists()) + if (!configFolder.mkdirs()) + throw new RuntimeException(new IOException("Can't create folder")); + + File mainConfig = new File(configFolder, "mainmenu.json"); + if (!mainConfig.exists()) { + try ( + InputStream input = getClass().getResourceAsStream("/assets/custommainmenu/mainmenu_default.json"); + OutputStream output = Files.newOutputStream(mainConfig.toPath()) + ) { + if (input == null) + throw new RuntimeException(new IOException("Default config not exist (/assets/custommainmenu/mainmenu_default.json)")); + IOUtils.copy(input, output); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + File[] jsonFiles = configFolder.listFiles(); + + if (jsonFiles == null) + return; + for (File guiFile : jsonFiles) { + if (!guiFile.getName().endsWith(".json")) + continue; + GuiConfig guiConfig = new GuiConfig(); + String name = guiFile.getName().replace(".json", ""); + + try ( + InputStream is = Files.newInputStream(guiFile.toPath()); + InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); + JsonReader reader = new JsonReader(isr) + ) { + JsonElement jsonElement = jsonParser.parse(reader); + JsonObject jsonObject = jsonElement.getAsJsonObject(); + guiConfig.load(name, jsonObject); + } catch (Exception e) { + e.printStackTrace(); + } + + this.config.addGui(guiConfig.name, new GuiCustom(guiConfig)); + } + } } diff --git a/src/main/java/lumien/custommainmenu/configuration/GuiConfig.java b/src/main/java/lumien/custommainmenu/configuration/GuiConfig.java index 065b2f0..f45a623 100644 --- a/src/main/java/lumien/custommainmenu/configuration/GuiConfig.java +++ b/src/main/java/lumien/custommainmenu/configuration/GuiConfig.java @@ -645,7 +645,7 @@ public IText getWantedText(JsonElement element) String textString = getStringPlease(element); if (textString.startsWith("web:")) { - String url = textString.substring(4, textString.length()); + String url = textString.substring(4); TextURL tURL = new TextURL(url, -1); diff --git a/src/main/java/lumien/custommainmenu/handler/LoadStringURL.java b/src/main/java/lumien/custommainmenu/handler/LoadStringURL.java index 00d27ab..1f93bb4 100644 --- a/src/main/java/lumien/custommainmenu/handler/LoadStringURL.java +++ b/src/main/java/lumien/custommainmenu/handler/LoadStringURL.java @@ -1,76 +1,32 @@ package lumien.custommainmenu.handler; +import lumien.custommainmenu.lib.texts.TextURL; + import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; - -import lumien.custommainmenu.lib.texts.TextURL; - -public class LoadStringURL extends Thread -{ - TextURL text; - - public LoadStringURL(TextURL text) - { - this.text = text; - - this.setDaemon(true); - } - - @Override - public void run() - { - BufferedReader in = null; - try - { - in = new BufferedReader(new InputStreamReader(text.getURL().openStream())); - } - catch (IOException e1) - { - e1.printStackTrace(); - } - - StringBuilder builder = new StringBuilder(); - - String inputLine = null; - do - { - if (inputLine != null) - { - builder.append(inputLine); - } - - String newInput = null; - try - { - newInput = in.readLine(); - } - catch (IOException e) - { - e.printStackTrace(); - } - - if (inputLine != null) - { - builder.append("\n"); - } - - inputLine = newInput; - } - while (inputLine != null); - - try - { - in.close(); - } - catch (IOException e) - { - e.printStackTrace(); - } - - synchronized (text.string) - { - text.string = builder.toString(); - } - } +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; + +public class LoadStringURL extends Thread { + volatile TextURL text; + + public LoadStringURL(TextURL text) { + this.text = text; + this.setDaemon(true); + } + + @Override + public void run() { + try ( + InputStream is = text.getURL().openStream(); + InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); + BufferedReader in = new BufferedReader(isr) + ) { + text.string = in.lines().collect(Collectors.joining("\n")); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index f04e323..f7e8e70 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,11 +3,11 @@ "modid": "custommainmenu", "name": "Custom Main Menu", "description": "Allows you to edit the mainmenu using json", - "version": "${version}", - "mcversion": "${mcversion}", - "url": "", + "version": "1.0", + "mcversion": "1.12.2", + "url": "https://github.com/slavapmk/Custom-Main-Menu-Slavapmk", "updateUrl": "", - "authorList": ["lumien"], + "authorList": ["lumien", "slavapmk"], "credits": "", "logoFile": "", "screenshots": [],