[Mod] Plants [3.5][plants]

User avatar
Bas080
Member
Posts: 398
Joined: Mon May 21, 2012 15:54
GitHub: bas080
IRC: bas080
In-game: bas080
Location: Netherlands

[Mod] Plants [3.5][plants]

by Bas080 » Post

Includes plants that spawn in specific habitats!

Possibilities
- Mine the plants till they drop seeds for farming mod (unless it is a plant that can be picked up)
- Pick flowers and make a garden
- Enjoy the colors in the landscape.
- Find coals or iron by looking for coals flowers.Image

Image
Image
Image
Image
Image

Changelog

Depends
habitat

Download
https://github.com/bas080/plants/zipball/master
or see code https://github.com/bas080/plants

License
WTFPL for LUA and PNG files
Last edited by Bas080 on Wed Mar 27, 2013 00:56, edited 1 time in total.

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

Great!! Keep this up!!
Suggestion: make the plants spawn on map generation and not with an abm.

User avatar
Lippis
Member
Posts: 65
Joined: Mon Feb 13, 2012 18:50
Location: Suomi

by Lippis » Post

Looks cool. I need to test right now :)
Started LUA coding again :P

User avatar
Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27

by Topywo » Post

Nice new plants!

When I start, minetest creates dummies for the cotton seeds, seedling and sapling

I think all the plants appeared

Unfortunately when I harvest them, they don't go into my inventory.

Harvesting doesn't make sound

But I still like this mod :-)

User avatar
Bas080
Member
Posts: 398
Joined: Mon May 21, 2012 15:54
GitHub: bas080
IRC: bas080
In-game: bas080
Location: Netherlands

by Bas080 » Post

Topywo and Lippis:
Thnx, stay tuned for many updates. :)

PilzAdam:
I would love to make it spawn in map generation. That would improve performance allot. Can you point me to an example? .... However I also like that the plants grow again in the same area after having dug them. I don't think that would be possible without abm's. We could improve performance by reducing the amount of nodes being abm'd by making invisible plant-spawning nodes at map generation. And performing abm's on them. Avoiding abm-ing on all dirt_with_grass nodes...

Or is it possible to make code perform several seconds later. In that case you could dig the node on plant node dig you could set a timer that would trigger a function that adds a plant in the same-ish area. So is there a function with which you can set a time before a function performs?

mauvebic
Member
Posts: 1550
Joined: Fri Jan 27, 2012 11:32

by mauvebic » Post

You might be better using 1 ABM with a random function than seperate ABMs for each type of plant to place. and you can use after_dig_node in your node definition to place a new plant /seedling upon harvest. :-)
Last edited by mauvebic on Wed Aug 01, 2012 01:42, edited 1 time in total.

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

Bas080 wrote: PilzAdam:
I would love to make it spawn in map generation. That would improve performance allot. Can you point me to an example? .... However I also like that the plants grow again in the same area after having dug them. I don't think that would be possible without abm's. We could improve performance by reducing the amount of nodes being abm'd by making invisible plant-spawning nodes at map generation. And performing abm's on them. Avoiding abm-ing on all dirt_with_grass nodes...

Or is it possible to make code perform several seconds later. In that case you could dig the node on plant node dig you could set a timer that would trigger a function that adds a plant in the same-ish area. So is there a function with which you can set a time before a function performs?
1. I would like it if they would not appear again in one area.
2. There is a timer function:

Code: Select all

minetest.after(2, function([param])

end, [param])
This will be called after 2 sec. You can leave [param] out if you dont need one or make a table if you want more than one.

User avatar
Bas080
Member
Posts: 398
Joined: Mon May 21, 2012 15:54
GitHub: bas080
IRC: bas080
In-game: bas080
Location: Netherlands

by Bas080 » Post

PilzAdam, I used your feedback and implemented it into the mod. Now harvest mod spawns plants on map generation. Tested it and it sure works faster better and with less lag. It does take a bit longer for the maps to generate. Please share your own experience.

