Skip to content
Draft

Mixin #299

Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1723428048
//version: 1743737794
/*
* DO NOT CHANGE THIS FILE!
* Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -80,6 +80,7 @@ propertyDefaultIfUnset("includeWellKnownRepositories", true)
propertyDefaultIfUnset("includeCommonDevEnvMods", true)
propertyDefaultIfUnset("stripForgeRequirements", false)
propertyDefaultIfUnset("noPublishedSources", false)
propertyDefaultIfUnset("mixinProviderSpec", "zone.rong:mixinbooter:10.6")
propertyDefaultIfUnset("forceEnableMixins", false)
propertyDefaultIfUnset("mixinConfigRefmap", "mixins.${project.modId}.refmap.json")
propertyDefaultIfUnsetWithEnvVar("enableCoreModDebug", false, "CORE_MOD_DEBUG")
Expand Down Expand Up @@ -518,7 +519,6 @@ configurations {
testRuntimeClasspath.extendsFrom(runtimeOnlyNonPublishable)
}

String mixinProviderSpec = 'zone.rong:mixinbooter:9.1'
dependencies {
if (usesMixins.toBoolean()) {
annotationProcessor 'org.ow2.asm:asm-debug-all:5.2'
Expand Down Expand Up @@ -871,9 +871,9 @@ if (enableJava17RunTasks.toBoolean()) {
dependencies {
if (modId != 'lwjgl3ify') {
java17Dependencies("io.github.twilightflower:lwjgl3ify:1.0.0")
}
java17PatchDependencies("io.github.twilightflower:lwjgl3ify:1.0.0:forgePatches") {
java17PatchDependencies("io.github.twilightflower:lwjgl3ify:1.0.0:forgePatches") {
transitive = false
}
}
}

Expand Down Expand Up @@ -1009,7 +1009,7 @@ abstract class RunHotswappableMinecraftTask extends RunMinecraftTask {

if (project.usesMixins.toBoolean()) {
this.extraJvmArgs.addAll(project.provider(() -> {
def mixinCfg = project.configurations.detachedConfiguration(project.dependencies.create(project.mixinProviderSpec))
def mixinCfg = project.configurations.detachedConfiguration(project.dependencies.create(mixinProviderSpec))
mixinCfg.canBeConsumed = false
mixinCfg.canBeResolved = true
mixinCfg.transitive = false
Expand Down
17 changes: 17 additions & 0 deletions examples/mixins/PlayerListMixin.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.NetworkManager;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.server.management.PlayerList

@Mixin(value=PlayerList.class, remap=false)
class PlayerListMixin {

@Inject(method = "initializeConnectionToPlayer", at = @At(value = "INVOKE",
target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;firePlayerLoggedIn(Lnet/minecraft/entity/player/EntityPlayer;)V"))
void init(NetworkManager netManager, EntityPlayerMP playerIn, NetHandlerPlayServer nethandlerplayserver, CallbackInfo ci) {
playerIn.sendMessage(new TextComponentString("Player " + playerIn.getName() + " logged in"));
}

}
14 changes: 14 additions & 0 deletions examples/mixins/TestClassMixin.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import com.cleanroommc.groovyscript.TestClass
import com.cleanroommc.groovyscript.api.GroovyLog

@Mixin(value = TestClass.class, remap=false)
class TestClassMixin {

@Inject(method = "sayHello", at = @At("HEAD"), cancellable = true)
private static void sayBye(CallbackInfo ci) {
GroovyLog.get().info("Bye from TestClassMixin");
ci.cancel();
}

}
10 changes: 1 addition & 9 deletions examples/runConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@
"version": "1.0.0",
"debug": true,
"loaders": {
"preInit": [
"classes/",
"preInit/"
],
"init": [
"init/"
],
"postInit": [
"postInit/",
"recipes/"
"test/"
]
},
"packmode": {
Expand Down
4 changes: 4 additions & 0 deletions examples/test/main.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

import com.cleanroommc.groovyscript.TestClass

TestClass.sayHello()
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ mixinsPackage = core.mixin
mixinConfigRefmap =
# Automatically generates a mixin config json if enabled, with the name mixins.modid.json
generateMixinConfig = false
# Mixin provider specification
mixinProviderSpec = zone.rong:mixinbooter:10.7
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
coreModClass = core.GroovyScriptCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void onConstruction(FMLConstructionEvent event) {
GroovyDeobfMapper.init();
LinkGeneratorHooks.init();
ReloadableRegistryManager.init();
((GroovyLogImpl) GroovyLog.get()).setPassedEarly();
GroovyScript.sandbox = new GroovyScriptSandbox();
ModSupport.INSTANCE.setup(event.getASMHarvestedData());

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/cleanroommc/groovyscript/TestClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cleanroommc.groovyscript;

import com.cleanroommc.groovyscript.api.GroovyLog;

public class TestClass {

static {
GroovyLog.get().info("Hello we are now initialising TestClass");
}

public static void sayHello() {
GroovyLog.get().info("Hello from TestClass");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public GSCommand() {
sender.sendMessage(new TextComponentString("Applied the default GameRules to the current world."));
}));


addSubcommand(new SimpleCommand("wiki", (server, sender, args) -> sender.sendMessage(getTextForUrl("GroovyScript wiki", "Click to open wiki in browser", new TextComponentString("https://cleanroommc.com/groovy-script/"))), "doc", "docs", "documentation"));

addSubcommand(new SimpleCommand("generateWiki", (server, sender, args) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cleanroommc.groovyscript.core;

import com.cleanroommc.groovyscript.sandbox.MixinSandbox;
import com.cleanroommc.groovyscript.sandbox.SandboxData;
import com.google.common.collect.ImmutableList;
import net.minecraftforge.common.ForgeVersion;
Expand Down Expand Up @@ -42,6 +43,7 @@ public void injectData(Map<String, Object> data) {
source = (File) data.getOrDefault("coremodLocation", null);
SandboxData.initialize((File) FMLInjectionData.data()[6], LOG);
SideOnlyConfig.init();
MixinSandbox.loadMixins();
}

@Override
Expand All @@ -51,6 +53,6 @@ public String getAccessTransformerClass() {

@Override
public List<String> getMixinConfigs() {
return ImmutableList.of("mixin.groovyscript.json");
return ImmutableList.of("mixin.groovyscript.groovy.json", "mixin.groovyscript.json");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class GroovyScriptTransformer implements IClassTransformer {
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
if (bytes == null) return null;
if (transformedName.contains("PlayerLoggedInEvent") || transformedName.endsWith("PlayerList") || transformedName.endsWith("EntityPlayerMP") || transformedName.endsWith("NetworkManager") || transformedName.endsWith("NetHandlerPlayServer") || transformedName.endsWith("TextComponentString")) {
GroovyScriptCore.LOG.info("Loading class {}", transformedName);
}
switch (name) {
case InvokerHelperVisitor.CLASS_NAME: {
ClassWriter classWriter = new ClassWriter(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void init(SourceUnit context, CallbackInfo ci) {
// inject correct package declaration into script
String packageName = rel.substring(0, i).replace('/', '.') + '.';
this.packageNode = new PackageNode(packageName);
this.packageNode.setSynthetic(true);
}
}

Expand Down
Loading