2024-03-13 21:47:45 -04:00
|
|
|
package net.kelsoncraft.test;
|
|
|
|
|
2024-03-14 05:48:14 -04:00
|
|
|
import com.mojang.brigadier.CommandDispatcher;
|
2024-03-13 21:47:45 -04:00
|
|
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
2024-03-14 05:48:14 -04:00
|
|
|
import net.minecraft.command.CommandRegistryAccess;
|
|
|
|
import net.minecraft.server.command.CommandManager;
|
|
|
|
import net.minecraft.server.command.ServerCommandSource;
|
2024-03-13 21:47:45 -04:00
|
|
|
import net.minecraft.text.Text;
|
|
|
|
|
2024-03-14 05:48:14 -04:00
|
|
|
import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal;
|
|
|
|
|
|
|
|
// https://www.reddit.com/r/fabricmc/comments/r3bd47/fabric_execute_commands/
|
|
|
|
|
2024-03-13 21:47:45 -04:00
|
|
|
public class CommandTest {
|
2024-03-14 05:48:14 -04:00
|
|
|
// 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;
|
|
|
|
})));
|
|
|
|
}
|
2024-03-13 21:47:45 -04:00
|
|
|
}
|
2024-03-14 05:48:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|