Properly remove spawner when used or dug

Using minetest.dig_node causes various issues. An example is that when
area protection is in effect, it fails (even for your own area, because
minetest.dig_node doesn't allow a player to be specfied, it uses a null
one). So in the event of failure, a) after spawning, the spawner stays
there, and b) when you dig it, you get a copy in your inventory (because
the return value from dig_node was ignored) but it stays there so you
can dig infinite amounts of it.

Just using remove_node resolves all this.
This commit is contained in:
Ciaran Gultnieks 2014-03-26 14:05:01 +00:00
parent d683387e92
commit ff2da40fb4

View File

@ -317,7 +317,7 @@ function npcf:register_npc(name, def)
local player_name = puncher:get_player_name()
local admin = minetest.check_player_privs(player_name, {server=true})
if admin or player_name == owner then
minetest.dig_node(pos)
minetest.remove_node(pos)
if player_name == owner then
puncher:get_inventory():add_item("main", node)
end
@ -340,7 +340,7 @@ function npcf:register_npc(name, def)
minetest.chat_send_player(player_name, "Error: Invalid NPC Name!")
return
end
minetest.dig_node(pos)
minetest.remove_node(pos)
local npc_pos = {x=pos.x, y=pos.y + 0.5, z=pos.z}
local yaw = sender:get_look_yaw() + math.pi * 0.5
local luaentity = npcf:spawn(npc_pos, name, {