36 lines
1.2 KiB
Java
36 lines
1.2 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.Util;
|
|
import net.minecraft.world.level.block.state.properties.Property.Value;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public record PropertyValueList(List<Value<?>> values) {
|
|
public static final PropertyValueList EMPTY = new PropertyValueList(List.of());
|
|
private static final Comparator<Value<?>> COMPARE_BY_NAME = Comparator.comparing(value -> value.property().getName());
|
|
|
|
public PropertyValueList extend(Value<?> value) {
|
|
return new PropertyValueList(Util.copyAndAdd(this.values, value));
|
|
}
|
|
|
|
public PropertyValueList extend(PropertyValueList values) {
|
|
return new PropertyValueList(ImmutableList.<Value<?>>builder().addAll(this.values).addAll(values.values).build());
|
|
}
|
|
|
|
public static PropertyValueList of(Value<?>... values) {
|
|
return new PropertyValueList(List.of(values));
|
|
}
|
|
|
|
public String getKey() {
|
|
return (String)this.values.stream().sorted(COMPARE_BY_NAME).map(Value::toString).collect(Collectors.joining(","));
|
|
}
|
|
|
|
public String toString() {
|
|
return this.getKey();
|
|
}
|
|
}
|