robocyclone

Turtle hay craft 2

Feb 27th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. function suck()
  2.     local s, i = turtle.inspect()
  3.     if s then
  4.         if i.name == "minecraft:chest" or i.name == "ironchest:BlockIronChest" then
  5.             for i = 1, 9 do turtle.suck() end
  6.             return
  7.         end
  8.     end
  9.     print("No chest infront of turtle")
  10. end
  11.  
  12. function dropAll()
  13.     for i = 1, 16 do
  14.         turtle.select(i)
  15.         if turtle.getItemDetail() then
  16.             if turtle.getItemDetail().name == "minecraft:wheat" then
  17.                 turtle.drop()
  18.             elseif turtle.getItemDetail().name == "minecraft:hay_block" then
  19.                 turtle.turnRight() turtle.turnRight()
  20.                 turtle.drop()
  21.                 turtle.turnRight() turtle.turnRight()
  22.             end
  23.         end
  24.     end
  25.     turtle.select(1)
  26. end
  27.  
  28. function check64()
  29.     local wheatNum = 0
  30.     for i = 1, 16 do
  31.         turtle.select(i)
  32.         wheatNum = wheatNum + turtle.getItemCount()
  33.     end
  34.     print(wheatNum)
  35.     if wheatNum == 576 then
  36.         print(wheatNum .. " >= 576")
  37.         return true
  38.     else print(wheatNum .. " < 576") return false end
  39. end
  40.  
  41. function craftFail()
  42.     print("Craft failed")
  43.     for i = 1, 16 do
  44.         turtle.select(i)
  45.         if turtle.getItemDetail() then print("Item exists") if turtle.getItemDetail().name == "minecraft:wheat" then print("Item is wheat")
  46.             turtle.drop() end
  47.         end
  48.     end
  49. end
  50.  
  51. function sort()
  52.     turtle.select(4)
  53.     turtle.transferTo(10, 64)
  54.     turtle.select(8)
  55.     turtle.transferTo(11, 64)
  56. end
  57.  
  58. function craftSucc()
  59.     for i = 1, 2 do turtle.turnRight() end
  60.     turtle.drop()
  61.     for i = 1, 2 do turtle.turnRight() end
  62. end
  63.  
  64. function craftHay()
  65.     dropAll()
  66.     suck()
  67.     if check64 then
  68.         sort()
  69.         print("Enough wheat for hay bales")
  70.         turtle.craft(64)
  71.         craftSucc()
  72.     else
  73.         print("Not enough wheat")
  74.         craftFail()
  75.     end
  76. end
  77.  
  78. while true do
  79.     craftHay()
  80.     sleep(300)
  81. end
Advertisement
Add Comment
Please, Sign In to add comment