Skip to content

Commit

Permalink
added egg collector
Browse files Browse the repository at this point in the history
  • Loading branch information
asweigart committed Aug 1, 2016
1 parent e26cc84 commit dd0fdf0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
59 changes: 59 additions & 0 deletions book/eggcollector.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- Egg Collector program
-- By Al Sweigart
-- al@inventwithpython.com
-- Collects eggs in a field.

os.loadAPI('hare')

local cliArgs = {...}
local rowsArg = tonumber(cliArgs[1])
local columnsArg = tonumber(cliArgs[2])

if columnsArg == nil then
print('Usage: eggcollect rows columns')
return
end


function storeItems()
if not hare.findBlock('minecraft:chest') then -- face the chest
print('Warning: Could not find chest.')
return
end

-- drop off items
local slot
for slot=1,16 do
turtle.select(slot)
turtle.drop()
end

-- face field again
turtle.turnLeft()
turtle.turnLeft()
end


print('Hold Ctrl+T to stop.')
if not hare.findBlock('minecraft:chest') then
print('ERROR: Must start next to a chest!')
end

-- face field
turtle.turnLeft()
turtle.turnLeft()

while true do
-- check fuel
if turtle.getFuelLevel() < (rowsArg * columnsArg) + rowsArg + columnsArg then
print('ERROR: Not enough fuel.')
return
end

-- collect eggs
print('Sweeping field...')
hare.sweepField(rowsArg, columnsArg, turtle.suckDown, storeItems)

print('Sleeping for 5 minutes...')
os.sleep(300)
end
1 change: 0 additions & 1 deletion book/harev2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,3 @@ function countItems(name)
end
return total
end

0 comments on commit dd0fdf0

Please sign in to comment.