mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +00:00
Fix dev launch for fabric and forge
This commit is contained in:
parent
d7be33fa55
commit
18de2c3f99
5
.gitignore
vendored
5
.gitignore
vendored
@ -246,4 +246,7 @@ nbdist/
|
||||
/run/
|
||||
|
||||
**/testDir/
|
||||
platforms/fabric/run/config/Terra/config.yml
|
||||
|
||||
platforms/fabric/run/**
|
||||
|
||||
platforms/forge/run/**
|
||||
|
@ -20,11 +20,8 @@ object Versions {
|
||||
object Fabric {
|
||||
const val fabricLoader = "0.14.2"
|
||||
const val fabricAPI = "0.56.0+1.19"
|
||||
const val minecraft = "1.19"
|
||||
const val yarn = "$minecraft+build.1"
|
||||
const val mixin = "0.11.2+mixin.0.8.5"
|
||||
const val loom = "0.12-SNAPSHOT"
|
||||
const val loomQuiltflower = "1.7.1"
|
||||
const val minotaur = "1.1.0"
|
||||
}
|
||||
|
||||
@ -35,13 +32,13 @@ object Versions {
|
||||
|
||||
const val architecuryLoom = "0.12.0-SNAPSHOT"
|
||||
const val architectutyPlugin = "3.4-SNAPSHOT"
|
||||
|
||||
const val loomQuiltflower = "1.7.1"
|
||||
}
|
||||
|
||||
object Forge {
|
||||
const val minecraft = "1.19"
|
||||
const val forge = "$minecraft-41.0.38"
|
||||
const val yarn = "$minecraft+build.1"
|
||||
const val architecuryLoom = "0.12.0-SNAPSHOT"
|
||||
const val forge = "${Mod.minecraft}-41.0.38"
|
||||
const val burningwave = ""
|
||||
}
|
||||
|
||||
object Bukkit {
|
||||
|
@ -96,7 +96,6 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "BOOTSTRAP";
|
||||
|
@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
id("fabric-loom") version Versions.Fabric.loom
|
||||
id("io.github.juuxel.loom-quiltflower") version Versions.Fabric.loomQuiltflower
|
||||
id("architectury-plugin") version Versions.Mod.architectutyPlugin
|
||||
id("io.github.juuxel.loom-quiltflower") version Versions.Mod.loomQuiltflower
|
||||
}
|
||||
|
||||
|
||||
@ -20,12 +21,12 @@ dependencies {
|
||||
"common"(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false }
|
||||
shaded(project(path = ":platforms:mixin-common", configuration = "transformProductionFabric")) { isTransitive = false }
|
||||
|
||||
minecraft("com.mojang:minecraft:${Versions.Fabric.minecraft}")
|
||||
mappings("net.fabricmc:yarn:${Versions.Fabric.yarn}:v2")
|
||||
minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}")
|
||||
mappings("net.fabricmc:yarn:${Versions.Mod.yarn}:v2")
|
||||
|
||||
modImplementation("net.fabricmc:fabric-loader:${Versions.Fabric.fabricLoader}")
|
||||
|
||||
setOf("fabric-lifecycle-events-v1", "fabric-resource-loader-v0", "fabric-api-base", "fabric-command-api-v2").forEach { apiModule ->
|
||||
setOf("fabric-lifecycle-events-v1", "fabric-resource-loader-v0", "fabric-api-base", "fabric-command-api-v2", "fabric-networking-api-v1").forEach { apiModule ->
|
||||
val module = fabricApi.module(apiModule, Versions.Fabric.fabricAPI)
|
||||
modImplementation(module)
|
||||
include(module)
|
||||
@ -36,16 +37,16 @@ dependencies {
|
||||
}
|
||||
|
||||
loom {
|
||||
accessWidenerPath.set(project(":platforms:mixin-common").file("src/main/resources/terra.accesswidener"))
|
||||
accessWidenerPath.set(project(":platforms:mixin-common").file("terra.accesswidener"))
|
||||
|
||||
mixin {
|
||||
defaultRefmapName.set("terra-fabric-refmap.json")
|
||||
defaultRefmapName.set("terra.fabric.refmap.json")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
addonDir(project.file("./run/config/Terra/addons"), tasks.named("runClient").get())
|
||||
addonDir(project.file("./run/config/Terra/addons"), tasks.named("runServer").get())
|
||||
|
||||
addonDir(project.file("./run/config/Terra/addons"), tasks.named("configureLaunch").get())
|
||||
|
||||
tasks {
|
||||
compileJava {
|
||||
@ -56,4 +57,8 @@ tasks {
|
||||
inputFile.set(shadowJar.get().archiveFile)
|
||||
archiveFileName.set("${rootProject.name.capitalize()}-${project.version}.jar")
|
||||
}
|
||||
|
||||
processResources {
|
||||
from(project(":platforms:mixin-common").file("terra.accesswidener"))
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,8 @@
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"terra.fabric.mixins.json"
|
||||
"terra.fabric.mixins.json",
|
||||
"terra.common.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.2",
|
||||
|
@ -16,6 +16,5 @@
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"refmap": "terra-fabric-refmap.json"
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
id("dev.architectury.loom") version Versions.Forge.architecuryLoom
|
||||
id("dev.architectury.loom") version Versions.Mod.architecuryLoom
|
||||
id("architectury-plugin") version Versions.Mod.architectutyPlugin
|
||||
id("io.github.juuxel.loom-quiltflower") version Versions.Fabric.loomQuiltflower
|
||||
id("io.github.juuxel.loom-quiltflower") version Versions.Mod.loomQuiltflower
|
||||
}
|
||||
|
||||
architectury {
|
||||
@ -17,34 +17,43 @@ configurations {
|
||||
|
||||
dependencies {
|
||||
shadedApi(project(":common:implementation:base"))
|
||||
"forgeRuntimeLibrary"(project(":common:implementation:base"))
|
||||
|
||||
|
||||
"common"(project(path = ":platforms:mixin-common", configuration = "namedElements")) { isTransitive = false }
|
||||
shaded(project(path = ":platforms:mixin-common", configuration = "transformProductionForge")) { isTransitive = false }
|
||||
"developmentForge"(project(":platforms:mixin-common", configuration = "namedElements")) {
|
||||
"developmentForge"(project(path = ":platforms:mixin-common", configuration = "namedElements")) {
|
||||
isTransitive = false
|
||||
}
|
||||
|
||||
|
||||
forge(group = "net.minecraftforge", name = "forge", version = Versions.Forge.forge)
|
||||
|
||||
minecraft("com.mojang:minecraft:${Versions.Forge.minecraft}")
|
||||
mappings("net.fabricmc:yarn:${Versions.Forge.yarn}:v2")
|
||||
minecraft("com.mojang:minecraft:${Versions.Mod.minecraft}")
|
||||
mappings("net.fabricmc:yarn:${Versions.Mod.yarn}:v2")
|
||||
|
||||
//forge is not ok.
|
||||
compileOnly("org.burningwave:core:12.53.0")
|
||||
"forgeRuntimeLibrary"("org.burningwave:core:12.53.0")
|
||||
}
|
||||
|
||||
loom {
|
||||
accessWidenerPath.set(project(":platforms:mixin-common").file("src/main/resources/terra.accesswidener"))
|
||||
accessWidenerPath.set(project(":platforms:mixin-common").file("terra.accesswidener"))
|
||||
|
||||
mixin {
|
||||
defaultRefmapName.set("terra-forge-refmap.json")
|
||||
defaultRefmapName.set("terra.forge.refmap.json")
|
||||
}
|
||||
|
||||
forge {
|
||||
convertAccessWideners.set(true)
|
||||
mixinConfig("terra.common.mixins.json")
|
||||
mixinConfig("terra.forge.mixins.json")
|
||||
extraAccessWideners.add(loom.accessWidenerPath.get().asFile.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addonDir(project.file("./run/config/Terra/addons"), tasks.named("configureLaunch").get())
|
||||
|
||||
tasks {
|
||||
jar {
|
||||
@ -66,4 +75,8 @@ tasks {
|
||||
inputFile.set(shadowJar.get().archiveFile)
|
||||
archiveFileName.set("${rootProject.name.capitalize()}-${project.version}.jar")
|
||||
}
|
||||
|
||||
processResources {
|
||||
from(project(":platforms:mixin-common").file("terra.accesswidener"))
|
||||
}
|
||||
}
|
@ -1,16 +1,34 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
|
||||
import cpw.mods.cl.ModuleClassLoader;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import org.burningwave.core.classes.Classes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileVisitOption;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
|
||||
|
||||
|
||||
/**
|
||||
* Forge is really wacky and screws with class resolution in the addon loader. Loading every single Terra class *manually* on startup
|
||||
@ -33,7 +51,7 @@ public final class AwfulForgeHacks {
|
||||
*/
|
||||
public static JarFile getTerraJar() throws IOException {
|
||||
LOGGER.info("Scanning for Terra JAR...");
|
||||
return Files.walk(Path.of("./", "mods"), 1, FileVisitOption.FOLLOW_LINKS)
|
||||
return Files.walk(Path.of(System.getProperty("user.dir"), "mods"), 1, FileVisitOption.FOLLOW_LINKS)
|
||||
.filter(it -> it.getFileName().toString().endsWith(".jar"))
|
||||
.peek(path -> LOGGER.info("Found mod: {}", path))
|
||||
.map(Path::toFile)
|
||||
@ -52,30 +70,75 @@ public final class AwfulForgeHacks {
|
||||
.equals(ForgeEntryPoint.class.getName().replace('.', '/') + ".class")))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("Could not find Terra JAR"));
|
||||
|
||||
}
|
||||
|
||||
public static void loadAllTerraClasses() {
|
||||
|
||||
try(JarFile jar = getTerraJar()) {
|
||||
jar.stream()
|
||||
.forEach(jarEntry -> {
|
||||
if(jarEntry.getName().startsWith("com/dfsek/terra/forge/mixin")
|
||||
|| jarEntry.getName().startsWith("com/dfsek/terra/mod/mixin")) {
|
||||
return;
|
||||
}
|
||||
if(jarEntry.getName().endsWith(".class")) {
|
||||
String name = jarEntry.getName().replace('/', '.');
|
||||
name = name.substring(0, name.length() - 6);
|
||||
try {
|
||||
Class.forName(name);
|
||||
} catch(ClassNotFoundException | NoClassDefFoundError e) {
|
||||
LOGGER.warn("Failed to load class {}: {}", name, e);
|
||||
if (FMLLoader.isProduction()) {
|
||||
try(JarFile jar = getTerraJar()) {
|
||||
jar.stream()
|
||||
.forEach(jarEntry -> {
|
||||
if(jarEntry.getName().startsWith("com/dfsek/terra/forge/mixin")
|
||||
|| jarEntry.getName().startsWith("com/dfsek/terra/mod/mixin")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
throw new IllegalStateException("Could not load all Terra classes", e);
|
||||
if(jarEntry.getName().endsWith(".class")) {
|
||||
String name = jarEntry.getName().replace('/', '.');
|
||||
name = name.substring(0, name.length() - 6);
|
||||
try {
|
||||
Class.forName(name);
|
||||
} catch(ClassNotFoundException | NoClassDefFoundError e) {
|
||||
LOGGER.warn("Failed to load class {}: {}", name, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
throw new IllegalStateException("Could not load all Terra classes", e);
|
||||
}
|
||||
} else {
|
||||
// Forgive me for what I'm about to do...
|
||||
LOGGER.warn("I felt a great disturbance in the JVM, as if millions of class not found exceptions suddenly cried out in terror and were suddenly silenced.");
|
||||
ArrayList<Path> pathsToLoad = new ArrayList<>();
|
||||
|
||||
Path terraRoot = Path.of(System.getProperty("user.dir")).getParent().getParent().getParent();
|
||||
Path commonRoot = terraRoot.resolve("common");
|
||||
Path implementationRoot = commonRoot.resolve("implementation");
|
||||
|
||||
pathsToLoad.add(commonRoot.resolve("api"));
|
||||
pathsToLoad.add(implementationRoot.resolve("base"));
|
||||
pathsToLoad.add(implementationRoot.resolve("bootstrap-addon-loader"));
|
||||
for (Path path : pathsToLoad) {
|
||||
try {
|
||||
Path target = path.resolve("build").resolve("classes").resolve("java").resolve("main");
|
||||
|
||||
BootstrapAddonClassLoader cl = new BootstrapAddonClassLoader(new URL[] { path.toUri().toURL()});
|
||||
|
||||
Classes.Loaders omegaCL = Classes.Loaders.create();
|
||||
Files.walk(target, Integer.MAX_VALUE, FileVisitOption.FOLLOW_LINKS)
|
||||
.filter(it -> it.getFileName().toString().endsWith(".class"))
|
||||
.map(Path::toFile)
|
||||
.forEach(it -> {
|
||||
String name = it.getAbsolutePath().replace(target + "/", "").replace('\\', '.').replace('/', '.');
|
||||
name = name.substring(0, name.length() - 6);
|
||||
LOGGER.info("Loading class {}", name);
|
||||
try {
|
||||
Class.forName(name);
|
||||
} catch(ClassNotFoundException e) {
|
||||
try {
|
||||
String pathToJar = cl.loadClass(name).getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
|
||||
|
||||
cl.addURL(new URL("jar:file:" + pathToJar + "!/"));
|
||||
Class newClassLoad = Class.forName(name, true, cl);
|
||||
omegaCL.loadOrDefine(newClassLoad, AbstractPlatform.class.getClassLoader());
|
||||
} catch(ClassNotFoundException | URISyntaxException | IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
throw new IllegalStateException("Could not load all Terra classes", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,5 @@
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"refmap": "terra-forge-refmap.json"
|
||||
}
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
plugins {
|
||||
id("dev.architectury.loom") version Versions.Mod.architecuryLoom
|
||||
id("architectury-plugin") version Versions.Mod.architectutyPlugin
|
||||
id("io.github.juuxel.loom-quiltflower") version Versions.Mod.loomQuiltflower
|
||||
}
|
||||
|
||||
loom {
|
||||
accessWidenerPath.set(file("terra.accesswidener"))
|
||||
|
||||
mixin {
|
||||
defaultRefmapName.set("terra-common-refmap.json")
|
||||
defaultRefmapName.set("terra.common.refmap.json")
|
||||
}
|
||||
accessWidenerPath.set(file("src/main/resources/terra.accesswidener"))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -23,3 +25,4 @@ architectury {
|
||||
common("fabric", "forge")
|
||||
minecraft = Versions.Mod.minecraft
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,6 @@ public final class MinecraftAddon implements BaseAddon {
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "terra-fabric";
|
||||
return "terra-mod";
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "terra-common",
|
||||
"version": "1.0.0",
|
||||
"mixins": [
|
||||
"terra.common.mixins.json"
|
||||
]
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
"package": "com.dfsek.terra.mod.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"access.BiomeAccessor",
|
||||
"access.MobSpawnerLogicAccessor",
|
||||
"access.StateAccessor",
|
||||
"access.StructureAccessorAccessor",
|
||||
@ -42,6 +43,5 @@
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"refmap": "terra-common-refmap.json"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user