package net.minecraft.client.renderer.block.model; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import java.lang.reflect.Type; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.stream.Stream; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; @Environment(EnvType.CLIENT) public class ItemOverride { private final ResourceLocation model; private final List predicates; public ItemOverride(ResourceLocation model, List predicates) { this.model = model; this.predicates = ImmutableList.copyOf(predicates); } /** * @return the location of the target model */ public ResourceLocation getModel() { return this.model; } public Stream getPredicates() { return this.predicates.stream(); } @Environment(EnvType.CLIENT) protected static class Deserializer implements JsonDeserializer { public ItemOverride deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); ResourceLocation resourceLocation = ResourceLocation.parse(GsonHelper.getAsString(jsonObject, "model")); List list = this.getPredicates(jsonObject); return new ItemOverride(resourceLocation, list); } protected List getPredicates(JsonObject json) { Map map = Maps.newLinkedHashMap(); JsonObject jsonObject = GsonHelper.getAsJsonObject(json, "predicate"); for (Entry entry : jsonObject.entrySet()) { map.put(ResourceLocation.parse((String)entry.getKey()), GsonHelper.convertToFloat((JsonElement)entry.getValue(), (String)entry.getKey())); } return (List)map.entrySet() .stream() .map(entryx -> new ItemOverride.Predicate((ResourceLocation)entryx.getKey(), (Float)entryx.getValue())) .collect(ImmutableList.toImmutableList()); } } @Environment(EnvType.CLIENT) public static class Predicate { private final ResourceLocation property; private final float value; public Predicate(ResourceLocation property, float value) { this.property = property; this.value = value; } public ResourceLocation getProperty() { return this.property; } public float getValue() { return this.value; } } }