47 lines
1.1 KiB
Java
47 lines
1.1 KiB
Java
package net.minecraft.client.data.models.blockstates;
|
|
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonObject;
|
|
import java.util.function.Function;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class VariantProperty<T> {
|
|
final String key;
|
|
final Function<T, JsonElement> serializer;
|
|
|
|
public VariantProperty(String key, Function<T, JsonElement> serializer) {
|
|
this.key = key;
|
|
this.serializer = serializer;
|
|
}
|
|
|
|
public VariantProperty<T>.Value withValue(T value) {
|
|
return new VariantProperty.Value(value);
|
|
}
|
|
|
|
public String toString() {
|
|
return this.key;
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class Value {
|
|
private final T value;
|
|
|
|
public Value(final T value) {
|
|
this.value = value;
|
|
}
|
|
|
|
public VariantProperty<T> getKey() {
|
|
return VariantProperty.this;
|
|
}
|
|
|
|
public void addToVariant(JsonObject json) {
|
|
json.add(VariantProperty.this.key, (JsonElement)VariantProperty.this.serializer.apply(this.value));
|
|
}
|
|
|
|
public String toString() {
|
|
return VariantProperty.this.key + "=" + this.value;
|
|
}
|
|
}
|
|
}
|