Rewriting rope ladder and rope severing to be more robust, can now be done with a default axe

This commit is contained in:
FaceDeer 2017-01-30 01:56:44 -07:00
parent e2eb4c6db3
commit d202fd497f
4 changed files with 192 additions and 146 deletions

@ -10,7 +10,7 @@ minetest.register_craft({
}) })
minetest.register_craftitem("vines:ropesegment", { minetest.register_craftitem("vines:ropesegment", {
description = "Rope", description = "Rope",
groups = {vines = 1}, groups = {vines = 1},
inventory_image = "vines_item.png", inventory_image = "vines_item.png",
}) })

@ -132,42 +132,69 @@ end
local c_air = minetest.get_content_id("air") local c_air = minetest.get_content_id("air")
vines.destroy_rope_starting = function( p, targetnode, bottomnode, topnode ) vines.destroy_rope_starting = function(pos, targetnode, bottomnode, topnode )
local n = minetest.get_node(p).name local node_name = minetest.get_node(pos).name
if n ~= targetnode and n ~= bottomnode then if node_name ~= targetnode and node_name ~= bottomnode then
return return
end end
local y1 = p.y local y_top = pos.y
local tab = {} local y_bottom = y_top
local i = 1 local true_bottom = true
while n == targetnode do while true do
tab[i] = p minetest.debug("loop", y_bottom)
i = i+1 node_name = minetest.get_node({x=pos.x, y=y_bottom - 1, z=pos.z}).name
p.y = p.y-1 if node_name == targetnode or node_name == bottomnode then
n = minetest.get_node(p).name y_bottom = y_bottom - 1
elseif node_name == "ignore" then
true_bottom = false
break
else
break
end
end end
if n == bottomnode then
tab[i] = p
end
local y0 = p.y
local manip = minetest.get_voxel_manip() local manip = minetest.get_voxel_manip()
local p0 = {x=p.x, y=y0, z=p.z} local pos_bottom = {x=pos.x, y=y_bottom, z=pos.z}
local p1 = {x=p.x, y=y0+1, z=p.z} local pos_top = {x=pos.x, y=y_top, z=pos.z}
local p2 = {x=p.x, y=y1, z=p.z} local pos1, pos2 = manip:read_from_map(pos_bottom, pos_top)
local pos1, pos2 = manip:read_from_map(p0, p2) local area = VoxelArea:new({MinEdge=pos1, MaxEdge=pos2})
area = VoxelArea:new({MinEdge=pos1, MaxEdge=pos2}) local nodes = manip:get_data()
nodes = manip:get_data()
for i in area:iterp(p1, p2) do for i in area:iterp(pos_bottom, pos_top) do
nodes[i] = c_air nodes[i] = c_air
end end
nodes[area:indexp(p0)] = minetest.get_content_id(topnode) if not true_bottom then
nodes[area:indexp(pos_bottom)] = minetest.get_content_id(topnode)
end
manip:set_data(nodes) manip:set_data(nodes)
manip:write_to_map() manip:write_to_map()
manip:update_map() -- <— this takes time manip:update_map() -- <— this takes time
local timer = minetest.get_node_timer( p0 ) if not true_bottom then
timer:start( 1 ) minetest.get_node_timer(pos_bottom):start(1)
end
end end
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

