Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- TMDart's Modification of
- Lazy Nub's Sugar Cane Harvester v0.01a
- Original code http://www.pastebin.com/wG6EartB
- This program will teach your turtle how to
- harvest a micro farm of sugar cane crops.
- Things you will need are:
- 1 Turtle (Felling,digging,mining does not matter)
- 1 chest (wood,iron,gold,diamond you pick)
- 1 bucket of water
- 4 pieces of sugar cane to plant
- and a fuel source like coal. (fueling slot is slot 1)
- Link to you tube video: http://youtu.be/34B3dsVHU4s
- Link to post of program: http://www.computercraft.info/forums2/index.php?/topic/13176-lazy-nub-sugar-cane-farmer-v001/
- Pastebin link: http://pastebin.com/BXwFpnnc
- Type the following into your turtle to load program: (Must have http enabled)
- pastebin get BXwFpnnc sugarfarm
- To optionally enable automatic restarting:
- pastebin get BXwFpnnc startup
- There are two modes you can run the harvester in:
- Regular and Economy
- In Regular mode you will need to supply fuel to use it.
- In Economy mode you need no fuel in the turtle to use it.
- The following options modified by TMDart to reverse the modes on startup:
- Just start the program as normal to use economy.
- To enter normal mode start the program with /n after the program name.
- ie: sugarfarm /n
- ]]--
- --[[ Robust Turtle
- Modified version of
- Robust Turtle API by SpeedR
- integrated
- ]]--
- --Digging with gravel/sand detection
- local maxTries = 5
- function dig()
- local tries = 0
- while turtle.detect() do
- turtle.dig()
- sleep(0.5)
- tries = tries + 1
- if tries>maxTries then
- print("Error: dug for too long.")
- return false
- end
- end
- return true
- end
- function digUp()
- local tries = 0
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.5)
- tries = tries + 1
- if tries>maxTries then
- print("Error: dug up for too long.")
- return false
- end
- end
- return true
- end
- function digDown()
- local tries = 0
- while turtle.detectDown() do
- turtle.digDown()
- sleep(0.5)
- tries = tries + 1
- if tries>maxTries then
- print("Error: dug down for too long.")
- return false
- end
- end
- return true
- end
- --Traveling: Goes in the direction no matter what (almost)
- --Will not be stopped by blocks or mobs
- function forward(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.forward() ~= true do
- turtle.dig()
- turtle.attack()
- sleep(0.2)
- tries = tries + 1
- if tries>maxTries then
- print("Error: can't move forward.")
- return false
- end
- end
- end
- return true
- end
- function up(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.up() ~= true do
- turtle.digUp()
- turtle.attackUp()
- sleep(0.2)
- tries = tries + 1
- if tries>maxTries then
- print("Error: can't move up.")
- return false
- end
- end
- end
- return true
- end
- function down(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.down() ~= true do
- turtle.digDown()
- turtle.attackDown()
- sleep(0.2)
- tries = tries + 1
- if tries>maxTries then
- print("Error: can't move down.")
- return false
- end
- end
- end
- return true
- end
- function back(l)
- l=l or 1
- for i=1,l do
- if turtle.back() ~= true then
- turnAround()
- forward()
- turnAround()
- end
- end
- end
- --Place blocks
- --Does not place when there's already the right block.
- function place(block)
- turtle.select(block)
- if turtle.compare()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- dig()
- turtle.place()
- end
- end
- function placeUp(block)
- turtle.select(block)
- if turtle.compareUp()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- digUp()
- turtle.placeUp()
- end
- end
- function placeDown(block)
- turtle.select(block)
- if turtle.compareDown()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- digDown()
- turtle.placeDown()
- end
- end
- local function outOfResource()
- print("Ran out of a resource. Block: ",block , ".")
- print("Refill, then say something to proceed.")
- read()
- end
- function placeRight(block)
- turtle.turnRight()
- place(block)
- turtle.turnLeft()
- end
- function placeLeft(block)
- turtle.turnLeft()
- place(block)
- turtle.turnRight()
- end
- function placeBack(block)
- turnAround()
- place(block)
- turnAround()
- end
- --place row e.g. placeRow(up, marble, forward, 15)
- function placeRow(placeDir, block, travelDir, l)
- l=l or 1
- for i=1,l do
- if placeDir == "forward" then
- place(block)
- elseif placeDir == "up" then
- placeUp(block)
- elseif placeDir == "down" then
- placeDown(block)
- elseif placeDir == "right" then
- placeRight(block)
- elseif placeDir == "left" then
- placeLeft(block)
- elseif placeDir == "back" then
- placeBack(block)
- else
- print('"', placeDir, '" is not a valid direction!')
- return false
- end
- if travelDir == "forward" then
- forward()
- elseif travelDir == "up" then
- up()
- elseif travelDir == "down" then
- down()
- elseif travelDir == "right" then
- strafeRight()
- elseif travelDir == "left" then
- strafeLeft()
- elseif travelDir == "back" then
- back()
- else
- print('"', travelDir, '" is not a valid direction!')
- return false
- end
- end
- return true
- end
- --Turning
- function turnAround()
- turtle.turnRight()
- turtle.turnRight()
- end
- function right()
- turtle.turnRight()
- end
- function left()
- turtle.turnLeft()
- end
- function goRight(l)
- l=l or 1
- turtle.turnRight()
- forward(l)
- end
- function goLeft(l)
- l=l or 1
- turtle.turnLeft()
- forward(l)
- end
- function strafeRight(l)
- l=l or 1
- goRight(l)
- turtle.turnLeft()
- end
- function strafeLeft(l)
- l=l or 1
- goLeft(l)
- turtle.turnRight()
- end
- --[[ End of Robust Turtle
- ]]--
- --[[
- MAIN LOOP START HERE
- ]]--
- local args = { ... }
- local running = true
- local isEconoMode = false
- local currFuelLevel = 0
- if (#args == 0) then -- start in Economy Mode or Regular
- isEconoMode = true
- print("Economy Mode Active")
- elseif (args[1] == "/n") then
- isEconoMode = false
- print("Entering Regular Mode")
- end
- while running do -- start of main loop
- while not turtle.dig() do -- start loop looking for harvest-able crop
- term.clear()
- if isEconoMode then
- print("Economy Mode Working...")
- else
- print("Regular Mode Working...")
- end
- left()
- turtle.select(1) -- make sure on fuel slot
- if not isEconoMode then
- currFuelLevel = turtle.getFuelLevel()
- while (currFuelLevel ~= "unlimited")
- and (currFuelLevel < 4) do -- if out of fuel stop to refuel
- print("Need fuel, refuelling from slot 1")
- turtle.refuel()
- currFuelLevel = turtle.getFuelLevel()
- end
- end
- end
- -- got growth so time to harvest
- dig()
- if not isEconoMode then
- down()
- dig()
- end
- turtle.dropDown()
- if not isEconoMode then
- up()
- end
- end -- end of program
Advertisement
Add Comment
Please, Sign In to add comment