Use creative.is_enabled_for for creative mode if possible (#1558)

This commit is contained in:
zaoqi 2017-03-29 21:02:26 +02:00 committed by SmallJoker
parent b847888cb7
commit 077316b4cd
13 changed files with 34 additions and 19 deletions

View File

@ -89,7 +89,8 @@ function beds.register_bed(name, def)
minetest.set_node(pos, {name = name .. "_bottom", param2 = dir}) minetest.set_node(pos, {name = name .. "_bottom", param2 = dir})
minetest.set_node(botpos, {name = name .. "_top", 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() itemstack:take_item()
end end
return itemstack return itemstack

View File

@ -110,7 +110,8 @@ function boat.on_punch(self, puncher)
if not self.driver then if not self.driver then
self.removed = true self.removed = true
local inv = puncher:get_inventory() 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 or not inv:contains_item("main", "boats:boat") then
local leftover = inv:add_item("main", "boats:boat") local leftover = inv:add_item("main", "boats:boat")
-- if no room in inventory add a replacement boat to the world -- 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") boat = minetest.add_entity(pointed_thing.under, "boats:boat")
if boat then if boat then
boat:setyaw(placer:get_look_horizontal()) 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() itemstack:take_item()
end end
end end

View File

@ -167,7 +167,8 @@ minetest.register_on_dieplayer(function(player)
end end
-- return if keep inventory set or in creative mode -- 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 return
end end

View File

@ -92,7 +92,8 @@ function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities,
end end
-- Pick up cart -- Pick up cart
local inv = puncher:get_inventory() 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 or not inv:contains_item("main", "carts:cart") then
local leftover = inv:add_item("main", "carts:cart") local leftover = inv:add_item("main", "carts:cart")
-- If no room in inventory add a replacement cart to the world -- 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}, minetest.sound_play({name = "default_place_node_metal", gain = 0.5},
{pos = pointed_thing.above}) {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() itemstack:take_item()
end end
return itemstack return itemstack

View File

@ -8,7 +8,7 @@ end
dofile(minetest.get_modpath("creative") .. "/inventory.lua") 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 -- Dig time is modified according to difference (leveldiff) between tool
-- 'maxlevel' and node 'level'. Digtime is divided by the larger of -- 'maxlevel' and node 'level'. Digtime is divided by the larger of
-- leveldiff and 1. -- leveldiff and 1.

View 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) player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
-- set GUI -- 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) player:set_inventory_formspec(default.gui_survival_form)
end end
player:hud_set_hotbar_image("gui_hotbar.png") player:hud_set_hotbar_image("gui_hotbar.png")

View File

@ -471,7 +471,8 @@ function default.sapling_on_place(itemstack, placer, pointed_thing,
minetest.log("action", player_name .. " places node " minetest.log("action", player_name .. " places node "
.. sapling_name .. " at " .. minetest.pos_to_string(pos)) .. 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 newnode = {name = sapling_name}
local ndef = minetest.registered_nodes[sapling_name] local ndef = minetest.registered_nodes[sapling_name]
minetest.set_node(pos, newnode) minetest.set_node(pos, newnode)

View File

@ -328,7 +328,7 @@ function doors.register(name, def)
meta:set_string("infotext", "Owned by " .. pn) meta:set_string("infotext", "Owned by " .. pn)
end 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() itemstack:take_item()
end end
@ -576,7 +576,7 @@ function doors.register_trapdoor(name, def)
meta:set_string("owner", pn) meta:set_string("owner", pn)
meta:set_string("infotext", "Owned by "..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 end
def.on_blast = function() end def.on_blast = function() end

View File

@ -57,7 +57,8 @@ farming.hoe_on_use = function(itemstack, user, pointed_thing, uses)
gain = 0.5, 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 -- wear tool
local wdef = itemstack:get_definition() local wdef = itemstack:get_definition()
itemstack:add_wear(65535/(uses-1)) 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 -- add the node and remove 1 item from the itemstack
minetest.add_node(pt.above, {name = plantname, param2 = 1}) minetest.add_node(pt.above, {name = plantname, param2 = 1})
tick(pt.above) 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() itemstack:take_item()
end end
return itemstack return itemstack

View File

@ -85,13 +85,13 @@ minetest.register_tool("fire:flint_and_steel", {
"fire_flint_and_steel", "fire_flint_and_steel",
{pos = sound_pos, gain = 0.5, max_hear_distance = 8} {pos = sound_pos, gain = 0.5, max_hear_distance = 8}
) )
local player_name = user:get_player_name()
if pointed_thing.type == "node" then if pointed_thing.type == "node" then
local node_under = minetest.get_node(pointed_thing.under).name local node_under = minetest.get_node(pointed_thing.under).name
local nodedef = minetest.registered_nodes[node_under] local nodedef = minetest.registered_nodes[node_under]
if not nodedef then if not nodedef then
return return
end end
local player_name = user:get_player_name()
if minetest.is_protected(pointed_thing.under, player_name) then if minetest.is_protected(pointed_thing.under, player_name) then
minetest.chat_send_player(player_name, "This area is protected") minetest.chat_send_player(player_name, "This area is protected")
return return
@ -103,7 +103,8 @@ minetest.register_tool("fire:flint_and_steel", {
minetest.set_node(pointed_thing.above, {name = "fire:basic_flame"}) minetest.set_node(pointed_thing.above, {name = "fire:basic_flame"})
end end
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 -- Wear tool
local wdef = itemstack:get_definition() local wdef = itemstack:get_definition()
itemstack:add_wear(1000) itemstack:add_wear(1000)

View File

@ -289,7 +289,8 @@ minetest.register_node("flowers:waterlily", {
if not minetest.is_protected(pos, player_name) then if not minetest.is_protected(pos, player_name) then
minetest.set_node(pos, {name = "flowers:waterlily", minetest.set_node(pos, {name = "flowers:waterlily",
param2 = math.random(0, 3)}) 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() itemstack:take_item()
end end
else else

View File

@ -128,7 +128,8 @@ screwdriver.handler = function(itemstack, user, pointed_thing, mode, uses)
minetest.check_for_falling(pos) minetest.check_for_falling(pos)
end 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)) itemstack:add_wear(65535 / ((uses or 200) - 1))
end end

View File

@ -150,6 +150,8 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local under = minetest.get_node(pointed_thing.under) local under = minetest.get_node(pointed_thing.under)
local wield_item = itemstack:get_name() 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 if under and wield_item == under.name then
-- place slab using under node orientation -- place slab using under node orientation
@ -171,7 +173,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
return return
end end
minetest.set_node(pointed_thing.under, {name = recipeitem, param2 = p2}) 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() itemstack:take_item()
end end
return itemstack return itemstack
@ -187,7 +189,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
-- else attempt to place node with proper param2 -- else attempt to place node with proper param2
minetest.item_place_node(ItemStack(wield_item), placer, pointed_thing, p2) 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() itemstack:take_item()
end end
return itemstack return itemstack