add transformable plant.
|
@ -8,14 +8,12 @@
|
|||
chance
|
||||
}
|
||||
}
|
||||
|
||||
--
|
||||
--
|
||||
--
|
||||
]]--
|
||||
|
||||
STANDART_SPGROW_TIME = 120
|
||||
|
||||
local TRANSFORMS = {}
|
||||
|
||||
function register_plant_with_full_stages(grow_table)
|
||||
|
||||
for stage in ipairs(grow_table) do
|
||||
|
@ -75,3 +73,56 @@ function register_simple_plant(name, final_description, stage_max, stage_time, i
|
|||
|
||||
register_plant_with_full_stages(ngrow_table)
|
||||
end
|
||||
|
||||
function register_transform_plant(grow_table)
|
||||
|
||||
for stage in ipairs(grow_table) do
|
||||
if grow_table[stage].chance > 1 then
|
||||
grow_table[stage].chance = 1
|
||||
end
|
||||
|
||||
minetest.register_node(grow_table[stage].name, {
|
||||
description = grow_table[stage].name,
|
||||
drawtype = "plantlike",
|
||||
walkable = false,
|
||||
tile_images = {grow_table[stage].image},
|
||||
inventory_image = grow_table[stage].image,
|
||||
wield_image = grow_table[stage].image,
|
||||
paramtype = "light",
|
||||
drop = grow_table[stage].drop,
|
||||
groups = grow_table[stage].groups,
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
|
||||
if (grow_table[stage].transform ~= nil) then
|
||||
|
||||
TRANSFORMS[grow_table[stage].name] = grow_table[stage].transform
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = { grow_table[stage].name },
|
||||
interval = grow_table[stage].time * STANDART_SPGROW_TIME,
|
||||
chance = grow_table[stage].chance,
|
||||
action = function (pos, node)
|
||||
if math.random() < grow_table[stage].chance then
|
||||
local rnd = 1
|
||||
if #(TRANSFORMS[node.name]) > 1 then
|
||||
rnd = math.random(#(TRANSFORMS[node.name]))
|
||||
end
|
||||
local transform = TRANSFORMS[node.name][rnd]
|
||||
|
||||
minetest.env:add_node({
|
||||
x = pos.x + transform.x,
|
||||
y = pos.y + transform.y,
|
||||
z = pos.z + transform.z
|
||||
},
|
||||
{name = transform.newname}
|
||||
)
|
||||
if transform.oldname ~= nil then
|
||||
minetest.env:add_node(pos, {name = transform.oldname})
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
|
@ -68,4 +68,70 @@ minetest.register_craftitem('simple_plant:n_seed', {
|
|||
end
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
------------------------
|
||||
minetest.register_craftitem('simple_plant:strange_seed', {
|
||||
description = 'Strange seed',
|
||||
inventory_image = 'seed_strange.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:sp1'})
|
||||
end
|
||||
itemstack:take_item()
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
register_transform_plant({
|
||||
{
|
||||
name = 'simple_plant:sp1',
|
||||
transform = {{newname = 'simple_plant:sp2', x =0, y=0, z=0}},
|
||||
time = 0.5,
|
||||
image = 'sp1.png',
|
||||
drop = '',
|
||||
groups = {snappy=3},
|
||||
chance = 0.7
|
||||
},
|
||||
{
|
||||
name = 'simple_plant:sp2',
|
||||
transform = {{newname = 'simple_plant:sp_fin', oldname ='simple_plant:sp_stem', x =0, y=1, z=0},
|
||||
{newname = 'simple_plant:sp_fin', oldname ='simple_plant:sp_stem2', x =0, y=1, z=0}},
|
||||
time = 0.5,
|
||||
image = 'sp2.png',
|
||||
drop = '',
|
||||
groups = {snappy=3},
|
||||
chance = 0.7
|
||||
},
|
||||
{
|
||||
name = 'simple_plant:sp_stem',
|
||||
transform = nil,
|
||||
time = 0.5,
|
||||
image = 'sp_stem.png',
|
||||
drop = '',
|
||||
groups = {snappy=3},
|
||||
chance = 0.7
|
||||
},
|
||||
{
|
||||
name = 'simple_plant:sp_stem2',
|
||||
transform = nil,
|
||||
time = 0.5,
|
||||
image = 'sp_stem2.png',
|
||||
drop = '',
|
||||
groups = {snappy=3},
|
||||
chance = 0.7
|
||||
},
|
||||
{
|
||||
name = 'simple_plant:sp_fin',
|
||||
time = 0.5,
|
||||
image = 'sp_fin.png',
|
||||
drop = 'simple_plant:strange_seed',
|
||||
groups = {snappy=3},
|
||||
chance = 0.7
|
||||
}
|
||||
})
|
After Width: | Height: | Size: 212 B |
After Width: | Height: | Size: 221 B |
After Width: | Height: | Size: 216 B |
After Width: | Height: | Size: 218 B |
After Width: | Height: | Size: 217 B |
After Width: | Height: | Size: 239 B |
After Width: | Height: | Size: 260 B |
After Width: | Height: | Size: 287 B |
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 161 B |
After Width: | Height: | Size: 210 B |
After Width: | Height: | Size: 214 B |
After Width: | Height: | Size: 244 B |