Plz move me to mod releases. (plz help me with sounds, i can't get that to work)

I look forward to more feedback and ideas for plants and crops.
Last edited by Bas080 on Fri Aug 03, 2012 13:22, edited 1 time in total.

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

Some suggestions:
  • Add descriptions to all items that you can have in your inventory.
  • Increase the chance to get seeds.
  • Make the seeds only placeable on soil.
Some code:

Code: Select all

minetest.register_craft({
    output = 'harvets:hoe_wood',
    recipe = {
        {"default:wood", "default:wood"},
        {"", "default:stick"},
        {"", "default:stick"},
    },
})

Code: Select all

minetest.register_abm({
    nodenames = {"harvest:corn_seedling"},
    interval = 60,
    chance = 2,
    action = function(pos, node)
        if find_node_near(pos, 10, "default:water_source") ~= nil then
            node.name = "harvest:corn_seedling"
            minetest.env:set_node(pos, node)
        end
    end
})
Hope this code helps a bit (not testet).

User avatar
Bas080
Member
Posts: 398
Joined: Mon May 21, 2012 15:54
GitHub: bas080
IRC: bas080
In-game: bas080
Location: Netherlands

by Bas080 » Post

PilzAdam wrote:

Code: Select all

minetest.register_abm({
    nodenames = {"harvest:corn_seedling"},
    interval = 60,
    chance = 2,
    action = function(pos, node)
        if find_node_near(pos, 10, "default:water_source") ~= nil then
            node.name = "harvest:corn_seedling"
            minetest.env:set_node(pos, node)
        end
    end
})
If I where to do it like that, then it would only work for the corn. It has to be dynamic. With which I mean that it should be possible to turn the cotton into a farming plant without having to make a new abm for cotton. I was thinking to abm the worked soil, adding farm-able plants to an array and checking if the node on top of the soil is part of that farm plants array. If so make it evolve to next level farming node till it's the harvestable node type which gives corn or cotton and some seeds when dug.
EDIT:
Other feedback has been implemented except the only placeable on soil. Still thinking about how to do that.
Last edited by Bas080 on Fri Aug 03, 2012 14:20, edited 1 time in total.

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

Bas080 wrote:
PilzAdam wrote:

Code: Select all

minetest.register_abm({
    nodenames = {"harvest:corn_seedling"},
    interval = 60,
    chance = 2,
    action = function(pos, node)
        if find_node_near(pos, 10, "default:water_source") ~= nil then
            node.name = "harvest:corn_seedling"
            minetest.env:set_node(pos, node)
        end
    end
})
If I where to do it like that, then it would only work for the corn. It has to be dynamic. With which I mean that it should be possible to turn the cotton into a farming plant without having to make a new abm for cotton. I was thinking to abm the worked soil, adding farm-able plants to an array and checking if the node on top of the soil is part of that farm plants array. If so make it evolve to next level farming node till it's the harvestable node type which gives corn or cotton and some seeds when dug.
I guessed that you want to do it this way. Its better.

User avatar
Bas080
Member
Posts: 398
Joined: Mon May 21, 2012 15:54
GitHub: bas080
IRC: bas080
In-game: bas080
Location: Netherlands

by Bas080 » Post

Big changes to the code and concept. Removed farming ideas. PilzAdam has made separate farming mod which i find better to keep separated. I would however like to see that this mod's plants provide seeds for PilzAdam's farming mod. Still have to think about how to implement seeds from this mod in the farming mod.

Further changes include sound added and some code cleanup.

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

Bas080 wrote:Big changes to the code and concept. Removed farming ideas. PilzAdam has made separate farming mod which i find better to keep separated. I would however like to see that this mod's plants provide seeds for PilzAdam's farming mod. Still have to think about how to implement seeds from this mod in the farming mod.

Further changes include sound added and some code cleanup.
When you add farming to dependecies you can change the drop from the plants to

Code: Select all

farming:wheat_seed
farming:cotton_seed
farming:pumpkin_seed
Then the seeds can be planted and grow. I can also add some plants from your mod to my mod, when you provide textures.
Last edited by PilzAdam on Tue Aug 21, 2012 10:49, edited 1 time in total.

User avatar
tonyka
Member
Posts: 320
Joined: Sat Jun 16, 2012 04:08
Location: Alicante, España

by tonyka » Post

I get the following error:
AL lib: pulseaudio.c:612: Context did not connect: Access denied
13:49:14: ERROR[main]: ========== ERROR FROM LUA ===========
13:49:14: ERROR[main]: Failed to load and run script from
13:49:14: ERROR[main]: /usr/share/minetest/games/avatar/mods/harvest/init.lua:
13:49:14: ERROR[main]: ...sr/share/minetest/games/avatar/mods/harvest/init.lua:85: attempt to call field 'node_sound_leaves_default' (a nil value)
13:49:14: ERROR[main]: stack traceback:
13:49:14: ERROR[main]: ...sr/share/minetest/games/avatar/mods/harvest/init.lua:85: in function 'add_plant'
13:49:14: ERROR[main]: ...sr/share/minetest/games/avatar/mods/harvest/init.lua:106: in main chunk
13:49:14: ERROR[main]: =======END OF ERROR FROM LUA ========
13:49:14: ERROR[main]: Server: Failed to load and run /usr/share/minetest/games/avatar/mods/harvest/init.lua
13:49:14: ERROR[main]: ModError: Failed to load and run /usr/share/minetest/games/avatar/mods/harvest/init.lua
My mod: [MOD]3D Forniture 1.0
Download: 3DForniture_v_1.0.zip
Page development (European Castilian):
Moviliario 3D (proyecto 3D Forniture)

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

tonyka wrote:I get the following error:
AL lib: pulseaudio.c:612: Context did not connect: Access denied
13:49:14: ERROR[main]: ========== ERROR FROM LUA ===========
13:49:14: ERROR[main]: Failed to load and run script from
13:49:14: ERROR[main]: /usr/share/minetest/games/avatar/mods/harvest/init.lua:
13:49:14: ERROR[main]: ...sr/share/minetest/games/avatar/mods/harvest/init.lua:85: attempt to call field 'node_sound_leaves_default' (a nil value)
13:49:14: ERROR[main]: stack traceback:
13:49:14: ERROR[main]: ...sr/share/minetest/games/avatar/mods/harvest/init.lua:85: in function 'add_plant'
13:49:14: ERROR[main]: ...sr/share/minetest/games/avatar/mods/harvest/init.lua:106: in main chunk
13:49:14: ERROR[main]: =======END OF ERROR FROM LUA ========
13:49:14: ERROR[main]: Server: Failed to load and run /usr/share/minetest/games/avatar/mods/harvest/init.lua
13:49:14: ERROR[main]: ModError: Failed to load and run /usr/share/minetest/games/avatar/mods/harvest/init.lua
Add a file called depends.txt to the mod folder and add default in the first line.

User avatar
tonyka
Member
Posts: 320
Joined: Sat Jun 16, 2012 04:08
Location: Alicante, España

by tonyka » Post

PilzAdam wrote:
tonyka wrote:I get the following error:
AL lib: pulseaudio.c:612: Context did not connect: Access denied
13:49:14: ERROR[main]: ========== ERROR FROM LUA ===========
13:49:14: ERROR[main]: Failed to load and run script from
13:49:14: ERROR[main]: /usr/share/minetest/games/avatar/mods/harvest/init.lua:
13:49:14: ERROR[main]: ...sr/share/minetest/games/avatar/mods/harvest/init.lua:85: attempt to call field 'node_sound_leaves_default' (a nil value)
13:49:14: ERROR[main]: stack traceback:
13:49:14: ERROR[main]: ...sr/share/minetest/games/avatar/mods/harvest/init.lua:85: in function 'add_plant'
13:49:14: ERROR[main]: ...sr/share/minetest/games/avatar/mods/harvest/init.lua:106: in main chunk
13:49:14: ERROR[main]: =======END OF ERROR FROM LUA ========
13:49:14: ERROR[main]: Server: Failed to load and run /usr/share/minetest/games/avatar/mods/harvest/init.lua
13:49:14: ERROR[main]: ModError: Failed to load and run /usr/share/minetest/games/avatar/mods/harvest/init.lua

Add a file called depends.txt to the mod folder and add default in the first line.
fixed, I changed the name of the mod folder ...
harvest => Plants
Now I see the little plants in the world ...

should include a folder with the name of the mod and the mod in, would save a lot of headaches ...
My mod: [MOD]3D Forniture 1.0
Download: 3DForniture_v_1.0.zip
Page development (European Castilian):
Moviliario 3D (proyecto 3D Forniture)

User avatar
tonyka
Member
Posts: 320
Joined: Sat Jun 16, 2012 04:08
Location: Alicante, España

by tonyka » Post

hehe
I is great for my game mode ...
this already looks a bit more to the planet Pandora (Avatar)...
only I have to change the textures ...
Image

Image
My mod: [MOD]3D Forniture 1.0
Download: 3DForniture_v_1.0.zip
Page development (European Castilian):
Moviliario 3D (proyecto 3D Forniture)

Spots
Member
Posts: 124
Joined: Tue Jul 24, 2012 12:12
Location: Outta my mind someplace.

by Spots » Post

tonyka wrote:hehe
I is great for my game mode ...
this already looks a bit more to the planet Pandora (Avatar)...
only I have to change the textures ...
Image

Image
nice what texture pack are you using i would love to check it out

User avatar
tonyka
Member
Posts: 320
Joined: Sat Jun 16, 2012 04:08
Location: Alicante, España

by tonyka » Post

Spots wrote: nice what texture pack are you using i would love to check it out
I'm changing the textures of the game, with gimp ...
ideas as I come ...
I can upload the project to GitHub ...
but do not think they finalize ... this is just to hang out ...
I dont know how to create biomes, and many other things ...
My mod: [MOD]3D Forniture 1.0
Download: 3DForniture_v_1.0.zip
Page development (European Castilian):
Moviliario 3D (proyecto 3D Forniture)

User avatar
Bas080
Member
Posts: 398
Joined: Mon May 21, 2012 15:54
GitHub: bas080
IRC: bas080
In-game: bas080
Location: Netherlands

by Bas080 » Post

Tonyka, not a bad idea making the plants give light. Maybe I’ll make plants series called luminescence plants.

Spots, I agree. The textures of tonyka look nice. I would like to see them for myself too. Plz share :)

