Use minetest.env:place_node and minetest.env:dig_node to enable usage of the on_place and on_dig callbacks.

This commit is contained in:
Anthony Zhang 2012-06-21 20:32:48 -04:00
parent 87442f0c31
commit 1e569782f5
2 changed files with 14 additions and 14 deletions

View File

@ -64,7 +64,7 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
local direction=mesecon:get_movestone_direction(pos) local direction=mesecon:get_movestone_direction(pos)
if not direction then if not direction then
minetest.env:add_node(pos, {name="mesecons_movestones:movestone"}) minetest.env:place_node(pos, {name="mesecons_movestones:movestone"})
self.object:remove() self.object:remove()
return return
end end
@ -75,13 +75,13 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
if lnode.name ~= "ignore" and lnode.name ~= "air" and lnode.name ~= "default:water" and lnode.name ~= "default:water_flowing" then if lnode.name ~= "ignore" and lnode.name ~= "air" and lnode.name ~= "default:water" and lnode.name ~= "default:water_flowing" then
local newnode local newnode
repeat repeat
minetest.env:remove_node(pos) minetest.env:dig_node(pos)
pos.x=pos.x+direction.x pos.x=pos.x+direction.x
pos.y=pos.y+direction.y pos.y=pos.y+direction.y
pos.z=pos.z+direction.z pos.z=pos.z+direction.z
newnode = {name=lnode.name} newnode = {name=lnode.name}
lnode = minetest.env:get_node(pos) lnode = minetest.env:get_node(pos)
minetest.env:add_node(pos, newnode) minetest.env:place_node(pos, newnode)
nodeupdate(pos) nodeupdate(pos)
until lnode.name == "ignore" or lnode.name == "air" or lnode.name == "default:water" or lnode.name == "default:water_flowing" until lnode.name == "ignore" or lnode.name == "air" or lnode.name == "default:water" or lnode.name == "default:water_flowing"
end end
@ -113,7 +113,7 @@ mesecon:register_on_signal_on(function (pos, node)
or checknode.name=="ignore" or checknode.name=="ignore"
or checknode.name=="default:water" or checknode.name=="default:water"
or checknode.name=="default:water_flowing" or checknode.name=="default:water_flowing"
minetest.env:remove_node(pos) minetest.env:dig_node(pos)
nodeupdate(pos) nodeupdate(pos)
minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity") minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity")
end end
@ -160,7 +160,7 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
if not direction then if not direction then
--or (minetest.env:get_node_or_nil(pos).name ~="air" --or (minetest.env:get_node_or_nil(pos).name ~="air"
--and minetest.env:get_node_or_nil(pos).name ~= nil) then --and minetest.env:get_node_or_nil(pos).name ~= nil) then
minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"}) minetest.env:place_node(pos, {name="mesecons_movestones:sticky_movestone"})
self.object:remove() self.object:remove()
return return
end end
@ -176,13 +176,13 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
if lnode.name ~= "ignore" and lnode.name ~= "air" and lnode.name ~= "default:water" and lnode.name ~= "default:water_flowing" then if lnode.name ~= "ignore" and lnode.name ~= "air" and lnode.name ~= "default:water" and lnode.name ~= "default:water_flowing" then
local newnode local newnode
repeat repeat
minetest.env:remove_node(lpos) minetest.env:dig_node(lpos)
lpos.x=lpos.x+direction.x lpos.x=lpos.x+direction.x
lpos.y=lpos.y+direction.y lpos.y=lpos.y+direction.y
lpos.z=lpos.z+direction.z lpos.z=lpos.z+direction.z
newnode = {name=lnode.name} newnode = {name=lnode.name}
lnode = minetest.env:get_node(lpos) lnode = minetest.env:get_node(lpos)
minetest.env:add_node(lpos, newnode) minetest.env:place_node(lpos, newnode)
nodeupdate(lpos) nodeupdate(lpos)
until lnode.name == "ignore" or lnode.name == "air" or lnode.name == "default:water" or lnode.name == "default:water_flowing" until lnode.name == "ignore" or lnode.name == "air" or lnode.name == "default:water" or lnode.name == "default:water_flowing"
end end
@ -198,7 +198,7 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
local oldpos = {x=lpos2.x+direction.x, y=lpos2.y+direction.y, z=lpos2.z+direction.z} local oldpos = {x=lpos2.x+direction.x, y=lpos2.y+direction.y, z=lpos2.z+direction.z}
repeat repeat
minetest.env:add_node(oldpos, {name=minetest.env:get_node(lpos2).name}) minetest.env:place_node(oldpos, {name=minetest.env:get_node(lpos2).name})
nodeupdate(oldpos) nodeupdate(oldpos)
oldpos = {x=lpos2.x, y=lpos2.y, z=lpos2.z} oldpos = {x=lpos2.x, y=lpos2.y, z=lpos2.z}
lpos2.x = lpos2.x-direction.x lpos2.x = lpos2.x-direction.x
@ -206,7 +206,7 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
lpos2.z = lpos2.z-direction.z lpos2.z = lpos2.z-direction.z
lnode = minetest.env:get_node(lpos2) lnode = minetest.env:get_node(lpos2)
until lnode.name=="air" or lnode.name=="ignore" or lnode.name=="default:water" or lnode.name=="default:water_flowing" until lnode.name=="air" or lnode.name=="ignore" or lnode.name=="default:water" or lnode.name=="default:water_flowing"
minetest.env:remove_node(oldpos) minetest.env:dig_node(oldpos)
end end
}) })
@ -237,7 +237,7 @@ mesecon:register_on_signal_on(function (pos, node)
or checknode.name=="default:water" or checknode.name=="default:water"
or checknode.name=="default:water_flowing" or checknode.name=="default:water_flowing"
minetest.env:remove_node(pos) minetest.env:dig_node(pos)
nodeupdate(pos) nodeupdate(pos)
minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity") minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity")
end end

View File

@ -195,13 +195,13 @@ mesecon:register_on_signal_on(function (pos, node)
local thisp= {x=np.x, y=np.y, z=np.z} local thisp= {x=np.x, y=np.y, z=np.z}
local thisnode=minetest.env:get_node(thisp) local thisnode=minetest.env:get_node(thisp)
local nextnode={} local nextnode={}
minetest.env:remove_node(thisp) minetest.env:dig_node(thisp)
repeat repeat
thisp.x=thisp.x+direction.x thisp.x=thisp.x+direction.x
thisp.y=thisp.y+direction.y thisp.y=thisp.y+direction.y
thisp.z=thisp.z+direction.z thisp.z=thisp.z+direction.z
nextnode=minetest.env:get_node(thisp) nextnode=minetest.env:get_node(thisp)
minetest.env:add_node(thisp, {name=thisnode.name}) minetest.env:place_node(thisp, {name=thisnode.name})
nodeupdate(thisp) nodeupdate(thisp)
thisnode=nextnode thisnode=nextnode
until thisnode.name=="air" until thisnode.name=="air"
@ -233,8 +233,8 @@ mesecon:register_on_signal_off(function (pos, node)
if thisnode.name~="air" and thisnode.name~="water" and not mesecon:is_mvps_stopper(thisnode.name) then if thisnode.name~="air" and thisnode.name~="water" and not mesecon:is_mvps_stopper(thisnode.name) then
local newpos={} local newpos={}
local oldpos={} local oldpos={}
minetest.env:add_node(np, {name=thisnode.name}) minetest.env:place_node(np, {name=thisnode.name})
minetest.env:remove_node(thisp) minetest.env:dig_node(thisp)
end end
end end
end end