forked from ChomeNS/chipmunkmod
added .eval java with jshell and fixed TitleScreenMixin not being in mixins
This commit is contained in:
parent
11dbc4665a
commit
b5ba97afaf
4 changed files with 41 additions and 8 deletions
|
@ -3,6 +3,7 @@ package land.chipmunk.chipmunkmod.commands;
|
|||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import land.chipmunk.chipmunkmod.util.Eval;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.Text;
|
||||
|
@ -21,14 +22,22 @@ public class EvalCommand {
|
|||
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("eval")
|
||||
.then(
|
||||
argument("code", greedyString())
|
||||
.executes(EvalCommand::eval)
|
||||
.then(literal("java")
|
||||
.then(
|
||||
argument("code", greedyString())
|
||||
.executes(EvalCommand::evalJava)
|
||||
)
|
||||
)
|
||||
.then(literal("lua")
|
||||
.then(
|
||||
argument("code", greedyString())
|
||||
.executes(EvalCommand::evalLua)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static int eval (CommandContext<FabricClientCommandSource> context) {
|
||||
public static int evalLua(CommandContext<FabricClientCommandSource> context) {
|
||||
final String code = getString(context, "code");
|
||||
|
||||
try {
|
||||
|
@ -45,6 +54,13 @@ public class EvalCommand {
|
|||
context.getSource().sendError(Text.literal(e.toString()));
|
||||
}
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
public static int evalJava(CommandContext<FabricClientCommandSource> context) {
|
||||
final String code = getString(context, "code");
|
||||
|
||||
Eval.shell(code);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.slf4j.Logger;
|
|||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
@ -18,6 +19,7 @@ import java.io.IOException;
|
|||
|
||||
@Mixin(TitleScreen.class)
|
||||
public class TitleScreenMixin {
|
||||
@Shadow
|
||||
private SplashTextRenderer splashText;
|
||||
|
||||
@Inject(method = "init", at = @At("HEAD"))
|
||||
|
@ -28,6 +30,7 @@ public class TitleScreenMixin {
|
|||
Gui.addComponents();
|
||||
Gui.gui = new Gui();
|
||||
ModuleMemory.load();
|
||||
ChipmunkMod.LOGGER.info("Initialised gui!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
17
src/main/java/land/chipmunk/chipmunkmod/util/Eval.java
Normal file
17
src/main/java/land/chipmunk/chipmunkmod/util/Eval.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package land.chipmunk.chipmunkmod.util;
|
||||
|
||||
import jdk.jshell.JShell;
|
||||
|
||||
public class Eval {
|
||||
public static JShell shell = JShell.create();
|
||||
public static void shell(String code) {
|
||||
shell.eval(code);
|
||||
}
|
||||
static {
|
||||
shell.onSnippetEvent(event -> {
|
||||
Chat.sendGold(event.value());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -28,10 +28,7 @@
|
|||
"SharedConstantsMixin",
|
||||
"StringHelperMixin",
|
||||
"TextMixin",
|
||||
"ClientConnectionInvoker",
|
||||
"ClientConnectionAccessor",
|
||||
"PlayerListEntryAccessor",
|
||||
"SharedConstantsMixin"
|
||||
"TitleScreenMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in a new issue