Add command to audit mixin environment in game (#1174)

* Add command to audit mixin environment in game

* Throw assertion error instead and add success message

Assertion errors will bypass the command exceptions being eaten.
This commit is contained in:
i509VCB 2020-11-23 13:32:33 -06:00 committed by GitHub
parent 6d328b5e45
commit ab87788dbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -2,5 +2,6 @@ archivesBaseName = "fabric-api-base"
version = getSubprojectVersion(project, "0.2.0")
dependencies {
testmodCompile project(path: ':fabric-command-api-v1', configuration: 'dev')
testmodCompile project(path: ':fabric-lifecycle-events-v1', configuration: 'dev')
}

View file

@ -16,9 +16,14 @@
package net.fabricmc.fabric.test.base;
import static net.minecraft.server.command.CommandManager.literal;
import org.spongepowered.asm.mixin.MixinEnvironment;
import net.minecraft.text.LiteralText;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
public class FabricApiBaseTestInit implements ModInitializer {
@ -36,5 +41,23 @@ public class FabricApiBaseTestInit implements ModInitializer {
}
});
}
// Command to call audit the mixin environment
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
dispatcher.register(literal("audit_mixins").executes(context -> {
context.getSource().sendFeedback(new LiteralText("Auditing mixin environment"), false);
try {
MixinEnvironment.getCurrentEnvironment().audit();
} catch (Exception e) {
// Use an assertion error to bypass error checking in CommandManager
throw new AssertionError("Failed to audit mixin environment", e);
}
context.getSource().sendFeedback(new LiteralText("Successfully audited mixin environment"), false);
return 1;
}));
});
}
}