Skip to content

Commit

Permalink
implement asm in fabric
Browse files Browse the repository at this point in the history
fix some compile errors
setup fake mod in fabric
  • Loading branch information
Wyvest committed Jan 1, 2025
1 parent 7b0e1f8 commit a49c5e3
Show file tree
Hide file tree
Showing 29 changed files with 319 additions and 143 deletions.
100 changes: 42 additions & 58 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,74 +1,60 @@
@file:Suppress("UnstableApiUsage", "PropertyName")

import dev.deftu.gradle.utils.GameSide
import dev.deftu.gradle.utils.includeOrShade

plugins {
java
kotlin("jvm")
id("dev.deftu.gradle.multiversion")
id("dev.deftu.gradle.tools")
id("dev.deftu.gradle.tools.resources")
id("dev.deftu.gradle.tools.bloom")
id("dev.deftu.gradle.tools.shadow")
id("dev.deftu.gradle.tools.minecraft.loom")
id("dev.deftu.gradle.multiversion") // Applies preprocessing for multiple versions of Minecraft and/or multiple mod loaders.
id("dev.deftu.gradle.tools") // Applies several configurations to things such as the Java version, project name/version, etc.
id("dev.deftu.gradle.tools.resources") // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources.
id("dev.deftu.gradle.tools.bloom") // Applies the Bloom plugin, which allows us to replace tokens in our source files, such as being able to use `@MOD_VERSION` in our source files.
id("dev.deftu.gradle.tools.shadow") // Applies the Shadow plugin, which allows us to shade our dependencies into our mod JAR. This is NOT recommended for Fabric mods, but we have an *additional* configuration for those!
id("dev.deftu.gradle.tools.minecraft.loom") // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you.
id("dev.deftu.gradle.tools.minecraft.releases") // Applies the Minecraft auto-releasing plugin, which allows you to automatically release your mod to CurseForge and Modrinth.
}

val accessTransformerName = "patcher1${mcData.version.minor}_at.cfg"

