--[[

This is used with a construct consisting of a vertical stack of

* some chest (I used wood/copper, it does not have to be big)

* a turtle (with this code)

* ender chest, bound to a pouch

Followed by these items to the NORTH!

logistics remote order pipe (next to chest)

logistics provider pipe (next to turtle)

me interface (next to Ender Chest)

Bind your remote orderer to the remote order pipe,

The turtle monitors the chest above for orders, waits for an

empty slot in the enderchest's bottom row, and then places

said item in there

The turtle also monitors the ender chests top two rows and

spits them into the me interface to return them into your inventory

You may need to power this through a power provider.

]]

local exportChest = peripheral . wrap ( "top" )

local enderChest = peripheral . wrap ( "bottom" )

local exportSlots = 9

function findExportSlot ( )

local start = enderChest . getInventorySize ( ) - exportSlots + 1

local stacks = enderChest . getAllStacks ( )

for i = start , enderChest . getInventorySize ( ) do

if stacks [ i ] == nil then

return i

end

end

return nil

end

function waitForExportSlot ( )

local slot = findExportSlot ( )

while slot == nil do

slot = findExportSlot ( )

os . sleep ( 1 )

end

return slot

end

function exportStack ( i , stack )

local slot = waitForExportSlot ( )

print ( "Found slot " , slot )

exportChest . pushItem ( "down" , i , 64 , 1 )

os . sleep ( .125 )

enderChest . pullItem ( "up" , 1 , 64 , slot )

end

function checkExports ( )

local stacks = exportChest . getAllStacks ( )

for i = 1 , exportChest . getInventorySize ( ) do

local stack = stacks [ i ]

if stack then

exportStack ( i , stack )

end

end

end

function watchExports ( )

while true do

checkExports ( )

os . sleep ( .5 )

end

end

function checkImports ( )

local stacks = enderChest . getAllStacks ( )

local size = enderChest . getInventorySize ( ) - exportSlots

for i = 1 , size do

if stacks [ i ] then

enderChest . pushItem ( "north" , i , 64 , 1 )

os . sleep ( .1 )

end

end

end

function watchImports ( )

while true do

checkImports ( )

os . sleep ( .5 )

end

end

parallel . waitForAny (

watchImports ,

watchExports