add new function

master
Nemo08 2012-04-05 16:24:39 +04:00
parent 039f470bb4
commit a2e63fdb86
2 changed files with 51 additions and 6 deletions

View File

@ -16,7 +16,7 @@
STANDART_SPGROW_TIME = 120
function register_simple_plant(grow_table)
function register_plant_with_full_stages(grow_table)
for stage in ipairs(grow_table) do
if grow_table[stage].chance > 1 then
@ -50,3 +50,28 @@ function register_simple_plant(grow_table)
end
end
end
function register_simple_plant(name, final_description, stage_max, stage_time, image_template, final_drop)
-- number of stages of growth [1 .. stage_max]
-- image template .. [1 .. stage_max] .. ".png" --> png
local ngrow_table = {}
local cur_drop = ''
for i=1, stage_max do
cur_drop = ''
if i == stage_max then
cur_drop = final_drop
end
table.insert(ngrow_table, {
name = name .. i,
time = stage_time,
image = image_template .. i .. ".png",
drop = cur_drop,
groups = {snappy=3},
chance = 0.6
})
end
register_plant_with_full_stages(ngrow_table)
end

View File

@ -1,13 +1,13 @@
minetest.register_craftitem("simple_plant:seed0", {
inventory_image = "seed0.png",
minetest.register_craftitem('simple_plant:seed0', {
inventory_image = 'seed0.png',
stack_max = 99,
usable = true,
on_use = function(itemstack, user, pointed_thing)
-- Must be pointing to node
if pointed_thing.type == "node" then
if pointed_thing.type == 'node' then
n = minetest.env:get_node(pointed_thing.under)
if n.name == 'default:dirt_with_grass' then
minetest.env:add_node(pointed_thing.above, {name="simple_plant:splant1"})
minetest.env:add_node(pointed_thing.above, {name='simple_plant:splant1'})
end
itemstack:take_item()
end
@ -15,7 +15,7 @@ minetest.register_craftitem("simple_plant:seed0", {
end,
})
register_simple_plant({
register_plant_with_full_stages({
{
name = 'simple_plant:splant1',
time = 0.5,
@ -49,3 +49,23 @@ register_simple_plant({
chance = 0.4
},
})
---------------------
register_simple_plant('simple_plant:n', 'Odd flower', 6, 0.5, 'n', 'simple_plant:n_seed 5')
minetest.register_craftitem('simple_plant:n_seed', {
description = 'N seed',
inventory_image = 'n_seed.png',
stack_max = 99,
usable = true,
on_use = function(itemstack, user, pointed_thing)
-- Must be pointing to node
if pointed_thing.type == 'node' then
n = minetest.env:get_node(pointed_thing.under)
if n.name == 'default:dirt_with_grass' then
minetest.env:add_node(pointed_thing.above, {name='simple_plant:n1'})
end
itemstack:take_item()
end
return itemstack
end,
})