2019-09-10 19:09:51 +02:00
|
|
|
-- creative/init.lua
|
|
|
|
|
|
|
|
-- Load support for MT game translation.
|
|
|
|
local S = minetest.get_translator("creative")
|
|
|
|
|
2016-12-30 23:13:27 +01:00
|
|
|
creative = {}
|
2019-09-10 19:09:51 +02:00
|
|
|
creative.get_translator = S
|
2016-12-30 23:13:27 +01:00
|
|
|
|
2019-02-03 12:45:45 +01:00
|
|
|
local function update_sfinv(name)
|
|
|
|
minetest.after(0, function()
|
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
if player then
|
|
|
|
if sfinv.get_page(player):sub(1, 9) == "creative:" then
|
|
|
|
sfinv.set_page(player, sfinv.get_homepage_name(player))
|
|
|
|
else
|
|
|
|
sfinv.set_player_inventory_formspec(player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2017-02-01 20:07:30 +01:00
|
|
|
minetest.register_privilege("creative", {
|
2019-09-10 19:09:51 +02:00
|
|
|
description = S("Allow player to use creative inventory"),
|
2017-09-29 21:59:11 +02:00
|
|
|
give_to_singleplayer = false,
|
2019-02-03 12:45:45 +01:00
|
|
|
give_to_admin = false,
|
|
|
|
on_grant = update_sfinv,
|
|
|
|
on_revoke = update_sfinv,
|
2017-02-01 20:07:30 +01:00
|
|
|
})
|
|
|
|
|
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)
|
2017-02-01 20:07:30 +01:00
|
|
|
return creative_mode_cache or
|
|
|
|
minetest.check_player_privs(name, {creative = true})
|
2016-12-30 23:13:27 +01:00
|
|
|
end
|
|
|
|
|
2016-07-04 20:19:39 +02:00
|
|
|
dofile(minetest.get_modpath("creative") .. "/inventory.lua")
|
2013-05-18 16:05:16 +02:00
|
|
|
|
2017-03-29 21:02:26 +02:00
|
|
|
if creative_mode_cache then
|
2016-11-28 00:52:28 +01:00
|
|
|
-- 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}
|
2016-03-17 00:11:44 +01:00
|
|
|
|
2019-08-31 20:44:17 +02:00
|
|
|
-- Override the hand tool
|
|
|
|
minetest.override_item("", {
|
2013-08-06 15:39:22 +02:00
|
|
|
range = 10,
|
2013-05-18 16:05:16 +02:00
|
|
|
tool_capabilities = {
|
|
|
|
full_punch_interval = 0.5,
|
|
|
|
max_drop_level = 3,
|
|
|
|
groupcaps = {
|
2016-03-17 00:11:44 +01:00
|
|
|
crumbly = caps,
|
|
|
|
cracky = caps,
|
|
|
|
snappy = caps,
|
|
|
|
choppy = caps,
|
|
|
|
oddly_breakable_by_hand = caps,
|
2019-08-03 21:51:58 +02:00
|
|
|
-- dig_immediate group doesn't use value 1. Value 3 is instant dig
|
|
|
|
dig_immediate =
|
|
|
|
{times = {[2] = digtime, [3] = 0}, uses = 0, maxlevel = 256},
|
2013-05-18 16:05:16 +02:00
|
|
|
},
|
|
|
|
damage_groups = {fleshy = 10},
|
|
|
|
}
|
|
|
|
})
|
2016-12-30 23:13:27 +01:00
|
|
|
end
|
2015-12-07 11:36:40 +01:00
|
|
|
|
2016-12-30 23:13:27 +01:00
|
|
|
-- Unlimited node placement
|
|
|
|
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
2017-10-02 03:32:01 +02:00
|
|
|
if placer and placer:is_player() then
|
|
|
|
return creative.is_enabled_for(placer:get_player_name())
|
|
|
|
end
|
2016-12-30 23:13:27 +01:00
|
|
|
end)
|
2015-12-07 11:36:40 +01:00
|
|
|
|
2016-12-30 23:13:27 +01:00
|
|
|
-- Don't pick up if the item is already in the inventory
|
2017-01-27 20:48:27 +01:00
|
|
|
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)
|
2017-10-02 03:20:50 +02:00
|
|
|
if not digger or not digger:is_player() or
|
|
|
|
not creative.is_enabled_for(digger:get_player_name()) then
|
2017-01-27 20:48:27 +01:00
|
|
|
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
|
2017-04-22 14:34:51 +02:00
|
|
|
if not inv:contains_item("main", item, true) then
|
2016-12-30 23:13:27 +01:00
|
|
|
inv:add_item("main", item)
|
2013-05-18 16:05:16 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|