diff --git a/src/main/java/net/kelsoncraft/test/CommandTest.java b/src/main/java/net/kelsoncraft/test/CommandTest.java index 1f83338..8455271 100644 --- a/src/main/java/net/kelsoncraft/test/CommandTest.java +++ b/src/main/java/net/kelsoncraft/test/CommandTest.java @@ -1,18 +1,34 @@ package net.kelsoncraft.test; +import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; +import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; + +// https://www.reddit.com/r/fabricmc/comments/r3bd47/fabric_execute_commands/ + public class CommandTest { - // This doesn't work at all in other classes. -// -// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("test") -// .executes(context -> { -// // For versions below 1.19, replace "Text.literal" with "new LiteralText". -// // For versions below 1.20, remode "() ->" directly. -// context.getSource().sendFeedback(() -> Text.literal("Called /test with no arguments"), false); -// -// -// return 1; -// }))); + // This idea came from here: + // https://github.com/Draylar/get-off-my-lawn/blob/1.17/src/main/java/draylar/goml/command/ClaimCommand.java#L32-L98 + + public CommandTest() { + + } + // This works like this, now I know how to add commands to other classes, add them like this then initialize them in the main class. + public static void init() { + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(CommandManager.literal("teleport") + .executes(context -> { + context.getSource().sendFeedback(() -> Text.literal("Teleport to %s"), false); + return 1; + }))); + } } + + + + + diff --git a/src/main/java/net/kelsoncraft/test/KelsonCraftTest.java b/src/main/java/net/kelsoncraft/test/KelsonCraftTest.java index a330356..d030687 100644 --- a/src/main/java/net/kelsoncraft/test/KelsonCraftTest.java +++ b/src/main/java/net/kelsoncraft/test/KelsonCraftTest.java @@ -73,8 +73,6 @@ public class KelsonCraftTest implements ModInitializer { // For versions below 1.19, replace "Text.literal" with "new LiteralText". // For versions below 1.20, remode "() ->" directly. context.getSource().sendFeedback(() -> Text.literal("Called /test with no arguments"), false); - - return 1; }))); @@ -84,6 +82,17 @@ public class KelsonCraftTest implements ModInitializer { context.getSource().sendFeedback(() -> Text.literal("Hello player %s"), false); return 1; }))); + // This should add the teleport command, I got the idea from this: + // https://github.com/Draylar/get-off-my-lawn/blob/1.17/src/main/java/draylar/goml/GetOffMyLawn.java#L30-L37 + CommandTest.init(); +// CommandTest commandTest = new CommandTest(); + + //I wonder how to implement a teleport command, and a try to put this in another class. +// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("teleport") +// .executes(context -> { +// context.getSource().sendFeedback(() -> Text.literal("Teleport to %s"), false); +// return 1; +// }))); // This is a way to use the item as fuel FuelRegistry.INSTANCE.add(CustomItems.CUSTOM_ITEM, 300);