1 local S
= minetest
.get_translator("creative")
5 minetest
.register_privilege("creative", {
6 description
= S("Allow player to use creative inventory"),
7 give_to_singleplayer
= false,
9 on_grant
= function(name
)
10 minetest
.after(0, function(name
)
11 local player
= minetest
.get_player_by_name(name
)
13 sfinv
.set_player_inventory_formspec(player
)
17 on_revoke
= function(name
)
18 minetest
.after(0, function(name
)
19 local player
= minetest
.get_player_by_name(name
)
23 sfinv
.set_player_inventory_formspec(player
)
24 sfinv
.set_page(player
, sfinv
.get_homepage_name(player
))
29 local creative_mode_cache
= minetest
.settings
:get_bool("creative_mode")
31 function minetest
.is_creative_enabled(name
)
32 return creative_mode_cache
or
33 minetest
.check_player_privs(name
, {creative
= true})
36 dofile(minetest
.get_modpath("creative") .. "/inventory.lua")
38 if creative_mode_cache
then
39 -- Dig time is modified according to difference (leveldiff) between tool
40 -- 'maxlevel' and node 'level'. Digtime is divided by the larger of
42 -- To speed up digging in creative, hand 'maxlevel' and 'digtime' have been
43 -- increased such that nodes of differing levels have an insignificant
46 local caps
= {times
= {digtime
, digtime
, digtime
}, uses
= 0, maxlevel
= 256}
48 minetest
.register_item(":", {
50 wield_image
= "wieldhand.png",
51 wield_scale
= {x
= 1, y
= 1, z
= 2.5},
54 full_punch_interval
= 0.5,
61 oddly_breakable_by_hand
= caps
,
63 damage_groups
= {fleshy
= 10},
68 -- Unlimited node placement
69 minetest
.register_on_placenode(function(pos
, newnode
, placer
, oldnode
, itemstack
)
70 if placer
and placer
:is_player() then
71 return minetest
.is_creative_enabled(placer
:get_player_name())
75 -- Don't pick up if the item is already in the inventory
76 local old_handle_node_drops
= minetest
.handle_node_drops
77 function minetest
.handle_node_drops(pos
, drops
, digger
)
78 if not digger
or not digger
:is_player() or
79 not minetest
.is_creative_enabled(digger
:get_player_name()) then
80 return old_handle_node_drops(pos
, drops
, digger
)
82 local inv
= digger
:get_inventory()
84 for _
, item
in ipairs(drops
) do
85 if not inv
:contains_item("main", item
, true) then
86 inv
:add_item("main", item
)