command to open screen failed #2004
-
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
dispatcher.register(CommandManager.literal("test").executes(context -> {
MinecraftClient.getInstance().setScreen(new TestScreen());
return Command.SINGLE_SUCCESS;
}));
});
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The error says your TestScreen class is not doing the init() correctly.
But your overall approach is wrong. The commands run on the server, you cannot use the client api directly from them. If you want to change the screen from a command running on the server, IIRC, I think you also need to make sure you do the setScreen() on the render thread rather than the network thread.
(I think adding this execute indirection would probably also fix your current code? i.e. make it run on the client's render thread, but that would only work because you are running the server in co-located client mode it is the wrong thing to do in general). Fabric does have a client command api. I have personally never used it. |
Beta Was this translation helpful? Give feedback.
The error says your TestScreen class is not doing the init() correctly.
But your overall approach is wrong.
The commands run on the server, you cannot use the client api directly from them.
If you want to change the screen from a command running on the server,
you will need to send a network message to the player telling their client to do the open.
https://fabricmc.net/wiki/tutorial:networking