Skip to content

Commit c1dabe3

Browse files
committed
Add access transformers
1 parent b96ba8a commit c1dabe3

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ are used by the build system but *do not work* in a normal forge installation.
3030
If you don't want mixins (which allow for modifying vanilla code), then you can remove the references to mixins from
3131
the `build.gradle.kts` at the lines specified with comments and the `com.example.mixin` package.
3232

33+
If you don't want access transformers (which allow for making methods public/non-final) you can delete the
34+
`accesstransformer.cfg` file. If you make a change to the `accesstransformers.cfg` you might need to rebuild your
35+
project using `./gradlew build --refresh-dependencies`.
36+
3337
### For those who have not an attention span
3438

3539
[![Youtube Tutorial](https://i.ytimg.com/vi/nWzHlomdCgc/maxresdefault.jpg)](https://www.youtube.com/watch?v=nWzHlomdCgc)

build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ val mcVersion: String by project
1515
val version: String by project
1616
val mixinGroup = "$baseGroup.mixin"
1717
val modid: String by project
18+
val transformerFile = file("src/main/resources/accesstransformer.cfg")
1819

1920
// Toolchains:
2021
java {
@@ -44,6 +45,10 @@ loom {
4445
pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter())
4546
// If you don't want mixins, remove this lines
4647
mixinConfig("mixins.$modid.json")
48+
if (transformerFile.exists()) {
49+
println("Installing access transformer")
50+
accessTransformer(transformerFile)
51+
}
4752
}
4853
// If you don't want mixins, remove these lines
4954
mixin {
@@ -99,6 +104,8 @@ tasks.withType(org.gradle.jvm.tasks.Jar::class) {
99104
// If you don't want mixins, remove these lines
100105
this["TweakClass"] = "org.spongepowered.asm.launch.MixinTweaker"
101106
this["MixinConfigs"] = "mixins.$modid.json"
107+
if (transformerFile.exists())
108+
this["FMLAT"] = "${modid}_at.cfg"
102109
}
103110
}
104111

@@ -112,7 +119,7 @@ tasks.processResources {
112119
expand(inputs.properties)
113120
}
114121

115-
rename("(.+_at.cfg)", "META-INF/$1")
122+
rename("accesstransformer.cfg", "META-INF/${modid}_at.cfg")
116123
}
117124

118125

src/main/java/com/example/ExampleMod.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.example;
22

3+
import net.minecraft.client.renderer.GlStateManager;
34
import net.minecraft.init.Blocks;
45
import net.minecraftforge.fml.common.Mod;
56
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@@ -9,5 +10,7 @@ public class ExampleMod {
910
@Mod.EventHandler
1011
public void init(FMLInitializationEvent event) {
1112
System.out.println("Dirt: " + Blocks.dirt.getUnlocalizedName());
13+
// Below is a demonstration of an access-transformed class access.
14+
System.out.println("Color State: " + new GlStateManager.Color());
1215
}
1316
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
public net.minecraft.client.renderer.GlStateManager$Color

0 commit comments

Comments
 (0)