Skip to content

Commit

Permalink
buildscript
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Dec 8, 2022
1 parent 5aba22f commit 54b2b9b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 48 deletions.
11 changes: 11 additions & 0 deletions buildscript/buildscript.properties
Original file line number Diff line number Diff line change
@@ -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
81 changes: 45 additions & 36 deletions buildscript/src/main/java/Buildscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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);
});

}
Expand All @@ -98,14 +92,29 @@ 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;
}

@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
Expand Down
12 changes: 0 additions & 12 deletions buildscript/src/main/java/Properties.java

This file was deleted.

0 comments on commit 54b2b9b

Please sign in to comment.