Use creative.is_enabled_for for creative mode if possible (#1558)
authorzaoqi <zaoqiff@gmail.com>
Wed, 29 Mar 2017 19:02:26 +0000 (21:02 +0200)
committerSmallJoker <mk939@ymail.com>
Wed, 29 Mar 2017 19:02:26 +0000 (21:02 +0200)
13 files changed:
mods/beds/api.lua
mods/boats/init.lua
mods/bones/init.lua
mods/carts/cart_entity.lua
mods/creative/init.lua
mods/default/player.lua
mods/default/trees.lua
mods/doors/init.lua
mods/farming/api.lua
mods/fire/init.lua
mods/flowers/init.lua
mods/screwdriver/init.lua
mods/stairs/init.lua

index daa6d8e2622265ae88defe2573bdabf4a3e9bfca..97dde43dfabe9bc10c408ee8ec6a6dac35816e83 100644 (file)
@@ -89,7 +89,8 @@ function beds.register_bed(name, def)
                        minetest.set_node(pos, {name = name .. "_bottom", param2 = dir})
                        minetest.set_node(botpos, {name = name .. "_top", param2 = dir})
 
-                       if not minetest.setting_getbool("creative_mode") then
+                       if not (creative and creative.is_enabled_for
+                                       and creative.is_enabled_for(placer:get_player_name())) then
                                itemstack:take_item()
                        end
                        return itemstack
index 6e1565d49f5f0cd1a9a083502fad4bd4f1f5362e..4d8f4673db205aff05cd8ace8fdddeb6d050635b 100644 (file)
@@ -110,7 +110,8 @@ function boat.on_punch(self, puncher)
        if not self.driver then
                self.removed = true
                local inv = puncher:get_inventory()
-               if not minetest.setting_getbool("creative_mode")
+               if not (creative and creative.is_enabled_for
+                               and creative.is_enabled_for(puncher:get_player_name()))
                                or not inv:contains_item("main", "boats:boat") then
                        local leftover = inv:add_item("main", "boats:boat")
                        -- if no room in inventory add a replacement boat to the world
@@ -244,7 +245,8 @@ minetest.register_craftitem("boats:boat", {
                boat = minetest.add_entity(pointed_thing.under, "boats:boat")
                if boat then
                        boat:setyaw(placer:get_look_horizontal())
-                       if not minetest.setting_getbool("creative_mode") then
+                       if not (creative and creative.is_enabled_for
+                                       and creative.is_enabled_for(placer:get_player_name())) then
                                itemstack:take_item()
                        end
                end
index 9542cab0945797cb17b2bce85a0d1e119aeeed51..56f5fd04f5e2a1764bc7a727393d45f2af17a6f9 100644 (file)
@@ -167,7 +167,8 @@ minetest.register_on_dieplayer(function(player)
        end
 
        -- return if keep inventory set or in creative mode
-       if bones_mode == "keep" or minetest.setting_getbool("creative_mode") then
+       if bones_mode == "keep" or (creative and creative.is_enabled_for
+                       and creative.is_enabled_for(player:get_player_name())) then
                return
        end
 
index bf0a450d2e90407d2ad6e2a9212a16659b1c9fba..4d44c8730481632f62b2d822bbe067c7d78aeac1 100644 (file)
@@ -92,7 +92,8 @@ function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities,
                end
                -- Pick up cart
                local inv = puncher:get_inventory()
-               if not minetest.setting_getbool("creative_mode")
+               if not (creative and creative.is_enabled_for
++                              and creative.is_enabled_for(puncher:get_player_name()))
                                or not inv:contains_item("main", "carts:cart") then
                        local leftover = inv:add_item("main", "carts:cart")
                        -- If no room in inventory add a replacement cart to the world
@@ -385,7 +386,8 @@ minetest.register_craftitem("carts:cart", {
                minetest.sound_play({name = "default_place_node_metal", gain = 0.5},
                        {pos = pointed_thing.above})
 
-               if not minetest.setting_getbool("creative_mode") then
+               if not (creative and creative.is_enabled_for
+                               and creative.is_enabled_for(placer:get_player_name())) then
                        itemstack:take_item()
                end
                return itemstack
index 7471e603f51af66e13e5ea57ea60707a638417e6..f9047189561c5a07416fe83ff6114c6821795d9b 100644 (file)
@@ -8,7 +8,7 @@ end
 
 dofile(minetest.get_modpath("creative") .. "/inventory.lua")
 
-if minetest.setting_getbool("creative_mode") then
+if creative_mode_cache then
        -- Dig time is modified according to difference (leveldiff) between tool
        -- 'maxlevel' and node 'level'. Digtime is divided by the larger of
        -- leveldiff and 1.
index fd7341f4d5e54e6d59fe7045a58502e96d234461..cd89a24c5c3361d1a4d8b6defee3db4c766b4683 100644 (file)
@@ -96,7 +96,8 @@ minetest.register_on_joinplayer(function(player)
        player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
 
        -- set GUI
-       if not minetest.setting_getbool("creative_mode") then
+       if not (creative and creative.is_enabled_for
+                       and creative.is_enabled_for(player:get_player_name())) then
                player:set_inventory_formspec(default.gui_survival_form)
        end
        player:hud_set_hotbar_image("gui_hotbar.png")
index 3e1bf102254023fa3068487f4a7084d1789f17d5..0b829a7585985a0e59e7a4fec7becdb9b0bbe6d2 100644 (file)
@@ -471,7 +471,8 @@ function default.sapling_on_place(itemstack, placer, pointed_thing,
        minetest.log("action", player_name .. " places node "
                        .. sapling_name .. " at " .. minetest.pos_to_string(pos))
 
-       local take_item = not minetest.setting_getbool("creative_mode")
+       local take_item = not (creative and creative.is_enabled_for
+               and creative.is_enabled_for(player_name))
        local newnode = {name = sapling_name}
        local ndef = minetest.registered_nodes[sapling_name]
        minetest.set_node(pos, newnode)
index 4ab40111931fa186e99bd0779e060f625e830500..8ca26dac700274c6545192c00645aeca6bbcf8fc 100644 (file)
@@ -328,7 +328,7 @@ function doors.register(name, def)
                                meta:set_string("infotext", "Owned by " .. pn)
                        end
 
-                       if not minetest.setting_getbool("creative_mode") then
+                       if not (creative and creative.is_enabled_for and creative.is_enabled_for(pn)) then
                                itemstack:take_item()
                        end
 
@@ -576,7 +576,7 @@ function doors.register_trapdoor(name, def)
                        meta:set_string("owner", pn)
                        meta:set_string("infotext", "Owned by "..pn)
 
-                       return minetest.setting_getbool("creative_mode")
+                       return (creative and creative.is_enabled_for and creative.is_enabled_for(pn))
                end
 
                def.on_blast = function() end
index 0ba756cc756a7ca0451139c3b25cbd1525acc162..35a77e9fcac3d0dc592219c6f441815c117fc22d 100644 (file)
@@ -57,7 +57,8 @@ farming.hoe_on_use = function(itemstack, user, pointed_thing, uses)
                gain = 0.5,
        })
 
-       if not minetest.setting_getbool("creative_mode") then
+       if not (creative and creative.is_enabled_for
+                       and creative.is_enabled_for(user:get_player_name())) then
                -- wear tool
                local wdef = itemstack:get_definition()
                itemstack:add_wear(65535/(uses-1))
@@ -187,7 +188,8 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
        -- add the node and remove 1 item from the itemstack
        minetest.add_node(pt.above, {name = plantname, param2 = 1})
        tick(pt.above)
-       if not minetest.setting_getbool("creative_mode") then
+       if not (creative and creative.is_enabled_for
+                       and creative.is_enabled_for(placer:get_player_name())) then
                itemstack:take_item()
        end
        return itemstack
index a846b2896c731050db371011f21ee29aca9e1c74..a9ceb9ea7dd8bf2f11d5a8e363020dbc1a7f0729 100644 (file)
@@ -85,13 +85,13 @@ minetest.register_tool("fire:flint_and_steel", {
                        "fire_flint_and_steel",
                        {pos = sound_pos, gain = 0.5, max_hear_distance = 8}
                )
+               local player_name = user:get_player_name()
                if pointed_thing.type == "node" then
                        local node_under = minetest.get_node(pointed_thing.under).name
                        local nodedef = minetest.registered_nodes[node_under]
                        if not nodedef then
                                return
                        end
-                       local player_name = user:get_player_name()
                        if minetest.is_protected(pointed_thing.under, player_name) then
                                minetest.chat_send_player(player_name, "This area is protected")
                                return
@@ -103,7 +103,8 @@ minetest.register_tool("fire:flint_and_steel", {
                                minetest.set_node(pointed_thing.above, {name = "fire:basic_flame"})
                        end
                end
-               if not minetest.setting_getbool("creative_mode") then
+               if not (creative and creative.is_enabled_for
+                               and creative.is_enabled_for(player_name)) then
                        -- Wear tool
                        local wdef = itemstack:get_definition()
                        itemstack:add_wear(1000)
index db7a4eb35178956aa0a667f71710894ff0039be7..cb5b21930cb2cfe624fae75f095fcbd9f93677c6 100644 (file)
@@ -289,7 +289,8 @@ minetest.register_node("flowers:waterlily", {
                        if not minetest.is_protected(pos, player_name) then
                                minetest.set_node(pos, {name = "flowers:waterlily",
                                        param2 = math.random(0, 3)})
-                               if not minetest.setting_getbool("creative_mode") then
+                               if not (creative and creative.is_enabled_for
+                                               and creative.is_enabled_for(player_name)) then
                                        itemstack:take_item()
                                end
                        else
index 49544de389e678729d42886552bf8b003db9908b..2a53ae377ffab174d8711915f1e58e047e8f2c54 100644 (file)
@@ -128,7 +128,8 @@ screwdriver.handler = function(itemstack, user, pointed_thing, mode, uses)
                minetest.check_for_falling(pos)
        end
 
-       if not minetest.setting_getbool("creative_mode") then
+       if not (creative and creative.is_enabled_for
+                       and creative.is_enabled_for(user:get_player_name())) then
                itemstack:add_wear(65535 / ((uses or 200) - 1))
        end
 
index 86dadf97e4785a4b4595a794ac7fcac2ccbdc087..1379c8c0cb45d63c5961b75a71c9c5681972da3e 100644 (file)
@@ -150,6 +150,8 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
                on_place = function(itemstack, placer, pointed_thing)
                        local under = minetest.get_node(pointed_thing.under)
                        local wield_item = itemstack:get_name()
+                       local creative_enabled = (creative and creative.is_enabled_for
+                                       and creative.is_enabled_for(placer:get_player_name()))
 
                        if under and wield_item == under.name then
                                -- place slab using under node orientation
@@ -171,7 +173,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
                                                return
                                        end
                                        minetest.set_node(pointed_thing.under, {name = recipeitem, param2 = p2})
-                                       if not minetest.setting_getbool("creative_mode") then
+                                       if not creative_enabled then
                                                itemstack:take_item()
                                        end
                                        return itemstack
@@ -187,7 +189,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
 
                                -- else attempt to place node with proper param2
                                minetest.item_place_node(ItemStack(wield_item), placer, pointed_thing, p2)
-                               if not minetest.setting_getbool("creative_mode") then
+                               if not creative_enabled then
                                        itemstack:take_item()
                                end
                                return itemstack