diff --git a/games/default/files/crafting/README.txt b/games/default/files/crafting/README.txt index 9bad3be9f..523a3a116 100644 --- a/games/default/files/crafting/README.txt +++ b/games/default/files/crafting/README.txt @@ -1,4 +1,4 @@ -multicraft mod "Crafting" +MultiCraft mod "Crafting" ======================= Version: 2.0.1 diff --git a/games/default/files/crafting/init.lua b/games/default/files/crafting/init.lua index 26cafbc24..b0d39fa84 100644 --- a/games/default/files/crafting/init.lua +++ b/games/default/files/crafting/init.lua @@ -8,12 +8,12 @@ local function item_drop(itemstack, dropper, pos) local p = {x=pos.x, y=pos.y+1.2, z=pos.z} p.x = p.x+(math.random(1,3)*0.2) p.z = p.z+(math.random(1,3)*0.2) - local obj = minetest.env:add_item(p, itemstack) + local obj = minetest.env:add_item(p, itemstack) if obj then v.x = v.x*4 v.y = v.y*4 + 2 v.z = v.z*4 - obj:setvelocity(v) + obj:set_velocity(v) end else minetest.add_item(pos, itemstack) @@ -101,7 +101,7 @@ local function set_inventory(player) end end local split_form = "" - split_form = + split_form = "list[detached:split;main;7.99,3.15;1,1;]" form = form .. "list[current_player;main;0,4.5;9,3;9]".. @@ -130,19 +130,16 @@ end) minetest.register_on_joinplayer(function(player) if minetest.setting_getbool("creative_mode") then - minetest.after(0.5,function() + --[[minetest.after(0.5,function() dofile(minetest.get_modpath("crafting").."/creative.lua") crafting.set_creative_formspec(player, 0, 1) return - end) + end)]] else --init inventory set_inventory(player) end - --set hotbar size - --if player.hud_set_hotbar_itemcount then - --minetest.after(0.5, player.hud_set_hotbar_itemcount, player, 8) - --end + --add hotbar images minetest.after(0.5,function() if show_armor then @@ -166,4 +163,4 @@ local split_inv = minetest.create_detached_inventory("split", { return stack:get_count() end, }) -split_inv:set_size("main", 1) \ No newline at end of file +split_inv:set_size("main", 1) diff --git a/games/default/files/creative/README.txt b/games/default/files/creative/README.txt new file mode 100644 index 000000000..82357f30e --- /dev/null +++ b/games/default/files/creative/README.txt @@ -0,0 +1,12 @@ +Minetest Game mod: creative +=========================== +See license.txt for license information. + +Authors of source code +---------------------- +Originally by Perttu Ahola (celeron55) (MIT) +Jean-Patrick G. (kilbith) (MIT) + +Author of media (textures) +-------------------------- +Jean-Patrick G. (kilbith) (CC BY-SA 3.0) diff --git a/games/default/files/creative/depends.txt b/games/default/files/creative/depends.txt new file mode 100644 index 000000000..975e65250 --- /dev/null +++ b/games/default/files/creative/depends.txt @@ -0,0 +1,2 @@ +default +sfinv diff --git a/games/default/files/creative/init.lua b/games/default/files/creative/init.lua index 16d1d1e3b..d7fed607a 100644 --- a/games/default/files/creative/init.lua +++ b/games/default/files/creative/init.lua @@ -1,40 +1,63 @@ -if minetest.setting_getbool("creative_mode") then - local digtime = 1 +creative = {} + +local creative_mode_cache = minetest.settings:get_bool("creative_mode") + +function creative.is_enabled_for(name) + return creative_mode_cache +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 = 96 + local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 256} + minetest.register_item(":", { type = "none", wield_image = "wieldhand.png", - wield_scale = {x = 0.7, y = 2, z = 0.0001}, + wield_scale = {x = 0.7, y = 2, z = 0}, range = 10, tool_capabilities = { full_punch_interval = 0.9, max_drop_level = 3, groupcaps = { - crumbly = {times={[1]=digtime, [2]=digtime, [3]=digtime}, uses=0, maxlevel=3}, - cracky = {times={[1]=digtime, [2]=digtime, [3]=digtime}, uses=0, maxlevel=3}, - snappy = {times={[1]=digtime, [2]=digtime, [3]=digtime}, uses=0, maxlevel=3}, - choppy = {times={[1]=digtime, [2]=digtime, [3]=digtime}, uses=0, maxlevel=3}, - oddly_breakable_by_hand = {times={[1]=digtime, [2]=digtime, [3]=digtime}, uses=0, maxlevel=3}, + crumbly = caps, + cracky = caps, + snappy = caps, + choppy = caps, + oddly_breakable_by_hand = caps, }, damage_groups = {fleshy = 5}, } }) +end - minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) - return true - end) +-- Unlimited node placement +minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) + if placer and placer:is_player() then + return creative.is_enabled_for(placer:get_player_name()) + end +end) - function minetest.handle_node_drops(pos, drops, digger) - if not digger or not digger:is_player() then - return - end - local inv = digger:get_inventory() - if inv then - for _, item in ipairs(drops) do - item = ItemStack(item):get_name() - if not inv:contains_item("main", item) then - inv:add_item("main", item) - end +-- Don't pick up if the item is already in the inventory +local old_handle_node_drops = minetest.handle_node_drops +function minetest.handle_node_drops(pos, drops, digger) + if not digger or not digger:is_player() or + not creative.is_enabled_for(digger:get_player_name()) then + return old_handle_node_drops(pos, drops, digger) + 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 end end -end \ No newline at end of file +end diff --git a/games/default/files/creative/inventory.lua b/games/default/files/creative/inventory.lua new file mode 100644 index 000000000..2b0d4ead5 --- /dev/null +++ b/games/default/files/creative/inventory.lua @@ -0,0 +1,193 @@ +local player_inventory = {} +local inventory_cache = {} + +local function init_creative_cache(items) + inventory_cache[items] = {} + local i_cache = inventory_cache[items] + + for name, def in pairs(items) do + if def.groups.not_in_creative_inventory ~= 1 and + def.description and def.description ~= "" then + i_cache[name] = def + end + end + table.sort(i_cache) + return i_cache +end + +function creative.init_creative_inventory(player) + local player_name = player:get_player_name() + player_inventory[player_name] = { + size = 0, + filter = "", + start_i = 0 + } + + minetest.create_detached_inventory("creative_" .. player_name, { + allow_move = function(inv, from_list, from_index, to_list, to_index, count, player2) + local name = player2 and player2:get_player_name() or "" + if not creative.is_enabled_for(name) or + to_list == "main" then + return 0 + end + return count + end, + allow_put = function(inv, listname, index, stack, player2) + return 0 + end, + allow_take = function(inv, listname, index, stack, player2) + local name = player2 and player2:get_player_name() or "" + if not creative.is_enabled_for(name) then + return 0 + end + return -1 + end, + on_move = function(inv, from_list, from_index, to_list, to_index, count, player2) + end, + on_take = function(inv, listname, index, stack, player2) + if stack and stack:get_count() > 0 then + minetest.log("action", player_name .. " takes " .. stack:get_name().. " from creative inventory") + end + end, + }, player_name) + + return player_inventory[player_name] +end + +function creative.update_creative_inventory(player_name, tab_content) + local creative_list = {} + local inv = player_inventory[player_name] or + creative.init_creative_inventory(minetest.get_player_by_name(player_name)) + local player_inv = minetest.get_inventory({type = "detached", name = "creative_" .. player_name}) + + local items = inventory_cache[tab_content] or init_creative_cache(tab_content) + + for name, def in pairs(items) do + if def.name:find(inv.filter, 1, true) or + def.description:lower():find(inv.filter, 1, true) then + creative_list[#creative_list+1] = name + end + end + + table.sort(creative_list) + player_inv:set_size("main", #creative_list) + player_inv:set_list("main", creative_list) + inv.size = #creative_list +end + +-- Create the trash field +local trash = minetest.create_detached_inventory("creative_trash", { + -- Allow the stack to be placed and remove it in on_put() + -- This allows the creative inventory to restore the stack + allow_put = function(inv, listname, index, stack, player) + return stack:get_count() + end, + on_put = function(inv, listname) + inv:set_list(listname, {}) + end, +}) +trash:set_size("main", 1) + +creative.formspec_add = "" + +function creative.register_tab(name, title, items) + sfinv.register_page("creative:" .. name, { + title = title, + is_in_nav = function(self, player, context) + return creative.is_enabled_for(player:get_player_name()) + end, + get = function(self, player, context) + local player_name = player:get_player_name() + creative.update_creative_inventory(player_name, items) + local inv = player_inventory[player_name] + local start_i = inv.start_i or 0 + local pagenum = math.floor(start_i / (3*8) + 1) + local pagemax = math.ceil(inv.size / (3*8)) + return sfinv.make_formspec(player, context, + "label[6.2,3.35;" .. minetest.colorize("#FFFF00", tostring(pagenum)) .. " / " .. tostring(pagemax) .. "]" .. + [[ + image[4.06,3.4;0.8,0.8;creative_trash_icon.png] + listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF] + list[current_player;main;0,4.7;8,1;] + list[current_player;main;0,5.85;8,3;8] + list[detached:creative_trash;main;4,3.3;1,1;] + listring[] + button[5.4,3.2;0.8,0.9;creative_prev;<] + button[7.25,3.2;0.8,0.9;creative_next;>] + button[2.1,3.4;0.8,0.5;creative_search;?] + button[2.75,3.4;0.8,0.5;creative_clear;X] + tooltip[creative_search;Search] + tooltip[creative_clear;Reset] + tooltip[creative_prev;Previous page] + tooltip[creative_next;Next page] + listring[current_player;main] + field_close_on_enter[creative_filter;false] + ]] .. + "field[0.3,3.5;2.2,1;creative_filter;;" .. minetest.formspec_escape(inv.filter) .. "]" .. + "listring[detached:creative_" .. player_name .. ";main]" .. + "list[detached:creative_" .. player_name .. ";main;0,0;8,3;" .. tostring(start_i) .. "]" .. +-- default.get_hotbar_bg(0,4.7) .. +-- default.gui_bg .. default.gui_bg_img .. default.gui_slots .. + creative.formspec_add, false) + end, + on_enter = function(self, player, context) + local player_name = player:get_player_name() + local inv = player_inventory[player_name] + if inv then + inv.start_i = 0 + end + end, + on_player_receive_fields = function(self, player, context, fields) + local player_name = player:get_player_name() + local inv = player_inventory[player_name] + assert(inv) + + if fields.creative_clear then + inv.start_i = 0 + inv.filter = "" + creative.update_creative_inventory(player_name, items) + sfinv.set_player_inventory_formspec(player, context) + elseif fields.creative_search or + fields.key_enter_field == "creative_filter" then + inv.start_i = 0 + inv.filter = fields.creative_filter:lower() + creative.update_creative_inventory(player_name, items) + sfinv.set_player_inventory_formspec(player, context) + elseif not fields.quit then + local start_i = inv.start_i or 0 + + if fields.creative_prev then + start_i = start_i - 3*8 + if start_i < 0 then + start_i = inv.size - (inv.size % (3*8)) + if inv.size == start_i then + start_i = math.max(0, inv.size - (3*8)) + end + end + elseif fields.creative_next then + start_i = start_i + 3*8 + if start_i >= inv.size then + start_i = 0 + end + end + + inv.start_i = start_i + sfinv.set_player_inventory_formspec(player, context) + end + end + }) +end + +creative.register_tab("all", "All", minetest.registered_items) +creative.register_tab("nodes", "Nodes", minetest.registered_nodes) +creative.register_tab("tools", "Tools", minetest.registered_tools) +creative.register_tab("craftitems", "Items", minetest.registered_craftitems) + +local old_homepage_name = sfinv.get_homepage_name +function sfinv.get_homepage_name(player) + if creative.is_enabled_for(player:get_player_name()) then + return "creative:all" + else + return old_homepage_name(player) + end +end diff --git a/games/default/files/creative/license.txt b/games/default/files/creative/license.txt new file mode 100644 index 000000000..4ad1d5ffd --- /dev/null +++ b/games/default/files/creative/license.txt @@ -0,0 +1,60 @@ +License of source code +---------------------- + +The MIT License (MIT) +Copyright (C) 2012-2016 Perttu Ahola (celeron55) +Copyright (C) 2015-2016 Jean-Patrick G. (kilbith) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, and to permit +persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +For more details: +https://opensource.org/licenses/MIT + + +Licenses of media (textures) +---------------------------- + +Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) +Copyright (C) 2016 Jean-Patrick G. (kilbith) + +You are free to: +Share — copy and redistribute the material in any medium or format. +Adapt — remix, transform, and build upon the material for any purpose, even commercially. +The licensor cannot revoke these freedoms as long as you follow the license terms. + +Under the following terms: + +Attribution — You must give appropriate credit, provide a link to the license, and +indicate if changes were made. You may do so in any reasonable manner, but not in any way +that suggests the licensor endorses you or your use. + +ShareAlike — If you remix, transform, or build upon the material, you must distribute +your contributions under the same license as the original. + +No additional restrictions — You may not apply legal terms or technological measures that +legally restrict others from doing anything the license permits. + +Notices: + +You do not have to comply with the license for elements of the material in the public +domain or where your use is permitted by an applicable exception or limitation. +No warranties are given. The license may not give you all of the permissions necessary +for your intended use. For example, other rights such as publicity, privacy, or moral +rights may limit how you use the material. + +For more details: +http://creativecommons.org/licenses/by-sa/3.0/ diff --git a/games/default/files/creative/textures/creative_trash_icon.png b/games/default/files/creative/textures/creative_trash_icon.png new file mode 100644 index 000000000..e789ad634 Binary files /dev/null and b/games/default/files/creative/textures/creative_trash_icon.png differ diff --git a/games/default/files/default/init.lua b/games/default/files/default/init.lua index d346f4a55..bc1ab9eb8 100644 --- a/games/default/files/default/init.lua +++ b/games/default/files/default/init.lua @@ -25,4 +25,9 @@ minetest.register_on_newplayer(function (player) player:get_inventory():add_item('main', 'default:sword_steel') player:get_inventory():add_item('main', 'default:torch 8') player:get_inventory():add_item('main', 'default:wood 64') -end) \ No newline at end of file +end) + +-- GUI related stuff +default.gui_bg = "bgcolor[#080808BB;true]" +default.gui_bg_img = "background[5,5;1,1;gui_formbg.png;true]" +default.gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]" diff --git a/games/default/files/railcart/init.lua b/games/default/files/railcart/init.lua index a18b5a08c..9abd62424 100644 --- a/games/default/files/railcart/init.lua +++ b/games/default/files/railcart/init.lua @@ -117,7 +117,7 @@ railcart:register_entity("railcart:cart_entity", { "list[current_player;main;0,6.08;8,3;8]".. "listring[detached:railcart_"..cart.id..";main]".. "listring[current_player;main]".. - default.get_hotbar_bg(0,4.85) + --default.get_hotbar_bg(0,4.85) minetest.show_formspec(name, "inventory", formspec) end return diff --git a/games/default/files/sfinv/README.md b/games/default/files/sfinv/README.md new file mode 100644 index 000000000..6ff33923f --- /dev/null +++ b/games/default/files/sfinv/README.md @@ -0,0 +1,21 @@ +Simple Fast Inventory +==================== + +![SFINV Screeny](https://cdn.pbrd.co/images/1yQhd1TI.png) + +A cleaner, simpler, solution to having an advanced inventory in Minetest. + +Written by rubenwardy. +License: MIT + +See game_api.txt for this mod's API + +License of source code and media files: +--------------------------------------- +Copyright (C) 2016 rubenwardy + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/games/default/files/sfinv/api.lua b/games/default/files/sfinv/api.lua new file mode 100644 index 000000000..fdb652b8d --- /dev/null +++ b/games/default/files/sfinv/api.lua @@ -0,0 +1,182 @@ +sfinv = { + pages = {}, + pages_unordered = {}, + contexts = {}, + enabled = true +} + +function sfinv.register_page(name, def) + assert(name, "Invalid sfinv page. Requires a name") + assert(def, "Invalid sfinv page. Requires a def[inition] table") + assert(def.get, "Invalid sfinv page. Def requires a get function.") + assert(not sfinv.pages[name], "Attempt to register already registered sfinv page " .. dump(name)) + + sfinv.pages[name] = def + def.name = name + table.insert(sfinv.pages_unordered, def) +end + +function sfinv.override_page(name, def) + assert(name, "Invalid sfinv page override. Requires a name") + assert(def, "Invalid sfinv page override. Requires a def[inition] table") + local page = sfinv.pages[name] + assert(page, "Attempt to override sfinv page " .. dump(name) .. " which does not exist.") + for key, value in pairs(def) do + page[key] = value + end +end + +function sfinv.get_nav_fs(player, context, nav, current_idx) + -- Only show tabs if there is more than one page + if #nav > 1 then + return "tabheader[0,0;sfinv_nav_tabs;" .. table.concat(nav, ",") .. + ";" .. current_idx .. ";true;false]" + else + return "" + end +end + +local theme_main = "bgcolor[#080808BB;true]" .. default.gui_bg .. + default.gui_bg_img + +local theme_inv = default.gui_slots .. [[ + list[current_player;main;0,4.7;8,1;] + list[current_player;main;0,5.85;8,3;8] + ]] + +function sfinv.make_formspec(player, context, content, show_inv, size) + local tmp = { + size or "size[8,8.6]", + theme_main, + sfinv.get_nav_fs(player, context, context.nav_titles, context.nav_idx), + content + } + if show_inv then + tmp[#tmp + 1] = theme_inv + end + return table.concat(tmp, "") +end + +function sfinv.get_homepage_name(player) + return "sfinv:crafting" +end + +function sfinv.get_formspec(player, context) + -- Generate navigation tabs + local nav = {} + local nav_ids = {} + local current_idx = 1 + for i, pdef in pairs(sfinv.pages_unordered) do + if not pdef.is_in_nav or pdef:is_in_nav(player, context) then + nav[#nav + 1] = pdef.title + nav_ids[#nav_ids + 1] = pdef.name + if pdef.name == context.page then + current_idx = #nav_ids + end + end + end + context.nav = nav_ids + context.nav_titles = nav + context.nav_idx = current_idx + + -- Generate formspec + local page = sfinv.pages[context.page] or sfinv.pages["404"] + if page then + return page:get(player, context) + else + local old_page = context.page + local home_page = sfinv.get_homepage_name(player) + + if old_page == home_page then + minetest.log("error", "[sfinv] Couldn't find " .. dump(old_page) .. + ", which is also the old page") + + return "" + end + + context.page = home_page + assert(sfinv.pages[context.page], "[sfinv] Invalid homepage") + minetest.log("warning", "[sfinv] Couldn't find " .. dump(old_page) .. + " so switching to homepage") + + return sfinv.get_formspec(player, context) + end +end + +function sfinv.get_or_create_context(player) + local name = player:get_player_name() + local context = sfinv.contexts[name] + if not context then + context = { + page = sfinv.get_homepage_name(player) + } + sfinv.contexts[name] = context + end + return context +end + +function sfinv.set_context(player, context) + sfinv.contexts[player:get_player_name()] = context +end + +function sfinv.set_player_inventory_formspec(player, context) + local fs = sfinv.get_formspec(player, + context or sfinv.get_or_create_context(player)) + player:set_inventory_formspec(fs) +end + +function sfinv.set_page(player, pagename) + local context = sfinv.get_or_create_context(player) + local oldpage = sfinv.pages[context.page] + if oldpage and oldpage.on_leave then + oldpage:on_leave(player, context) + end + context.page = pagename + local page = sfinv.pages[pagename] + if page.on_enter then + page:on_enter(player, context) + end + sfinv.set_player_inventory_formspec(player, context) +end + +minetest.register_on_joinplayer(function(player) + if sfinv.enabled then + sfinv.set_player_inventory_formspec(player) + end +end) + +minetest.register_on_leaveplayer(function(player) + sfinv.contexts[player:get_player_name()] = nil +end) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "" or not sfinv.enabled then + return false + end + + -- Get Context + local name = player:get_player_name() + local context = sfinv.contexts[name] + if not context then + sfinv.set_player_inventory_formspec(player) + return false + end + + -- Was a tab selected? + if fields.sfinv_nav_tabs and context.nav then + local tid = tonumber(fields.sfinv_nav_tabs) + if tid and tid > 0 then + local id = context.nav[tid] + local page = sfinv.pages[id] + if id and page then + sfinv.set_page(player, id) + end + end + else + -- Pass event to page + local page = sfinv.pages[context.page] + if page and page.on_player_receive_fields then + return page:on_player_receive_fields(player, context, fields) + end + end +end) diff --git a/games/default/files/sfinv/depends.txt b/games/default/files/sfinv/depends.txt new file mode 100644 index 000000000..4ad96d515 --- /dev/null +++ b/games/default/files/sfinv/depends.txt @@ -0,0 +1 @@ +default diff --git a/games/default/files/sfinv/init.lua b/games/default/files/sfinv/init.lua new file mode 100644 index 000000000..b25aa083b --- /dev/null +++ b/games/default/files/sfinv/init.lua @@ -0,0 +1 @@ +dofile(minetest.get_modpath("sfinv") .. "/api.lua") diff --git a/games/default/files/sfinv/textures/gui_formbg.png b/games/default/files/sfinv/textures/gui_formbg.png new file mode 100644 index 000000000..503ff0355 Binary files /dev/null and b/games/default/files/sfinv/textures/gui_formbg.png differ