Skip to content

Commit

Permalink
Add access transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
nea89o committed Aug 8, 2024
1 parent b96ba8a commit c1dabe3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

[![Youtube Tutorial](https://i.ytimg.com/vi/nWzHlomdCgc/maxresdefault.jpg)](https://www.youtube.com/watch?v=nWzHlomdCgc)
Expand Down
9 changes: 8 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ val mcVersion: String by project
val version: String by project
val mixinGroup = "$baseGroup.mixin"
val modid: String by project
val transformerFile = file("src/main/resources/accesstransformer.cfg")

// Toolchains:
java {
Expand Down Expand Up @@ -44,6 +45,10 @@ loom {
pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter())
// If you don't want mixins, remove this lines
mixinConfig("mixins.$modid.json")
if (transformerFile.exists()) {
println("Installing access transformer")
accessTransformer(transformerFile)
}
}
// If you don't want mixins, remove these lines
mixin {
Expand Down Expand Up @@ -99,6 +104,8 @@ tasks.withType(org.gradle.jvm.tasks.Jar::class) {
// If you don't want mixins, remove these lines
this["TweakClass"] = "org.spongepowered.asm.launch.MixinTweaker"
this["MixinConfigs"] = "mixins.$modid.json"
if (transformerFile.exists())
this["FMLAT"] = "${modid}_at.cfg"
}
}

Expand All @@ -112,7 +119,7 @@ tasks.processResources {
expand(inputs.properties)
}

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


Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/example/ExampleMod.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example;

import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.init.Blocks;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
Expand All @@ -9,5 +10,7 @@ public class ExampleMod {
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
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());
}
}
2 changes: 2 additions & 0 deletions src/main/resources/accesstransformer.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

public net.minecraft.client.renderer.GlStateManager$Color

0 comments on commit c1dabe3

Please sign in to comment.