Add minetest.is_creative_enabled
authorWuzzy <Wuzzy2@mail.ru>
Tue, 26 May 2020 00:11:19 +0000 (02:11 +0200)
committersfan5 <sfan5@live.de>
Fri, 29 May 2020 20:45:40 +0000 (22:45 +0200)
builtin/common/misc_helpers.lua
builtin/game/item.lua
builtin/game/misc.lua
doc/lua_api.txt
games/devtest/mods/util_commands/init.lua

index 1a0c71efd348b2766ec46cf8177fa3a2de66be66..a88adf96de5a2f4d6a21a4b4c5d10ad89877e218 100644 (file)
@@ -345,18 +345,12 @@ if INIT == "game" then
 --Wrapper for rotate_and_place() to check for sneak and assume Creative mode
 --implies infinite stacks when performing a 6d rotation.
 --------------------------------------------------------------------------------
-       local creative_mode_cache = core.settings:get_bool("creative_mode")
-       local function is_creative(name)
-               return creative_mode_cache or
-                               core.check_player_privs(name, {creative = true})
-       end
-
        core.rotate_node = function(itemstack, placer, pointed_thing)
                local name = placer and placer:get_player_name() or ""
                local invert_wall = placer and placer:get_player_control().sneak or false
                return core.rotate_and_place(itemstack, placer, pointed_thing,
-                               is_creative(name),
-                               {invert_wall = invert_wall}, true)
+                       core.is_creative_enabled(name),
+                       {invert_wall = invert_wall}, true)
        end
 end
 
index 3aaa71ef23a47cc32a6223061e90bd8dcd36feea..f680ce0d4bd9eb1e13be985665ffb709d670b122 100644 (file)
@@ -582,7 +582,7 @@ function core.node_dig(pos, node, digger)
                        wielded = wdef.after_use(wielded, digger, node, dp) or wielded
                else
                        -- Wear out tool
-                       if not core.settings:get_bool("creative_mode") then
+                       if not core.is_creative_enabled(diggername) then
                                wielded:add_wear(dp.wear)
                                if wielded:get_count() == 0 and wdef.sound and wdef.sound.breaks then
                                        core.sound_play(wdef.sound.breaks, {
index 0ed11ada024e41fb4ea940f8005d49ea2630f495..341e613c255add613bb43fd551937da764428ba4 100644 (file)
@@ -164,6 +164,12 @@ function core.record_protection_violation(pos, name)
        end
 end
 
+-- To be overridden by Creative mods
+
+local creative_mode_cache = core.settings:get_bool("creative_mode")
+function core.is_creative_enabled(name)
+       return creative_mode_cache
+end
 
 -- Checks if specified volume intersects a protected volume
 
index c4310aa5b57a34372fd37fbcae588022783a848c..bb9df53734696ba3a8aeeab1b036f02a1520b995 100644 (file)
@@ -5475,6 +5475,13 @@ Misc.
 * `minetest.record_protection_violation(pos, name)`
     * This function calls functions registered with
       `minetest.register_on_protection_violation`.
+* `minetest.is_creative_enabled(name)`: returns boolean
+    * Returning `true` means that Creative Mode is enabled for player `name`.
+    * `name` will be `""` for non-players or if the player is unknown.
+    * This function should be overridden by Creative Mode-related mods to
+      implement a per-player Creative Mode.
+    * By default, this function returns `true` if the setting
+      `creative_mode` is `true` and `false` otherwise.
 * `minetest.is_area_protected(pos1, pos2, player_name, interval)`
     * Returns the position of the first node that `player_name` may not modify
       in the specified cuboid between `pos1` and `pos2`.
index ad8d3f9baa4a488acd9ffc349416c35f91fcf454..3a0e91a410a1575574ba62d0530882b647270829 100644 (file)
@@ -66,7 +66,7 @@ if s_infplace == "true" then
 elseif s_infplace == "false" then
        infplace = false
 else
-       infplace = minetest.settings:get_bool("creative_mode", false)
+       infplace = minetest.is_creative_enabled("")
 end
 
 minetest.register_chatcommand("infplace", {