From 49130736df2fdcc8d3322e40a7c5a7a9146f6db4 Mon Sep 17 00:00:00 2001 From: Marcel Kempf Date: Tue, 25 May 2021 18:11:41 +0200 Subject: [PATCH] FINALLY got stuff working, lol --- src/main/java/net/saltymc/eaa/EaaMod.java | 16 ++++--- .../saltymc/eaa/commands/EaaModCommand.java | 25 +++++++++++ .../net/saltymc/eaa/commands/EchoCommand.java | 38 ++++++++++++++++ .../net/saltymc/eaa/commands/TagCommand.java | 39 ++++++++++++++++ .../eaa/handler/commands/EaaModCommand.java | 15 ------- .../eaa/handler/commands/EchoCommand.java | 45 ------------------- .../net/saltymc/eaa/mixin/ExampleMixin.java | 4 +- .../net/saltymc/eaa/util/ResponseEntity.java | 29 ------------ 8 files changed, 114 insertions(+), 97 deletions(-) create mode 100644 src/main/java/net/saltymc/eaa/commands/EaaModCommand.java create mode 100644 src/main/java/net/saltymc/eaa/commands/EchoCommand.java create mode 100644 src/main/java/net/saltymc/eaa/commands/TagCommand.java delete mode 100644 src/main/java/net/saltymc/eaa/handler/commands/EaaModCommand.java delete mode 100644 src/main/java/net/saltymc/eaa/handler/commands/EchoCommand.java delete mode 100644 src/main/java/net/saltymc/eaa/util/ResponseEntity.java diff --git a/src/main/java/net/saltymc/eaa/EaaMod.java b/src/main/java/net/saltymc/eaa/EaaMod.java index 234137c..63f026c 100644 --- a/src/main/java/net/saltymc/eaa/EaaMod.java +++ b/src/main/java/net/saltymc/eaa/EaaMod.java @@ -1,25 +1,27 @@ package net.saltymc.eaa; -import com.mojang.brigadier.arguments.DoubleArgumentType; -import net.saltymc.eaa.handler.commands.EchoCommand; +import net.saltymc.eaa.commands.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; 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(); + public static Logger getLogger() { + return LOGGER; + } + @Override public void onInitializeClient() { - ClientCommandManager.DISPATCHER.register(literal("test_client_command_with_arg").then( - ClientCommandManager.argument("nachricht", DoubleArgumentType.doubleArg())).executes(EchoCommand::run)); + + //Register Commands + new EchoCommand(); + new TagCommand(); } } diff --git a/src/main/java/net/saltymc/eaa/commands/EaaModCommand.java b/src/main/java/net/saltymc/eaa/commands/EaaModCommand.java new file mode 100644 index 0000000..473b9a0 --- /dev/null +++ b/src/main/java/net/saltymc/eaa/commands/EaaModCommand.java @@ -0,0 +1,25 @@ +package net.saltymc.eaa.commands; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +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(ClientCommandManager.DISPATCHER); + } + + public EaaModCommand(CommandDispatcher dispatcher) { + this.register(dispatcher); + } + + public void register(CommandDispatcher dispatcher){ + dispatcher.register(this.getCommandSpecification()); + } + + public abstract LiteralArgumentBuilder getCommandSpecification(); + +} diff --git a/src/main/java/net/saltymc/eaa/commands/EchoCommand.java b/src/main/java/net/saltymc/eaa/commands/EchoCommand.java new file mode 100644 index 0000000..a3ede7a --- /dev/null +++ b/src/main/java/net/saltymc/eaa/commands/EchoCommand.java @@ -0,0 +1,38 @@ +package net.saltymc.eaa.commands; + +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; +import net.minecraft.client.toast.*; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +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{ + + public int run(CommandContext context) { // throws CommandSyntaxException + FabricClientCommandSource source = context.getSource(); + + String nachricht = StringArgumentType.getString(context,"nachricht"); + + SystemToast.add(source.getClient().getToastManager(), SystemToast.Type.TUTORIAL_HINT, Text.of("ECHO"), Text.of(nachricht)); + + source.sendFeedback( + new LiteralText("You said: ") + .formatted(Formatting.RED) + .append(new LiteralText(nachricht + "")) + ); + return 1; + } + + public LiteralArgumentBuilder getCommandSpecification() { + return literal("/echo").then( + argument("nachricht", StringArgumentType.greedyString()) + .executes(this) + ); + } +} diff --git a/src/main/java/net/saltymc/eaa/commands/TagCommand.java b/src/main/java/net/saltymc/eaa/commands/TagCommand.java new file mode 100644 index 0000000..473184f --- /dev/null +++ b/src/main/java/net/saltymc/eaa/commands/TagCommand.java @@ -0,0 +1,39 @@ +package net.saltymc.eaa.commands; + +import com.mojang.brigadier.arguments.StringArgumentType; +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.FabricClientCommandSource; +import net.minecraft.client.toast.SystemToast; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.argument; +import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal; + +public class TagCommand extends EaaModCommand{ + @Override + public int run(CommandContext context) throws CommandSyntaxException { + FabricClientCommandSource source = context.getSource(); + + String player = StringArgumentType.getString(context,"player"); + String tag = StringArgumentType.getString(context,"tag"); + + SystemToast.add(source.getClient().getToastManager(), SystemToast.Type.TUTORIAL_HINT, Text.of(tag), Text.of(player)); + + return 1; + } + + @Override + public LiteralArgumentBuilder getCommandSpecification() { + return literal("/tag").then( + argument("player", EntityArgumentType.player()) + .then(argument("tag", StringArgumentType.word()) + .executes(this) + )); + } +} diff --git a/src/main/java/net/saltymc/eaa/handler/commands/EaaModCommand.java b/src/main/java/net/saltymc/eaa/handler/commands/EaaModCommand.java deleted file mode 100644 index f1589cb..0000000 --- a/src/main/java/net/saltymc/eaa/handler/commands/EaaModCommand.java +++ /dev/null @@ -1,15 +0,0 @@ -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.FabricClientCommandSource; - -public abstract class EaaModCommand implements Command { - - 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 deleted file mode 100644 index c121cc8..0000000 --- a/src/main/java/net/saltymc/eaa/handler/commands/EchoCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.saltymc.eaa.handler.commands; - - -import com.mojang.brigadier.Command; -import com.mojang.brigadier.arguments.DoubleArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; -import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; -import net.minecraft.client.toast.SystemToast; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - -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 { - 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(nachricht + "")) - ); - return 1; - } - - public LiteralArgumentBuilder register() { - return this.getCommandSpecification().executes(context -> this.run(context)); - } - - public LiteralArgumentBuilder getCommandSpecification() { - //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/java/net/saltymc/eaa/mixin/ExampleMixin.java b/src/main/java/net/saltymc/eaa/mixin/ExampleMixin.java index ed1fb6e..a5eb080 100644 --- a/src/main/java/net/saltymc/eaa/mixin/ExampleMixin.java +++ b/src/main/java/net/saltymc/eaa/mixin/ExampleMixin.java @@ -6,10 +6,12 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import static net.saltymc.eaa.EaaMod.getLogger; + @Mixin(TitleScreen.class) public class ExampleMixin { @Inject(at = @At("HEAD"), method = "init()V") private void init(CallbackInfo info) { - System.out.println("This line is printed by EAA MOD!"); + getLogger().info("This line is printed by EAA MOD!"); } } \ No newline at end of file diff --git a/src/main/java/net/saltymc/eaa/util/ResponseEntity.java b/src/main/java/net/saltymc/eaa/util/ResponseEntity.java deleted file mode 100644 index a55f0f1..0000000 --- a/src/main/java/net/saltymc/eaa/util/ResponseEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.saltymc.eaa.util; - -public class ResponseEntity { - - private boolean interceptEvent; - private final boolean wasHandled; - - public ResponseEntity(boolean wasHandled){ - this.wasHandled = wasHandled; - } - - public ResponseEntity(boolean wasHandled, boolean interceptEvent){ - this.wasHandled = wasHandled; - this.interceptEvent = interceptEvent; - } - - - public boolean isInterceptEvent() { - return interceptEvent; - } - - public void setInterceptEvent(boolean interceptEvent) { - this.interceptEvent = interceptEvent; - } - - public boolean isWasHandled() { - return wasHandled; - } -}