API

You can use this API to register your own items for agricultural flower growing or basically anything that is the size of one node high, the mod is very agnostic regarding what counts as “flower” … Just depend on afgrow and use those functions in your own mod:

  • afgrow.register_table() -> To register as many plant tables as you like.
  • afgrow.register_lamp() -> To register plant lamps used for the tables.
  • afgrow.register_seeds() -> To register all the seeds to be used.

Plant table

A plant table is always crafted in the same way, where S being the defined soil node, B being the defined sides node, and F being the defined frame node. It is up to the game to allow for 3x3 shaped crafting recipes.

┌───┬───┬───┐
│ S │ S │ S │
├───┼───┼───┤
│ B │ B │ B │
├───┼───┼───┤
│ F │ F │ F │
└───┴───┴───┘

This example registers a plant table using the base ID my_cool_base_id. This base ID gets automatically prefixed: afgrow:plant_table_my_cool_base_id. You can register as many plant tables you like.

afgrow.register_table('my_cool_base_id', {
    name   = 'My Cool Plant Table',
    sounds = SimpleSoundSpec,
    soil   = { 'group:my_cool_soil',  'mymod_my_cool_soil.png'  },
    sides  = { 'mymod:my_cool_sides', 'mymod_my_cool_sides.png' },
    frame  = { 'mymod:my_cool_wood',  'mymod_my_cool_wood.png'  },
    liquid = {
        { 'mymod:liquid_container_full', 'mymod:liquid_container_empty'   },
        { 'mymod:another_full_container', 'mymod:another_empty_container' }
    },
    storage = {
        'mymod:my_cool_chest',
        { 'mymod:my_special_storage', inventory = 'my_cool_inventory' },
        { 'mymod:my_special_storage', hint = 'mymod:my_chest_node' }
    },
    free_space = { 'mymod:air', 'mymod:more_air' },
    groups     = { my_cool_group = 1, my_other_group = 2 }
})

With the optional name you can override the default name “Plant Table”. sounds is a SimpleSoundSpec as per Luanti API.

The soil, sides, and frame values are composed from tables with two entries. The first entry is the node, item, or group that is used in crafting. The second value defines the texture to use when creating the actual node textures. In the example, in the crafting recipe the soil will be represented by any member node of the my_cool_soil group. In the constructed plant table the texture mymod_my_cool_soil.png will be visible in places where the soil is to be shown.

Using the liquid table, it is defined what source of liquid is used. You can add as many containers you want. The first entry in the container table defines the full container of liquid, that is taken out of the storage nodes inventory, and the second value is the empty container that is placed back in the storage nodes inventory.

Within the storage table all storage nodes are defined. If the table entry is just a string, this string defines the storage nodes ID (name). The mod automatically uses the nodes description and ID to show the placement hent, and automatically sets the inventory main.

Within that table you can also specify hint = '' to define another node to be used for displaying the placement hint. With inventory = '' you can define another inventory. You can use all of the additional attributes together. For code style reasons you can also use node = '' to define the storage nodes ID.

The optional free_space table defines a set of nodes that are to be seen as “free space” between the plant table and the plant lamp. If omitted the generic air is used. This should be fine for almost all games.

With groups you can add additional groups (some games might need extra groups for having breakable nodes). By default oddly_breakable_by_hand = 3 and the corresponding afgrow group are set.

Plant lamp

A plant lamp is crafted from the defined crafting material in this shape, where H is the connector, C is the casing material, L is the light source and F being the light source cover. The game need to make sure that 3x3 crafting of shaped recipes is possible.

┌───┬───┬───┐
│   │ H │   │
├───┼───┼───┤
│ C │ L │ C │
├───┼───┼───┤
│ C │ F │ C │
└───┴───┴───┘

The following definition registers a regular plant lamp with the base ID my_cool_lamp which will automatically expanded to afgrow:plant_lamp_my_cool_lamp. You can register multiple plant lamps. Technically they all work the same but can look different for player experience.

afgrow.register_lamp('my_cool_lamp', {
    connector = { 'group:my_cool_rods', 'mymod_wooden_rod.png'  },
    casing    = { 'mymod:cool_casing',  'mymod_cool_casing.png' },
    cover     = { 'mymod:nice_cover',   'mymod_nice_cover.png'  },
    light     = 'group:lights',
    sounds    = SimpleSoundSpec,
    groups    = { my_cool_group = 1, my_other_group = 2 }
})

For defining items or nodes for crafting, and what texture to use, the same as for plant lamps apply. The light is used for crafting only and cannot have a texture (it is not seen anywhere). For gameplay reasons it should be an object emitting light. sounds is a SimpleSoundSpec as per Luanti API.

With groups you can add additional groups (some games might need extra groups for having breakable nodes). By default oddly_breakable_by_hand = 1 and the corresponding afgrow group are set.

Seeds

Seeds can be registered in batch, by providing a table containing the seeds definition. Each line represents the registration of one seed. The last entry of each line is the “helper object”, you can omit that if you do not run into recipe conflicts.

Seeds are always crafted in the same way, where S is the source for a seed, and H being the optional helper object. If registered with helper object, the helper object is returned on crafting. The game needs to take care of 2x2 (or 3x2 at minimum) crafting and returning of items on crafting things.

┌───┬───┬───┐
│ S │ S │   │
├───┼───┼───┤
│ S │ S │   │
├───┼───┼───┤
│ H │   │   │
└───┴───┴───┘

The following example registers 2 seeds with different options. The first seed is a simple, generic flower without any special options. The second one demonstrates all possible options for registering a seed using a table instead of a simple string.

-- Seed table definition
local special_seed = {
    result    = 'mymod:my_cool_flower',
    name      = 'My Cool Seed Name',
    colors    = { '#90b241', '#5d9b14' },
    helper    = 'mymod:my_cool_helper_object',
    craftitem = 'mymod:my_cool_flower_craftitem',
    groups    = { my_cool_group = 1, my_other_group = 2 }
}

-- Seeds registration function and provided table of seed tables
afgrow.register_seeds({
    'mymod:simple_flower',
    special_seed
})

When only a string is provided, this string is used as ID to “bootstrap” the seed definition. The mod uses the description of the item defined under that ID as seed name, and automatically generates everything. This is the easiest but most generic way to register a seed. When grown, the resulting flower is the one defined by the given ID.

The second registration in the example references the previously defined complex registration table. With this table it is possible to fine-tune the seed registration. All entries are optional, except result.

The result defines what item (ideally a flower-like item that can be grown, given the name and intention of this mod …) that grown on the plant table as a result. You can omit result = '...' if you like, and use '...' without explicitly defining the table entry result depending on your code style.

By explicitly setting the seeds name, you can override the default name being “Result Name Seed” (or whatever makes most sense and “feels” best in the translation).

Using the colors table makes it possible to add little accents on the created seeds (colors[1] being the primary color, and colors[2] the secondary or accent color). If omitted, some sort of green is used.

With helper the helper object is defined. This can be used to circumvent the issue of already existing recipes. The helper object is not consumed on crafting and is returned to the player.

Using the craftitem entry you can define the ID of the item to use for crafting a seed other than the result item. This is useful for when the flower drops something else than itself.

With groups you can add additional groups to the seeds. By default only the corresponding afgrow group is set.