2015-02-13 01:48:47 +01:00
|
|
|
vines.register_vine = function( name, defs, biome )
|
2015-02-10 07:15:16 +01:00
|
|
|
--different properties for bottom and side vines.
|
2015-02-13 01:48:47 +01:00
|
|
|
local drop_node = 'vines:'..name
|
2015-02-10 07:15:16 +01:00
|
|
|
local drawtype = ''
|
|
|
|
local selection_box
|
2015-02-13 01:48:47 +01:00
|
|
|
if ( biome.spawn_on_side ) then
|
2015-02-10 07:15:16 +01:00
|
|
|
selection_box = {
|
|
|
|
type = "wallmounted",
|
|
|
|
}
|
|
|
|
drawtype = 'signlike'
|
|
|
|
else
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = { -0.4, -1/2, -0.4, 0.4, 1/2, 0.4 },
|
|
|
|
}
|
|
|
|
drawtype = 'plantlike'
|
|
|
|
end
|
|
|
|
|
2015-02-13 01:48:47 +01:00
|
|
|
biome.spawn_plants = { "vines:"..name }
|
|
|
|
|
|
|
|
minetest.register_node( "vines:"..name, {
|
2015-02-10 07:15:16 +01:00
|
|
|
description = defs.description,
|
|
|
|
walkable = false,
|
|
|
|
climbable = true,
|
|
|
|
wield_image = "vines_"..name..".png",
|
|
|
|
drop = "",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "wallmounted",
|
|
|
|
buildable_to = true,
|
|
|
|
tile_images = { "vines_"..name..".png" },
|
|
|
|
drawtype = drawtype,
|
|
|
|
inventory_image = "vines_"..name..".png",
|
|
|
|
groups = vines.groups,
|
|
|
|
sounds = default.node_sound_leaves_defaults(),
|
|
|
|
selection_box = selection_box,
|
|
|
|
on_construct = function( pos )
|
|
|
|
local timer = minetest.get_node_timer( pos )
|
|
|
|
timer:start( math.random(5, 10) )
|
|
|
|
end,
|
|
|
|
on_timer = function( pos )
|
|
|
|
local node = minetest.get_node( pos )
|
|
|
|
local bottom = {x=pos.x, y=pos.y-1, z=pos.z}
|
|
|
|
local bottom_node = minetest.get_node( bottom )
|
|
|
|
if bottom_node.name == "air" then
|
|
|
|
if not ( math.random( defs.average_length ) == 1 ) then
|
|
|
|
minetest.set_node( pos, { name = node.name..'_rotten', param2 = node.param2 } )
|
|
|
|
minetest.set_node( bottom, { name = node.name, param2 = node.param2 } )
|
|
|
|
local timer = minetest.get_node_timer( bottom_node )
|
|
|
|
timer:start( math.random(5, 10) )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
after_dig_node = function(pos, node, oldmetadata, user)
|
2015-02-13 01:48:47 +01:00
|
|
|
vines.dig_vine( pos, drop_node, user )
|
2015-02-10 07:15:16 +01:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
local name = name..'_rotten'
|
|
|
|
|
|
|
|
minetest.register_node( "vines:"..name, {
|
|
|
|
description = "Rotten "..defs.description,
|
|
|
|
walkable = false,
|
|
|
|
climbable = true,
|
|
|
|
drop = "",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "wallmounted",
|
|
|
|
buildable_to = true,
|
|
|
|
tile_images = { "vines_"..name..".png" },
|
|
|
|
wield_image = "vines_"..name..".png",
|
|
|
|
drawtype = drawtype,
|
|
|
|
inventory_image = "vines_"..name..".png",
|
|
|
|
groups = vines.groups,
|
|
|
|
sounds = default.node_sound_leaves_defaults(),
|
|
|
|
selection_box = selection_box,
|
|
|
|
on_destruct = function( pos )
|
|
|
|
local node = minetest.get_node( pos )
|
|
|
|
local bottom = {x=pos.x, y=pos.y-1, z=pos.z}
|
|
|
|
local bottom_node = minetest.get_node( bottom )
|
|
|
|
if minetest.get_item_group( bottom_node.name, "vines") then
|
|
|
|
minetest.remove_node( bottom )
|
|
|
|
end
|
|
|
|
end,
|
2015-02-13 01:48:47 +01:00
|
|
|
after_dig_node = function( pos, node, oldmetadata, user )
|
|
|
|
vines.dig_vine( pos, drop_node, user )
|
2015-02-10 07:15:16 +01:00
|
|
|
end
|
|
|
|
})
|
2015-02-13 01:48:47 +01:00
|
|
|
|
|
|
|
plantslib:spawn_on_surfaces( biome )
|
|
|
|
|
|
|
|
local override_nodes = function( nodes, defs )
|
|
|
|
function override( index, registered )
|
|
|
|
local node = nodes[ index ]
|
|
|
|
if index > #nodes then return registered end
|
|
|
|
if minetest.registered_nodes[node] then
|
|
|
|
print('overiding: '..node)
|
|
|
|
minetest.override_item( node, defs )
|
|
|
|
registered[#registered+1] = node
|
|
|
|
end
|
|
|
|
override( index+1, registered )
|
|
|
|
end
|
|
|
|
override( 1, {} )
|
|
|
|
end
|
|
|
|
|
|
|
|
override_nodes( biome.spawn_surfaces,{
|
|
|
|
after_destruct = function( pos )
|
|
|
|
local pos_min = { x = pos.x -1, y = pos.y - 1, z = pos.z - 1 }
|
|
|
|
local pos_max = { x = pos.x +1, y = pos.y + 1, z = pos.z + 1 }
|
|
|
|
local positions = minetest.find_nodes_in_area( pos_min, pos_max, "group:vines" )
|
|
|
|
for index, position in pairs(positions) do
|
|
|
|
minetest.remove_node( position )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2015-02-10 07:15:16 +01:00
|
|
|
end
|
|
|
|
|
2015-02-13 01:48:47 +01:00
|
|
|
vines.dig_vine = function( pos, node_name, user )
|
2015-02-10 07:15:16 +01:00
|
|
|
--only dig give the vine if shears are used
|
|
|
|
if not user then return false end
|
|
|
|
local wielded = user:get_wielded_item()
|
|
|
|
if 'vines:shears' == wielded:get_name() then
|
|
|
|
local inv = user:get_inventory()
|
|
|
|
if inv then
|
2015-02-13 01:48:47 +01:00
|
|
|
inv:add_item("main", ItemStack( node_name ))
|
2015-02-10 07:15:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|