modified PR from coil0: used buildable_to instead of node names in order to determine if replacing can progress even if digging of the node doesn't work

This commit is contained in:
Sokomine 2021-09-30 00:18:34 +02:00
parent 889885049e
commit fe89553780
1 changed files with 8 additions and 10 deletions

View File

@ -228,16 +228,9 @@ replacer.replace = function( itemstack, user, pointed_thing, mode )
end
-- give the player the item by simulating digging if possible
if( node.name ~= "air"
and node.name ~= "ignore"
and node.name ~= "default:lava_source"
and node.name ~= "default:lava_flowing"
and node.name ~= "default:river_water_source"
and node.name ~= "default:river_water_flowing"
and node.name ~= "default:water_source"
and node.name ~= "default:water_flowing" ) then
and node.name ~= "ignore") then
minetest.node_dig( pos, node, user );
@ -245,8 +238,13 @@ replacer.replace = function( itemstack, user, pointed_thing, mode )
if( not( digged_node )
or digged_node.name == node.name ) then
minetest.chat_send_player( name, "Replacing '"..( node.name or "air" ).."' with '"..( item[ "metadata"] or "?" ).."' failed. Unable to remove old node.");
return nil;
-- some nodes - like liquids - cannot be digged. but they are buildable_to and
-- thus can be replaced
local node_def = minetest.registered_nodes[node.name]
if(not(node_def) or not(node_def.buildable_to)) then
minetest.chat_send_player( name, "Replacing '"..( node.name or "air" ).."' with '"..( item[ "metadata"] or "?" ).."' failed. Unable to remove old node.");
return nil;
end
end
end