Lupino

plant.lua

Jun 23rd, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. local robot = require('robot')
  2. local component = require('component')
  3. local craft = require('craft')
  4.  
  5. local dye = 'Bone Meal'
  6. local bone = 'Bone'
  7. local boneBlock = 'Bone Block'
  8. local fruitBone = 'Boneus Fruit'
  9. local currentDyeSlot = 2
  10. local currentSeedSlot = 1
  11.  
  12. local seed = craft.getItemName(1)
  13.  
  14. function placeItem(slot)
  15.     print('placeItem', slot)
  16.     local count = robot.count(slot)
  17.  
  18.     robot.select(slot)
  19.     robot.placeDown()
  20.  
  21.     if robot.count(slot) < count then
  22.         return true
  23.     else
  24.         return false
  25.     end
  26. end
  27.  
  28. function placeSeed()
  29.     if craft.isItem(currentSeedSlot, seed) then
  30.         if not placeItem(currentSeedSlot) then
  31.             robot.useDown()
  32.         end
  33.     end
  34.     local slot = craft.findItem(seed, 1)
  35.     if slot == 0 then
  36.         slot = craft.findItemOnSides(seed)
  37.         if slot == 0 then
  38.             return false
  39.         end
  40.     end
  41.     currentSeedSlot = slot
  42.     return placeSeed()
  43. end
  44.  
  45. function placeDye()
  46.     if craft.isItem(currentDyeSlot, dye) then
  47.         if placeItem(currentDyeSlot) then
  48.             return 1
  49.         else
  50.             return 0
  51.         end
  52.     end
  53.     local slot = craft.findItem(dye, 1)
  54.     if slot == 0 then
  55.         slot = craft.findItemOnSides(dye)
  56.         if slot == 0 then
  57.             return 2
  58.         end
  59.     end
  60.     currentDyeSlot = slot
  61.     return placeDye()
  62. end
  63.  
  64. function runPlaceDye()
  65.     local ret = placeDye()
  66.     if ret == 2 then
  67.         craft.mergeItems()
  68.         if not craft.crafting1(boneBlock) then
  69.             if not craft.crafting1(bone) then
  70.                 if not craft.crafting1(fruitBone) then
  71.                     return false
  72.                 end
  73.             end
  74.         end
  75.     elseif ret == 0 then
  76.         return true
  77.     end
  78.     return runPlaceDye()
  79. end
  80.  
  81. function main()
  82.     -- craft.scanItemsOnSides()
  83.     robot.swingDown()
  84.     if seed == '' then
  85.         print('Error: seed not found.')
  86.         return
  87.     end
  88.     while true do
  89.         if not placeSeed() then
  90.             break
  91.         end
  92.         if not runPlaceDye() then
  93.             break
  94.         end
  95.         robot.swingDown()
  96.     end
  97. end
  98.  
  99. main()
Advertisement
Add Comment
Please, Sign In to add comment