Search in sources :

Example 1 with ModuleBooleanData

use of mekanism.api.gear.config.ModuleBooleanData in project Mekanism by mekanism.

the class Module method init.

public void init() {
    enabled = addConfigItem(new ModuleConfigItem<Boolean>(this, ENABLED_KEY, MekanismLang.MODULE_ENABLED, new ModuleBooleanData(!data.isDisabledByDefault())) {

        @Override
        public void set(@Nonnull Boolean val, @Nullable Runnable callback) {
            // Custom override of set to see if it changed and if so notify the custom module of that fact
            boolean wasEnabled = get();
            super.set(val, callback);
            // we can assume it is server side
            if (callback == null && wasEnabled != get()) {
                customModule.onEnabledStateChange(Module.this);
            }
        }
    });
    if (data.handlesModeChange()) {
        handleModeChange = addConfigItem(new ModuleConfigItem<>(this, HANDLE_MODE_CHANGE_KEY, MekanismLang.MODULE_HANDLE_MODE_CHANGE, new ModuleBooleanData()));
    }
    if (data.rendersHUD()) {
        renderHUD = addConfigItem(new ModuleConfigItem<>(this, "renderHUD", MekanismLang.MODULE_RENDER_HUD, new ModuleBooleanData()));
    }
    customModule.init(this, new ModuleConfigItemCreator() {

        @Override
        public <TYPE> IModuleConfigItem<TYPE> createConfigItem(String name, ILangEntry description, ModuleConfigData<TYPE> data) {
            return addConfigItem(new ModuleConfigItem<>(Module.this, name, description, data));
        }

        @Override
        public IModuleConfigItem<Boolean> createDisableableConfigItem(String name, ILangEntry description, boolean def, BooleanSupplier isConfigEnabled) {
            return addConfigItem(new DisableableModuleConfigItem(Module.this, name, description, def, isConfigEnabled));
        }
    });
}
Also used : DisableableModuleConfigItem(mekanism.common.content.gear.ModuleConfigItem.DisableableModuleConfigItem) Nonnull(javax.annotation.Nonnull) IModuleConfigItem(mekanism.api.gear.config.IModuleConfigItem) ModuleBooleanData(mekanism.api.gear.config.ModuleBooleanData) ModuleConfigItemCreator(mekanism.api.gear.config.ModuleConfigItemCreator) IModuleConfigItem(mekanism.api.gear.config.IModuleConfigItem) DisableableModuleConfigItem(mekanism.common.content.gear.ModuleConfigItem.DisableableModuleConfigItem) BooleanSupplier(java.util.function.BooleanSupplier) Nullable(javax.annotation.Nullable) ILangEntry(mekanism.api.text.ILangEntry)

Aggregations

BooleanSupplier (java.util.function.BooleanSupplier)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 IModuleConfigItem (mekanism.api.gear.config.IModuleConfigItem)1 ModuleBooleanData (mekanism.api.gear.config.ModuleBooleanData)1 ModuleConfigItemCreator (mekanism.api.gear.config.ModuleConfigItemCreator)1 ILangEntry (mekanism.api.text.ILangEntry)1 DisableableModuleConfigItem (mekanism.common.content.gear.ModuleConfigItem.DisableableModuleConfigItem)1