-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please consider adding example code #35
Comments
You can for example see it being used in the tests, see:
|
After digging through the test cases I think I got a fairly good understanding how to use this library, thanks for the hint. However I'm still unable to compile even the base example. Here is a minimal example I created to test the issue: import com.mojang.brigadier.CommandDispatcher;
import static com.mojang.brigadier.arguments.IntegerArgumentType.*;
import static com.mojang.brigadier.builder.LiteralArgumentBuilder.*;
import static com.mojang.brigadier.builder.RequiredArgumentBuilder.*;
public class BrigadierMinimal {
public static void main(String[] args) {
CommandDispatcher<String> dispatcher = new CommandDispatcher<>();
dispatcher.register(literal("foo")
.then(argument("bar", integer())
.executes(c -> {
System.out.println("Bar is " + getInteger(c, "bar"));
return 1;
})
)
.executes(c -> {
System.out.println("Called foo with no arguments");
return 1;
})
);
}
} The error reported by the compiler (JDK 10.0.2) is as follows
Apparently, Java is unable to correctly infere the generic type of So I'm uncertain if I just ran into a strange compiler bug that only affects my specific setup or if I'm actually doing something wrong. |
It's a more general thing. MC itself defines more specific versions to work around that and statically imports those instead:
|
Can anyone show me a good example of using fork, redirect and forward. i has look in the tests but still doesn't understand it clearly. |
So I am new to modding minecraft but figured I would mod 1.14 since it is the latest at the moment of writing this. I stuck the code from the readme into my mod but it does not seem to link to the in-game console. I want to create a custom command: "/import" that opens a dialog window but when I type the command in the console it says 'Unknown command'. import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.common.MinecraftForge;
import com.mojang.brigadier.CommandDispatcher;
@Mod("importexportmod")
public class ImportExportMod {
private final Logger log = LogManager.getLogger();
private final ImportScreen importScreen = new ImportScreen();
public ImportExportMod() {
log.info("new ImportExportMod");
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<>();
dispatcher.register(Commands.literal("import").executes(command -> {
log.info("import command dispatched");
//importScreen.show();
return 0;
}));
}
} I imagine I am doing something wrong creating a new CommandDispatcher instead of acquiring one already created and linked to the command console. ===================== EDIT ========================= @SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
log.info("onServerStarting");
event.getServer().getCommandManager().getDispatcher().register(Commands.literal("import").executes(command -> {
log.info("/import command dispatched");
//importScreen.show();
return 0;
}));
} |
I agree that some example code is needed, especially code that shows people how to properly create new arguments! |
Have a +1 from me. |
So I did write up a tutorial on how to use brigadier within a fabric context but I did explain much of brigadier's logic including creating an argument type to parse a uuid which applies to about any project that would use brigadier (including some examples and even chainable commands [not exactly with any current logic to in a slight example). https://fabricmc.net/wiki/tutorial:commands#brigadier_explained This is also a great explanation on how to do brigadier a bit less messy. I've been using this personally in recent weeks. |
I struggle with creating a command source object, Clearly something is wrong, but I can't tell if the fault lies in my code or Brigadier. Please, we need a proper example code that shows how to properly set this up! |
The provided snipped on the project's readme doesn't even state which classes it's importing. I was unable to find out what
argument
is or where it is coming from. That's just one example but there are many more. I think a full example of a few simple commands should suffice.The text was updated successfully, but these errors were encountered: