Change the HP pusher and chest so that partial stacks can also be moved

This commit is contained in:
Joachim Stolberg 2021-08-01 16:11:12 +02:00
parent 786cc85a1e
commit 881696e9bc
2 changed files with 14 additions and 3 deletions

@ -151,7 +151,14 @@ tubelib.register_node("tubelib_addons3:chest", {}, {
end,
on_push_item = function(pos, side, item)
local meta = minetest.get_meta(pos)
return tubelib.put_item(meta, "main", item)
local res = tubelib.put_item(meta, "main", item)
if res == false then
local inv = meta:get_inventory()
local leftover = inv:add_item("main", item)
item:set_count(leftover:get_count())
return false
end
return true
end,
on_unpull_item = function(pos, side, item)
local meta = minetest.get_meta(pos)

@ -42,11 +42,15 @@ local function pushing(pos, meta)
local player_name = meta:get_string("player_name")
local items = tubelib.pull_stack(pos, "L", player_name)
if items ~= nil then
local count = items:get_count()
if tubelib.push_items(pos, "R", items, player_name) == false then
-- place item back
tubelib.unpull_items(pos, "L", items, player_name)
State:blocked(pos, meta)
return
-- Complete stack rejected
if count == items:get_count() then
State:blocked(pos, meta)
return
end
end
if State.get_state(pos, meta) ~= tubelib.STOPPED then
State:keep_running(pos, meta, COUNTDOWN_TICKS, 1)