SSCL Wiki

Example Project

This is a small example project guide, showing only how to use the API in your classes.

ExampleMod.java

package com.example.mymod;

import net.fabricmc.api.ModInitializer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExampleMod implements ModInitializer {
	public static final String MOD_ID = "mymod";
	public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

	@Override
	public void onInitialize() {
		ExampleModConfig.initialize();

		LOGGER.info("MyMod initialized.");
	}
}

ExampleModConfig.java

package com.example.mymod;

import smilenotalive.sscl.SSCL;
import smilenotalive.sscl.config.BooleanValue;
import smilenotalive.sscl.config.Config;
import smilenotalive.sscl.config.ConfigCategory;
import smilenotalive.sscl.config.ConfigSide;
import smilenotalive.sscl.config.DoubleValue;
import smilenotalive.sscl.config.IntValue;

public final class ExampleModConfig {
	public static final Config CONFIG = SSCL.create(
			ExampleMod.MOD_ID,
			"MyMod/config.toml",
			ConfigSide.COMMON
	);

	public static final ConfigCategory GENERAL = CONFIG
			.category("general")
			.comment("General mod settings.");

	public static final BooleanValue ENABLED = GENERAL
			.bool("enabled", true)
			.comment("Whether the mod is enabled.")
			.tooltip("Turns the mod on or off.");

	public static final IntValue DISTANCE = GENERAL
			.intValue("distance", 8)
			.min(1)
			.max(32)
			.comment("Maximum working distance.")
			.tooltip("Controls how far the mod can reach.");

	public static final DoubleValue SCALE = GENERAL
			.doubleValue("scale", 1.0)
			.min(0.5)
			.max(2.0)
			.decimals(2)
			.comment("Interface scale.")
			.tooltip("Controls the size of the interface.");

	public static void initialize() {
		// Call this to force the config class initialization
	}

	private ExampleModConfig() {
	}
}

Using the values

Anywhere in the mod:

if (ExampleModConfig.ENABLED.get()) {
	// Mod is enabled
}
int distance = ExampleModConfig.DISTANCE.get();
double scale = ExampleModConfig.SCALE.get();

Changing and saving:

ExampleModConfig.DISTANCE.set(16);
ExampleModConfig.SCALE.set(1.25);

ExampleModConfig.CONFIG.save();

The resulting config file will be:

config/MyMod/config.toml

with the values grouped under [general]