From 54b2b9b1f7bb59b56ee3e38e890eed2e4274de7c Mon Sep 17 00:00:00 2001 From: PinkGoosik Date: Thu, 8 Dec 2022 11:32:49 +0500 Subject: [PATCH] buildscript --- buildscript/buildscript.properties | 11 +++ buildscript/src/main/java/Buildscript.java | 81 ++++++++++++---------- buildscript/src/main/java/Properties.java | 12 ---- 3 files changed, 56 insertions(+), 48 deletions(-) delete mode 100644 buildscript/src/main/java/Properties.java diff --git a/buildscript/buildscript.properties b/buildscript/buildscript.properties index dc3a987..2e1cc5f 100644 --- a/buildscript/buildscript.properties +++ b/buildscript/buildscript.properties @@ -1,2 +1,13 @@ +# Mod Properties name = visuality +modVersion = 0.5.5 javaVersion = 17 + +# Dependencies +minecraftVersion = 1.19.2 +yarnMappings = 1.19.2+build.28 +fabricLoader = 0.14.11 +quiltflower = 1.9.0 + +fabricApi = 0.68.0+1.19.2 +clothConfig = 8.2.88 diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 5d5e564..88ad02c 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -2,7 +2,6 @@ import io.github.coolcrabs.brachyura.decompiler.fernflower.FernflowerDecompiler; import io.github.coolcrabs.brachyura.fabric.*; import io.github.coolcrabs.brachyura.fabric.FabricContext.ModDependencyCollector; -import io.github.coolcrabs.brachyura.fabric.FabricContext.ModDependencyFlag; import io.github.coolcrabs.brachyura.maven.Maven; import io.github.coolcrabs.brachyura.maven.MavenId; import io.github.coolcrabs.brachyura.minecraft.Minecraft; @@ -16,80 +15,75 @@ import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; -import java.util.ArrayList; -import java.util.List; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Properties; + +import static io.github.coolcrabs.brachyura.fabric.FabricContext.ModDependencyFlag.RUNTIME; +import static io.github.coolcrabs.brachyura.fabric.FabricContext.ModDependencyFlag.COMPILE; public class Buildscript extends SimpleFabricProject { + public Properties properties = null; @Override public String getModId() { - return Properties.MOD_ID; + return this.getProperties().getProperty("name"); } @Override public String getVersion() { - return Properties.MOD_VERSION; + return this.getProperties().getProperty("modVersion"); } @Override public VersionMeta createMcVersion() { - return Minecraft.getVersion(Properties.MINECRAFT); + return Minecraft.getVersion(this.getProperties().getProperty("minecraftVersion")); } @Override public MappingTree createMappings() { - return Yarn.ofMaven(FabricMaven.URL, FabricMaven.yarn(Properties.YARN_MAPPINGS)).tree; + return Yarn.ofMaven(FabricMaven.URL, FabricMaven.yarn(this.getProperties().getProperty("yarnMappings"))).tree; } @Override public FabricLoader getLoader() { - return new FabricLoader(FabricMaven.URL, FabricMaven.loader(Properties.FABRIC_LOADER)); + return new FabricLoader(FabricMaven.URL, FabricMaven.loader(this.getProperties().getProperty("fabricLoader"))); } @Override public void getModDependencies(ModDependencyCollector d) { + addFabricModules(d); + + d.addMaven("https://maven.shedaniel.me", new MavenId("me.shedaniel.cloth", "cloth-config-fabric", this.getProperties().getProperty("clothConfig")), RUNTIME, COMPILE); + d.addMaven("https://maven.shedaniel.me", new MavenId("me.shedaniel.cloth", "basic-math", "0.6.1"), RUNTIME, COMPILE); + + // Runtime Mods + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "lazydfu", "0.1.3"), RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "ferrite-core", "5.0.0-fabric"), RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "starlight", "1.1.1+1.19"), RUNTIME); + d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "lithium", "mc1.19.2-0.10.2"), RUNTIME); - addFabricModules(d, new String[] { - "fabric-api-base", - "fabric-resource-loader-v0", - "fabric-crash-report-info-v1", - "fabric-lifecycle-events-v1", - "fabric-particles-v1", - "fabric-registry-sync-v0", - "fabric-screen-api-v1", - "fabric-key-binding-api-v1", - "fabric-networking-api-v1" - }); - - d.addMaven("https://maven.shedaniel.me", new MavenId("me.shedaniel.cloth", "cloth-config-fabric", "8.2.88"), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE); - d.addMaven("https://maven.shedaniel.me", new MavenId("me.shedaniel.cloth", "basic-math", "0.6.1"), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE); - d.addMaven("https://api.modrinth.com/maven/", new MavenId("maven.modrinth", "modmenu", "4.0.6"), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE); - - d.addMaven("https://api.modrinth.com/maven/", new MavenId("maven.modrinth", "lazydfu", Properties.LAZY_DFU), ModDependencyFlag.RUNTIME); - d.addMaven("https://api.modrinth.com/maven/", new MavenId("maven.modrinth", "ferrite-core", "5.0.0-fabric"), ModDependencyFlag.RUNTIME); - d.addMaven("https://api.modrinth.com/maven/", new MavenId("maven.modrinth", "starlight", "1.1.1+1.19"), ModDependencyFlag.RUNTIME); - d.addMaven("https://api.modrinth.com/maven/", new MavenId("maven.modrinth", "lithium", "mc1.19.2-0.10.1"), ModDependencyFlag.RUNTIME); + // Compatibility + d.addMaven("https://maven.terraformersmc.com", new MavenId("com.terraformersmc", "modmenu", "4.1.1"), RUNTIME, COMPILE); } - public static void addFabricModules(ModDependencyCollector d, String[] modules) { - d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-api", Properties.FABRIC_API), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE); + public void addFabricModules(ModDependencyCollector d) { + String fabricApi = this.getProperties().getProperty("fabricApi"); + d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-api", fabricApi), RUNTIME, COMPILE); try { String temp = "https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/%version%/fabric-api-%version%.pom"; - String pom = temp.replaceAll("%version%", Properties.FABRIC_API); + String pom = temp.replaceAll("%version%", fabricApi); URL url = new URL(pom); URLConnection request = url.openConnection(); request.connect(); InputStreamReader isReader = new InputStreamReader(request.getInputStream()); MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = reader.read(isReader); - ArrayList mods = new ArrayList<>(List.of(modules)); model.getDependencies().forEach(dependency -> { var id = dependency.getArtifactId(); var ver = dependency.getVersion(); - if(mods.contains(id)) { - d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", id, ver), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE); - } + d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", id, ver), RUNTIME, COMPILE); }); } @@ -98,6 +92,21 @@ public static void addFabricModules(ModDependencyCollector d, String[] modules) } } + public Properties getProperties() { + if(this.properties == null) { + try (InputStream input = new FileInputStream(getProjectDir().resolve("buildscript").resolve("buildscript.properties").toFile())) { + Properties prop = new Properties(); + prop.load(input); + this.properties = prop; + } + catch (Exception e) { + System.out.println("Failed to read buildscript.properties due to an exception:\n" + e); + this.properties = new Properties(); + } + } + return this.properties; + } + @Override public int getJavaVersion() { return 17; @@ -105,7 +114,7 @@ public int getJavaVersion() { @Override public BrachyuraDecompiler decompiler() { - return new FernflowerDecompiler(Maven.getMavenJarDep(QuiltMaven.URL, new MavenId("org.quiltmc", "quiltflower", Properties.QUILTFLOWER))); + return new FernflowerDecompiler(Maven.getMavenJarDep(QuiltMaven.URL, new MavenId("org.quiltmc", "quiltflower", this.getProperties().getProperty("quiltflower")))); } @Override diff --git a/buildscript/src/main/java/Properties.java b/buildscript/src/main/java/Properties.java deleted file mode 100644 index 9cb2ff5..0000000 --- a/buildscript/src/main/java/Properties.java +++ /dev/null @@ -1,12 +0,0 @@ -public class Properties { - public static final String MOD_ID = "visuality"; - public static final String MOD_VERSION = "0.5.5"; - - public static final String MINECRAFT = "1.19.2"; - public static final String FABRIC_LOADER = "0.14.10"; - public static final String FABRIC_API = "0.64.0+1.19.2"; - public static final String YARN_MAPPINGS = "1.19.2+build.28"; - public static final String QUILTFLOWER = "1.9.0"; - - public static final String LAZY_DFU = "0.1.3"; -}