Search in sources :

Example 1 with IntegerProperty

use of net.minecraft.state.IntegerProperty in project Bookshelf by Darkhax-Minecraft.

the class SerializerBlockState method write.

@Override
public JsonElement write(BlockState toWrite) {
    final JsonObject json = new JsonObject();
    json.add("block", Serializers.BLOCK.write(toWrite.getBlock()));
    final JsonObject properties = new JsonObject();
    for (final Property prop : toWrite.getProperties()) {
        if (prop instanceof IntegerProperty) {
            properties.addProperty(prop.getName(), (int) toWrite.getValue((IntegerProperty) prop));
        } else if (prop instanceof BooleanProperty) {
            properties.addProperty(prop.getName(), (boolean) toWrite.getValue((BooleanProperty) prop));
        } else {
            properties.addProperty(prop.getName(), prop.getName(toWrite.getValue(prop)));
        }
    }
    json.add("properties", properties);
    return json;
}
Also used : IntegerProperty(net.minecraft.state.IntegerProperty) BooleanProperty(net.minecraft.state.BooleanProperty) JsonObject(com.google.gson.JsonObject) BooleanProperty(net.minecraft.state.BooleanProperty) IntegerProperty(net.minecraft.state.IntegerProperty) Property(net.minecraft.state.Property)

Aggregations

JsonObject (com.google.gson.JsonObject)1 BooleanProperty (net.minecraft.state.BooleanProperty)1 IntegerProperty (net.minecraft.state.IntegerProperty)1 Property (net.minecraft.state.Property)1