package net.minecraft.client.renderer.block.model; import com.google.common.base.Splitter; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Objects; import java.util.Map.Entry; import java.util.function.Predicate; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateHolder; import net.minecraft.world.level.block.state.properties.Property; import org.jetbrains.annotations.Nullable; @Environment(EnvType.CLIENT) public class VariantSelector { private static final Splitter COMMA_SPLITTER = Splitter.on(','); private static final Splitter EQUAL_SPLITTER = Splitter.on('=').limit(2); public static > Predicate> predicate(StateDefinition stateDefinition, String value) { Map, Comparable> map = new HashMap(); for (String string : COMMA_SPLITTER.split(value)) { Iterator iterator = EQUAL_SPLITTER.split(string).iterator(); if (iterator.hasNext()) { String string2 = (String)iterator.next(); Property property = stateDefinition.getProperty(string2); if (property != null && iterator.hasNext()) { String string3 = (String)iterator.next(); Comparable comparable = getValueHelper((Property>)property, string3); if (comparable == null) { throw new RuntimeException("Unknown value: '" + string3 + "' for blockstate property: '" + string2 + "' " + property.getPossibleValues()); } map.put(property, comparable); } else if (!string2.isEmpty()) { throw new RuntimeException("Unknown blockstate property: '" + string2 + "'"); } } } return stateHolder -> { for (Entry, Comparable> entry : map.entrySet()) { if (!Objects.equals(stateHolder.getValue((Property)entry.getKey()), entry.getValue())) { return false; } } return true; }; } @Nullable private static > T getValueHelper(Property property, String value) { return (T)property.getValue(value).orElse(null); } }