Trowel: Prevent hidden nodes from being dug.

As suggested by the player "felix7".
This commit is contained in:
Thomas--S 2020-07-29 18:37:12 +02:00
parent eac2cef4c7
commit b35b053966
3 changed files with 34 additions and 0 deletions

View File

@ -385,6 +385,7 @@ Type=Typ
Unlock=Entsperren Unlock=Entsperren
Unlock connected chest@nif all slots are below 2000=Nachfolgende Kiste entsperren,@nsofern alle Speicherplätze <= 2000 Unlock connected chest@nif all slots are below 2000=Nachfolgende Kiste entsperren,@nsofern alle Speicherplätze <= 2000
Update=Update Update=Update
Use a trowel to remove the node.=Verwende eine Kelle, um den Block zu entfernen.
Usmium Nuggets=Usmium Nuggets Usmium Nuggets=Usmium Nuggets
Usmium Powder=Usmium Pulver Usmium Powder=Usmium Pulver
WLAN Chip=WLAN Chip WLAN Chip=WLAN Chip

View File

@ -383,6 +383,7 @@ Type=
Unlock= Unlock=
Unlock connected chest@nif all slots are below 2000= Unlock connected chest@nif all slots are below 2000=
Update= Update=
Use a trowel to remove the node.=
Usmium Nuggets= Usmium Nuggets=
Usmium Powder= Usmium Powder=
WLAN Chip= WLAN Chip=

View File

@ -116,3 +116,35 @@ minetest.register_craft({
{"", "", "default:stick"}, {"", "", "default:stick"},
}, },
}) })
local function get_new_can_dig(old_can_dig)
return function(pos, player, ...)
if M(pos):get_string("techage_hidden_nodename") ~= "" then
if player and player.get_player_name then
minetest.chat_send_player(player:get_player_name(), S("Use a trowel to remove the node."))
end
return false
end
if old_can_dig then
return old_can_dig(pos, player, ...)
else
return true
end
end
end
-- Change can_dig for already registered nodes.
for _, ndef in pairs(minetest.registered_nodes) do
local old_can_dig = ndef.can_dig
minetest.override_item(ndef.name, {
can_dig = get_new_can_dig(old_can_dig)
})
end
-- Change can_dig for all nodes that are going to be registered in the future.
local old_register_node = minetest.register_node
minetest.register_node = function(name, def)
local old_can_dig = def.can_dig
def.can_dig = get_new_can_dig(old_can_dig)
return old_register_node(name, def)
end