1 Commits

Author SHA1 Message Date
15afd559f6 Fix crash caused by bag swapping 2018-08-10 16:11:35 +02:00
64 changed files with 316 additions and 802 deletions

View File

@ -1,19 +0,0 @@
Unified Inventory for Minetest
Copyright (C) 2012-2014 Maciej Kasatkin (RealBadAngel)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Contact information:
Examine a git patch to get the contributor's email address.

View File

@ -1,48 +1,22 @@
# Unified Inventory
Unified inventory
=================
Unified Inventory replaces the default survival and creative inventory.
It adds a nicer interface and a number of features, such as a crafting guide.
## Features
* Node, item and tool browser
* Crafting guide
* Can copy the recipe to the crafting grid
* Recipe search function by ingredients
* Up to four bags with up to 24 slots each
* Home function to teleport
* Trash slot
* Lite mode: reduces the item browser width
* Mod API for modders: see [mod_api.txt](doc/mod_api.txt)
* Setting-determinated features: see [settingtypes.txt](settingtypes.txt)
## Requirements
* Minetest 5.0.0+ since commit 4403b69
* Minetest 0.4.16+ prior commit 4403b69
# Licenses
License
=======
Copyright (C) 2012-2014 Maciej Kasatkin (RealBadAngel)
Copyright (C) 2012-? Various minetest-mods contributors
Unified inventory code is licensed under the GNU LGPLv2+.
## Code
GNU LGPLv2+, see [license notice](LICENSE.txt)
## Textures
Licenses for textures:
VanessaE: (CC-BY-4.0)
* `ui_group.png`
Tango Project: (Public Domain, CC-BY-4.0)
* [`ui_reset_icon.png`](https://commons.wikimedia.org/wiki/File:Edit-clear.svg)
* [`ui_doubleleft_icon.png`](http://commons.wikimedia.org/wiki/File:Media-seek-backward.svg)
* [`ui_doubleright_icon.png`](http://commons.wikimedia.org/wiki/File:Media-seek-forward.svg)
@ -51,7 +25,6 @@ Tango Project: (Public Domain, CC-BY-4.0)
* [`ui_skip_forward_icon.png`](http://commons.wikimedia.org/wiki/File:Media-skip-forward.svg)
From http://www.clker.com (Public Domain, CC-BY-4.0):
* [`bags_small.png`](http://www.clker.com/clipart-moneybag-empty.html)
* [`bags_medium.png`](http://www.clker.com/clipart-backpack-1.html)
* [`bags_large.png` / `ui_bags_icon.png`](http://www.clker.com/clipart-backpack-green-brown.html)
@ -64,33 +37,25 @@ From http://www.clker.com (Public Domain, CC-BY-4.0):
* [`ui_waypoint_set_icon.png`](http://www.clker.com/clipart-larger-flag.html)
Everaldo Coelho (YellowIcon) (LGPL v2.1+):
* [`ui_craftguide_icon.png` / `ui_craft_icon.png`](http://commons.wikimedia.org/wiki/File:Advancedsettings.png)
Gregory H. Revera: (CC-BY-SA 3.0)
* [`ui_moon_icon.png`](http://commons.wikimedia.org/wiki/File:FullMoon2010.jpg)
Thomas Bresson: (CC-BY 3.0)
* [`ui_sun_icon.png`](http://commons.wikimedia.org/wiki/File:2012-10-13_15-29-35-sun.jpg)
Fibonacci: (Public domain, CC-BY 4.0)
* [`ui_xyz_off_icon.png`](http://commons.wikimedia.org/wiki/File:No_sign.svg)
Gregory Maxwell: (Public domain, CC-BY 4.0)
* [`ui_ok_icon.png`](http://commons.wikimedia.org/wiki/File:Yes_check.svg)
Adrien Facélina: (LGPL v2.1+)
* [`inventory_plus_worldedit_gui.png`](http://commons.wikimedia.org/wiki/File:Erioll_world_2.svg)
Other files from Wikimedia Commons:
* [`ui_gohome_icon.png` / `ui_home_icon.png` / `ui_sethome_icon.png`](http://commons.wikimedia.org/wiki/File:Home_256x256.png) (GPL v2+)
RealBadAngel: (CC-BY-4.0)
* Everything else.

View File

@ -187,7 +187,7 @@ end
function unified_inventory.go_home(player)
local pos = unified_inventory.home_pos[player:get_player_name()]
if pos then
player:set_pos(pos)
player:setpos(pos)
end
end

115
bags.lua
View File

@ -1,9 +1,7 @@
--[[
Bags for Minetest
-- Bags for Minetest
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
License: GPLv3
--]]
-- Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
-- License: GPLv3
local S = unified_inventory.gettext
local F = minetest.formspec_escape
@ -11,19 +9,18 @@ local F = minetest.formspec_escape
unified_inventory.register_page("bags", {
get_formspec = function(player)
local player_name = player:get_player_name()
return { formspec = table.concat({
"background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]",
"label[0,0;" .. F(S("Bags")) .. "]",
"button[0,2;2,0.5;bag1;" .. F(S("Bag @1", 1)) .. "]",
"button[2,2;2,0.5;bag2;" .. F(S("Bag @1", 2)) .. "]",
"button[4,2;2,0.5;bag3;" .. F(S("Bag @1", 3)) .. "]",
"button[6,2;2,0.5;bag4;" .. F(S("Bag @1", 4)) .. "]",
"listcolors[#00000000;#00000000]",
"list[detached:" .. F(player_name) .. "_bags;bag1;0.5,1;1,1;]",
"list[detached:" .. F(player_name) .. "_bags;bag2;2.5,1;1,1;]",
"list[detached:" .. F(player_name) .. "_bags;bag3;4.5,1;1,1;]",
"list[detached:" .. F(player_name) .. "_bags;bag4;6.5,1;1,1;]"
}) }
local formspec = "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
formspec = formspec.."label[0,0;"..F(S("Bags")).."]"
formspec = formspec.."button[0,2;2,0.5;bag1;"..F(S("Bag @1", 1)).."]"
formspec = formspec.."button[2,2;2,0.5;bag2;"..F(S("Bag @1", 2)).."]"
formspec = formspec.."button[4,2;2,0.5;bag3;"..F(S("Bag @1", 3)).."]"
formspec = formspec.."button[6,2;2,0.5;bag4;"..F(S("Bag @1", 4)).."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag1;0.5,1;1,1;]"
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag2;2.5,1;1,1;]"
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag3;4.5,1;1,1;]"
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag4;6.5,1;1,1;]"
return {formspec=formspec}
end,
})
@ -41,39 +38,37 @@ local function get_player_bag_stack(player, i)
}):get_stack("bag" .. i, 1)
end
for bag_i = 1, 4 do
unified_inventory.register_page("bag" .. bag_i, {
for i = 1, 4 do
local bi = i
unified_inventory.register_page("bag"..bi, {
get_formspec = function(player)
local stack = get_player_bag_stack(player, bag_i)
local stack = get_player_bag_stack(player, bi)
local image = stack:get_definition().inventory_image
local fs = {
"image[7,0;1,1;" .. image .. "]",
"label[0,0;" .. F(S("Bag @1", bag_i)) .. "]",
"listcolors[#00000000;#00000000]",
"list[current_player;bag" .. bag_i .. "contents;0,1;8,3;]",
"listring[current_name;bag" .. bag_i .. "contents]",
"listring[current_player;main]"
}
local formspec = ("image[7,0;1,1;"..image.."]"
.."label[0,0;"..F(S("Bag @1", bi)).."]"
.."listcolors[#00000000;#00000000]"
.."list[current_player;bag"..bi.."contents;0,1;8,3;]"
.."listring[current_name;bag"..bi.."contents]"
.."listring[current_player;main]")
local slots = stack:get_definition().groups.bagslots
if slots == 8 then
fs[#fs + 1] = "background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]"
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]"
elseif slots == 16 then
fs[#fs + 1] = "background[0.06,0.99;7.92,7.52;ui_bags_med_form.png]"
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_med_form.png]"
elseif slots == 24 then
fs[#fs + 1] = "background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]"
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]"
end
local player_name = player:get_player_name() -- For if statement.
if unified_inventory.trash_enabled
or unified_inventory.is_creative(player_name)
or minetest.get_player_privs(player_name).give then
fs[#fs + 1] = "background[6.06,0;0.92,0.92;ui_bags_trash.png]"
.. "list[detached:trash;main;6,0.1;1,1;]"
if unified_inventory.trash_enabled or unified_inventory.is_creative(player_name) or minetest.get_player_privs(player_name).give then
formspec = (formspec.."background[6.06,0;0.92,0.92;ui_bags_trash.png]"
.."list[detached:trash;main;6,0.1;1,1;]")
end
local inv = player:get_inventory()
for i = 1, 4 do
local def = get_player_bag_stack(player, i):get_definition()
local button
if def.groups.bagslots then
local list_name = "bag" .. i .. "contents"
local list_name = "bag"..i.."contents"
local size = inv:get_size(list_name)
local used = 0
for si = 1, size do
@ -83,12 +78,14 @@ for bag_i = 1, 4 do
end
end
local img = def.inventory_image
local label = F(S("Bag @1", i)) .. "\n" .. used .. "/" .. size
fs[#fs + 1] = string.format("image_button[%i,0;1,1;%s;bag%i;%s]",
i + 1, img, i, label)
local label = F(S("Bag @1", i)).."\n"..used.."/"..size
button = "image_button["..(i+1)..",0;1,1;"..img..";bag"..i..";"..label.."]"
else
button = ""
end
formspec = formspec..button
end
return { formspec = table.concat(fs) }
return {formspec=formspec}
end,
})
end
@ -98,12 +95,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end
for i = 1, 4 do
if fields["bag" .. i] then
if fields["bag"..i] then
local stack = get_player_bag_stack(player, i)
if not stack:get_definition().groups.bagslots then
return
end
unified_inventory.set_inventory_formspec(player, "bag" .. i)
unified_inventory.set_inventory_formspec(player, "bag"..i)
return
end
end
@ -113,32 +110,30 @@ local function save_bags_metadata(player, bags_inv)
local is_empty = true
local bags = {}
for i = 1, 4 do
local bag = "bag" .. i
local bag = "bag"..i
if not bags_inv:is_empty(bag) then
-- Stack limit is 1, otherwise use stack:to_string()
bags[i] = bags_inv:get_stack(bag, 1):get_name()
is_empty = false
end
end
local meta = player:get_meta()
if is_empty then
meta:set_string("unified_inventory:bags", nil)
player:set_attribute("unified_inventory:bags", nil)
else
meta:set_string("unified_inventory:bags",
player:set_attribute("unified_inventory:bags",
minetest.serialize(bags))
end
end
local function load_bags_metadata(player, bags_inv)
local player_inv = player:get_inventory()
local meta = player:get_meta()
local bags_meta = meta:get_string("unified_inventory:bags")
local bags_meta = player:get_attribute("unified_inventory:bags")
local bags = bags_meta and minetest.deserialize(bags_meta) or {}
local dirty_meta = false
if not bags_meta then
-- Backwards compatiblity
for i = 1, 4 do
local bag = "bag" .. i
local bag = "bag"..i
if not player_inv:is_empty(bag) then
-- Stack limit is 1, otherwise use stack:to_string()
bags[i] = player_inv:get_stack(bag, 1):get_name()
@ -148,7 +143,7 @@ local function load_bags_metadata(player, bags_inv)
end
-- Fill detached slots
for i = 1, 4 do
local bag = "bag" .. i
local bag = "bag"..i
bags_inv:set_size(bag, 1)
bags_inv:set_stack(bag, 1, bags[i] or "")
end
@ -160,7 +155,7 @@ local function load_bags_metadata(player, bags_inv)
-- Clean up deprecated garbage after saving
for i = 1, 4 do
local bag = "bag" .. i
local bag = "bag"..i
player_inv:set_size(bag, 0)
end
end
@ -168,9 +163,9 @@ end
minetest.register_on_joinplayer(function(player)
local player_inv = player:get_inventory()
local player_name = player:get_player_name()
local bags_inv = minetest.create_detached_inventory(player_name .. "_bags",{
local bags_inv = minetest.create_detached_inventory(player_name.."_bags",{
on_put = function(inv, listname, index, stack, player)
player:get_inventory():set_size(listname .. "contents",
player:get_inventory():set_size(listname.."contents",
stack:get_definition().groups.bagslots)
save_bags_metadata(player, inv)
end,
@ -180,14 +175,14 @@ minetest.register_on_joinplayer(function(player)
return 0
end
local player_inv = player:get_inventory()
local old_slots = player_inv:get_size(listname .. "contents")
local old_slots = player_inv:get_size(listname.."contents")
if new_slots >= old_slots then
return 1
end
-- using a smaller bag, make sure it fits
local old_list = player_inv:get_list(listname .. "contents")
local old_list = player_inv:get_list(listname.."contents")
local new_list = {}
local slots_used = 0
local use_new_list = false
@ -201,7 +196,7 @@ minetest.register_on_joinplayer(function(player)
end
if new_slots >= slots_used then
if use_new_list then
player_inv:set_list(listname .. "contents", new_list)
player_inv:set_list(listname.."contents", new_list)
end
return 1
end
@ -209,13 +204,13 @@ minetest.register_on_joinplayer(function(player)
return 0
end,
allow_take = function(inv, listname, index, stack, player)
if player:get_inventory():is_empty(listname .. "contents") then
if player:get_inventory():is_empty(listname.."contents") then
return stack:get_count()
end
return 0
end,
on_take = function(inv, listname, index, stack, player)
player:get_inventory():set_size(listname .. "contents", 0)
player:get_inventory():set_size(listname.."contents", 0)
save_bags_metadata(player, inv)
end,
allow_move = function()

View File

@ -47,15 +47,6 @@ minetest.register_on_joinplayer(function(player)
refill:set_size("main", 1)
end)
local function apply_new_filter(player, search_text, new_dir)
local player_name = player:get_player_name()
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
unified_inventory.apply_filter(player, search_text, new_dir)
unified_inventory.current_searchbox[player_name] = search_text
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
local player_name = player:get_player_name()
@ -69,6 +60,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.searchbox
and fields.searchbox ~= unified_inventory.current_searchbox[player_name] then
unified_inventory.current_searchbox[player_name] = fields.searchbox
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
end
for i, def in pairs(unified_inventory.buttons) do
@ -120,18 +112,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
unified_inventory.current_page[player_name])
end
-- Check clicked item image button
local clicked_item
for name, value in pairs(fields) do
local new_dir, mangled_item = string.match(name, "^item_button_([a-z]+)_(.*)$")
if new_dir and mangled_item then
if string.sub(name, 1, 12) == "item_button_" then
local new_dir, mangled_item = string.match(name, "^item_button_([a-z]+)_(.*)$")
clicked_item = unified_inventory.demangle_for_formspec(mangled_item)
if string.sub(clicked_item, 1, 6) == "group:" then
-- Change search filter to this group
apply_new_filter(player, clicked_item, new_dir)
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
unified_inventory.apply_filter(player, clicked_item, new_dir)
unified_inventory.current_searchbox[player_name] = clicked_item
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
return
end
if new_dir == "recipe" or new_dir == "usage" then
if new_dir == "recipe"
or new_dir == "usage" then
unified_inventory.current_craft_direction[player_name] = new_dir
end
break
@ -150,7 +145,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
unified_inventory.alternate[player_name] = 1
unified_inventory.set_inventory_formspec(player, "craftguide")
elseif player_creative then
-- Creative page: Add entire stack to inventory
local inv = player:get_inventory()
local stack = ItemStack(clicked_item)
stack:set_count(stack:get_stack_max())
@ -168,7 +162,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
minetest.sound_play("paperflip2",
{to_player=player_name, gain = 1.0})
elseif fields.searchresetbutton then
apply_new_filter(player, "", "nochange")
unified_inventory.apply_filter(player, "", "nochange")
unified_inventory.current_searchbox[player_name] = ""
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
minetest.sound_play("click",
{to_player=player_name, gain = 0.1})
end
-- alternate buttons

View File

@ -1,95 +0,0 @@
unified_inventory API
=====================
This file provides information about the API of unified_inventory.
Misc functions
--------------
Grouped by use-case, afterwards sorted alphabetically.
* `unified_inventory.is_creative(name)`
* Checks whether creative is enabled or the player has `creative`
Pages
-----
Register a new page: The callback inside this function is called on user input.
unified_inventory.register_page("pagename", {
get_formspec = function(player)
-- ^ `player` is an `ObjectRef`
-- Compute the formspec string here
return {
formspec = "button[2,2;2,1;mybutton;Press me]",
-- ^ Final form of the formspec to display
draw_inventory = false, -- default `true`
-- ^ Optional. Hides the player's `main` inventory list
draw_item_list = false, -- default `true`
-- ^ Optional. Hides the item list on the right side
formspec_prepend = false, -- default `false`
-- ^ Optional. When `false`: Disables the formspec prepend
}
end,
})
Buttons
-------
Register a new button for the bottom row:
unified_inventory.register_button("skins", {
type = "image",
image = "skins_skin_button.png",
tooltip = "Skins",
hide_lite = true
-- ^ Button is hidden when following two conditions are met:
-- Configuration line `unified_inventory_lite = true`
-- Player does not have the privilege `ui_full`
})
Crafting
--------
The code blocks below document each possible parameter using exemplary values.
Provide information to display custom craft types:
unified_inventory.register_craft_type("mytype", {
-- ^ Unique identifier for `register_craft`
description = "Sample Craft",
-- ^ Text shown below the crafting arrow
icon = "dummy.png",
-- ^ Image shown above the crafting arrow
width = 3,
height = 3,
-- ^ Maximal input dimensions of the recipes
dynamic_display_size = function(craft)
-- ^ `craft` is the definition from `register_craft`
return {
width = 2,
height = 3
}
end,
-- ^ Optional callback to change the displayed recipe size
uses_crafting_grid = true,
})
Register a non-standard craft recipe:
unified_inventory.register_craft({
output = "default:foobar",
type = "mytype",
-- ^ Standard craft type or custom (see `register_craft_type`)
items = {
{ "default:foo" },
{ "default:bar" }
},
width = 3,
-- ^ Same as `minetest.register_recipe`
})

View File

@ -2,21 +2,19 @@ local S = unified_inventory.gettext
function unified_inventory.canonical_item_spec_matcher(spec)
local specname = ItemStack(spec):get_name()
if specname:sub(1, 6) ~= "group:" then
if specname:sub(1, 6) == "group:" then
local group_names = specname:sub(7):split(",")
return function (itemname)
return itemname == specname
end
end
local group_names = specname:sub(7):split(",")
return function (itemname)
local itemdef = minetest.registered_items[itemname]
for _, group_name in ipairs(group_names) do
if (itemdef.groups[group_name] or 0) == 0 then
return false
local itemdef = minetest.registered_items[itemname]
for _, group_name in ipairs(group_names) do
if (itemdef.groups[group_name] or 0) == 0 then
return false
end
end
return true
end
return true
else
return function (itemname) return itemname == specname end
end
end
@ -27,11 +25,23 @@ end
function unified_inventory.extract_groupnames(groupname)
local specname = ItemStack(groupname):get_name()
if specname:sub(1, 6) ~= "group:" then
if specname:sub(1, 6) == "group:" then
local group_names = specname:sub(7):split(",")
if #group_names == 1 then
return group_names[1], 1
end
local s = ""
for g=1,#group_names do
if g > 1 then
-- List connector
s = s .. S(" and ")
end
s = s .. group_names[g]
end
return s, #group_names
else
return nil, 0
end
local group_names = specname:sub(7):split(",")
return table.concat(group_names, S(" and ")), #group_names
end
unified_inventory.registered_group_items = {

View File

@ -82,5 +82,3 @@ dofile(modpath.."/item_names.lua")
if minetest.get_modpath("datastorage") then
dofile(modpath.."/waypoints.lua")
end
minetest.log("action", "[unified_inventory] loaded.")

View File

@ -58,20 +58,15 @@ function unified_inventory.get_formspec(player, page)
unified_inventory.current_page[player_name] = page
local pagedef = unified_inventory.pages[page]
if not pagedef then
return "" -- Invalid page name
end
local formspec = {
"size[14,10]",
pagedef.formspec_prepend and "" or "no_prepend[]",
"background[-0.19,-0.25;14.4,10.75;ui_form_bg.png]" -- Background
}
local n = 4
local n = 3
if draw_lite_mode then
formspec[1] = "size[11,7.7]"
formspec[3] = "background[-0.19,-0.2;11.4,8.4;ui_form_bg.png]"
formspec[2] = "background[-0.19,-0.2;11.4,8.4;ui_form_bg.png]"
end
if unified_inventory.is_creative(player_name)
@ -80,6 +75,11 @@ function unified_inventory.get_formspec(player, page)
n = n+1
end
-- Current page
if not unified_inventory.pages[page] then
return "" -- Invalid page name
end
local perplayer_formspec = unified_inventory.get_per_player_formspec(player_name)
local fsdata = pagedef.get_formspec(player, perplayer_formspec)
@ -99,21 +99,17 @@ function unified_inventory.get_formspec(player, page)
end
end
local j = 1 --Modif NALC (sys4 20/11/2018) 12 buttons max by row
for i, def in pairs(filtered_inv_buttons) do
if draw_lite_mode and i > 4 then
button_row = 1
button_col = 1
elseif not draw_lite_mode and j > 12 then
button_row = 1
j = 1
end
if def.type == "image" then
if (def.condition == nil or def.condition(player) == true) then
formspec[n] = "image_button["
formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (j - 1) - button_col * 0.65 * 4) -- Modif NALC
formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4)
formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * 0.7)..";0.8,0.8;"
formspec[n+3] = F(def.image)..";"
formspec[n+4] = F(def.name)..";]"
@ -122,14 +118,13 @@ function unified_inventory.get_formspec(player, page)
n = n+7
else
formspec[n] = "image["
formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (j - 1) - button_col * 0.65 * 4) -- Modif NALC
formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4)
formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * 0.7)..";0.8,0.8;"
formspec[n+3] = F(def.image).."^[colorize:#808080:alpha]"
n = n+4
end
end
j = j + 1 -- Modif NALC
end
if fsdata.draw_inventory ~= false then
@ -228,8 +223,7 @@ function unified_inventory.get_formspec(player, page)
for y = 0, ui_peruser.pagerows - 1 do
for x = 0, ui_peruser.pagecols - 1 do
local name = unified_inventory.filtered_items_list[player_name][list_index]
local item = minetest.registered_items[name]
if item then
if minetest.registered_items[name] then
-- Clicked on current item: Flip crafting direction
if name == unified_inventory.current_item[player_name] then
local cdir = unified_inventory.current_craft_direction[player_name]
@ -242,18 +236,12 @@ function unified_inventory.get_formspec(player, page)
-- Default: use active search direction by default
dir = unified_inventory.active_search_direction[player_name]
end
local button_name = "item_button_" .. dir .. "_"
.. unified_inventory.mangle_for_formspec(name)
formspec[n] = ("item_image_button[%f,%f;.81,.81;%s;%s;]"):format(
8.2 + x * 0.7, ui_peruser.formspec_y + ui_peruser.page_y + y * 0.7,
name, button_name
)
formspec[n + 1] = ("tooltip[%s;%s \\[%s\\]]"):format(
button_name, minetest.formspec_escape(item.description),
item.mod_origin or "??"
)
n = n + 2
formspec[n] = "item_image_button["
..(8.2 + x * 0.7)..","
..(ui_peruser.formspec_y + ui_peruser.page_y + y * 0.7)..";.81,.81;"
..name..";item_button_"..dir.."_"
..unified_inventory.mangle_for_formspec(name)..";]"
n = n+1
list_index = list_index + 1
end
end
@ -302,13 +290,15 @@ function unified_inventory.apply_filter(player, filter, search_dir)
return string.find(lname, lfilter, 1, true) or string.find(ldesc, lfilter, 1, true)
end
end
local is_creative = unified_inventory.is_creative(player_name)
unified_inventory.filtered_items_list[player_name]={}
for name, def in pairs(minetest.registered_items) do
if (not def.groups.not_in_creative_inventory
or def.groups.not_in_creative_inventory == 0)
and def.description
and def.description ~= ""
and ffilter(name, def) then
and ffilter(name, def)
and (is_creative or unified_inventory.crafts_for.recipe[def.name]) then
table.insert(unified_inventory.filtered_items_list[player_name], name)
end
end

View File

@ -1,369 +0,0 @@
# Malay translation for the unified_inventory mod.
# Copyright (C) 2018 Maciej Kasatkin (RealBadAngel)
# This file is distributed under the same license as the unified_inventory package.
# muhdnurhidayat <translation@mnh48.moe>, 2018.
#
msgid ""
msgstr ""
"Project-Id-Version: unified_inventory\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-02 03:34+0200\n"
"PO-Revision-Date: 2018-07-17 20:14+0800\n"
"Language-Team: muhdnurhidayat <translation@mnh48.moe>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.9\n"
"Last-Translator: muhdnurhidayat <translation@mnh48.moe>\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"Language: ms\n"
"X-Poedit-Flags-xgettext: --add-comments\n"
#: api.lua register.lua
msgid "Crafting"
msgstr "Pertukangan"
#: api.lua
msgid "Mixing"
msgstr "Pencampuran"
#: api.lua
msgid "Cooking"
msgstr "Pemasakan"
#: api.lua
msgid "Digging"
msgstr "Penggalian"
#: bags.lua
msgid "Bags"
msgstr "Beg"
#: bags.lua
msgid "Bag @1"
msgstr "Beg @1"
#: bags.lua
msgid "Small Bag"
msgstr "Beg Kecil"
#: bags.lua
msgid "Medium Bag"
msgstr "Beg Sederhana"
#: bags.lua
msgid "Large Bag"
msgstr "Beg Besar"
#: group.lua
msgid " and "
msgstr " dan "
#: internal.lua
msgid "First page"
msgstr "Halaman pertama"
#: internal.lua
msgid "Back three pages"
msgstr "Tiga halaman sebelumnya"
#: internal.lua
msgid "Back one page"
msgstr "Halaman sebelumnya"
#: internal.lua
msgid "Forward one page"
msgstr "Halaman seterusnya"
#: internal.lua
msgid "Forward three pages"
msgstr "Tiga halaman seterusnya"
#: internal.lua
msgid "Last page"
msgstr "Halaman terakhir"
#: internal.lua
msgid "Search"
msgstr "Cari"
#: internal.lua
msgid "Reset search and display everything"
msgstr "Set semula carian dan tunjukkan semua benda"
#: internal.lua
msgid "No matching items"
msgstr "Tiada item sepadan"
#: internal.lua
msgid "No matches."
msgstr "Tiada padanan."
#: internal.lua
msgid "Page"
msgstr "Halaman"
#: internal.lua
#, lua-format
msgid "%s of %s"
msgstr "%s drpd %s"
#: internal.lua
msgid "Filter"
msgstr "Tapis"
#: register.lua
msgid "Can use the creative inventory"
msgstr "Boleh guna inventori kreatif"
#: register.lua
msgid ""
"Forces Unified Inventory to be displayed in Full mode if Lite mode is "
"configured globally"
msgstr ""
"Memaksa Unified Inventory untuk dipaparkan dalam mod Full jika mod Lite "
"ditetapkan secara global"
#: register.lua
msgid "Crafting Grid"
msgstr "Grid Pertukangan"
#: register.lua
msgid "Crafting Guide"
msgstr "Panduan Pertukangan"
#: register.lua
msgid "Set home position"
msgstr "Tetapkan kedudukan rumah"
#: register.lua
#, lua-format
msgid "Home position set to: %s"
msgstr "Kedudukan rumah ditetapkan ke: %s"
#: register.lua
msgid "You don't have the \"home\" privilege!"
msgstr "Anda tidak ada keistimewaan \"home\"!"
#: register.lua
msgid "Go home"
msgstr "Balik rumah"
#: register.lua
msgid "Set time to day"
msgstr "Tetapkan masa jadi siang"
#: register.lua
msgid "Time of day set to 6am"
msgstr "Masa ditetapkan ke 6 pagi"
#: register.lua
msgid "You don't have the settime privilege!"
msgstr "Anda tidak ada keistimewaan settime!"
#: register.lua
msgid "Set time to night"
msgstr "Tetapkan masa jadi malam"
#: register.lua
msgid "Time of day set to 9pm"
msgstr "Masa ditetapkan ke 9 malam"
#: register.lua
msgid "Clear inventory"
msgstr "Kosongkan inventori"
#: register.lua
msgid ""
"This button has been disabled outside of creative mode to prevent accidental "
"inventory trashing.\n"
"Use the trash slot instead."
msgstr ""
"Butang ini dilumpuhkan di luar mod kreatif untuk mengelakkan pengosongan "
"inventori secara tidak sengaja.\n"
"Sebaliknya, gunakan slot tong sampah."
#: register.lua
msgid "Inventory cleared!"
msgstr "Inventori dikosongkan!"
#: register.lua
msgid "Trash:"
msgstr "Buang:"
#: register.lua
msgid "Refill:"
msgstr "Isi balik:"
#: register.lua
#, lua-format
msgid "Any item belonging to the %s group"
msgstr "Sebarang item dari kumpulan %s"
#: register.lua
#, lua-format
msgid "Any item belonging to the groups %s"
msgstr "Sebarang item dari kumpulan %s"
#: register.lua
#, lua-format
msgid "Recipe %d of %d"
msgstr "Resipi %d drpd %d"
#: register.lua
#, lua-format
msgid "Usage %d of %d"
msgstr "Kegunaan %d drpd %d"
#: register.lua
msgid "No recipes"
msgstr "Tiada resipi"
#: register.lua
msgid "No usages"
msgstr "Tiada kegunaan"
#: register.lua
msgid "Result"
msgstr "Hasil"
#: register.lua
msgid "Ingredient"
msgstr "Bahan"
#: register.lua
msgid "Show next recipe"
msgstr "Tunjuk resipi seterusnya"
#: register.lua
msgid "Show next usage"
msgstr "Tunjuk kegunaan seterusnya"
#: register.lua
msgid "Show previous recipe"
msgstr "Tunjuk resipi sebelumnya"
#: register.lua
msgid "Show previous usage"
msgstr "Tunjuk kegunaan sebelumnya"
#: register.lua
#, lua-format
msgid "%s (%s)"
msgstr "%s (%s)"
#: register.lua
msgid "Give me:"
msgstr "Beri saya:"
#: register.lua
msgid ""
"This recipe is too\n"
"large to be displayed."
msgstr ""
"Resipi ini terlalu\n"
"besar untuk paparan."
#: register.lua
msgid "To craft grid:"
msgstr "Ke grid pertukangan:"
#: register.lua
msgid "All"
msgstr ""
"SE\n"
"MUA"
#: waypoints.lua
msgid "White"
msgstr "Putih"
#: waypoints.lua
msgid "Yellow"
msgstr "Kuning"
#: waypoints.lua
msgid "Red"
msgstr "Merah"
#: waypoints.lua
msgid "Green"
msgstr "Hijau"
#: waypoints.lua
msgid "Blue"
msgstr "Biru"
#: waypoints.lua
msgid "Waypoints"
msgstr "Titik Arah"
#: waypoints.lua
#, lua-format
msgid "Select Waypoint #%d"
msgstr "Pilih Titik Arah #%d"
#: waypoints.lua
#, lua-format
msgid "Waypoint %d"
msgstr "Titik Arah %d"
#: waypoints.lua
msgid "Set waypoint to current location"
msgstr "Tetapkan titik arah ke lokasi semasa"
#: waypoints.lua
msgid "invisible"
msgstr "Sembunyikan"
#: waypoints.lua
msgid "visible"
msgstr "Paparkan"
#: waypoints.lua
msgid "Make waypoint @1"
msgstr "@1 titik arah"
#: waypoints.lua
msgid "Disable"
msgstr "Sembunyikan"
#: waypoints.lua
msgid "Enable"
msgstr "Paparkan"
#: waypoints.lua
msgid "@1 display of waypoint coordinates"
msgstr "@1 koordinat untuk titik arah"
#: waypoints.lua
msgid "Change color of waypoint display"
msgstr "Tukar warna paparan titik arah"
#: waypoints.lua
msgid "Edit waypoint name"
msgstr "Edit nama titik arah"
#: waypoints.lua
msgid "Waypoint active"
msgstr "Titik arah aktif"
#: waypoints.lua
msgid "Waypoint inactive"
msgstr "Titik arah tidak aktif"
#: waypoints.lua
msgid "Finish editing"
msgstr "Selesai edit"
#: waypoints.lua
msgid "World position"
msgstr "Kedudukan dunia"
#: waypoints.lua
msgid "Name"
msgstr "Nama"
#: waypoints.lua
msgid "HUD text color"
msgstr "Warna tulisan HUD"

View File

@ -1,4 +1 @@
name = unified_inventory
depends = default
optional_depends = creative, sfinv, intllib, datastorage, farming
description = Unified Inventory replaces the default survival and creative inventory. It adds a nicer interface and a number of features, such as a crafting guide.

View File

@ -40,6 +40,55 @@ unified_inventory.register_button("craftguide", {
tooltip = S("Crafting Guide")
})
unified_inventory.register_button("home_gui_set", {
type = "image",
image = "ui_sethome_icon.png",
tooltip = S("Set home position"),
hide_lite=true,
action = function(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {home=true}) then
unified_inventory.set_home(player, player:getpos())
local home = unified_inventory.home_pos[player_name]
if home ~= nil then
minetest.sound_play("dingdong",
{to_player=player_name, gain = 1.0})
minetest.chat_send_player(player_name,
S("Home position set to: %s"):format(minetest.pos_to_string(home)))
end
else
minetest.chat_send_player(player_name,
S("You don't have the \"home\" privilege!"))
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
end
end,
condition = function(player)
return minetest.check_player_privs(player:get_player_name(), {home=true})
end,
})
unified_inventory.register_button("home_gui_go", {
type = "image",
image = "ui_gohome_icon.png",
tooltip = S("Go home"),
hide_lite=true,
action = function(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {home=true}) then
minetest.sound_play("teleport",
{to_player=player:get_player_name(), gain = 1.0})
unified_inventory.go_home(player)
else
minetest.chat_send_player(player_name,
S("You don't have the \"home\" privilege!"))
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
end
end,
condition = function(player)
return minetest.check_player_privs(player:get_player_name(), {home=true})
end,
})
unified_inventory.register_button("misc_set_day", {
type = "image",
image = "ui_sun_icon.png",
@ -217,77 +266,65 @@ unified_inventory.register_page("craftguide", {
local player_name = player:get_player_name()
local player_privs = minetest.get_player_privs(player_name)
local fs = {
"background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]",
"label[0,"..formheadery..";" .. F(S("Crafting Guide")) .. "]",
"listcolors[#00000000;#00000000]"
}
local formspec = ""
formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]"
formspec = formspec.."label[0,"..formheadery..";" .. F(S("Crafting Guide")) .. "]"
formspec = formspec.."listcolors[#00000000;#00000000]"
local item_name = unified_inventory.current_item[player_name]
if not item_name then
return { formspec = table.concat(fs) }
end
if not item_name then return {formspec=formspec} end
local item_name_shown
if minetest.registered_items[item_name]
and minetest.registered_items[item_name].description then
item_name_shown = string.format(S("%s (%s)"),
minetest.registered_items[item_name].description, item_name)
if minetest.registered_items[item_name] and minetest.registered_items[item_name].description then
item_name_shown = string.format(S("%s (%s)"), minetest.registered_items[item_name].description, item_name)
else
item_name_shown = item_name
end
local dir = unified_inventory.current_craft_direction[player_name]
local rdir = dir == "recipe" and "usage" or "recipe"
local rdir
if dir == "recipe" then rdir = "usage" end
if dir == "usage" then rdir = "recipe" end
local crafts = unified_inventory.crafts_for[dir][item_name]
local alternate = unified_inventory.alternate[player_name]
local alternates, craft
if crafts and #crafts > 0 then
if crafts ~= nil and #crafts > 0 then
alternates = #crafts
craft = crafts[alternate]
end
local has_give = player_privs.give or unified_inventory.is_creative(player_name)
local has_creative = player_privs.give or player_privs.creative or
minetest.settings:get_bool("creative_mode")
fs[#fs + 1] = "background[0.5,"..(formspecy + 0.2)..";8,3;ui_craftguide_form.png]"
fs[#fs + 1] = string.format("textarea[%f,%f;10,1;;%s: %s;]",
craftresultx, craftresulty, F(role_text[dir]), item_name_shown)
fs[#fs + 1] = stack_image_button(0, formspecy, 1.1, 1.1,
"item_button_" .. rdir .. "_", ItemStack(item_name))
formspec = formspec.."background[0.5,"..(formspecy + 0.2)..";8,3;ui_craftguide_form.png]"
formspec = formspec.."textarea["..craftresultx..","..craftresulty
..";10,1;;"..F(role_text[dir])..": "..item_name_shown..";]"
formspec = formspec..stack_image_button(0, formspecy, 1.1, 1.1, "item_button_"
.. rdir .. "_", ItemStack(item_name))
if not craft then
-- No craft recipes available for this item.
fs[#fs + 1] = "label[5.5,"..(formspecy + 2.35)..";"
.. F(no_recipe_text[dir]) .. "]"
formspec = formspec.."label[5.5,"..(formspecy + 2.35)..";"
..F(no_recipe_text[dir]).."]"
local no_pos = dir == "recipe" and 4.5 or 6.5
local item_pos = dir == "recipe" and 6.5 or 4.5
fs[#fs + 1] = "image["..no_pos..","..formspecy..";1.1,1.1;ui_no.png]"
fs[#fs + 1] = stack_image_button(item_pos, formspecy, 1.1, 1.1,
"item_button_" .. other_dir[dir] .. "_", ItemStack(item_name))
if has_give then
fs[#fs + 1] = "label[0," .. (formspecy + 2.10) .. ";" .. F(S("Give me:")) .. "]"
.. "button[0, " .. (formspecy + 2.7) .. ";0.6,0.5;craftguide_giveme_1;1]"
.. "button[0.6," .. (formspecy + 2.7) .. ";0.7,0.5;craftguide_giveme_10;10]"
.. "button[1.3," .. (formspecy + 2.7) .. ";0.8,0.5;craftguide_giveme_99;99]"
formspec = formspec.."image["..no_pos..","..formspecy..";1.1,1.1;ui_no.png]"
formspec = formspec..stack_image_button(item_pos, formspecy, 1.1, 1.1, "item_button_"
..other_dir[dir].."_", ItemStack(item_name))
if has_creative then
formspec = formspec.."label[0,"..(formspecy + 2.10)..";" .. F(S("Give me:")) .. "]"
.."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
.."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
.."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
end
return { formspec = table.concat(fs) }
return {formspec = formspec}
end
local craft_type = unified_inventory.registered_craft_types[craft.type] or
unified_inventory.craft_type_defaults(craft.type, {})
if craft_type.icon then
fs[#fs + 1] = string.format("image[%f,%f;%f,%f;%s]",
5.7, (formspecy + 0.05), 0.5, 0.5, craft_type.icon)
formspec = formspec..string.format(" image[%f,%f;%f,%f;%s]",5.7,(formspecy + 0.05),0.5,0.5,craft_type.icon)
end
fs[#fs + 1] = "label[5.5,"..(formspecy + 1)..";" .. F(craft_type.description).."]"
fs[#fs + 1] = stack_image_button(6.5, formspecy, 1.1, 1.1,
"item_button_usage_", ItemStack(craft.output))
local display_size = craft_type.dynamic_display_size
and craft_type.dynamic_display_size(craft)
or { width = craft_type.width, height = craft_type.height }
local craft_width = craft_type.get_shaped_craft_width
and craft_type.get_shaped_craft_width(craft)
or display_size.width
formspec = formspec.."label[5.5,"..(formspecy + 1)..";" .. F(craft_type.description).."]"
formspec = formspec..stack_image_button(6.5, formspecy, 1.1, 1.1, "item_button_usage_", ItemStack(craft.output))
local display_size = craft_type.dynamic_display_size and craft_type.dynamic_display_size(craft) or { width = craft_type.width, height = craft_type.height }
local craft_width = craft_type.get_shaped_craft_width and craft_type.get_shaped_craft_width(craft) or display_size.width
-- This keeps recipes aligned to the right,
-- so that they're close to the arrow.
@ -322,67 +359,63 @@ unified_inventory.register_page("craftguide", {
local xof = (fx-1) * of + of
local yof = (y-1) * of + 1
if item then
fs[#fs + 1] = stack_image_button(
formspec = formspec..stack_image_button(
xoffset - xof, formspecy - 1 + yof, bsize_w, bsize_h,
"item_button_recipe_",
ItemStack(item))
else
-- Fake buttons just to make grid
fs[#fs + 1] = string.format("image_button[%f,%f;%f,%f;ui_blank_image.png;;]",
xoffset - xof, formspecy - 1 + yof, bsize_w, bsize_h)
formspec = formspec.."image_button["
..tostring(xoffset - xof)..","..tostring(formspecy - 1 + yof)
..";"..bsize_w..","..bsize_h..";ui_blank_image.png;;]"
end
end
end
else
-- Error
fs[#fs + 1] = string.format("label[2,%f;%s]",
formspecy, F(S("This recipe is too\nlarge to be displayed.")))
formspec = formspec.."label["
..tostring(2)..","..tostring(formspecy)
..";"..F(S("This recipe is too\nlarge to be displayed.")).."]"
end
if craft_type.uses_crafting_grid and display_size.width <= 3 then
fs[#fs + 1] = "label[0," .. (formspecy + 0.9) .. ";" .. F(S("To craft grid:")) .. "]"
.. "button[0, " .. (formspecy + 1.5) .. ";0.6,0.5;craftguide_craft_1;1]"
.. "button[0.6," .. (formspecy + 1.5) .. ";0.7,0.5;craftguide_craft_10;10]"
.. "button[1.3," .. (formspecy + 1.5) .. ";0.8,0.5;craftguide_craft_max;" .. F(S("All")) .. "]"
formspec = formspec.."label[0,"..(formspecy + 0.9)..";" .. F(S("To craft grid:")) .. "]"
.."button[0, "..(formspecy + 1.5)..";0.6,0.5;craftguide_craft_1;1]"
.."button[0.6,"..(formspecy + 1.5)..";0.7,0.5;craftguide_craft_10;10]"
.."button[1.3,"..(formspecy + 1.5)..";0.8,0.5;craftguide_craft_max;" .. F(S("All")) .. "]"
end
if has_give then
fs[#fs + 1] = "label[0," .. (formspecy + 2.1) .. ";" .. F(S("Give me:")) .. "]"
.. "button[0, " .. (formspecy + 2.7) .. ";0.6,0.5;craftguide_giveme_1;1]"
.. "button[0.6," .. (formspecy + 2.7) .. ";0.7,0.5;craftguide_giveme_10;10]"
.. "button[1.3," .. (formspecy + 2.7) .. ";0.8,0.5;craftguide_giveme_99;99]"
if has_creative then
formspec = formspec.."label[0,"..(formspecy + 2.1)..";" .. F(S("Give me:")) .. "]"
.."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
.."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
.."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
end
if alternates and alternates > 1 then
fs[#fs + 1] = "label[5.5," .. (formspecy + 1.6) .. ";"
.. string.format(F(recipe_text[dir]), alternate, alternates) .. "]"
.. "image_button[5.5," .. (formspecy + 2) .. ";1,1;ui_left_icon.png;alternate_prev;]"
.. "image_button[6.5," .. (formspecy + 2) .. ";1,1;ui_right_icon.png;alternate;]"
.. "tooltip[alternate_prev;" .. F(prev_alt_text[dir]) .. "]"
.. "tooltip[alternate;" .. F(next_alt_text[dir]) .. "]"
formspec = formspec.."label[5.5,"..(formspecy + 1.6)..";"
..string.format(F(recipe_text[dir]), alternate, alternates).."]"
.."image_button[5.5,"..(formspecy + 2)..";1,1;ui_left_icon.png;alternate_prev;]"
.."image_button[6.5,"..(formspecy + 2)..";1,1;ui_right_icon.png;alternate;]"
.."tooltip[alternate_prev;"..F(prev_alt_text[dir]).."]"
.."tooltip[alternate;"..F(next_alt_text[dir]).."]"
end
return { formspec = table.concat(fs) }
return {formspec = formspec}
end,
})
local function craftguide_giveme(player, formname, fields)
local player_name = player:get_player_name()
local player_privs = minetest.get_player_privs(player_name)
if not player_privs.give and
not unified_inventory.is_creative(player_name) then
minetest.log("action", "[unified_inventory] Denied give action to player " ..
player_name)
return
end
local amount
for k, v in pairs(fields) do
amount = k:match("craftguide_giveme_(.*)")
if amount then break end
end
if not amount then return end
amount = tonumber(amount) or 0
amount = tonumber(amount)
if amount == 0 then return end
local player_name = player:get_player_name()
local output = unified_inventory.current_item[player_name]
if (not output) or (output == "") then return end
@ -391,63 +424,78 @@ local function craftguide_giveme(player, formname, fields)
player_inv:add_item("main", {name = output, count = amount})
end
-- Takes any stack from "main" where the `amount` of `needed_item` may fit
-- into the given crafting stack (`craft_item`)
local function craftguide_move_stacks(inv, craft_item, needed_item, amount)
if craft_item:get_count() >= amount then
-- tells if an item can be moved and returns an index if so
local function item_fits(player_inv, craft_item, needed_item)
local need_group = string.sub(needed_item, 1, 6) == "group:"
if need_group then
need_group = string.sub(needed_item, 7)
end
if craft_item
and not craft_item:is_empty() then
local ciname = craft_item:get_name()
-- abort if the item there isn't usable
if ciname ~= needed_item
and not need_group then
return
end
-- abort if no item fits onto it
if craft_item:get_count() >= craft_item:get_definition().stack_max then
return
end
-- use the item there if it's in the right group and a group item is needed
if need_group then
if minetest.get_item_group(ciname, need_group) == 0 then
return
end
needed_item = ciname
need_group = false
end
end
if need_group then
-- search an item of the specific group
for i,item in pairs(player_inv:get_list("main")) do
if not item:is_empty()
and minetest.get_item_group(item:get_name(), need_group) > 0 then
return i
end
end
-- no index found
return
end
local get_item_group = minetest.get_item_group
local group = needed_item:match("^group:(.+)")
if group then
if not craft_item:is_empty() then
-- Source item must be the same to fill
if get_item_group(craft_item:get_name(), group) ~= 0 then
needed_item = craft_item:get_name()
else
-- TODO: Maybe swap unmatching "craft" items
-- !! Would conflict with recursive function call
return
end
else
-- Take matching group from the inventory (biggest stack)
local main = inv:get_list("main")
local max_found = 0
for i, stack in ipairs(main) do
if stack:get_count() > max_found and
get_item_group(stack:get_name(), group) ~= 0 then
needed_item = stack:get_name()
max_found = stack:get_count()
if max_found >= amount then
break
end
end
end
end
else
if not craft_item:is_empty() and
craft_item:get_name() ~= needed_item then
return -- Item must be identical
-- search an item with a the name needed_item
for i,item in pairs(player_inv:get_list("main")) do
if not item:is_empty()
and item:get_name() == needed_item then
return i
end
end
needed_item = ItemStack(needed_item)
local to_take = math.min(amount, needed_item:get_stack_max())
to_take = to_take - craft_item:get_count()
if to_take <= 0 then
return -- Nothing to do
end
needed_item:set_count(to_take)
-- no index found
end
local taken = inv:remove_item("main", needed_item)
local leftover = taken:add_item(craft_item)
if not leftover:is_empty() then
-- Somehow failed to add the existing "craft" item. Undo the action.
inv:add_item("main", leftover)
return taken
-- modifies the player inventory and returns the changed craft_item if possible
local function move_item(player_inv, craft_item, needed_item)
local stackid = item_fits(player_inv, craft_item, needed_item)
if not stackid then
return
end
return taken
local wanted_stack = player_inv:get_stack("main", stackid)
local taken_item = wanted_stack:take_item()
player_inv:set_stack("main", stackid, wanted_stack)
if not craft_item
or craft_item:is_empty() then
return taken_item
end
craft_item:add_item(taken_item)
return craft_item
end
local function craftguide_craft(player, formname, fields)
@ -457,21 +505,15 @@ local function craftguide_craft(player, formname, fields)
if amount then break end
end
if not amount then return end
amount = tonumber(amount) or 99 -- fallback for "all"
if amount <= 0 or amount > 99 then return end
local player_name = player:get_player_name()
local output = unified_inventory.current_item[player_name] or ""
if output == "" then return end
local output = unified_inventory.current_item[player_name]
if (not output) or (output == "") then return end
local player_inv = player:get_inventory()
local craft_list = player_inv:get_list("craft")
local crafts = unified_inventory.crafts_for[
unified_inventory.current_craft_direction[player_name]][output] or {}
if #crafts == 0 then return end
local crafts = unified_inventory.crafts_for[unified_inventory.current_craft_direction[player_name]][output]
if (not crafts) or (#crafts == 0) then return end
local alternate = unified_inventory.alternate[player_name]
@ -479,17 +521,24 @@ local function craftguide_craft(player, formname, fields)
if craft.width > 3 then return end
local needed = craft.items
local craft_list = player_inv:get_list("craft")
local width = craft.width
if width == 0 then
-- Shapeless recipe
width = 3
end
-- To spread the items evenly
local STEPSIZE = math.ceil(math.sqrt(amount) / 5) * 5
local current_count = 0
repeat
current_count = math.min(current_count + STEPSIZE, amount)
amount = tonumber(amount) or 99
--[[
if amount == "max" then
amount = 99 -- Arbitrary; need better way to do this.
else
amount = tonumber(amount)
end--]]
for iter = 1, amount do
local index = 1
for y = 1, 3 do
for x = 1, width do
@ -497,9 +546,7 @@ local function craftguide_craft(player, formname, fields)
if needed_item then
local craft_index = ((y - 1) * 3) + x
local craft_item = craft_list[craft_index]
local newitem = craftguide_move_stacks(player_inv,
craft_item, needed_item, current_count)
local newitem = move_item(player_inv, craft_item, needed_item)
if newitem then
craft_list[craft_index] = newitem
end
@ -507,7 +554,7 @@ local function craftguide_craft(player, formname, fields)
index = index + 1
end
end
until current_count == amount
end
player_inv:set_list("craft", craft_list)
@ -515,10 +562,6 @@ local function craftguide_craft(player, formname, fields)
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "" then
return
end
for k, v in pairs(fields) do
if k:match("craftguide_craft_") then
craftguide_craft(player, formname, fields)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 456 B

After

Width:  |  Height:  |  Size: 546 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 961 B

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 658 B

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 928 B

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 B

After

Width:  |  Height:  |  Size: 81 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 483 B

After

Width:  |  Height:  |  Size: 896 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 962 B

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 629 B

After

Width:  |  Height:  |  Size: 988 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -174,7 +174,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields["set_waypoint"..i] then
hit = true
local pos = player:get_pos()
local pos = player:getpos()
pos.x = math.floor(pos.x)
pos.y = math.floor(pos.y)
pos.z = math.floor(pos.z)