// Sets up the variables for when we preprocess to other Minecraft versions.
preprocess {
vars.put("MODERN", if (mcData.version.minor >= 16) 1 else 0)
}
toolkitLoomHelper {
useOneConfig {
version = "1.0.0-alpha.49"
loaderVersion = "1.1.0-alpha.35"

//if (project.platform.isLegacyForge) {
// runConfigs {
// "client" {
// property("patcher.debugBytecode", "true")
// property("mixin.debug.verbose", "true")
// property("mixin.debug.export", "true")
// property("mixin.dumpTargetOnFailure", "true")
// property("fml.coreMods.load", "club.sk1er.patcher.tweaker.PatcherTweaker")
// programArgs("--tweakClass", "org.polyfrost.oneconfig.internal.legacy.OneConfigTweaker")
// programArgs("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker")
// property("mixin.debug.export", "true")
// programArgs("--mixin", "mixins.${mod_id}.json")
// }
// }
//}

//if (project.platform.isForge) {
// forge {
// accessTransformer(rootProject.file("src/main/resources/$accessTransformerName"))
// mixinConfig("mixins.${mod_id}.json")
// }
//}
usePolyMixin = true
polyMixinVersion = "0.8.4+build.2"

toolkitLoomHelper {
useOneConfig("1.1.0-alpha.34", "1.0.0-alpha.43", mcData, "commands", "config-impl", "events", "hud", "internal", "ui")
useDevAuth()
applyLoaderTweaker = true

for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) {
+module
}
}
useDevAuth("1.2.1")
useMixinExtras("0.4.1")

// Turns off the server-side run configs, as we're building a client-sided mod.
disableRunConfigs(GameSide.SERVER)

// Defines the name of the Mixin refmap, which is used to map the Mixin classes to the obfuscated Minecraft classes.
if (!mcData.isNeoForge) {
useMixinRefMap(modData.id)
}

if (mcData.isLegacyForge) {
useTweaker("org.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker", GameSide.CLIENT)
useForgeMixin(modData.id) // Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects.
if (mcData.isForge) {
// Configures the Mixin tweaker if we are building for Forge.
useForgeMixin(modData.id)

useProperty("patcher.debugBytecode", "true", GameSide.CLIENT)
useProperty("mixin.debug.verbose", "true", GameSide.CLIENT)
useProperty("mixin.debug.export", "true", GameSide.CLIENT)
useProperty("mixin.dumpTargetOnFailure", "true", GameSide.CLIENT)
useProperty("fml.coreMods.load", "club.sk1er.patcher.tweaker.PatcherTweaker", GameSide.CLIENT)
}
}

if (mcData.isForge) {
loom {
forge {
accessTransformer(rootProject.file("src/main/resources/$accessTransformerName"))
accessTransformer(rootProject.file("src/main/resources/META-INF/$accessTransformerName"))
}
}
}
Expand All @@ -85,49 +71,47 @@ sourceSets {

// Configures the libraries/dependencies for your mod.
dependencies {
modImplementation(shade("org.polyfrost:elementa-$mcData:562") {
modImplementation(includeOrShade("org.polyfrost:elementa-$mcData:562") {
isTransitive = false
})

implementation(shade("com.github.ben-manes.caffeine:caffeine:2.9.3")!!)
implementation(includeOrShade("com.github.ben-manes.caffeine:caffeine:2.9.3")!!)

implementation(shade("com.github.videogame-hacker:Koffee:88ba1b0") {
implementation(includeOrShade("com.github.char:Koffee:88ba1b0") {
isTransitive = false
})

if (mcData.version.minor < 12) {
implementation(shade("it.unimi.dsi:fastutil:8.5.13")!!)
implementation(includeOrShade("it.unimi.dsi:fastutil:8.5.13")!!)
}

// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
if (mcData.isLegacyForge) {
compileOnly("org.polyfrost:polymixin:0.8.4+build.2")
//todo fix with V1
//modImplementation("org.polyfrost:legacy-crafty-crashes:1.0.0") {
// isTransitive = false
//}
if (mcData.isFabric) {
runtimeOnly("include"(rootProject.project(":fake-mod"))!!)
implementation(includeOrShade("com.github.Chocohead:Fabric-ASM:2.3")!!)
}
}

tasks {
compileKotlin {
kotlinOptions {
freeCompilerArgs += listOf("-Xopt-in=kotlin.RequiresOptIn", "-Xno-param-assertions", "-Xjvm-default=all-compatibility")
compilerOptions {
optIn.add("kotlin.RequiresOptIn")
freeCompilerArgs.add("-Xno-param-assertions")
freeCompilerArgs.add("-Xjvm-default=all-compatibility")
}
}

jar {
// Sets the jar manifest attributes.
if (mcData.isLegacyForge) {
manifest.attributes += mapOf(
"FMLCorePlugin" to "club.sk1er.patcher.tweaker.PatcherTweaker",
"FMLCorePluginContainsFMLMod" to "Yes, yes it does",
"FMLAT" to accessTransformerName,
"Main-Class" to "club.sk1er.container.ContainerMessage"
)
}
}

processResources {
exclude("patcher18_at.cfg")
exclude("patcher112_at.cfg")
exclude("**/*.at.cfg")
}
}
13 changes: 13 additions & 0 deletions fake-mod/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@file:Suppress("UnstableApiUsage", "PropertyName")

import dev.deftu.gradle.utils.GameSide

plugins {
java
id("dev.deftu.gradle.tools") // Applies several configurations to things such as the Java version, project name/version, etc.
id("dev.deftu.gradle.tools.minecraft.loom") // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you.
}

toolkitLoomHelper {
disableRunConfigs(GameSide.BOTH)
}
5 changes: 5 additions & 0 deletions fake-mod/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Configures the mod loader that we're developing for.
loom.platform=fabric
loom.loader.use=false
# Configures the Minecraft version that we're developing for.
minecraft.version=1.8.9
22 changes: 22 additions & 0 deletions fake-mod/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@file:Suppress("PropertyName")

pluginManagement {
repositories {
// Releases
maven("https://maven.deftu.dev/releases")
maven("https://maven.fabricmc.net")
maven("https://maven.architectury.dev/")
maven("https://maven.minecraftforge.net")
maven("https://repo.essential.gg/repository/maven-public")
maven("https://server.bbkr.space/artifactory/libs-release/")
maven("https://jitpack.io/")

// Snapshots
maven("https://maven.deftu.dev/snapshots")
mavenLocal()

// Default
gradlePluginPortal()
mavenCentral()
}
}
21 changes: 21 additions & 0 deletions fake-mod/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"schemaVersion": 1,
"id": "polypatcher",
"name": "PolyPatcher",
"version": "1",
"description": "",
"authors": [
"Polyfrost"
],
"contact": {
"homepage": "https://polyfrost.org",
"sources": "https://github.com/Polyfrost/OneConfig",
"issues": "https://inv.wtf/polyfrost"
},
"environment": "client",
"custom": {
"modmenu": {
"parent": "patcher"
}
}
}
27 changes: 11 additions & 16 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureoncommand=true
org.gradle.parallel.threads=4
org.gradle.jvmargs=-Xmx2G

# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod_*` AND REMOVE THIS COMMENT.

# Sets the name of your mod.
mod.name=Patcher
# Sets the id of your mod that mod loaders use to recognize it.
# Sets the ID of your mod that mod loaders use to recognize it.
mod.id=patcher
# Sets the version of your mod.
# normal versions will be "1.x.x"
# betas will be "1.x.x+beta-y" / "1.x.x+branch_beta-y"
# rcs will be 1.x.x+rc-y
# extra branches will be 1.x.x+branch-y
# Sets the version of your mod. Make sure to update this when you make changes according to the SemVer specification.
mod.version=1.10.1
# Sets the name of the jar file that you put in your 'mods' folder.
mod.group=club.sk1er

# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
polyfrost.defaults.loom=3
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureoncommand=true
org.gradle.parallel.threads=4
org.gradle.jvmargs=-Xmx2G
# Sets the Maven group ID of your mod. This is effectively unused but is good practice to set regardless.
mod.group=club.sk1er
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
10 changes: 9 additions & 1 deletion root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ plugins {
}

preprocess {
strictExtraMappings.set(true)
// Adding new versions/loaders can be done like so:
// For each version, we add a new wrapper around the last from highest to lowest.
// Each mod loader needs to link up to the previous version's mod loader so that the mappings can be processed from the previous version.
// "1.12.2-forge"(11202, "srg") {
// "1.8.9-forge"(10809, "srg")
// }

"1.12.2-forge"(11202, "srg") {
"1.12.2-fabric"(11202, "yarn") {
"1.8.9-fabric"(10809, "yarn", file("versions/1.12.2-1.8.9.txt")) {
"1.8.9-forge"(10809, "srg")
}
}
}

strictExtraMappings.set(true)
}
15 changes: 12 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@file:Suppress("PropertyName")

import groovy.lang.MissingPropertyException

pluginManagement {
repositories {
// Repositories
// Releases
maven("https://maven.deftu.dev/releases")
maven("https://maven.fabricmc.net")
maven("https://maven.architectury.dev/")
Expand All @@ -15,23 +17,30 @@ pluginManagement {
maven("https://maven.deftu.dev/snapshots")
mavenLocal()

// Default repositories
// Default
gradlePluginPortal()
mavenCentral()
}

plugins {
kotlin("jvm") version("2.0.0")
id("dev.deftu.gradle.multiversion-root") version("2.13.0")
id("dev.deftu.gradle.multiversion-root") version("2.17.0")
}
}

val projectName: String = extra["mod.name"]?.toString()
?: throw MissingPropertyException("mod.name has not been set.")

// Configures the root project Gradle name based on the value in `gradle.properties`
rootProject.name = projectName
rootProject.buildFileName = "root.gradle.kts"

include(":fake-mod")

// Adds all of our build target versions to the classpath if we need to add version-specific code.
// Update this list if you want to remove/add a version and/or mod loader.
// The format is: version-modloader (f.ex: 1.8.9-forge, 1.17.1-fabric, etc)
// **REMEMBER TO ALSO UPDATE THE `root.gradle.kts` FILE WITH THE NEW VERSION(S).
listOf(
"1.8.9-forge",
"1.8.9-fabric",
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/club/sk1er/patcher/Patcher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package club.sk1er.patcher;

import club.sk1er.patcher.tweaker.TweakerHooks;
import org.polyfrost.oneconfig.api.ui.v1.Notifications;
import org.polyfrost.oneconfig.utils.v1.JsonUtils;
import org.polyfrost.polyui.unit.Units;
Expand All @@ -21,7 +22,6 @@
import club.sk1er.patcher.screen.render.overlay.ImagePreview;
import club.sk1er.patcher.screen.render.overlay.metrics.MetricsRenderer;
import club.sk1er.patcher.screen.render.title.TitleFix;
import club.sk1er.patcher.tweaker.PatcherTweaker;
import club.sk1er.patcher.util.chat.ChatHandler;
import club.sk1er.patcher.util.enhancement.EnhancementManager;
import club.sk1er.patcher.util.enhancement.ReloadListener;
Expand Down Expand Up @@ -64,17 +64,19 @@
import java.util.*;
import java.util.stream.Collectors;

//#if FORGE
@Mod(modid = "@MOD_ID@", name = "@MOD_NAME@", version = Patcher.VERSION, clientSideOnly = true)
public class Patcher {
//#endif
public class Patcher
//#if FABRIC
//$$ implements net.fabricmc.api.ClientModInitializer
//#endif
{

@Mod.Instance("patcher")
public static Patcher instance;

// normal versions will be "1.x.x"
// betas will be "1.x.x+beta-y" / "1.x.x+branch_beta-y"
// rcs will be 1.x.x+rc-y
// extra branches will be 1.x.x+branch-y
public static final String VERSION = "@VER@";
public static final String VERSION = "@MOD_VERSION@";

private static final Logger logger = LogManager.getLogger("Patcher");
private final File logsDirectory = new File(Minecraft.getMinecraft().mcDataDir + File.separator + "logs" + File.separator);
Expand Down Expand Up @@ -161,7 +163,7 @@ public void onLoadComplete(FMLLoadCompleteEvent event) {
this.detectIncompatibilities(activeModList);
this.detectReplacements(activeModList);

long time = (System.currentTimeMillis() - PatcherTweaker.clientLoadTime);
long time = (System.currentTimeMillis() - TweakerHooks.clientLoadTime);
if (PatcherConfig.startupNotification) {
Notifications.enqueue(Notifications.Type.Info, "Minecraft Startup", "Minecraft started in " + (time / 1000L) + " seconds.");
}
Expand Down
Loading

0 comments on commit a49c5e3

Please sign in to comment.