Merge pull request 'Instadig and -kill mobs in (gamemode-)creative mode' (#2646) from creative_digging into master

Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/2646
Reviewed-by: PrairieWind <prairie.astronomer1@gmail.com>
This commit is contained in:
cora 2022-09-13 17:07:46 +00:00
commit 03f5c2908f
2 changed files with 19 additions and 0 deletions

@ -3148,6 +3148,10 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
return
end
if minetest.is_creative_enabled(hitter:get_player_name()) then
self.health = 0
end
-- set/update 'drop xp' timestamp if hitted by player
self.xp_timestamp = minetest.get_us_time()
end

@ -196,6 +196,7 @@ local mt_is_creative_enabled = minetest.is_creative_enabled
function minetest.is_creative_enabled(name)
if mt_is_creative_enabled(name) then return true end
if not name then return false end
local p = minetest.get_player_by_name(name)
if p then
return p:get_meta():get_string("gamemode") == "creative"
@ -203,6 +204,20 @@ function minetest.is_creative_enabled(name)
return false
end
--Insta "digging" nodes in gamemode-creative
minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
if minetest.is_creative_enabled() then return end
local name = puncher:get_player_name()
if not minetest.is_creative_enabled(name) then return end
if pointed_thing.type ~= "node" then return end
local def = minetest.registered_nodes[node.name]
if def then
if def.on_destruct then def.on_destruct(pos) end
minetest.remove_node(pos)
return true
end
end)
local function in_table(n,h)
for k,v in pairs(h) do
if v == n then return true end