Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---@diagnostic disable: lowercase-global
- -- Getting fuel level
- local fuelLevel = turtle.getFuelLevel()
- -- Getting GPS coordinates
- local x1, y1, z1 = gps.locate()
- -- Asking user for length and width
- print("How far do you want the turtle to go in front")
- local length = io.read()
- print("How far do you want the turtle to go to the side")
- local width = io.read()
- -- Asking for direction
- print("Would you like the turtle to go left (after it moves one forward) ONLY TYPE 'True' OR 'False'")
- local direction = io.read()
- -- Getting fuel needed
- local fuelNeeded = (length*width) + 1 + (1/2*length) + (1/2*width)
- -- Making function to take crops
- local function getCrop()
- local isBlock, data = turtle.inspectDown()
- if(isBlock)then
- if (string.match(data.name, "croptopia:") and data['state']['age'] == 7) then
- turtle.digDown()
- for i = 6, 1, -1
- do
- turtle.suckDown()
- end
- end
- end
- end
- -- Making function to get the slot index of the seed
- local function getSeedIndex()
- for slot = 1, 16, 1 do
- local item = turtle.getItemDetail(slot)
- if (item ~= nil) then
- if (string.match(item.name, "seed")) then
- return slot
- end
- end
- end
- end
- if(fuelLevel > fuelNeeded) then
- for a = length, 1, -1
- do
- direction = not(direction)
- turtle.forward()
- getCrop()
- local seedIndex = getSeedIndex()
- if(seedIndex ~= nil) then
- turtle.select(seedIndex)
- turtle.placeDown()
- end
- if(direction) then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- for b = width, 1, -1
- do
- turtle.forward()
- getCrop()
- seedIndex = getSeedIndex()
- if(seedIndex ~= nil) then
- turtle.select(seedIndex)
- turtle.placeDown()
- end
- end
- if(direction) then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- -- Getting turtles NEW GPS coordinates
- local x2, y2, z2 = gps.locate()
- -- If the new x-coord is less than the first, then go West (vice versa)
- if x2 < x1 then
- goEast = true
- goWest = false
- elseif x2 > x1 then
- goWest = true
- goEast = false
- else
- goEast = false
- goWest = false
- end
- -- If the new y-coord is less than the first, then go Up (vice versa)
- if y2 < y1 then
- goUp = true
- goDown = false
- elseif y2 > y1 then
- goDown = true
- goUp = false
- else
- goDown = false
- goUp = false
- end
- -- If the new z-coord is less than the first, then go North (vice versa)
- if z2 < z1 then
- goSouth = true
- goNorth = false
- elseif z2 > z1 then
- goNorth = true
- goSouth = false
- else
- goSouth = false
- goNorth = false
- end
- -- Move forward ONCE
- turtle.forward()
- -- Refresh GPS location (for calibrating direction of turtle)
- local x3, y3, z3 = gps.locate()
- -- If the turtle's x-coordinate gets bigger, it is facing East (vice versa)
- if x3 > x2 then
- faceEast = true
- faceWest = false
- faceNorth = false
- faceSouth = false
- elseif x3 < x2 then
- faceWest = true
- faceEast = false
- faceNorth = false
- faceSouth = false
- end
- -- If the turtle's z-coordinate gets bigger, it is facing South (vice versa)
- if z3 > z2 then
- faceSouth = true
- faceNorth = false
- faceEast = false
- faceWest = false
- elseif z3 < z2 then
- faceNorth = true
- faceSouth = false
- faceEast = false
- faceWest = false
- end
- -- Match z-coords to the beginning position
- if ((faceNorth == true and goNorth == true) or (faceSouth == true and goSouth == true)) then
- for a = math.abs(z3 - z1), 1, -1
- do
- while turtle.detect() == true
- do
- turtle.dig()
- end
- turtle.forward()
- end
- end
- if ((faceNorth == true and goSouth == true) or (faceSouth == true and goNorth == true)) then
- turtle.turnRight()
- turtle.turnRight()
- for b = math.abs(z3 - z1), 1, -1
- do
- while turtle.detect() == true
- do
- turtle.dig()
- end
- turtle.forward()
- end
- end
- -- Match x-coords to the beginning position
- if ((faceEast == true and goEast == true) or (faceWest == true and goWest == true)) then
- for c = math.abs(x3 - x1), 1, -1
- do
- while turtle.detect() == true
- do
- turtle.dig()
- end
- turtle.forward()
- end
- end
- if ((faceEast == true and goWest == true) or (faceWest == true and goEast == true)) then
- turtle.turnRight()
- turtle.turnRight()
- for d = math.abs(x3 - x1), 1, -1
- do
- while turtle.detect() == true
- do
- turtle.dig()
- end
- turtle.forward()()
- end
- end
- -- Match y-coords to the beginning position
- if (goUp == true) then
- for e = math.abs(y3 - y1), 1, -1
- do
- while turtle.detectUp() == true
- do
- turtle.digUp()
- end
- turtle.Up()
- end
- end
- if (goDown == true) then
- for f = math.abs(y3 - y1), 1, -1
- do
- while turtle.detectDown() == true
- do
- turtle.digDown()
- end
- turtle.Down()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement