top.hendrixshen.magiclib.malilib.impl.config.MagicConfigBoolean Maven / Gradle / Ivy
package top.hendrixshen.magiclib.malilib.impl.config;
import com.google.gson.JsonElement;
import fi.dy.masa.malilib.config.options.ConfigBase;
import fi.dy.masa.malilib.config.options.ConfigBoolean;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.Nullable;
import top.hendrixshen.magiclib.malilib.api.config.IMagicConfigBase;
import java.util.function.Consumer;
@Environment(EnvType.CLIENT)
public class MagicConfigBoolean extends ConfigBoolean implements IMagicConfigBase {
private final String prefix;
@Nullable
private Consumer> valueChangedFromJsonCallback;
public MagicConfigBoolean(String prefix, String name, boolean defaultValue) {
super(name, defaultValue,
String.format("%s.%s.comment", prefix, name),
String.format("%s.%s.pretty_name", prefix, name));
this.prefix = prefix;
}
@Override
public void setValueFromJsonElement(JsonElement jsonElement) {
super.setValueFromJsonElement(jsonElement);
if (this.valueChangedFromJsonCallback != null) {
this.valueChangedFromJsonCallback.accept(this);
}
}
@Override
@Nullable
public Consumer> getValueChangedFromJsonCallback() {
return this.valueChangedFromJsonCallback;
}
@Override
public void setValueChangedFromJsonCallback(@Nullable Consumer> valueChangedFromJsonCallback) {
this.valueChangedFromJsonCallback = valueChangedFromJsonCallback;
}
@Override
public String getPrefix() {
return this.prefix;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy