star_wars/mods/creative/init.lua

70 lines
1.9 KiB
Lua
Raw Normal View History

2016-12-30 23:13:27 +01:00
creative = {}
minetest.register_privilege("creative", {
description = "Allow player to use creative inventory",
give_to_singleplayer = false
})
2017-05-22 15:41:17 +02:00
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
2017-01-31 12:41:50 +01:00
2016-12-30 23:13:27 +01:00
function creative.is_enabled_for(name)
return creative_mode_cache or
minetest.check_player_privs(name, {creative = true})
2016-12-30 23:13:27 +01:00
end
dofile(minetest.get_modpath("creative") .. "/inventory.lua")
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.
-- To speed up digging in creative, hand 'maxlevel' and 'digtime' have been
-- increased such that nodes of differing levels have an insignificant
-- effect on digtime.
local digtime = 42
local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 256}
minetest.register_item(":", {
type = "none",
wield_image = "wieldhand.png",
wield_scale = {x = 1, y = 1, z = 2.5},
2013-08-06 15:39:22 +02:00
range = 10,
tool_capabilities = {
full_punch_interval = 0.5,
max_drop_level = 3,
groupcaps = {
crumbly = caps,
cracky = caps,
snappy = caps,
choppy = caps,
oddly_breakable_by_hand = caps,
},
damage_groups = {fleshy = 10},
}
})
2016-12-30 23:13:27 +01:00
end
2016-12-30 23:13:27 +01:00
-- Unlimited node placement
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
return creative.is_enabled_for(placer:get_player_name())
end)
2016-12-30 23:13:27 +01:00
-- Don't pick up if the item is already in the inventory
local old_handle_node_drops = minetest.handle_node_drops
2016-12-30 23:13:27 +01:00
function minetest.handle_node_drops(pos, drops, digger)
if not digger or not digger:is_player() then
2016-12-30 23:13:27 +01:00
return
end
if not creative.is_enabled_for(digger:get_player_name()) then
return old_handle_node_drops(pos, drops, digger)
end
2016-12-30 23:13:27 +01:00
local inv = digger:get_inventory()
if inv then
for _, item in ipairs(drops) do
if not inv:contains_item("main", item, true) then
2016-12-30 23:13:27 +01:00
inv:add_item("main", item)
end
end
end
end