2023-06-11 06:09:30 -04:00
|
|
|
-- creative/init.lua
|
|
|
|
|
|
|
|
-- Load support for MT game translation.
|
|
|
|
local S
|
|
|
|
|
|
|
|
if minetest.get_translator ~= nil then
|
|
|
|
S = minetest.get_translator("creative") -- 5.x translation function
|
|
|
|
else
|
|
|
|
if minetest.get_modpath("intllib") then
|
|
|
|
dofile(minetest.get_modpath("intllib") .. "/init.lua")
|
|
|
|
if intllib.make_gettext_pair then
|
|
|
|
S = intllib.make_gettext_pair() -- new gettext method
|
|
|
|
else
|
|
|
|
S = intllib.Getter() -- old text file method
|
|
|
|
end
|
|
|
|
else -- boilerplate function
|
|
|
|
S = function(str, ...)
|
|
|
|
local args = {...}
|
|
|
|
return str:gsub("@%d+", function(match)
|
|
|
|
return args[tonumber(match:sub(2))]
|
|
|
|
end)
|
upgrade beds,boats,bucket,carts,creative,doors,farming,fire,stairs,tnt,wool
* beds https://codeberg.org/minenux/minetest-mod-beds/commit/7b6fae96d5e273dad9a373e63eb958145c9bfbef
* boats https://codeberg.org/minenux/minetest-mod-boats/commit/3832de08f705d5d2e7b5a971760e5fad1653305f
* bucket https://codeberg.org/minenux/minetest-mod-bucket/commit/1d9f32295aba3ef2a86be302050f34c1766e93d5
* carts https://codeberg.org/minenux/minetest-mod-carts/commit/dcbca916cffdcec281f0129ef350db2686bda933
* creative https://codeberg.org/minenux/minetest-mod-creative/commit/ca09e773701f834fec7de18bf13598b3323778db
* doors https://codeberg.org/minenux/minetest-mod-doors/commit/a89ab0454deb4933b6e4971c57055c40b7938e5b
* farming https://codeberg.org/minenux/minetest-mod-farming/commit/00e4b3cb89d3c1b1d66b6af4821191c1d667e1bc
* fire https://codeberg.org/minenux/minetest-mod-fire/commit/4e5f7ad55314bd9b126fb133cfc5a32fa58b20d2
* stairs https://codeberg.org/minenux/minetest-mod-stairs/commit/c3a5af6c452daca599d226df694df1b75f15c110
* tnt https://codeberg.org/minenux/minetest-mod-tnt/commit/8195861f905a90b53cd52348deb34df41a053027
* wool https://codeberg.org/minenux/minetest-mod-wool/commit/de642a08e80bfd7a4a1e5629e50458a609dbda3a
2022-03-09 12:47:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-16 00:38:15 -04:00
|
|
|
local is_50 = minetest.has_feature("object_use_texture_alpha")
|
2023-06-11 06:09:30 -04:00
|
|
|
local is_53 = minetest.has_feature("object_step_has_moveresult")
|
|
|
|
local is_54 = minetest.has_feature("direct_velocity_on_players")
|
upgrade beds,boats,bucket,carts,creative,doors,farming,fire,stairs,tnt,wool
* beds https://codeberg.org/minenux/minetest-mod-beds/commit/7b6fae96d5e273dad9a373e63eb958145c9bfbef
* boats https://codeberg.org/minenux/minetest-mod-boats/commit/3832de08f705d5d2e7b5a971760e5fad1653305f
* bucket https://codeberg.org/minenux/minetest-mod-bucket/commit/1d9f32295aba3ef2a86be302050f34c1766e93d5
* carts https://codeberg.org/minenux/minetest-mod-carts/commit/dcbca916cffdcec281f0129ef350db2686bda933
* creative https://codeberg.org/minenux/minetest-mod-creative/commit/ca09e773701f834fec7de18bf13598b3323778db
* doors https://codeberg.org/minenux/minetest-mod-doors/commit/a89ab0454deb4933b6e4971c57055c40b7938e5b
* farming https://codeberg.org/minenux/minetest-mod-farming/commit/00e4b3cb89d3c1b1d66b6af4821191c1d667e1bc
* fire https://codeberg.org/minenux/minetest-mod-fire/commit/4e5f7ad55314bd9b126fb133cfc5a32fa58b20d2
* stairs https://codeberg.org/minenux/minetest-mod-stairs/commit/c3a5af6c452daca599d226df694df1b75f15c110
* tnt https://codeberg.org/minenux/minetest-mod-tnt/commit/8195861f905a90b53cd52348deb34df41a053027
* wool https://codeberg.org/minenux/minetest-mod-wool/commit/de642a08e80bfd7a4a1e5629e50458a609dbda3a
2022-03-09 12:47:54 -04:00
|
|
|
|
2023-06-11 06:09:30 -04:00
|
|
|
creative = {}
|
|
|
|
creative.get_translator = S
|
2023-06-16 00:38:15 -04:00
|
|
|
creative.is_50 = is_50
|
2023-06-11 06:09:30 -04:00
|
|
|
creative.is_53 = is_53
|
|
|
|
creative.is_54 = is_54
|
|
|
|
|
2023-06-16 00:38:15 -04:00
|
|
|
local privs_description = "Allow player to use creative inventory"
|
|
|
|
local privs_definition = {}
|
|
|
|
|
2023-06-11 06:09:30 -04: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)
|
upgrade beds,boats,bucket,carts,creative,doors,farming,fire,stairs,tnt,wool
* beds https://codeberg.org/minenux/minetest-mod-beds/commit/7b6fae96d5e273dad9a373e63eb958145c9bfbef
* boats https://codeberg.org/minenux/minetest-mod-boats/commit/3832de08f705d5d2e7b5a971760e5fad1653305f
* bucket https://codeberg.org/minenux/minetest-mod-bucket/commit/1d9f32295aba3ef2a86be302050f34c1766e93d5
* carts https://codeberg.org/minenux/minetest-mod-carts/commit/dcbca916cffdcec281f0129ef350db2686bda933
* creative https://codeberg.org/minenux/minetest-mod-creative/commit/ca09e773701f834fec7de18bf13598b3323778db
* doors https://codeberg.org/minenux/minetest-mod-doors/commit/a89ab0454deb4933b6e4971c57055c40b7938e5b
* farming https://codeberg.org/minenux/minetest-mod-farming/commit/00e4b3cb89d3c1b1d66b6af4821191c1d667e1bc
* fire https://codeberg.org/minenux/minetest-mod-fire/commit/4e5f7ad55314bd9b126fb133cfc5a32fa58b20d2
* stairs https://codeberg.org/minenux/minetest-mod-stairs/commit/c3a5af6c452daca599d226df694df1b75f15c110
* tnt https://codeberg.org/minenux/minetest-mod-tnt/commit/8195861f905a90b53cd52348deb34df41a053027
* wool https://codeberg.org/minenux/minetest-mod-wool/commit/de642a08e80bfd7a4a1e5629e50458a609dbda3a
2022-03-09 12:47:54 -04:00
|
|
|
end
|
|
|
|
end
|
2023-06-11 06:09:30 -04:00
|
|
|
end)
|
upgrade beds,boats,bucket,carts,creative,doors,farming,fire,stairs,tnt,wool
* beds https://codeberg.org/minenux/minetest-mod-beds/commit/7b6fae96d5e273dad9a373e63eb958145c9bfbef
* boats https://codeberg.org/minenux/minetest-mod-boats/commit/3832de08f705d5d2e7b5a971760e5fad1653305f
* bucket https://codeberg.org/minenux/minetest-mod-bucket/commit/1d9f32295aba3ef2a86be302050f34c1766e93d5
* carts https://codeberg.org/minenux/minetest-mod-carts/commit/dcbca916cffdcec281f0129ef350db2686bda933
* creative https://codeberg.org/minenux/minetest-mod-creative/commit/ca09e773701f834fec7de18bf13598b3323778db
* doors https://codeberg.org/minenux/minetest-mod-doors/commit/a89ab0454deb4933b6e4971c57055c40b7938e5b
* farming https://codeberg.org/minenux/minetest-mod-farming/commit/00e4b3cb89d3c1b1d66b6af4821191c1d667e1bc
* fire https://codeberg.org/minenux/minetest-mod-fire/commit/4e5f7ad55314bd9b126fb133cfc5a32fa58b20d2
* stairs https://codeberg.org/minenux/minetest-mod-stairs/commit/c3a5af6c452daca599d226df694df1b75f15c110
* tnt https://codeberg.org/minenux/minetest-mod-tnt/commit/8195861f905a90b53cd52348deb34df41a053027
* wool https://codeberg.org/minenux/minetest-mod-wool/commit/de642a08e80bfd7a4a1e5629e50458a609dbda3a
2022-03-09 12:47:54 -04:00
|
|
|
end
|
|
|
|
|
2023-06-16 00:38:15 -04:00
|
|
|
if is_50 then
|
|
|
|
privs_definition = {
|
|
|
|
description = privs_description,
|
|
|
|
give_to_singleplayer = false,
|
|
|
|
give_to_admin = false,
|
|
|
|
on_grant = update_sfinv,
|
|
|
|
on_revoke = update_sfinv
|
|
|
|
}
|
|
|
|
else
|
|
|
|
privs_definition = {
|
|
|
|
description = privs_description,
|
|
|
|
give_to_singleplayer = false
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_privilege("creative", privs_definition)
|
upgrade beds,boats,bucket,carts,creative,doors,farming,fire,stairs,tnt,wool
* beds https://codeberg.org/minenux/minetest-mod-beds/commit/7b6fae96d5e273dad9a373e63eb958145c9bfbef
* boats https://codeberg.org/minenux/minetest-mod-boats/commit/3832de08f705d5d2e7b5a971760e5fad1653305f
* bucket https://codeberg.org/minenux/minetest-mod-bucket/commit/1d9f32295aba3ef2a86be302050f34c1766e93d5
* carts https://codeberg.org/minenux/minetest-mod-carts/commit/dcbca916cffdcec281f0129ef350db2686bda933
* creative https://codeberg.org/minenux/minetest-mod-creative/commit/ca09e773701f834fec7de18bf13598b3323778db
* doors https://codeberg.org/minenux/minetest-mod-doors/commit/a89ab0454deb4933b6e4971c57055c40b7938e5b
* farming https://codeberg.org/minenux/minetest-mod-farming/commit/00e4b3cb89d3c1b1d66b6af4821191c1d667e1bc
* fire https://codeberg.org/minenux/minetest-mod-fire/commit/4e5f7ad55314bd9b126fb133cfc5a32fa58b20d2
* stairs https://codeberg.org/minenux/minetest-mod-stairs/commit/c3a5af6c452daca599d226df694df1b75f15c110
* tnt https://codeberg.org/minenux/minetest-mod-tnt/commit/8195861f905a90b53cd52348deb34df41a053027
* wool https://codeberg.org/minenux/minetest-mod-wool/commit/de642a08e80bfd7a4a1e5629e50458a609dbda3a
2022-03-09 12:47:54 -04:00
|
|
|
|
2023-06-11 06:09:30 -04:00
|
|
|
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
upgrade beds,boats,bucket,carts,creative,doors,farming,fire,stairs,tnt,wool
* beds https://codeberg.org/minenux/minetest-mod-beds/commit/7b6fae96d5e273dad9a373e63eb958145c9bfbef
* boats https://codeberg.org/minenux/minetest-mod-boats/commit/3832de08f705d5d2e7b5a971760e5fad1653305f
* bucket https://codeberg.org/minenux/minetest-mod-bucket/commit/1d9f32295aba3ef2a86be302050f34c1766e93d5
* carts https://codeberg.org/minenux/minetest-mod-carts/commit/dcbca916cffdcec281f0129ef350db2686bda933
* creative https://codeberg.org/minenux/minetest-mod-creative/commit/ca09e773701f834fec7de18bf13598b3323778db
* doors https://codeberg.org/minenux/minetest-mod-doors/commit/a89ab0454deb4933b6e4971c57055c40b7938e5b
* farming https://codeberg.org/minenux/minetest-mod-farming/commit/00e4b3cb89d3c1b1d66b6af4821191c1d667e1bc
* fire https://codeberg.org/minenux/minetest-mod-fire/commit/4e5f7ad55314bd9b126fb133cfc5a32fa58b20d2
* stairs https://codeberg.org/minenux/minetest-mod-stairs/commit/c3a5af6c452daca599d226df694df1b75f15c110
* tnt https://codeberg.org/minenux/minetest-mod-tnt/commit/8195861f905a90b53cd52348deb34df41a053027
* wool https://codeberg.org/minenux/minetest-mod-wool/commit/de642a08e80bfd7a4a1e5629e50458a609dbda3a
2022-03-09 12:47:54 -04:00
|
|
|
|
2023-07-13 22:35:30 -04:00
|
|
|
function minetest.is_creative_enabled(name)
|
|
|
|
if name == "" then
|
|
|
|
return creative_mode_cache
|
upgrade beds,boats,bucket,carts,creative,doors,farming,fire,stairs,tnt,wool
* beds https://codeberg.org/minenux/minetest-mod-beds/commit/7b6fae96d5e273dad9a373e63eb958145c9bfbef
* boats https://codeberg.org/minenux/minetest-mod-boats/commit/3832de08f705d5d2e7b5a971760e5fad1653305f
* bucket https://codeberg.org/minenux/minetest-mod-bucket/commit/1d9f32295aba3ef2a86be302050f34c1766e93d5
* carts https://codeberg.org/minenux/minetest-mod-carts/commit/dcbca916cffdcec281f0129ef350db2686bda933
* creative https://codeberg.org/minenux/minetest-mod-creative/commit/ca09e773701f834fec7de18bf13598b3323778db
* doors https://codeberg.org/minenux/minetest-mod-doors/commit/a89ab0454deb4933b6e4971c57055c40b7938e5b
* farming https://codeberg.org/minenux/minetest-mod-farming/commit/00e4b3cb89d3c1b1d66b6af4821191c1d667e1bc
* fire https://codeberg.org/minenux/minetest-mod-fire/commit/4e5f7ad55314bd9b126fb133cfc5a32fa58b20d2
* stairs https://codeberg.org/minenux/minetest-mod-stairs/commit/c3a5af6c452daca599d226df694df1b75f15c110
* tnt https://codeberg.org/minenux/minetest-mod-tnt/commit/8195861f905a90b53cd52348deb34df41a053027
* wool https://codeberg.org/minenux/minetest-mod-wool/commit/de642a08e80bfd7a4a1e5629e50458a609dbda3a
2022-03-09 12:47:54 -04:00
|
|
|
else
|
2023-06-11 06:09:30 -04:00
|
|
|
return minetest.check_player_privs(name, {creative = true}) or creative_mode_cache
|
upgrade beds,boats,bucket,carts,creative,doors,farming,fire,stairs,tnt,wool
* beds https://codeberg.org/minenux/minetest-mod-beds/commit/7b6fae96d5e273dad9a373e63eb958145c9bfbef
* boats https://codeberg.org/minenux/minetest-mod-boats/commit/3832de08f705d5d2e7b5a971760e5fad1653305f
* bucket https://codeberg.org/minenux/minetest-mod-bucket/commit/1d9f32295aba3ef2a86be302050f34c1766e93d5
* carts https://codeberg.org/minenux/minetest-mod-carts/commit/dcbca916cffdcec281f0129ef350db2686bda933
* creative https://codeberg.org/minenux/minetest-mod-creative/commit/ca09e773701f834fec7de18bf13598b3323778db
* doors https://codeberg.org/minenux/minetest-mod-doors/commit/a89ab0454deb4933b6e4971c57055c40b7938e5b
* farming https://codeberg.org/minenux/minetest-mod-farming/commit/00e4b3cb89d3c1b1d66b6af4821191c1d667e1bc
* fire https://codeberg.org/minenux/minetest-mod-fire/commit/4e5f7ad55314bd9b126fb133cfc5a32fa58b20d2
* stairs https://codeberg.org/minenux/minetest-mod-stairs/commit/c3a5af6c452daca599d226df694df1b75f15c110
* tnt https://codeberg.org/minenux/minetest-mod-tnt/commit/8195861f905a90b53cd52348deb34df41a053027
* wool https://codeberg.org/minenux/minetest-mod-wool/commit/de642a08e80bfd7a4a1e5629e50458a609dbda3a
2022-03-09 12:47:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-13 22:35:30 -04:00
|
|
|
-- backguard compatibility
|
|
|
|
function creative.is_creative(name)
|
2023-06-11 06:09:30 -04:00
|
|
|
if name == "" then
|
2023-07-13 22:35:30 -04:00
|
|
|
return creative_mode_cache
|
|
|
|
else
|
|
|
|
return minetest.check_player_privs(name, {creative = true}) or creative_mode_cache
|
2023-06-11 06:09:30 -04:00
|
|
|
end
|
|
|
|
end
|
2013-05-18 16:05:16 +02:00
|
|
|
|
2023-07-13 22:35:30 -04:00
|
|
|
|
2023-06-11 06:09:30 -04:00
|
|
|
-- For backwards compatibility:
|
|
|
|
function creative.is_enabled_for(name)
|
2023-06-16 00:38:15 -04:00
|
|
|
return creative.is_creative(name)
|
2023-06-11 06:09:30 -04:00
|
|
|
end
|
2016-03-17 00:11:44 +01:00
|
|
|
|
2023-06-11 06:09:30 -04:00
|
|
|
dofile(minetest.get_modpath("creative") .. "/inventory.lua")
|
|
|
|
|
|
|
|
if minetest.is_creative_enabled("") then
|
|
|
|
local hand_hack = function()
|
|
|
|
-- 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.
|
2023-06-16 00:38:15 -04:00
|
|
|
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},
|
|
|
|
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,
|
2023-06-11 06:09:30 -04:00
|
|
|
-- dig_immediate group doesn't use value 1. Value 3 is instant dig
|
2023-06-16 00:38:15 -04:00
|
|
|
dig_immediate = {times = {[2] = digtime, [3] = 0}, uses = 0, maxlevel = 256},
|
|
|
|
},
|
|
|
|
damage_groups = {fleshy = 10},
|
|
|
|
}
|
|
|
|
})
|
2023-06-11 06:09:30 -04:00
|
|
|
end
|
|
|
|
if minetest.register_on_mods_loaded then
|
|
|
|
minetest.register_on_mods_loaded(hand_hack)
|
|
|
|
else
|
2023-06-16 00:38:15 -04:00
|
|
|
minetest.after(0.2, hand_hack)
|
2023-06-11 06:09:30 -04:00
|
|
|
end
|
2016-12-30 22:13:27 +00:00
|
|
|
end
|
2015-12-07 11:36:40 +01:00
|
|
|
|
2016-12-30 22:13:27 +00:00
|
|
|
-- Unlimited node placement
|
|
|
|
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
2023-06-16 00:38:15 -04:00
|
|
|
if placer then
|
|
|
|
if placer:is_player() then
|
|
|
|
return creative.is_creative(placer:get_player_name())
|
|
|
|
end
|
2017-10-01 18:32:01 -07:00
|
|
|
end
|
2016-12-30 22:13:27 +00:00
|
|
|
end)
|
2015-12-07 11:36:40 +01:00
|
|
|
|
2023-06-16 00:38:15 -04:00
|
|
|
-- Don't pick up if the item is already in the inventory only in hard creative single
|
|
|
|
if creative_mode_cache then
|
|
|
|
local old_handle_node_drops = minetest.handle_node_drops
|
|
|
|
function minetest.handle_node_drops(pos, drops, digger)
|
|
|
|
if not digger then
|
|
|
|
if not digger:is_player() then
|
|
|
|
if not creative.is_creative(digger:get_player_name()) then
|
|
|
|
return old_handle_node_drops(pos, drops, digger)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local inv = digger:get_inventory()
|
|
|
|
if inv then
|
|
|
|
for _, item in ipairs(drops) do
|
|
|
|
if not inv:contains_item("main", item, true) then
|
|
|
|
inv:add_item("main", item)
|
|
|
|
end
|
2013-05-18 16:05:16 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-06-16 00:38:15 -04:00
|
|
|
|
|
|
|
print("[creative] mod loaded")
|
|
|
|
|