Skip to content

Commit 8cbdc83

Browse files
authored
Add support for pulling items out of controller using techage (#101)
1 parent 7f28f7e commit 8cbdc83

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lua/controller.lua

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ local function controller_on_digiline_receive(pos, _, channel, msg)
394394
drawers_index[item:get_name()]["drawer_pos"], item)
395395
local dir = core.facedir_to_dir(core.get_node(pos).param2)
396396

397-
-- prevent crash if taken_stack ended up with a nil value
397+
-- prevent error if taken_stack ended up with a nil value
398398
if taken_stack then
399399
pipeworks.tube_inject_item(pos, pos, dir, taken_stack:to_string())
400400
end
@@ -506,7 +506,23 @@ local function register_controller()
506506
techage.register_node({"drawers:controller"}, {
507507
on_push_item = function(pos, in_dir, stack)
508508
return controller_insert_to_drawers(pos, stack)
509-
end
509+
end,
510+
on_pull_item = function(pos, in_dir, num, item_name)
511+
if not item_name then
512+
return
513+
end
514+
515+
local item = ItemStack(item_name)
516+
local drawers_index = controller_get_drawer_index(pos, item:get_name())
517+
518+
if not drawers_index[item:get_name()] then
519+
-- we can't do anything: the requested item doesn't exist
520+
return
521+
end
522+
523+
item:set_count(num)
524+
return drawers.drawer_take_item(drawers_index[item:get_name()]["drawer_pos"], item)
525+
end,
510526
})
511527
end
512528
end

0 commit comments

Comments
 (0)