minecraft-src/net/minecraft/data/models/blockstates/VariantProperty.java
2025-07-04 01:41:11 +03:00

43 lines
978 B
Java

package net.minecraft.data.models.blockstates;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.function.Function;
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;
}
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 jsonObject) {
jsonObject.add(VariantProperty.this.key, (JsonElement)VariantProperty.this.serializer.apply(this.value));
}
public String toString() {
return VariantProperty.this.key + "=" + this.value;
}
}
}