User avatar
tonyka
Member
Posts: 320
Joined: Sat Jun 16, 2012 04:08
Location: Alicante, España

by tonyka » Post

Bas080 wrote:Tonyka, not a bad idea making the plants give light. Maybe I’ll make plants series called luminescence plants.

Spots, I agree. The textures of tonyka look nice. I would like to see them for myself too. Plz share :)
ok, I created a post for the game mode ...
http://minetest.net/forum/viewtopic.php?id=2845
Last edited by tonyka on Thu Aug 23, 2012 15:43, edited 1 time in total.
My mod: [MOD]3D Forniture 1.0
Download: 3DForniture_v_1.0.zip
Page development (European Castilian):
Moviliario 3D (proyecto 3D Forniture)

Alfino
Member
Posts: 32
Joined: Sun Sep 16, 2012 12:11

by Alfino » Post

Hello Bas080,

I was tweaking your mods so its can drops seed, unfortunately its give init.lua error.

here's the code :

Code: Select all

--Harvest
--A simple farming mod
--A extended plant spawning mod

--register alias to avoid unknown plants from previous harvest version

--Variable and function definitions
local mod_name = "harvest"

local wild_crops = {}
local wild_crop_count = 0

local add_plant = function(name_plant) -- register a wild plant
    
    local name = mod_name..":"..name_plant
    local img = mod_name.."_"..name_plant
    
    minetest.register_node(name.."_wild", {--register wild plant
        tile_images = {img.."_wild.png"},
        inventory_image = img.."_wild.png",
        description = name_plant,
        drawtype = "plantlike",
        sunlight_propagates = true,
        paramtype = "light",
        walkable = false,
        groups = { snappy = 3,flammable=2 },
        sounds = default.node_sound_leaves_defaults(),
    })

        minetest.register_node("harvest:wheat_wild", {
            paramtype = "light",
            walkable = false,
            drawtype = "plantlike",
            tiles = {"harvest_wheat_wild.png"},
            drop = {
                max_items = 4,
                items = {
                    { items = {'farming:wheat_seed'} },
                    { items = {'farming:wheat_seed'}, rarity = 2},
                    { items = {'farming:wheat_seed'}, rarity = 5},
                    { items = {'farming:wheat_harvested'} }
                }
            },
            groups = {snappy=3, flammable=2},
            sounds = default.node_sound_leaves_defaults(),
        })

        minetest.register_node("harvest:brownshroom_wild", 
            tile_images = {"harvest_brownshroom_wild.png"},
            inventory_image = "harvest_brownshroom_wild.png",
            description = name_plant,
            drawtype = "plantlike",
            light_propagates = true,
            sunlight_propagates = true,
            paramtype = "light",
    `        light_source = 12,
            walkable = false,
            groups = { snappy = 3,flammable=2 },
            sounds = default.node_sound_leaves_defaults(),
        })

        minetest.register_node("harvest:redshroom_wild", 
            tile_images = {"harvest_redshroom_wild.png"},
            inventory_image = "harvest_redshroom_wild.png",
            description = name_plant,
            drawtype = "plantlike",
            light_propagates = true,
            sunlight_propagates = true,
            paramtype = "light",
    `        light_source = 12,
            walkable = false,
            groups = { snappy = 3,flammable=2 },
            sounds = default.node_sound_leaves_defaults(),
        })

        minetest.register_node("harvest:cotton_wild", {
            paramtype = "light",
            walkable = false,
            drawtype = "plantlike",
            tiles = {"harvest_cotton_wild.png"},
            drop = {
                max_items = 6,
                items = {
                    { items = {'farming:cotton_seed'} },
                    { items = {'farming:cotton_seed'}, rarity = 2},
                    { items = {'farming:cotton_seed'}, rarity = 5},
                    { items = {'farming:string'} },
                    { items = {'farming:string'}, rarity = 2 },
                    { items = {'farming:string'}, rarity = 5 }
                }
            },
            groups = {snappy=3, flammable=2},
            sounds = default.node_sound_leaves_defaults(),
        })
        
