Replace wrong along_shore node identifier
[minetest_hades/hades_revisited.git] / mods / creative / init.lua
blobd5bec84f651695ba0c439fae0d808c959d9ecc88
1 local S = minetest.get_translator("creative")
3 creative = {}
5 minetest.register_privilege("creative", {
6 description = S("Allow player to use creative inventory"),
7 give_to_singleplayer = false,
8 give_to_admin = false,
9 on_grant = function(name)
10 minetest.after(0, function(name)
11 local player = minetest.get_player_by_name(name)
12 if player then
13 sfinv.set_player_inventory_formspec(player)
14 end
15 end, name)
16 end,
17 on_revoke = function(name)
18 minetest.after(0, function(name)
19 local player = minetest.get_player_by_name(name)
20 if not player then
21 return
22 end
23 sfinv.set_player_inventory_formspec(player)
24 sfinv.set_page(player, sfinv.get_homepage_name(player))
25 end, name)
26 end,
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})
34 end
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
41 -- leveldiff and 1.
42 -- To speed up digging in creative, hand 'maxlevel' and 'digtime' have been
43 -- increased such that nodes of differing levels have an insignificant
44 -- effect on digtime.
45 local digtime = 42
46 local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 256}
48 minetest.register_item(":", {
49 type = "none",
50 wield_image = "wieldhand.png",
51 wield_scale = {x = 1, y = 1, z = 2.5},
52 range = 10,
53 tool_capabilities = {
54 full_punch_interval = 0.5,
55 max_drop_level = 3,
56 groupcaps = {
57 crumbly = caps,
58 cracky = caps,
59 snappy = caps,
60 choppy = caps,
61 oddly_breakable_by_hand = caps,
63 damage_groups = {fleshy = 10},
66 end
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())
72 end
73 end)
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)
81 end
82 local inv = digger:get_inventory()
83 if inv then
84 for _, item in ipairs(drops) do
85 if not inv:contains_item("main", item, true) then
86 inv:add_item("main", item)
87 end
88 end
89 end
90 end