Improve default sorting
parent
f2706fb38b
commit
b25a14188a
17
init.lua
17
init.lua
|
@ -56,8 +56,23 @@ local get_items = function(filter)
|
||||||
table.insert(it, {itemstring=itemstring, itemdef=itemdef})
|
table.insert(it, {itemstring=itemstring, itemdef=itemdef})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Sort alphabetically by itemstring
|
-- Default sorting: Move description-less items and
|
||||||
|
-- items not_in_creative_inventory=1 to the end, then sort by itemstring.
|
||||||
local compare = function(t1, t2)
|
local compare = function(t1, t2)
|
||||||
|
local t1d = minetest.registered_items[t1.itemstring].description
|
||||||
|
local t2d = minetest.registered_items[t2.itemstring].description
|
||||||
|
local t1g = minetest.get_item_group(t1.itemstring, "not_in_creative_inventory")
|
||||||
|
local t2g = minetest.get_item_group(t2.itemstring, "not_in_creative_inventory")
|
||||||
|
if (t1d == "" and t2d ~= "") then
|
||||||
|
return false
|
||||||
|
elseif (t1d ~= "" and t2d == "") then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if (t1g == 1 and t2g == 0) then
|
||||||
|
return false
|
||||||
|
elseif (t1g == 0 and t2g == 1) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
return t1.itemstring < t2.itemstring
|
return t1.itemstring < t2.itemstring
|
||||||
end
|
end
|
||||||
table.sort(it, compare)
|
table.sort(it, compare)
|
||||||
|
|
Loading…
Reference in New Issue