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;
}
}
)