Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ======================================
- -- Moon Leaf Placer Turtle
- -- brendan@slayweb.com 2013-06-03
- -- ======================================
- -- ======================
- -- Variables
- -- ======================
- local programrunning = true
- local walllength = 18
- -- ======================
- -- Functions
- -- ======================
- function refuel()
- -- refuel turtle from one of the bottom four slots
- if turtle.getItemCount(16)==64 then
- turtle.select(16)
- turtle.refuel(64)
- else
- if turtle.getItemCount(15)==64 then
- turtle.select(15)
- turtle.refuel(64)
- else
- if turtle.getItemCount(14)==64 then
- turtle.select(14)
- turtle.refuel(64)
- else
- if turtle.getItemCount(13)==64 then
- turtle.select(13)
- turtle.refuel(64)
- else
- programrunning = false
- print("Error: Ran out of fuel")
- end
- end
- end
- end
- end
- function check_fuel()
- if turtle.getFuelLevel()<1 then
- refuel()
- end
- end
- function place_leaf()
- if turtle.getItemCount(1)>0 then
- turtle.select(1)
- turtle.place()
- else
- if turtle.getItemCount(2)>0 then
- turtle.select(2)
- turtle.place()
- else
- if turtle.getItemCount(3)>0 then
- turtle.select(3)
- turtle.place()
- else
- if turtle.getItemCount(4)>0 then
- turtle.select(4)
- turtle.place()
- else
- programrunning = false
- print("Error: Ran out of leaves")
- end
- end
- end
- end
- end
- function need_fuel()
- if turtle.getItemCount(13)==0 then
- turtle.select(13)
- turtle.suck()
- end
- if turtle.getItemCount(14)==0 then
- turtle.select(14)
- turtle.suck()
- end
- if turtle.getItemCount(15)==0 then
- turtle.select(15)
- turtle.suck()
- end
- if turtle.getItemCount(16)==0 then
- turtle.select(16)
- turtle.suck()
- end
- end
- function need_leaves()
- if turtle.getItemCount(1)==0 then
- turtle.select(1)
- turtle.suck()
- end
- if turtle.getItemCount(2)==0 then
- turtle.select(2)
- turtle.suck()
- end
- if turtle.getItemCount(3)==0 then
- turtle.select(3)
- turtle.suck()
- end
- if turtle.getItemCount(4)==0 then
- turtle.select(4)
- turtle.suck()
- end
- end
- -- ======================
- -- Main Program
- -- ======================
- while programrunning==true do
- -- start in front of fuel box
- -- do we need to pick up more fuel?
- need_fuel()
- -- do we need to refuel?
- check_fuel()
- -- move to leaf box
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- -- do we need to restock on leaves?
- need_leaves()
- -- about face
- turtle.turnLeft()
- turtle.turnLeft()
- -- move to top
- turtle.up()
- check_fuel()
- turtle.up()
- check_fuel()
- turtle.up()
- check_fuel()
- -- check row 1 of leaves
- for n = 1,walllength,1 do
- check_fuel()
- if turtle.detect()==false then
- -- move forward
- turtle.forward()
- check_fuel()
- -- place leaf if not there
- if turtle.detect()==false then
- place_leaf()
- end
- -- move back
- turtle.back()
- check_fuel()
- -- place leaf
- place_leaf()
- end
- turtle.turnLeft()
- turtle.forward()
- check_fuel()
- turtle.turnRight()
- end
- -- down for next row
- turtle.down()
- check_fuel()
- -- check row 2 of leaves
- for n = 1,walllength,1 do
- check_fuel()
- if turtle.detect()==false then
- -- move forward
- turtle.forward()
- check_fuel()
- -- place leaf if not there
- if turtle.detect()==false then
- place_leaf()
- end
- -- move back
- turtle.back()
- check_fuel()
- -- place leaf
- place_leaf()
- end
- turtle.turnRight()
- turtle.forward()
- check_fuel()
- turtle.turnLeft()
- end
- -- down for next row
- turtle.down()
- check_fuel()
- -- check row 3 of leaves
- for n = 1,walllength,1 do
- check_fuel()
- if turtle.detect()==false then
- -- move forward
- turtle.forward()
- check_fuel()
- -- place leaf if not there
- if turtle.detect()==false then
- place_leaf()
- end
- -- move back
- turtle.back()
- check_fuel()
- -- place leaf
- place_leaf()
- end
- turtle.turnLeft()
- turtle.forward()
- check_fuel()
- turtle.turnRight()
- end
- -- down for next row
- turtle.down()
- check_fuel()
- -- check row 4 of leaves
- for n = 1,walllength,1 do
- check_fuel()
- if turtle.detect()==false then
- -- move forward
- turtle.forward()
- check_fuel()
- -- place leaf if not there
- if turtle.detect()==false then
- place_leaf()
- end
- -- move back
- turtle.back()
- check_fuel()
- -- place leaf
- place_leaf()
- end
- turtle.turnRight()
- turtle.forward()
- check_fuel()
- turtle.turnLeft()
- end
- -- back to start
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement