Taruu

Farmer.lua

Jan 20th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. -- pastebin run Pc6MGrfZ
  2. local robot = require("robot")
  3. local comp = require("computer")
  4. local component = require("component")
  5. local sides = require("sides")
  6. local item = component.inventory_controller
  7.  
  8.  
  9. slotrobot = robot.inventorySize()
  10. colvo = 16
  11. needseeds = 256
  12.  
  13.  
  14.  
  15.  
  16. robot.select(1)
  17.  
  18.  
  19.  
  20. function go()
  21.     slot = slotget(1)
  22.     if slot["name"] ~= "minecraft:wheat_seeds" then
  23.         seed()
  24.     end
  25.     status = robot.forward()
  26.     robot.swingDown()
  27.     robot.placeDown()
  28.     return status
  29. end
  30.  
  31. function slotget(idslot)
  32.     idslot = tonumber(idslot)
  33.     if item.getStackInInternalSlot(idslot) ~= nil then
  34.         get = item.getStackInInternalSlot(idslot)
  35.         resp = {name = get.name, size = get.size}
  36.     else
  37.         resp = {name = "none", size = 0}
  38.     end
  39.     return resp
  40. end
  41.  
  42. function clearinv()
  43.     print("use clearinv()")
  44.     for i = 1, slotrobot do
  45.         slot = slotget(i)
  46.         if slot["name"] ~= "minecraft:wheat_seeds" and slot["name"] ~= "minecraft:wheat" and slot["name"] == "none" then
  47.             robot.select(i)
  48.             robot.dropDown()
  49.             print("Мусора удален слоте:", i)
  50.         else
  51.             print("Мусора нет в слоте:", i)
  52.         end
  53.     end
  54. end
  55.  
  56. function seed()
  57.     print("use seed()")
  58.     robot.select(1)
  59.     slot1 = slotget(1)
  60.     if slot1["name"] ~= "minecraft:wheat_seeds" then
  61.         for i = 2, slotrobot do
  62.             getslot = slotget(i)
  63.             if getslot["name"] == "minecraft:wheat_seeds" and getslot["size"] + slot1["size"] <= 64 or getslot["size"] == 0 then
  64.                 robot.transferTo(i)
  65.             end
  66.         end
  67.     end
  68.     if slot1["size"] == 0 then
  69.         for i = 1, slotrobot do
  70.             getslot = slotget(i)
  71.             if getslot["name"] == "minecraft:wheat_seeds" then
  72.                 robot.select(i)
  73.                 if slot1["size"] < 64 then
  74.                     robot.transferTo(1)
  75.                 end
  76.             end
  77.         end
  78.     end
  79.     robot.select(1)
  80. end
  81. function gotohome()
  82.     print("use gotohome()")
  83.     robot.turnRight()
  84.     repeat
  85.     status = robot.forward()
  86.     until status == nil
  87.     robot.turnRight()
  88.     robot.forward()
  89. end
  90. function clearinvwheat()
  91.     print("use clearinvwheat()")
  92.     seeds = 0
  93.     print(slotrobot)
  94.     for i = 1, slotrobot do
  95.         getslot = slotget(i)
  96.         print(getslot["size"])
  97.         if getslot["name"] == "minecraft:wheat" then
  98.             robot.select(i)
  99.             robot.drop()
  100.         end
  101.     end
  102.     clearinv()
  103.     for i = 1, slotrobot do
  104.         getslot = slotget(i)
  105.         if seeds >= needseeds then
  106.             robot.select(i)
  107.             robot.drop()
  108.         end
  109.         slotsize = getslot["size"]
  110.         seeds = seeds + slotsize
  111.         print("кол-во семян:",seeds)
  112.     end
  113.     robot.select(1)
  114.     robot.turnRight()
  115.     robot.turnRight()
  116. end
  117.    
  118. function work()
  119.     print("use work()")
  120.     repeat
  121.     go()
  122.     until status == nil
  123. end
  124. function worked()
  125.     print("use worked()")
  126.  
  127.     for i = 1, colvo/2 do
  128.         print(i)
  129.         work()
  130.         robot.turnLeft()
  131.         robot.forward()
  132.         robot.turnLeft()
  133.         robot.swingDown()
  134.         robot.placeDown()
  135.         work()
  136.         robot.turnRight()
  137.         robot.forward()
  138.         robot.turnRight()
  139.         robot.swingDown()
  140.         robot.placeDown()
  141.     end
  142. end
  143.  
  144. while true do
  145.   -- one hour sleeping
  146.     print("НАЧАЛО")
  147.     clearinv()
  148.     robot.select(1)
  149.     seed()
  150.     worked()
  151.     gotohome()
  152.     clearinvwheat()
  153.     print("Ожидание")
  154.     for i=1, 10 do
  155.         print((10*i)..'%')
  156.         os.sleep(360)  
  157.     end
  158. end
Add Comment
Please, Sign In to add comment