Advertisement
demon012

Minecraft - Planter Turtle

Feb 8th, 2015
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.91 KB | None | 0 0
  1. function performPlanting()
  2.     -- get seeds
  3.     turtle.suck()
  4.  
  5.     -- move to the initial planting position
  6.     moveToPlant()
  7.  
  8.     -- perform planting
  9.     plantFarm(6,9)
  10.  
  11.     -- return to home
  12.     returnHome()
  13. end
  14.  
  15. function moveToPlant()--{{{
  16.     turtle.turnRight()
  17.     forward(2)
  18.     moveUp(4)
  19.     turtle.turnRight()
  20.     forward(2)
  21.     turtle.turnRight()
  22.     forward(2)
  23. end--}}}
  24.  
  25. function plantFarm(rowLength, rows, direction)--{{{
  26.     if direction == nil then
  27.         direction = "right"
  28.     end
  29.     for row = 1, rows do
  30.         for count = 1, rowLength do
  31.             -- plant crop
  32.             turtle.placeDown()
  33.  
  34.             -- move forward
  35.             forward()
  36.         end
  37.  
  38.         if row ~= rows then
  39.             -- turn at end of row
  40.             turtle.placeDown()
  41.             if direction == "right" then
  42.                 turtle.turnRight()
  43.                 forward(1)
  44.                 turtle.turnRight()
  45.                 direction = "left"
  46.             else
  47.                 turtle.turnLeft()
  48.                 forward(1)
  49.                 turtle.turnLeft()
  50.                 direction = "right"
  51.             end
  52.         end
  53.     end
  54. end--}}}
  55.  
  56. function returnHome()--{{{
  57.     turtle.placeDown()
  58.     turnAround()
  59.     forward(8)
  60.     turtle.turnRight()
  61.     forward(6)
  62.     moveDown(4)
  63.     turtle.turnRight()
  64.     forward(2)
  65.     turtle.turnRight()
  66. end--}}}
  67.  
  68. function forward(distance)--{{{
  69.     if distance == nil then
  70.         distance = 1
  71.     end
  72.     for count = 1, distance do
  73.         local moved = false
  74.         while not moved do
  75.             moved = turtle.forward()
  76.         end
  77.     end
  78. end--}}}
  79.  
  80. function moveUp(distance)--{{{
  81.     if distance == nil then
  82.         distance = 1
  83.     end
  84.     for count = 1, distance do
  85.         local moved = false
  86.         while not moved do
  87.             moved = turtle.up()
  88.         end
  89.     end
  90. end--}}}
  91.  
  92. function moveDown(distance)--{{{
  93.     if distance == nil then
  94.         distance = 1
  95.     end
  96.     for count = 1, distance do
  97.         local moved = false
  98.         while not moved do
  99.             moved = turtle.down()
  100.         end
  101.     end
  102. end--}}}
  103.  
  104. function turnAround()--{{{
  105.     turtle.turnRight()
  106.     turtle.turnRight()
  107. end--}}}
  108.  
  109. local redstoneEventCount = 0
  110. local justPlanted = false
  111. turtle.select(1)
  112.  
  113. while true do
  114.     eventName, event1, event2, event3 = os.pullEvent("redstone")
  115.  
  116.     if eventName == "redstone" then
  117.         if justPlanted == false then
  118.             redstoneEventCount = redstoneEventCount + 1
  119.         else
  120.             justPlanted = false
  121.         end
  122.         print("Redstone Event Count == " .. redstoneEventCount)
  123.         if redstoneEventCount == 2 then
  124.             print("Waiting for seeds")
  125.             os.sleep(10)
  126.             print("Planting")
  127.             performPlanting()
  128.             print("finished planting")
  129.             redstoneEventCount = 0
  130.             justPlanted = true
  131.         end
  132.     end
  133.  
  134. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement