User Tools

Site Tools


tutorial:commands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:commands [2019/07/29 15:20] – [ServerCommandSource] Neaten commenting i509vcbtutorial:commands [2019/07/29 19:03] – Removed references to internals pyrofab
Line 8: Line 8:
 If you just want to see how to register commands you've come to the right place here. If you just want to see how to register commands you've come to the right place here.
  
-Registering commands is done through ''CommandRegistryImpl'' or ''CommandRegistry'' through the ''register'' method. Doesn't matter which one you choose as they go to the same place.+Registering commands is done through ''CommandRegistry'' through the ''register'' method.
  
 The register method specifies two arguments, the dedicated flag and a consumer representing the CommandDispatcher. These methods should be placed in your mod's initalizer. The register method specifies two arguments, the dedicated flag and a consumer representing the CommandDispatcher. These methods should be placed in your mod's initalizer.
Line 17: Line 17:
  
 <code java> <code java>
-CommandRegistryImpl.INSTANCE.register(false, dispatcher -> TutorialCommands.register(dispatcher)); // All commands are registered in a single class that refrences every command.+CommandRegistry.INSTANCE.register(false, dispatcher -> TutorialCommands.register(dispatcher)); // All commands are registered in a single class that references every command.
   
 CommandRegistry.INSTANCE.register(false, dispatcher -> { // You can also just reference every single class also. There is also the alternative of just using CommandRegistry CommandRegistry.INSTANCE.register(false, dispatcher -> { // You can also just reference every single class also. There is also the alternative of just using CommandRegistry
Line 285: Line 285:
 } }
  
-public int broadcast(ServerCommandSource source, Formatting formatting, String message) {+public static int broadcast(ServerCommandSource source, Formatting formatting, String message) {
     Text text = new LiteralText(message).formatting(formatting);     Text text = new LiteralText(message).formatting(formatting);
  
Line 307: Line 307:
  
 <code java> <code java>
-public static void giveDiamond(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {+public static int giveDiamond(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
     ServerCommandSource source = ctx.getSource();     ServerCommandSource source = ctx.getSource();
   
Line 343: Line 343:
  
 <code java> <code java>
-public static void antioch(ServerCommandSource source, BlockPos blockPos) throws CommandSyntaxException { +public static int antioch(ServerCommandSource source, BlockPos blockPos) throws CommandSyntaxException { 
   
     if(blockPos==null) {     if(blockPos==null) {
Line 354: Line 354:
     source.getMinecraftServer().getPlayerManager().broadcastChatMessage(new LiteralText("who being naughty in My sight, shall snuff it.").formatting(Formatting.RED), false);     source.getMinecraftServer().getPlayerManager().broadcastChatMessage(new LiteralText("who being naughty in My sight, shall snuff it.").formatting(Formatting.RED), false);
     source.getWorld().spawnEntity(tnt);     source.getWorld().spawnEntity(tnt);
 +    return 1;
 } }
 </code> </code>
tutorial/commands.txt · Last modified: 2024/02/23 14:22 by allen1210