package net.minecraft.client.data.models.blockstates; import com.google.common.collect.Maps; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import java.util.List; import java.util.Map; import java.util.function.Supplier; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @Environment(EnvType.CLIENT) public class Variant implements Supplier { private final Map, VariantProperty.Value> values = Maps., VariantProperty.Value>newLinkedHashMap(); public Variant with(VariantProperty property, T value) { VariantProperty.Value value2 = (VariantProperty.Value)this.values.put(property, property.withValue(value)); if (value2 != null) { throw new IllegalStateException("Replacing value of " + value2 + " with " + value); } else { return this; } } public static Variant variant() { return new Variant(); } public static Variant merge(Variant first, Variant second) { Variant variant = new Variant(); variant.values.putAll(first.values); variant.values.putAll(second.values); return variant; } public JsonElement get() { JsonObject jsonObject = new JsonObject(); this.values.values().forEach(value -> value.addToVariant(jsonObject)); return jsonObject; } public static JsonElement convertList(List list) { if (list.size() == 1) { return ((Variant)list.get(0)).get(); } else { JsonArray jsonArray = new JsonArray(); list.forEach(variant -> jsonArray.add(variant.get())); return jsonArray; } } }