From 9aed953f22a7776fc68dc4bc7a50176ee27e4e1d Mon Sep 17 00:00:00 2001 From: Marcel Kempf Date: Mon, 24 May 2021 15:23:28 +0200 Subject: [PATCH] tried out different shit, didnt work --- src/main/java/net/saltymc/eaa/EaaMod.java | 26 ++++++++------ .../eaa/handler/commands/EaaModCommand.java | 10 ++---- .../eaa/handler/commands/EchoCommand.java | 36 +++++++++++-------- src/main/resources/fabric.mod.json | 2 +- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/main/java/net/saltymc/eaa/EaaMod.java b/src/main/java/net/saltymc/eaa/EaaMod.java index bb3c6cc..234137c 100644 --- a/src/main/java/net/saltymc/eaa/EaaMod.java +++ b/src/main/java/net/saltymc/eaa/EaaMod.java @@ -1,19 +1,25 @@ package net.saltymc.eaa; -import net.fabricmc.api.ModInitializer; +import com.mojang.brigadier.arguments.DoubleArgumentType; import net.saltymc.eaa.handler.commands.EchoCommand; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; -public class EaaMod implements ModInitializer { +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; + +import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal; + +@Environment(EnvType.CLIENT) +public final class EaaMod implements ClientModInitializer { + private static final Logger LOGGER = LogManager.getLogger(); @Override - public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - - System.out.println("EAA Mod initializing..."); - - new EchoCommand(); + public void onInitializeClient() { + ClientCommandManager.DISPATCHER.register(literal("test_client_command_with_arg").then( + ClientCommandManager.argument("nachricht", DoubleArgumentType.doubleArg())).executes(EchoCommand::run)); } } diff --git a/src/main/java/net/saltymc/eaa/handler/commands/EaaModCommand.java b/src/main/java/net/saltymc/eaa/handler/commands/EaaModCommand.java index f7ca365..f1589cb 100644 --- a/src/main/java/net/saltymc/eaa/handler/commands/EaaModCommand.java +++ b/src/main/java/net/saltymc/eaa/handler/commands/EaaModCommand.java @@ -2,18 +2,12 @@ package net.saltymc.eaa.handler.commands; import com.mojang.brigadier.Command; import com.mojang.brigadier.builder.LiteralArgumentBuilder; - -import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; public abstract class EaaModCommand implements Command { - public EaaModCommand() { - this.register(); - } - - public void register(){ - ClientCommandManager.DISPATCHER.register(getCommandSpecification().executes(this)); + public LiteralArgumentBuilder register(){ + return this.getCommandSpecification().executes(this); } public abstract LiteralArgumentBuilder getCommandSpecification(); diff --git a/src/main/java/net/saltymc/eaa/handler/commands/EchoCommand.java b/src/main/java/net/saltymc/eaa/handler/commands/EchoCommand.java index 3c2de3b..c121cc8 100644 --- a/src/main/java/net/saltymc/eaa/handler/commands/EchoCommand.java +++ b/src/main/java/net/saltymc/eaa/handler/commands/EchoCommand.java @@ -1,9 +1,10 @@ package net.saltymc.eaa.handler.commands; -import com.mojang.brigadier.arguments.StringArgumentType; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.arguments.DoubleArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; import net.minecraft.client.toast.SystemToast; @@ -11,29 +12,34 @@ import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.argument; +import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal; - -public class EchoCommand extends EaaModCommand { - @Override - public int run(CommandContext context) throws CommandSyntaxException { - FabricClientCommandSource source = (FabricClientCommandSource) (context.getSource()); +public class EchoCommand { + public static int run(CommandContext context) { // throws CommandSyntaxException + FabricClientCommandSource source = context.getSource(); SystemToast.add(source.getClient().getToastManager(), SystemToast.Type.TUTORIAL_HINT, Text.of("ECHO"), Text.of(context.getInput())); + //String nachricht = getString(context,"nachricht"); + double nachricht = DoubleArgumentType.getDouble(context, "nachricht"); + System.out.println("nachricht is " + nachricht); + source.sendFeedback( new LiteralText("You said input: ") .formatted(Formatting.RED) - .append(new LiteralText(getString(context, "message")) - .formatted(Formatting.WHITE, Formatting.ITALIC) - ) + .append(new LiteralText(nachricht + "")) ); - return SINGLE_SUCCESS; + return 1; + } + + public LiteralArgumentBuilder register() { + return this.getCommandSpecification().executes(context -> this.run(context)); } - @Override public LiteralArgumentBuilder getCommandSpecification() { - return ClientCommandManager.literal("echo") - .then(ClientCommandManager.argument("message", StringArgumentType.greedyString())); + //return literal("echo").then(argument("nachricht", DoubleArgumentType.doubleArg())); + return literal("test_client_command_with_arg").then( + ClientCommandManager.argument("nachricht", DoubleArgumentType.doubleArg())); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 02c54f7..f09e006 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,7 +19,7 @@ "environment": "*", "entrypoints": { - "main": [ + "client": [ "net.saltymc.eaa.EaaMod" ] },