mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-23 16:18:29 -05:00
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:
parent
6d328b5e45
commit
ab87788dbc
2 changed files with 24 additions and 0 deletions
|
@ -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')
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue