2015-02-13 01:48:47 +01:00
|
|
|
vines.register_vine = function( name, defs, biome )
|
2015-02-19 22:36:50 +01:00
|
|
|
local biome = biome
|
2015-02-13 03:10:15 +01:00
|
|
|
local groups = { vines=1, snappy=3, flammable=2 }
|
|
|
|
|
2015-02-16 20:46:24 +01:00
|
|
|
local vine_name_end = 'vines:'..name..'_end'
|
|
|
|
local vine_name_middle = 'vines:'..name..'_middle'
|
2015-02-13 03:10:15 +01:00
|
|
|
|
2015-02-16 20:46:24 +01:00
|
|
|
local vine_image_end = "vines_"..name.."_end.png"
|
|
|
|
local vine_image_middle = "vines_"..name.."_middle.png"
|
|
|
|
|
|
|
|
local drop_node = vine_name_end
|
|
|
|
|
|
|
|
biome.spawn_plants = { vine_name_end }
|
|
|
|
|
|
|
|
local vine_group = 'group:'..name..'_vines'
|
|
|
|
biome.spawn_surfaces[ #biome.spawn_surfaces + 1 ] = vine_group
|
|
|
|
|
|
|
|
local selection_box = { type = "wallmounted", }
|
|
|
|
local drawtype = 'signlike'
|
|
|
|
if ( not biome.spawn_on_side ) then
|
2015-02-19 22:36:50 +01:00
|
|
|
--different properties for bottom and side vines.
|
2015-02-16 20:46:24 +01:00
|
|
|
selection_box = { type = "fixed", fixed = { -0.4, -1/2, -0.4, 0.4, 1/2, 0.4 }, }
|
2015-02-10 07:15:16 +01:00
|
|
|
drawtype = 'plantlike'
|
|
|
|
end
|
|
|
|
|
2015-02-16 20:46:24 +01:00
|
|
|
minetest.register_node( vine_name_end, {
|
2015-02-10 07:15:16 +01:00
|
|
|
description = defs.description,
|
|
|
|
walkable = false,
|
|
|
|
climbable = true,
|
2015-02-16 20:46:24 +01:00
|
|
|
wield_image = vine_image_end,
|
2015-02-10 07:15:16 +01:00
|
|
|
drop = "",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "wallmounted",
|
2017-01-29 19:13:17 +01:00
|
|
|
buildable_to = false,
|
2016-06-08 09:30:00 +02:00
|
|
|
tiles = { vine_image_end },
|
2015-02-10 07:15:16 +01:00
|
|
|
drawtype = drawtype,
|
2015-02-16 20:46:24 +01:00
|
|
|
inventory_image = vine_image_end,
|
2015-02-13 03:10:15 +01:00
|
|
|
groups = groups,
|
2015-02-10 07:15:16 +01:00
|
|
|
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
|
2015-02-16 20:46:24 +01:00
|
|
|
minetest.set_node( pos, { name = vine_name_middle, param2 = node.param2 } )
|
2015-02-10 07:15:16 +01:00
|
|
|
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
|
|
|
|
})
|
|
|
|
|
2015-02-16 20:46:24 +01:00
|
|
|
minetest.register_node( vine_name_middle, {
|
|
|
|
description = "Matured "..defs.description,
|
2015-02-10 07:15:16 +01:00
|
|
|
walkable = false,
|
|
|
|
climbable = true,
|
|
|
|
drop = "",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "wallmounted",
|
2017-01-29 19:13:17 +01:00
|
|
|
buildable_to = false,
|
2016-06-08 09:30:00 +02:00
|
|
|
tiles = { vine_image_middle },
|
2015-02-16 20:46:24 +01:00
|
|
|
wield_image = vine_image_middle,
|
2015-02-10 07:15:16 +01:00
|
|
|
drawtype = drawtype,
|
2015-02-16 20:46:24 +01:00
|
|
|
inventory_image = vine_image_middle,
|
2015-02-13 03:10:15 +01:00
|
|
|
groups = groups,
|
2015-02-10 07:15:16 +01:00
|
|
|
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
|
2017-01-29 19:13:17 +01:00
|
|
|
minetest.after( 0, minetest.remove_node, bottom )
|
2015-02-10 07:15:16 +01:00
|
|
|
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
|
|
|
|
2015-08-09 17:07:19 +02:00
|
|
|
biome_lib:spawn_on_surfaces( biome )
|
2015-02-13 01:48:47 +01:00
|
|
|
|
|
|
|
local override_nodes = function( nodes, defs )
|
2017-01-29 19:13:17 +01:00
|
|
|
local function override( index, registered )
|
2015-02-13 01:48:47 +01:00
|
|
|
local node = nodes[ index ]
|
|
|
|
if index > #nodes then return registered end
|
|
|
|
if minetest.registered_nodes[node] then
|
|
|
|
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
|
2016-06-08 09:30:00 +02:00
|
|
|
|
|
|
|
local c_air = minetest.get_content_id("air")
|
|
|
|
|
2017-01-30 09:56:44 +01:00
|
|
|
vines.destroy_rope_starting = function(pos, targetnode, bottomnode, topnode )
|
|
|
|
local node_name = minetest.get_node(pos).name
|
|
|
|
if node_name ~= targetnode and node_name ~= bottomnode then
|
2016-06-08 09:30:00 +02:00
|
|
|
return
|
|
|
|
end
|
2017-01-30 09:56:44 +01:00
|
|
|
local y_top = pos.y
|
|
|
|
local y_bottom = y_top
|
|
|
|
local true_bottom = true
|
|
|
|
while true do
|
|
|
|
minetest.debug("loop", y_bottom)
|
|
|
|
node_name = minetest.get_node({x=pos.x, y=y_bottom - 1, z=pos.z}).name
|
|
|
|
if node_name == targetnode or node_name == bottomnode then
|
|
|
|
y_bottom = y_bottom - 1
|
|
|
|
elseif node_name == "ignore" then
|
|
|
|
true_bottom = false
|
|
|
|
break
|
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
2016-06-08 09:30:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local manip = minetest.get_voxel_manip()
|
2017-01-30 09:56:44 +01:00
|
|
|
local pos_bottom = {x=pos.x, y=y_bottom, z=pos.z}
|
|
|
|
local pos_top = {x=pos.x, y=y_top, z=pos.z}
|
|
|
|
local pos1, pos2 = manip:read_from_map(pos_bottom, pos_top)
|
|
|
|
local area = VoxelArea:new({MinEdge=pos1, MaxEdge=pos2})
|
|
|
|
local nodes = manip:get_data()
|
|
|
|
|
|
|
|
for i in area:iterp(pos_bottom, pos_top) do
|
2016-06-08 09:30:00 +02:00
|
|
|
nodes[i] = c_air
|
|
|
|
end
|
2017-01-30 09:56:44 +01:00
|
|
|
if not true_bottom then
|
|
|
|
nodes[area:indexp(pos_bottom)] = minetest.get_content_id(topnode)
|
|
|
|
end
|
2016-06-08 09:30:00 +02:00
|
|
|
|
|
|
|
manip:set_data(nodes)
|
|
|
|
manip:write_to_map()
|
|
|
|
manip:update_map() -- <— this takes time
|
|
|
|
|
2017-01-30 09:56:44 +01:00
|
|
|
if not true_bottom then
|
|
|
|
minetest.get_node_timer(pos_bottom):start(1)
|
|
|
|
end
|
2016-06-08 09:30:00 +02:00
|
|
|
end
|
2017-01-30 09:56:44 +01:00
|
|
|
|
|
|
|
vines.hanging_after_destruct = function(pos, top_node, middle_node, bottom_node)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if node.name == top_node or node.name == middle_node or node.name == bottom_node then
|
|
|
|
return -- this was done by another ladder node changing this one, don't react
|
|
|
|
end
|
|
|
|
|
|
|
|
pos.y = pos.y + 1 -- one up
|
|
|
|
local node_above = minetest.get_node(pos)
|
|
|
|
if node_above.name == middle_node then
|
|
|
|
minetest.swap_node(pos, {name=bottom_node, param2=node_above.param2})
|
|
|
|
end
|
|
|
|
|
|
|
|
pos.y = pos.y - 2 -- one down
|
|
|
|
local node_below = minetest.get_node(pos)
|
|
|
|
if node_below.name == middle_node then
|
|
|
|
vines.destroy_rope_starting(pos, middle_node, bottom_node, top_node)
|
|
|
|
--minetest.swap_node(pos, {name="vines:ropeladder_falling", param2=node_below.param2})
|
|
|
|
--minetest.get_node_timer(pos):start(0)
|
|
|
|
elseif node_below.name == bottom_node then
|
|
|
|
minetest.swap_node(pos, {name="air"})
|
|
|
|
end
|
|
|
|
end
|