Advertisement
Arc13

OC Farm Program

Jul 18th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local robot = require("robot")
  2. local component = require("component")
  3. local geolyzer = component.geolyzer
  4. local sides = require("sides")
  5. local controller = component.inventory_controller
  6. local turtle = robot
  7. local event = require("event")
  8.  
  9. print("Wheat Harvester by arc13 version 1.2")
  10.  
  11. t = geolyzer.analyze(sides.bottom)
  12. local bRun = true
  13.  
  14. robot.select(1)
  15.  
  16. local function detectWheat()
  17.   t = geolyzer.analyze(sides.bottom)
  18.  
  19.   local oldSlot = robot.select()
  20.  
  21.   if robot.count(oldSlot) == 0 or controller.getStackInInternalSlot(oldSlot).name ~= "minecraft:wheat_seeds" then
  22.     --print("no seed in slot "..oldSlot)
  23.     for i = 1, robot.inventorySize() do
  24.       if robot.count(i) > 0 then
  25.         if controller.getStackInInternalSlot(i).name == "minecraft:wheat_seeds" then
  26.           robot.select(i)
  27.           break
  28.         end
  29.       end
  30.     end
  31.   end
  32.  
  33.   if t.metadata == 7 then
  34.     robot.swingDown()
  35.     robot.placeDown()
  36.     robot.select(oldSlot)
  37.     return true
  38.   elseif t.metadata < 7 then
  39.     for i = 1, robot.inventorySize() do
  40.       if robot.count(i) > 0 then
  41.         if controller.getStackInInternalSlot(i).name == "minecraft:dye" and controller.getStackInInternalSlot(i).damage == 15 then
  42.           robot.select(i)
  43.  
  44.           t = geolyzer.analyze(sides.bottom)
  45.           while t.metadata < 7 do
  46.             robot.placeDown()
  47.             t = geolyzer.analyze(sides.bottom)
  48.           end
  49.  
  50.           robot.swingDown()
  51.           robot.select(oldSlot)
  52.           robot.placeDown()
  53.           return true
  54.         end
  55.       end
  56.     end
  57.   elseif not robot.detectDown() then
  58.     robot.placeDown()
  59.     robot.select(oldSlot)
  60.     return false
  61.   else
  62.     robot.select(oldSlot)
  63.     return false
  64.   end
  65. end
  66.  
  67. local function dropWheat()
  68.   for i = 1, robot.inventorySize() do
  69.     if robot.count(i) > 0 then
  70.       if controller.getStackInInternalSlot(i).name == "minecraft:wheat" then
  71.         oldSlot = robot.select()
  72.         robot.select(i)
  73.         robot.drop()
  74.         robot.select(oldSlot)
  75.       elseif controller.getStackInInternalSlot(i).name == "minecraft:wheat_seeds" then
  76.         oldSlot = robot.select()
  77.         robot.select(i)
  78.         robot.transferTo(1)
  79.         robot.select(oldSlot)
  80.       end
  81.     end
  82.   end
  83. end
  84.  
  85. while bRun do
  86.   if not robot.detect() then
  87.     detectWheat()
  88.    
  89.     robot.forward()
  90.   else
  91.     robot.turnRight()
  92.     detectWheat()
  93.     robot.forward()
  94.    
  95.     c = geolyzer.analyze(sides.left)
  96.  
  97.     if c.name == "minecraft:chest" then
  98.       robot.turnLeft()
  99.       dropWheat()
  100.       robot.turnRight()
  101.     end  
  102.    
  103.     robot.turnRight()
  104.   end
  105. end
  106.  
  107. print("Terminated")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement