package com.dairymoose.modernlife.core;

import com.dairymoose.modernlife.blocks.ModernBookshelfBlock;
import com.dairymoose.modernlife.tileentities.SeedSpreaderBlockEntity;
import java.util.List;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod.EventBusSubscriber(modid = "modernlife", bus = Mod.EventBusSubscriber.Bus.MOD)
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/core/ModernLifeConfig.class */
public class ModernLifeConfig {
    private static final Logger LOGGER = LogManager.getLogger();
    public static final ForgeConfigSpec serverSpec;
    public static final ModernLifeServerConfig SERVER;
    public static final ForgeConfigSpec clientSpec;
    public static final ModernLifeClientConfig CLIENT;
    public static final ForgeConfigSpec commonSpec;
    public static final ModernLifeCommonConfig COMMON;

    static {
        Pair<ModernLifeServerConfig, ForgeConfigSpec> pair1 = new ForgeConfigSpec.Builder().configure(ModernLifeServerConfig::new);
        serverSpec = (ForgeConfigSpec) pair1.getRight();
        SERVER = (ModernLifeServerConfig) pair1.getLeft();
        Pair<ModernLifeClientConfig, ForgeConfigSpec> pair2 = new ForgeConfigSpec.Builder().configure(ModernLifeClientConfig::new);
        clientSpec = (ForgeConfigSpec) pair2.getRight();
        CLIENT = (ModernLifeClientConfig) pair2.getLeft();
        Pair<ModernLifeCommonConfig, ForgeConfigSpec> pair3 = new ForgeConfigSpec.Builder().configure(ModernLifeCommonConfig::new);
        commonSpec = (ForgeConfigSpec) pair3.getRight();
        COMMON = (ModernLifeCommonConfig) pair3.getLeft();
    }

    private static void addConfigElement(ForgeConfigSpec.BooleanValue configElement) {
        List<String> path = configElement.getPath();
        String key = path.get(path.size() - 1);
        ModernLifeCraftingFlags.putFlag(key, ((Boolean) configElement.get()).booleanValue());
    }

    public static void reinit() {
        addConfigElement(COMMON.enableChainsaw);
        addConfigElement(COMMON.enableFlashlight);
        addConfigElement(COMMON.enableBicycle);
        addConfigElement(COMMON.enableSpeedometer);
        addConfigElement(COMMON.enableCamera);
        addConfigElement(COMMON.enableCanvas);
        addConfigElement(COMMON.enableEasel);
        addConfigElement(COMMON.enableGuitar);
        addConfigElement(COMMON.enableGuitarAmplifier);
        addConfigElement(COMMON.enableChessBoard);
        addConfigElement(COMMON.enablePavedRoad);
        addConfigElement(COMMON.enableRoadMarker);
        addConfigElement(COMMON.enableRefrigerator);
        addConfigElement(COMMON.enableTrashCan);
        addConfigElement(COMMON.enableSeedSpreader);
        addConfigElement(COMMON.enableDeluxeBed);
        addConfigElement(COMMON.enableExtractor);
        addConfigElement(COMMON.enableGrate);
        addConfigElement(COMMON.enableMicrowave);
        addConfigElement(COMMON.enableStove);
        addConfigElement(COMMON.enableTurntable);
        addConfigElement(COMMON.enableToilet);
        addConfigElement(COMMON.enableRadiator);
        addConfigElement(COMMON.enablePowerTransmitter);
        addConfigElement(COMMON.enablePowerReceiver);
        addConfigElement(COMMON.enableMirror);
        addConfigElement(COMMON.enableCctvCamera);
        addConfigElement(COMMON.enableCctvScreen);
        addConfigElement(COMMON.enableAlarmClock);
        addConfigElement(COMMON.enableWallShelf);
        addConfigElement(COMMON.enableHandgun);
        addConfigElement(COMMON.enableMotorboat);
        addConfigElement(COMMON.enableWinch);
        addConfigElement(COMMON.enableBookshelf);
        addConfigElement(COMMON.enablePhotocopier);
        Integer ssThrowCd = (Integer) SERVER.seedSpreaderThrowCooldown.get();
        if (ssThrowCd != null) {
            SeedSpreaderBlockEntity.RECENT_LOCATIONS_EXPIRY_MS = ssThrowCd.intValue();
        }
        ModernBookshelfBlock.whitelist = new CsvSourcedHashSet((String) COMMON.bookshelfWhitelist.get());
        ModernBookshelfBlock.blacklist = new CsvSourcedHashSet((String) COMMON.bookshelfBlacklist.get());
        ModernBookshelfBlock.textToSearch = new CsvSourcedHashSet((String) COMMON.bookshelfSearchText.get());
        ModernBookshelfBlock.textToAvoid = new CsvSourcedHashSet((String) COMMON.bookshelfAvoidText.get());
    }

    @SubscribeEvent
    public static void onConfigReloaded(ModConfigEvent.Reloading event) {
        reinit();
    }
}
