mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-23 07:10:19 +01:00
Creative: Add creative.is_enabled_for
This commit is contained in:
parent
ae426878d4
commit
bee5b316a8
@ -78,6 +78,12 @@ For example,
|
|||||||
is used to show all tools. Name is used in the sfinv page name, title is the
|
is used to show all tools. Name is used in the sfinv page name, title is the
|
||||||
human readable title.
|
human readable title.
|
||||||
|
|
||||||
|
`is_enabled_for` is used to check whether a player is in creative mode:
|
||||||
|
|
||||||
|
creative.is_enabled_for(name)
|
||||||
|
|
||||||
|
Override this to allow per-player game modes.
|
||||||
|
|
||||||
The contents of `creative.formspec_add` is appended to every creative inventory
|
The contents of `creative.formspec_add` is appended to every creative inventory
|
||||||
page. Mods can use it to add additional formspec elements onto the default
|
page. Mods can use it to add additional formspec elements onto the default
|
||||||
creative inventory formspec to be drawn after each update.
|
creative inventory formspec to be drawn after each update.
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
creative = {}
|
||||||
|
|
||||||
|
function creative.is_enabled_for(name)
|
||||||
|
return minetest.setting_getbool("creative_mode")
|
||||||
|
end
|
||||||
|
|
||||||
dofile(minetest.get_modpath("creative") .. "/inventory.lua")
|
dofile(minetest.get_modpath("creative") .. "/inventory.lua")
|
||||||
|
|
||||||
if minetest.setting_getbool("creative_mode") then
|
if minetest.setting_getbool("creative_mode") then
|
||||||
@ -28,22 +34,25 @@ if minetest.setting_getbool("creative_mode") then
|
|||||||
damage_groups = {fleshy = 10},
|
damage_groups = {fleshy = 10},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
-- Unlimited node placement
|
||||||
return true
|
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
||||||
end)
|
return creative.is_enabled_for(placer:get_player_name())
|
||||||
|
end)
|
||||||
|
|
||||||
function minetest.handle_node_drops(pos, drops, digger)
|
-- Don't pick up if the item is already in the inventory
|
||||||
if not digger or not digger:is_player() then
|
function minetest.handle_node_drops(pos, drops, digger)
|
||||||
return
|
if not digger or not digger:is_player() or
|
||||||
end
|
not creative.is_enabled_for(digger:get_player_name()) then
|
||||||
local inv = digger:get_inventory()
|
return
|
||||||
if inv then
|
end
|
||||||
for _, item in ipairs(drops) do
|
local inv = digger:get_inventory()
|
||||||
item = ItemStack(item):get_name()
|
if inv then
|
||||||
if not inv:contains_item("main", item) then
|
for _, item in ipairs(drops) do
|
||||||
inv:add_item("main", item)
|
item = ItemStack(item):get_name()
|
||||||
end
|
if not inv:contains_item("main", item) then
|
||||||
|
inv:add_item("main", item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
creative = {}
|
|
||||||
local player_inventory = {}
|
local player_inventory = {}
|
||||||
|
|
||||||
function creative.init_creative_inventory(player)
|
function creative.init_creative_inventory(player)
|
||||||
@ -79,7 +78,7 @@ function creative.register_tab(name, title, items)
|
|||||||
sfinv.register_page("creative:" .. name, {
|
sfinv.register_page("creative:" .. name, {
|
||||||
title = title,
|
title = title,
|
||||||
is_in_nav = function(self, player, context)
|
is_in_nav = function(self, player, context)
|
||||||
return minetest.setting_getbool("creative_mode")
|
return creative.is_enabled_for(player:get_player_name())
|
||||||
end,
|
end,
|
||||||
get = function(self, player, context)
|
get = function(self, player, context)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
@ -172,7 +171,7 @@ creative.register_tab("craftitems", "Items", minetest.registered_craftitems)
|
|||||||
|
|
||||||
local old_homepage_name = sfinv.get_homepage_name
|
local old_homepage_name = sfinv.get_homepage_name
|
||||||
function sfinv.get_homepage_name(player)
|
function sfinv.get_homepage_name(player)
|
||||||
if minetest.setting_getbool("creative_mode") then
|
if creative.is_enabled_for(player:get_player_name()) then
|
||||||
return "creative:all"
|
return "creative:all"
|
||||||
else
|
else
|
||||||
return old_homepage_name(player)
|
return old_homepage_name(player)
|
||||||
|
Loading…
Reference in New Issue
Block a user