Add access transformers

This commit is contained in:
Linnea Gräf 2024-08-08 12:44:50 +02:00
parent b96ba8a968
commit c1dabe37d8
No known key found for this signature in database
GPG key ID: AA563E93EB628D91
4 changed files with 17 additions and 1 deletions

View file

@ -30,6 +30,10 @@ are used by the build system but *do not work* in a normal forge installation.
If you don't want mixins (which allow for modifying vanilla code), then you can remove the references to mixins from If you don't want mixins (which allow for modifying vanilla code), then you can remove the references to mixins from
the `build.gradle.kts` at the lines specified with comments and the `com.example.mixin` package. the `build.gradle.kts` at the lines specified with comments and the `com.example.mixin` package.
If you don't want access transformers (which allow for making methods public/non-final) you can delete the
`accesstransformer.cfg` file. If you make a change to the `accesstransformers.cfg` you might need to rebuild your
project using `./gradlew build --refresh-dependencies`.
### For those who have not an attention span ### For those who have not an attention span
[![Youtube Tutorial](https://i.ytimg.com/vi/nWzHlomdCgc/maxresdefault.jpg)](https://www.youtube.com/watch?v=nWzHlomdCgc) [![Youtube Tutorial](https://i.ytimg.com/vi/nWzHlomdCgc/maxresdefault.jpg)](https://www.youtube.com/watch?v=nWzHlomdCgc)

View file

@ -15,6 +15,7 @@ val mcVersion: String by project
val version: String by project val version: String by project
val mixinGroup = "$baseGroup.mixin" val mixinGroup = "$baseGroup.mixin"
val modid: String by project val modid: String by project
val transformerFile = file("src/main/resources/accesstransformer.cfg")
// Toolchains: // Toolchains:
java { java {
@ -44,6 +45,10 @@ loom {
pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter()) pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter())
// If you don't want mixins, remove this lines // If you don't want mixins, remove this lines
mixinConfig("mixins.$modid.json") mixinConfig("mixins.$modid.json")
if (transformerFile.exists()) {
println("Installing access transformer")
accessTransformer(transformerFile)
}
} }
// If you don't want mixins, remove these lines // If you don't want mixins, remove these lines
mixin { mixin {
@ -99,6 +104,8 @@ tasks.withType(org.gradle.jvm.tasks.Jar::class) {
// If you don't want mixins, remove these lines // If you don't want mixins, remove these lines
this["TweakClass"] = "org.spongepowered.asm.launch.MixinTweaker" this["TweakClass"] = "org.spongepowered.asm.launch.MixinTweaker"
this["MixinConfigs"] = "mixins.$modid.json" this["MixinConfigs"] = "mixins.$modid.json"
if (transformerFile.exists())
this["FMLAT"] = "${modid}_at.cfg"
} }
} }
@ -112,7 +119,7 @@ tasks.processResources {
expand(inputs.properties) expand(inputs.properties)
} }
rename("(.+_at.cfg)", "META-INF/$1") rename("accesstransformer.cfg", "META-INF/${modid}_at.cfg")
} }

View file

@ -1,5 +1,6 @@
package com.example; package com.example;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@ -9,5 +10,7 @@ public class ExampleMod {
@Mod.EventHandler @Mod.EventHandler
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
System.out.println("Dirt: " + Blocks.dirt.getUnlocalizedName()); System.out.println("Dirt: " + Blocks.dirt.getUnlocalizedName());
// Below is a demonstration of an access-transformed class access.
System.out.println("Color State: " + new GlStateManager.Color());
} }
} }

View file

@ -0,0 +1,2 @@
public net.minecraft.client.renderer.GlStateManager$Color