#Command not being registered even on environment: "*" in fabric.mod.json

7 messages · Page 1 of 1 (latest)

rigid ether
#

I tried to add a new command to minecraft for debugging purposes
But for some reason running /despair 100.0 didn't work

// ...

// ignore the 8 space indent
public class MonstersUnshackled implements ModInitializer {
        public static final String MOD_ID = "monsters-unshackled";
        public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

        @Override
        public void onInitialize() {
                CommandRegistrationCallback.EVENT
                                .register(((dispatcher, buildContext, selection) -> {
                                        dispatcher.register(Commands.literal("despair")
                                                        .then(Commands.argument("value",
                                                                        FloatArgumentType.floatArg(
                                                                                        0, 100)))
                                                        .executes(DespairCommand::setDespair));
                                }));
        }
}
// ...
public class DespairCommand {
    public static int setDespair(CommandContext<CommandSourceStack> context) {
        MonstersUnshackled.LOGGER.debug("despair command exec start");
        final float newValue = FloatArgumentType.getFloat(context, "value");
        final DespairData despair =
                DespairData.getDespairData(context.getSource().getLevel());
        despair.setDespair(newValue);

        context.getSource().sendSuccess(
                () -> Component.literal("despair set to: " + newValue), false);
        return 1;
    }

    // unused
    public static int getDespair(CommandContext<CommandSourceStack> context) {
        context.getSource()
                .sendSuccess(() -> Component.literal("about" + DespairData
                        .getDespairData(context.getSource().getLevel())),
                        false);
        return 1;
    }
}
#

fabric.mod.json

{
        "schemaVersion": 1,
        "id": "monsters-unshackled",
        "version": "${version}",
        "name": "Monsters Unshackled",
        "description": "This is an example description! Tell everyone what your mod is about!",
        "authors": [
                "Me!"
        ],
        "contact": {
                "homepage": "https://fabricmc.net/",
                "sources": "https://github.com/FabricMC/fabric-example-mod"
        },
        "license": "CC0-1.0",
        "icon": "assets/monsters-unshackled/icon.png",
        "environment": "*",
        "entrypoints": {
                "main": [
                        "dev.pastaya.mu.MonstersUnshackled"
                ],
                "client": [
                        "dev.pastaya.mu.client.MonstersUnshackledClient"
                ]
        },
        "mixins": [
                "monsters-unshackled.mixins.json",
                {
                        "config": "monsters-unshackled.client.mixins.json",
                        "environment": "client"
                }
        ],
        "depends": {
                "fabricloader": ">=0.19.1",
                "minecraft": "~26.1.2",
                "java": ">=25",
                "fabric-api": "*"
        }
}
rigid ether
#

am i cooked

astral widget
#

You didn't chain the executes properly, currently /despair executes DespairCommand::setDespair, which will fail because it tries to get an argument it doesn't have (and /despair <value> does not have an executes, so it does nothing - hence "incomplete command"). You need to chain the executes on Commands.argument, or structure your commands like what I'm about to send (so that you avoid lambdasoup)

#

!!brigadier

wooden prairieBOT