Using hopper.lua as a library - umnikos/hopper.lua GitHub Wiki
Hopper.lua can be used within scripts by importing the file as a library. This will give you a single function called hopper
, which accepts an arguments string with the exact same syntax as the command line interface. This is better than using shell.run()
to call hopper.lua because it allows for caching various data and thus way faster transfer. The function passes -once -quiet
by default, use -forever
and -verbose
to override them.
Example program to autocraft buckets:
local hopper = require("hopper")
turtle.select(16)
while true do
-- fill inventory with iron
hopper("*storage*_6958 self *:iron_ingot -to_slot 1 -to_slot 3 -to_slot 6 -to_limit 16 -per_slot")
-- check how many slots have at least 1 iron ingot in them
local count = hopper("self void *:iron_ingot -transfer_limit 1 -per_slot")
if count >= 3 then
-- all is good, craft!
turtle.craft(16)
end
-- regardless of success, output the buckets
hopper("self *storage*_6959 *bucket* -to_slot_range 1 9")
sleep(1)
end
Chest ender_storage_6958
is full of iron ingots and chest ender_storage_6959
is where the finished buckets should go. The program is written in such a way as to not break if the turtle randomly gets rebooted or the source chest runs out of iron ingots.