Interface CustomIngredientSerializer<T extends CustomIngredient>

Type Parameters:
T - the type of the custom ingredient

public interface CustomIngredientSerializer<T extends CustomIngredient>
Serializer for a CustomIngredient.

All instances must be registered using register(net.fabricmc.fabric.api.recipe.v1.ingredient.CustomIngredientSerializer<?>) for deserialization to work.

  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable CustomIngredientSerializer<?>
    get(Identifier identifier)
    Returns the custom ingredient serializer registered with the given identifier, or null if there is no such serializer.
    Returns the identifier of this serializer.
    read(com.google.gson.JsonObject json)
    Deserializes the custom ingredient from a JSON object.
    Deserializes the custom ingredient from a packet buffer.
    static void
    Registers a custom ingredient serializer, using the serializer's identifier.
    void
    write(com.google.gson.JsonObject json, T ingredient)
    Serializes the custom ingredient to a JSON object.
    void
    write(PacketByteBuf buf, T ingredient)
    Serializes the custom ingredient to a packet buffer.
  • Method Details

    • register

      static void register(CustomIngredientSerializer<?> serializer)
      Registers a custom ingredient serializer, using the serializer's identifier.
      Throws:
      IllegalArgumentException - if the serializer is already registered
    • get

      @Nullable static @Nullable CustomIngredientSerializer<?> get(Identifier identifier)
      Returns the custom ingredient serializer registered with the given identifier, or null if there is no such serializer..
      Returns:
      the custom ingredient serializer registered with the given identifier, or null if there is no such serializer
    • getIdentifier

      Identifier getIdentifier()
      Returns the identifier of this serializer..
      Returns:
      the identifier of this serializer
    • read

      T read(com.google.gson.JsonObject json)
      Deserializes the custom ingredient from a JSON object.
      Throws:
      com.google.gson.JsonSyntaxException - if the JSON object does not match the format expected by the serializer
      IllegalArgumentException - if the JSON object is invalid for some other reason
    • write

      void write(com.google.gson.JsonObject json, T ingredient)
      Serializes the custom ingredient to a JSON object.
    • read

      T read(PacketByteBuf buf)
      Deserializes the custom ingredient from a packet buffer.
    • write

      void write(PacketByteBuf buf, T ingredient)
      Serializes the custom ingredient to a packet buffer.