package client.renderer.blockmodel;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import common.collect.Lists;
import common.collect.Maps;
import common.init.BlockRegistry;
import common.properties.IProperty;
import common.world.State;

public class MultiStateMap extends StateMap
{
    private final IProperty<?> name;
    private final String suffix;
    private final List < IProperty<? >> ignored;

    private MultiStateMap(IProperty<?> name, String suffix, List < IProperty<? >> ignored)
    {
        this.name = name;
        this.suffix = suffix;
        this.ignored = ignored;
    }

    protected String getResourceLocation(State state)
    {
        Map<IProperty, Comparable> map = Maps.<IProperty, Comparable>newLinkedHashMap(state.getProperties());
        String s;

        if (this.name == null)
        {
            s = BlockRegistry.getNameFromBlock(state.getBlock());
        }
        else
        {
            s = ((IProperty)this.name).getName((Comparable)map.remove(this.name));
        }

        if (this.suffix != null)
        {
            s = s + this.suffix;
        }

        for (IProperty<?> iproperty : this.ignored)
        {
            map.remove(iproperty);
        }

        return s + '#' + this.getPropertyString(map);
    }

    public static class Builder
    {
        private IProperty<?> name;
        private String suffix;
        private final List < IProperty<? >> ignored = Lists. < IProperty<? >> newArrayList();

        public MultiStateMap.Builder withName(IProperty<?> builderPropertyIn)
        {
            this.name = builderPropertyIn;
            return this;
        }

        public MultiStateMap.Builder withSuffix(String builderSuffixIn)
        {
            this.suffix = builderSuffixIn;
            return this;
        }

        public MultiStateMap.Builder ignore(IProperty<?>... p_178442_1_)
        {
            Collections.addAll(this.ignored, p_178442_1_);
            return this;
        }

        public MultiStateMap build()
        {
            return new MultiStateMap(this.name, this.suffix, this.ignored);
        }
    }
}