@ -18,24 +18,23 @@ minetest.register_node("vines:ropeladder_top", {
}, },
groups = { choppy=2, oddly_breakable_by_hand=1,flammable=2}, groups = { choppy=2, oddly_breakable_by_hand=1,flammable=2},
legacy_wallmounted = true,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
after_place_node = function(pos) after_place_node = function(pos)
local p = {x=pos.x, y=pos.y-1, z=pos.z} local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
local n = minetest.get_node(p) local node_below = minetest.get_node(pos_below)
local o = minetest.get_node(pos) local this_node = minetest.get_node(pos)
-- param2 holds the facing direction of this node. If it's 0 or 1 the node is "flat" and we don't want the ladder to extend. -- param2 holds the facing direction of this node. If it's 0 or 1 the node is "flat" and we don't want the ladder to extend.
if n.name == "air" and o.param2 > 1 then if node_below.name == "air" and this_node.param2 > 1 then
minetest.add_node(p, {name="vines:ropeladder_bottom", param2=o.param2}) minetest.add_node(pos_below, {name="vines:ropeladder_bottom", param2=this_node.param2})
local meta = minetest.get_meta(p) local meta = minetest.get_meta(pos_below)
meta:set_int("length_remaining", vines.ropeLadderLength) meta:set_int("length_remaining", vines.ropeLadderLength)
end end
end, end,
after_destruct = function(pos) after_destruct = function(pos)
local p = {x=pos.x, y=pos.y-1, z=pos.z} local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
vines.destroy_rope_starting(p, 'vines:ropeladder', 'vines:ropeladder_bottom', 'vines:ropeladder_falling') vines.destroy_rope_starting(pos_below, "vines:ropeladder", "vines:ropeladder_bottom", "vines:ropeladder_falling")
end end,
}) })
minetest.register_craft({ minetest.register_craft({
@ -48,6 +47,7 @@ minetest.register_craft({
minetest.register_node("vines:ropeladder", { minetest.register_node("vines:ropeladder", {
description = "Rope ladder", description = "Rope ladder",
drop = "",
drawtype = "signlike", drawtype = "signlike",
tiles = {"default_ladder_wood.png^vines_ropeladder.png"}, tiles = {"default_ladder_wood.png^vines_ropeladder.png"},
is_ground_content = false, is_ground_content = false,
@ -63,15 +63,18 @@ minetest.register_node("vines:ropeladder", {
--wall_top = = <default> --wall_top = = <default>
--wall_bottom = = <default> --wall_bottom = = <default>
--wall_side = = <default> --wall_side = = <default>
}, },
groups = {flammable=2, not_in_creative_inventory=1}, groups = {choppy=2, flammable=2, not_in_creative_inventory=1},
legacy_wallmounted = true,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
after_destruct = function(pos)
vines.hanging_after_destruct(pos, "vines:ropeladder_falling", "vines:ropeladder", "vines:ropeladder_bottom")
end,
}) })
minetest.register_node("vines:ropeladder_bottom", { minetest.register_node("vines:ropeladder_bottom", {
description = "Rope ladder", description = "Rope ladder",
drop = "",
drawtype = "signlike", drawtype = "signlike",
tiles = {"default_ladder_wood.png^vines_ropeladder_bottom.png"}, tiles = {"default_ladder_wood.png^vines_ropeladder_bottom.png"},
is_ground_content = false, is_ground_content = false,
@ -89,8 +92,7 @@ minetest.register_node("vines:ropeladder_bottom", {
--wall_side = = <default> --wall_side = = <default>
}, },
groups = {flammable=2, not_in_creative_inventory=1}, groups = {choppy=2, flammable=2, not_in_creative_inventory=1},
legacy_wallmounted = true,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function( pos ) on_construct = function( pos )
local timer = minetest.get_node_timer( pos ) local timer = minetest.get_node_timer( pos )
@ -100,23 +102,30 @@ minetest.register_node("vines:ropeladder_bottom", {
local currentend = minetest.get_node(pos) local currentend = minetest.get_node(pos)
local currentmeta = minetest.get_meta(pos) local currentmeta = minetest.get_meta(pos)
local currentlength = currentmeta:get_int("length_remaining") local currentlength = currentmeta:get_int("length_remaining")
local p = {x=pos.x, y=pos.y-1, z=pos.z} local newpos = {x=pos.x, y=pos.y-1, z=pos.z}
local n = minetest.get_node(p) local newnode = minetest.get_node(newpos)
local o = minetest.get_node(pos) local oldnode = minetest.get_node(pos)
if n.name == "air" and (currentlength > 1) then if currentlength > 1 then
minetest.add_node(p, {name="vines:ropeladder_bottom", param2=o.param2}) if newnode.name == "air" then
local newmeta = minetest.get_meta(p) minetest.add_node(newpos, {name="vines:ropeladder_bottom", param2=oldnode.param2})
newmeta:set_int("length_remaining", currentlength-1) local newmeta = minetest.get_meta(newpos)
minetest.set_node(pos, {name="vines:ropeladder", param2=o.param2}) newmeta:set_int("length_remaining", currentlength-1)
else minetest.set_node(pos, {name="vines:ropeladder", param2=oldnode.param2})
local timer = minetest.get_node_timer( pos ) else
timer:start( 1 ) local timer = minetest.get_node_timer( pos )
timer:start( 1 )
end
end end
end end,
after_destruct = function(pos)
vines.hanging_after_destruct(pos, "vines:ropeladder_falling", "vines:ropeladder", "vines:ropeladder_bottom")
end,
}) })
minetest.register_node("vines:ropeladder_falling", { minetest.register_node("vines:ropeladder_falling", {
description = "Rope ladder", description = "Rope ladder",
drop = "",
drawtype = "signlike", drawtype = "signlike",
tiles = {"default_ladder_wood.png^vines_ropeladder.png"}, tiles = {"default_ladder_wood.png^vines_ropeladder.png"},
is_ground_content = false, is_ground_content = false,
@ -135,19 +144,18 @@ minetest.register_node("vines:ropeladder_falling", {
}, },
groups = {flammable=2, not_in_creative_inventory=1}, groups = {flammable=2, not_in_creative_inventory=1},
legacy_wallmounted = true,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_construct = function( pos ) on_construct = function( pos )
local timer = minetest.get_node_timer( pos ) local timer = minetest.get_node_timer( pos )
timer:start( 1 ) timer:start( 1 )
end, end,
on_timer = function( pos, elapsed ) on_timer = function( pos, elapsed )
local p = {x=pos.x, y=pos.y-1, z=pos.z} local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
local n = minetest.get_node(p) local node_below = minetest.get_node(pos_below)
if (n.name ~= "ignore") then if (node_below.name ~= "ignore") then
vines.destroy_rope_starting(p, 'vines:ropeladder', 'vines:ropeladder_bottom', 'vines:ropeladder_falling') vines.destroy_rope_starting(pos_below, 'vines:ropeladder', 'vines:ropeladder_bottom', 'vines:ropeladder_falling')
minetest.set_node(pos, {name="air"}) minetest.swap_node(pos, {name="air"})
else else
local timer = minetest.get_node_timer( pos ) local timer = minetest.get_node_timer( pos )
timer:start( 1 ) timer:start( 1 )

@ -26,20 +26,20 @@ local function register_rope_block(multiple, pixels)
}, },
selection_box = {type="regular"}, selection_box = {type="regular"},
collision_box = {type="regular"}, collision_box = {type="regular"},
groups = { flammable=2, choppy=2, oddly_breakable_by_hand=1 }, groups = {flammable=2, choppy=2, oddly_breakable_by_hand=1},
after_place_node = function(pos) after_place_node = function(pos)
local p = {x=pos.x, y=pos.y-1, z=pos.z} local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
local n = minetest.get_node(p) local node_below = minetest.get_node(pos_below)
if n.name == "air" then if node_below.name == "air" then
minetest.add_node(p, {name="vines:rope_bottom"}) minetest.add_node(pos_below, {name="vines:rope_bottom"})
local meta = minetest.get_meta(p) local meta = minetest.get_meta(pos_below)
meta:set_int("length_remaining", vines.ropeLength*multiple) meta:set_int("length_remaining", vines.ropeLength*multiple)
end end
end, end,
after_destruct = function(pos) after_destruct = function(pos)
local p = {x=pos.x, y=pos.y-1, z=pos.z} local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
vines.destroy_rope_starting(p, 'vines:rope', 'vines:rope_bottom', 'vines:rope_top') vines.destroy_rope_starting(pos_below, 'vines:rope', 'vines:rope_bottom', 'vines:rope_top')
end end
}) })
@ -82,88 +82,99 @@ register_rope_block(4, 10)
register_rope_block(5, 12) register_rope_block(5, 12)
minetest.register_node("vines:rope", { minetest.register_node("vines:rope", {
description = "Rope", description = "Rope",
walkable = false, walkable = false,
climbable = true, climbable = true,
sunlight_propagates = true, sunlight_propagates = true,
paramtype = "light", paramtype = "light",
drop = "", drop = "",
tiles = { "vines_rope.png" }, tiles = { "vines_rope.png" },
drawtype = "plantlike", drawtype = "plantlike",
groups = {flammable=2, not_in_creative_inventory=1}, groups = {choppy=2, flammable=2, not_in_creative_inventory=1},
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
}, },
after_destruct = function(pos)
vines.hanging_after_destruct(pos, "vines:rope_top", "vines:rope", "vines:rope_bottom")
end,
}) })
minetest.register_node("vines:rope_bottom", { minetest.register_node("vines:rope_bottom", {
description = "Rope", description = "Rope",
walkable = false, walkable = false,
climbable = true, climbable = true,
sunlight_propagates = true, sunlight_propagates = true,
paramtype = "light", paramtype = "light",
drop = "", drop = "",
tiles = { "vines_rope_bottom.png" }, tiles = { "vines_rope_bottom.png" },
drawtype = "plantlike", drawtype = "plantlike",
groups = {flammable=2, not_in_creative_inventory=1}, groups = {choppy=2, flammable=2, not_in_creative_inventory=1},
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
}, },
on_construct = function( pos )
local timer = minetest.get_node_timer( pos ) on_construct = function( pos )
timer:start( 1 ) local timer = minetest.get_node_timer( pos )
end, timer:start( 1 )
on_timer = function( pos, elapsed ) end,
local currentend = minetest.get_node(pos)
local currentmeta = minetest.get_meta(pos) on_timer = function( pos, elapsed )
local currentlength = currentmeta:get_int("length_remaining") local currentend = minetest.get_node(pos)
local p = {x=pos.x, y=pos.y-1, z=pos.z} local currentmeta = minetest.get_meta(pos)
local n = minetest.get_node(p) local currentlength = currentmeta:get_int("length_remaining")
if n.name == "air" and (currentlength > 1) then local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
minetest.add_node(p, {name="vines:rope_bottom"}) local node_below = minetest.get_node(pos_below)
local newmeta = minetest.get_meta(p) if node_below.name == "air" and (currentlength > 1) then
newmeta:set_int("length_remaining", currentlength-1) minetest.add_node(pos_below, {name="vines:rope_bottom"})
minetest.set_node(pos, {name="vines:rope"}) local newmeta = minetest.get_meta(pos_below)
else newmeta:set_int("length_remaining", currentlength-1)
local timer = minetest.get_node_timer( pos ) minetest.set_node(pos, {name="vines:rope"})
timer:start( 1 ) else
end local timer = minetest.get_node_timer( pos )
end timer:start( 1 )
end
end,
after_destruct = function(pos)
vines.hanging_after_destruct(pos, "vines:rope_top", "vines:rope", "vines:rope_bottom")
end,
}) })
minetest.register_node("vines:rope_top", { minetest.register_node("vines:rope_top", {
description = "Rope", description = "Rope",
walkable = false, walkable = false,
climbable = true, climbable = true,
sunlight_propagates = true, sunlight_propagates = true,
paramtype = "light", paramtype = "light",
drop = "", drop = "",
tiles = { "vines_rope_top.png" }, tiles = { "vines_rope_top.png" },
drawtype = "plantlike", drawtype = "plantlike",
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
}, },
on_construct = function( pos )
local timer = minetest.get_node_timer( pos ) on_construct = function( pos )
timer:start( 1 ) local timer = minetest.get_node_timer( pos )
end,
on_timer = function( pos, elapsed )
local p = {x=pos.x, y=pos.y-1, z=pos.z}
local n = minetest.get_node(p)
if (n.name ~= "ignore") then
vines.destroy_rope_starting(p, 'vines:rope', 'vines:rope_bottom', 'vines:rope_top')
minetest.set_node(pos, {name="air"})
else
local timer = minetest.get_node_timer( pos )
timer:start( 1 ) timer:start( 1 )
end end,
end
on_timer = function( pos, elapsed )
local p = {x=pos.x, y=pos.y-1, z=pos.z}
local n = minetest.get_node(p)
if (n.name ~= "ignore") then
vines.destroy_rope_starting(p, 'vines:rope', 'vines:rope_bottom', 'vines:rope_top')
minetest.swap_node(pos, {name="air"})
else
local timer = minetest.get_node_timer( pos )
timer:start( 1 )
end
end,
}) })