minecraft-src/net/minecraft/client/data/models/blockstates/VariantProperty.java
2025-07-04 03:15:13 +03:00

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;
}
}
}