/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.minecraft.class_2248
 *  net.minecraft.class_2487
 *  net.minecraft.class_2520
 *  net.minecraft.class_2960
 *  net.minecraft.class_7923
 */
package meteordevelopment.meteorclient.settings;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import meteordevelopment.meteorclient.settings.IBlockData;
import meteordevelopment.meteorclient.settings.IVisible;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.utils.misc.ICopyable;
import meteordevelopment.meteorclient.utils.misc.IGetter;
import meteordevelopment.meteorclient.utils.misc.ISerializable;
import net.minecraft.class_2248;
import net.minecraft.class_2487;
import net.minecraft.class_2520;
import net.minecraft.class_2960;
import net.minecraft.class_7923;

public class BlockDataSetting<T extends ICopyable<T> & ISerializable<T> & IBlockData<T>>
extends Setting<Map<class_2248, T>> {
    public final IGetter<T> defaultData;

    public BlockDataSetting(String name, String description, Map<class_2248, T> defaultValue, Consumer<Map<class_2248, T>> onChanged, Consumer<Setting<Map<class_2248, T>>> onModuleActivated, IGetter<T> defaultData, IVisible visible) {
        super(name, description, defaultValue, onChanged, onModuleActivated, visible);
        this.defaultData = defaultData;
    }

    @Override
    public void resetImpl() {
        this.value = new HashMap((Map)this.defaultValue);
    }

    @Override
    protected Map<class_2248, T> parseImpl(String str) {
        return new HashMap(0);
    }

    @Override
    protected boolean isValueValid(Map<class_2248, T> value) {
        return true;
    }

    @Override
    protected class_2487 save(class_2487 tag) {
        class_2487 valueTag = new class_2487();
        for (class_2248 block : ((Map)this.get()).keySet()) {
            valueTag.method_10566(class_7923.field_41175.method_10221((Object)block).toString(), (class_2520)((ISerializable)((Object)((ICopyable)((Map)this.get()).get(block)))).toTag());
        }
        tag.method_10566("value", (class_2520)valueTag);
        return tag;
    }

    @Override
    protected Map<class_2248, T> load(class_2487 tag) {
        ((Map)this.get()).clear();
        class_2487 valueTag = tag.method_68568("value");
        for (String key : valueTag.method_10541()) {
            ((Map)this.get()).put((class_2248)class_7923.field_41175.method_63535(class_2960.method_60654((String)key)), (ICopyable)((ISerializable)((ICopyable)this.defaultData.get()).copy()).fromTag(valueTag.method_68568(key)));
        }
        return (Map)this.get();
    }

    public static class Builder<T extends ICopyable<T> & ISerializable<T> & IBlockData<T>>
    extends Setting.SettingBuilder<Builder<T>, Map<class_2248, T>, BlockDataSetting<T>> {
        private IGetter<T> defaultData;

        public Builder() {
            super(new HashMap(0));
        }

        public Builder<T> defaultData(IGetter<T> defaultData) {
            this.defaultData = defaultData;
            return this;
        }

        @Override
        public BlockDataSetting<T> build() {
            return new BlockDataSetting<T>(this.name, this.description, (Map)this.defaultValue, this.onChanged, this.onModuleActivated, this.defaultData, this.visible);
        }
    }
}