end

--plant registration
--Just wild plant
--node registration
minetest.register_alias("harvest:lavender_wild", "plants:lavender_wild")
minetest.register_alias("harvest:redshroom_wild", "plants:redshroom_wild")
minetest.register_alias("harvest:wheat_wild", "plants:wheat_wild")
minetest.register_alias("harvest:cotton_wild", "plants:cotton_wild")
minetest.register_alias("harvest:brownshroom_wild", "plants:brownshroom_wild")
minetest.register_alias("harvest:chamomile_wild", "plants:chamomile_wild")
minetest.register_alias("harvest:colchicum_wild", "plants:colchicum_wild")
minetest.register_alias("harvest:poppy_wild", "plants:poppy_wild")
minetest.register_alias("harvest:grasstall_wild", "plants:grasstall_wild")
minetest.register_alias("harvest:grass_wild", "plants:grass_wild")
--Make node in which dirt changes after hoe preperation

--create plant nodes. Not all plants spawn in the wild for this you have to define it on the generate on function
add_plant("cotton")
add_plant("wheat")
add_plant("lavender")
add_plant("potato")
add_plant("redshroom")
add_plant("cacao")
add_plant("brownshroom")
add_plant("chamomile")
add_plant("colchicum")
add_plant("poppy")
add_plant("grasstall")
add_plant("grass")

