tried out different shit, didnt work

This commit is contained in:
Marcel Marcel 2021-05-24 15:23:28 +02:00
parent 865abd7c29
commit 9aed953f22
4 changed files with 40 additions and 34 deletions

View file

@ -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));
}
}

View file

@ -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<FabricClientCommandSource> {
public EaaModCommand() {
this.register();
}
public void register(){
ClientCommandManager.DISPATCHER.register(getCommandSpecification().executes(this));
public LiteralArgumentBuilder<FabricClientCommandSource> register(){
return this.getCommandSpecification().executes(this);
}
public abstract LiteralArgumentBuilder<FabricClientCommandSource> getCommandSpecification();

View file

@ -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<FabricClientCommandSource> 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<FabricClientCommandSource> register() {
return this.getCommandSpecification().executes(context -> this.run(context));
}
@Override
public LiteralArgumentBuilder<FabricClientCommandSource> 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()));
}
}

View file

@ -19,7 +19,7 @@
"environment": "*",
"entrypoints": {
"main": [
"client": [
"net.saltymc.eaa.EaaMod"
]
},