mirror of
https://github.com/minetest/minetest_game.git
synced 2025-01-08 22:50:16 +01:00
bones inventory reordering
This commit is contained in:
parent
dfd0805e84
commit
58797832e3
@ -64,6 +64,45 @@ end
|
|||||||
local share_bones_time = tonumber(minetest.settings:get("share_bones_time")) or 1200
|
local share_bones_time = tonumber(minetest.settings:get("share_bones_time")) or 1200
|
||||||
local share_bones_time_early = tonumber(minetest.settings:get("share_bones_time_early")) or share_bones_time / 4
|
local share_bones_time_early = tonumber(minetest.settings:get("share_bones_time_early")) or share_bones_time / 4
|
||||||
|
|
||||||
|
local function find_next_empty(inv,listname,start)
|
||||||
|
while start <= inv:get_size(listname) do
|
||||||
|
if inv:get_stack(listname, start):get_count() == 0 then
|
||||||
|
return start
|
||||||
|
end
|
||||||
|
start = start + 1
|
||||||
|
end
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
|
||||||
|
local function find_next_populated(inv, listname, start)
|
||||||
|
while start <= inv:get_size(listname) do
|
||||||
|
if inv:get_stack(listname, start):get_count() > 0 then
|
||||||
|
return start
|
||||||
|
end
|
||||||
|
start = start + 1
|
||||||
|
end
|
||||||
|
return -1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- slot reordering to make sure the first rows of the bone are always populated
|
||||||
|
local function bones_inv_reorder(meta)
|
||||||
|
local next_empty=1 -- there are no empty slots inside the bones before this
|
||||||
|
local next_populated=1 -- there are no populated slots preceded by unpopulated slots before this
|
||||||
|
local inv=meta:get_inventory()
|
||||||
|
next_empty=find_next_empty(inv,"main",next_empty)
|
||||||
|
if next_empty < 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
next_populated=find_next_populated(inv,"main",next_empty+1)
|
||||||
|
while next_populated > 0 do
|
||||||
|
local stack = inv:get_stack("main", next_populated)
|
||||||
|
inv:set_stack("main", next_populated, ItemStack())
|
||||||
|
inv:set_stack("main", next_empty, stack)
|
||||||
|
next_empty=find_next_empty(inv,"main",next_empty+1)
|
||||||
|
next_populated=find_next_populated(inv,"main",next_populated+1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local bones_def = {
|
local bones_def = {
|
||||||
description = S("Bones"),
|
description = S("Bones"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -115,6 +154,8 @@ local bones_def = {
|
|||||||
minetest.add_item(pos, "bones:bones")
|
minetest.add_item(pos, "bones:bones")
|
||||||
end
|
end
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
|
else
|
||||||
|
bones_inv_reorder(meta)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -127,7 +168,8 @@ local bones_def = {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
local player_inv = player:get_inventory()
|
local player_inv = player:get_inventory()
|
||||||
local has_space = true
|
local has_space = true
|
||||||
|
|
||||||
@ -142,14 +184,17 @@ local bones_def = {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- remove bones if player emptied them
|
|
||||||
if has_space then
|
if has_space then
|
||||||
|
-- remove bones if player emptied them
|
||||||
if player_inv:room_for_item("main", {name = "bones:bones"}) then
|
if player_inv:room_for_item("main", {name = "bones:bones"}) then
|
||||||
player_inv:add_item("main", {name = "bones:bones"})
|
player_inv:add_item("main", {name = "bones:bones"})
|
||||||
else
|
else
|
||||||
minetest.add_item(pos,"bones:bones")
|
minetest.add_item(pos,"bones:bones")
|
||||||
end
|
end
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
|
else
|
||||||
|
-- reorder items if player haven't emptied the bones
|
||||||
|
bones_inv_reorder(meta)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user