--generate(node, surface, minp, maxp, height_min, height_max, spread, habitat_size, habitat_nodes)
--For the plants that do spawn on the lang we have the generate function. This makes sure that plants are placed when new peaces of the level are loaded.
minetest.register_on_generated(function(minp, maxp, seed)
    generate("harvest:lavender_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 60, 4, 4, {"default:sand"},0,{""})
    generate("harvest:redshroom_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 60, 20, 8, {"default:leaves"},0,{""})
    generate("harvest:wheat_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 60, 8, 10, {"default:water_source"},0,{""})
    generate("harvest:cotton_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 60, 8, 10, {"default:desert_sand"},0,{""})
    generate("harvest:brownshroom_wild", {"default:stone"}, minp, maxp, -40, -10, 2, 10, {"default:water_source"},0,{""})
    generate("harvest:chamomile_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 40, 8, 4, {"default:stone_with_coal"},0,{""})
    generate("harvest:colchicum_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 40, 4, 10, {"default:stone_with_iron"},0,{""})
    generate("harvest:poppy_wild", {"default:desert_sand"}, minp, maxp, -10, 20, 4, 10, {"default:water_source"},0,{""})
    generate("harvest:grasstall_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 20, 3, 3, {"default:water_source"},0,{""})
    generate("harvest:grass_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 20, 3, 3, {"default:water_source"},0,{""})
end)

print("[Harvest] Loaded!")
i don't know whats wrong with it, could you help me ?

User avatar
Bas080
Member
Posts: 398
Joined: Mon May 21, 2012 15:54
GitHub: bas080
IRC: bas080
In-game: bas080
Location: Netherlands

by Bas080 » Post

@Alfino

Good idea, but what are you going to do with the seeds?

I see your code. I see that you added a drop function to some of the nodes. So in this case wheat drops seeds and others don't. Your code is however very redundant(repeats itself unnecessarily). You could make an extra argument for the add_plant function.

Code: Select all

local add_plant = function(name_plant, [color=red]has_seeds[/color]) -- register a wild plant
  if has_seeds then
    define node with drop and seed item.
  else
    define node without drop
  end
end
Let me know if it helped you and please share the reason why you want the seeds feature. If you want to get used to the LUA, I still have a work in progress mod which is the portal mod to which you can contribute. Tip: also use other peoples mods to checkout how they achieved certain features. Have fun modding.

Alfino
Member
Posts: 32
Joined: Sun Sep 16, 2012 12:11

by Alfino » Post

thx Bas080,

the reason why add seeds,
Combine with PilzAdam's mod so wild plants give seeds
I will try it soon.

User avatar
Bas080
Member
Posts: 398
Joined: Mon May 21, 2012 15:54
GitHub: bas080
IRC: bas080
In-game: bas080
Location: Netherlands

by Bas080 » Post

Finally made it support PilzAdam's farming mod. Better late then never.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest