52 lines
1.5 KiB
Java
52 lines
1.5 KiB
Java
package net.minecraft.client.data.models.blockstates;
|
|
|
|
import com.google.common.collect.ImmutableList;
|
|
import java.util.Comparator;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.world.level.block.state.properties.Property.Value;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public final class Selector {
|
|
private static final Selector EMPTY = new Selector(ImmutableList.of());
|
|
private static final Comparator<Value<?>> COMPARE_BY_NAME = Comparator.comparing(value -> value.property().getName());
|
|
private final List<Value<?>> values;
|
|
|
|
public Selector extend(Value<?> value) {
|
|
return new Selector(ImmutableList.<Value<?>>builder().addAll(this.values).add(value).build());
|
|
}
|
|
|
|
public Selector extend(Selector selector) {
|
|
return new Selector(ImmutableList.<Value<?>>builder().addAll(this.values).addAll(selector.values).build());
|
|
}
|
|
|
|
private Selector(List<Value<?>> values) {
|
|
this.values = values;
|
|
}
|
|
|
|
public static Selector empty() {
|
|
return EMPTY;
|
|
}
|
|
|
|
public static Selector of(Value<?>... values) {
|
|
return new Selector(ImmutableList.copyOf(values));
|
|
}
|
|
|
|
public boolean equals(Object object) {
|
|
return this == object || object instanceof Selector && this.values.equals(((Selector)object).values);
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.values.hashCode();
|
|
}
|
|
|
|
public String getKey() {
|
|
return (String)this.values.stream().sorted(COMPARE_BY_NAME).map(Value::toString).collect(Collectors.joining(","));
|
|
}
|
|
|
|
public String toString() {
|
|
return this.getKey();
|
|
}
|
|
}
|