Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local BASE = {
- x = -75,
- y = 64,
- z = -252
- }
- local GROUND_HEIGHT = 64
- --posZ = 0, posX = 1, negZ = 2, negX = 3
- local CURRENT_ANGLE = nil
- local LAST_TURN_DIRECTION = 1
- local NODES = {
- {
- z = -253,
- xStart = -71,
- xEnd = -85
- },
- {
- z = -256,
- xStart = -85,
- xEnd = -71
- },
- {
- z = -259,
- xStart = -71,
- xEnd = -85
- },
- {
- z = -262,
- xStart = -85,
- xEnd = -71
- },
- }
- function turnOnce(direction)
- local success = false
- if(direction == 1) then
- success = turtle.turnLeft()
- elseif(direction == -1) then
- success = turtle.turnRight()
- end
- if(success) then
- CURRENT_ANGLE = (CURRENT_ANGLE + direction) % 4
- end
- return success
- end
- function turn(angle)
- local success = true
- local absoluteAngle = math.abs(angle)
- local direction = angle / absoluteAngle
- for _ = 1, absoluteAngle do
- success = success and turnOnce(direction)
- end
- if(success) then
- LAST_TURN_DIRECTION = direction
- end
- return success
- end
- function turnTo(angle)
- diffAngle = (angle - CURRENT_ANGLE) % 4
- diffAngle = diffAngle > 2 and diffAngle - 4 or diffAngle
- diffAngle = diffAngle == 2 and -1 * LAST_TURN_DIRECTION * diffAngle or diffAngle
- return turn(diffAngle)
- end
- function goTo(x, y, z)
- local currX, currY, currZ = gps.locate()
- local stepsX = x - currX
- local stepsY = y - currY
- local stepsZ = z - currZ
- if(stepsY ~= 0) then
- local units = math.abs(stepsY)
- local direction = stepsY / units
- if(direction > 0) then
- for _ = 1, units do
- if(not turtle.up()) then
- return false
- end
- end
- else
- for _ = 1, units do
- if(not turtle.down()) then
- return false
- end
- end
- end
- end
- if(stepsX ~= 0) then
- local units = math.abs(stepsX)
- local direction = stepsX / units
- if(direction > 0) then
- if(not turnTo(1)) then
- return false
- end
- else
- if(not turnTo(3)) then
- return false
- end
- end
- for _ = 1, units do
- if(not turtle.forward()) then
- return false
- end
- end
- end
- if(stepsZ ~= 0) then
- local units = math.abs(stepsZ)
- local direction = stepsZ / units
- if(direction > 0) then
- if(not turnTo(0)) then
- return false
- end
- else
- if(not turnTo(2)) then
- return false
- end
- end
- for _ = 1, units do
- if(not turtle.forward()) then
- return false
- end
- end
- end
- end
- function findFacing()
- local currX, currY, currZ = gps.locate()
- local moved = false
- local blocked = false
- local up = 0
- repeat
- local turnCount = 0
- while((not moved) and (turnCount < 4)) do
- if(turtle.forward()) then
- moved = true
- else
- turtle.turnLeft()
- turnCount = turnCount + 1
- end
- end
- if(not moved) then
- blocked = blocked or (not turtle.up())
- if(not blocked) then
- up = up + 1
- end
- end
- until(moved or blocked)
- local newX, newY, newZ = gps.locate()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- for _ = 1,up do
- turtle.down()
- end
- if(not moved) then
- return false
- end
- local diffX = newX - currX
- local diffZ = newZ - currZ
- if(diffZ > 0) then
- CURRENT_ANGLE = 0
- elseif(diffX > 0) then
- CURRENT_ANGLE = 1
- elseif(diffZ < 0) then
- CURRENT_ANGLE = 2
- else
- CURRENT_ANGLE = 3
- end
- return true
- end
- function hoverTo(x, y, z)
- local currX, currY, currZ = gps.locate()
- goTo(currX, GROUND_HEIGHT + 1, currZ)
- goTo(x, GROUND_HEIGHT + 1, z)
- goTo(x, y, z)
- end
- function getToBase()
- hoverTo(BASE.x, BASE.y, BASE.z)
- end
- function refuel()
- goTo(BASE.x, BASE.y + 3, BASE.z)
- turnTo(0)
- while(turtle.getFuelLevel() < 500) do
- turtle.suck(1)
- turtle.refuel()
- end
- end
- function refurbish()
- goTo(BASE.x, BASE.y + 2, BASE.z)
- turnTo(0)
- turtle.select(1)
- turtle.suck(64)
- end
- function harvestSeed()
- inspect, result = turtle.inspect()
- if(inspect and result.name == "minecraft:wheat" and result.state.age >= 7) then
- turtle.dig()
- turtle.place()
- end
- end
- function harvest()
- turtle.select(1)
- hoverTo(NODES[1].xStart, GROUND_HEIGHT, NODES[1].z)
- for i = 1,4 do
- local step = nil
- if(NODES[i].xStart < NODES[i].xEnd) then
- step = 1
- else
- step = -1
- end
- for x = NODES[i].xStart, NODES[i].xEnd, step do
- goTo(x, GROUND_HEIGHT, NODES[i].z)
- if(x ~= NODES[i].xStart and x ~= NODES[i].xEnd) then
- turnTo(0)
- harvestSeed()
- turnTo(2)
- harvestSeed()
- end
- end
- if(i < 4) then
- goTo(NODES[i+1].xStart, GROUND_HEIGHT, NODES[i+1].z)
- end
- end
- getToBase()
- end
- function deposit()
- goTo(BASE.x, BASE.y + 2, BASE.z)
- turnTo(0)
- for i=1,16 do
- turtle.select(i)
- local details = turtle.getItemDetail()
- if(details and details.name == "minecraft:wheat_seeds") then
- turtle.drop()
- end
- end
- goTo(BASE.x, BASE.y + 1, BASE.z)
- turnTo(0)
- for i=1,16 do
- turtle.select(i)
- local details = turtle.getItemDetail()
- if(details and details.name == "minecraft:wheat") then
- turtle.drop()
- end
- end
- goTo(BASE.x, BASE.y, BASE.z)
- turnTo(0)
- for i=1,16 do
- turtle.select(i)
- local details = turtle.getItemDetail()
- if(details and details.name == "minecraft:bread") then
- turtle.drop()
- end
- end
- goTo(BASE.x - 1, BASE.y, BASE.z)
- turnTo(0)
- for i=1,16 do
- turtle.select(i)
- local details = turtle.getItemDetail()
- if(details and details.name == "minecraft:diamond_hoe") then
- turtle.drop()
- end
- end
- goTo(BASE.x - 1, BASE.y + 1, BASE.z)
- turnTo(0)
- for i=1,16 do
- turtle.select(i)
- local details = turtle.getItemDetail()
- if(details and details.name == "minecraft:crafting_table") then
- turtle.drop()
- end
- end
- goTo(BASE.x - 1, BASE.y, BASE.z)
- for i=1,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- function unequip()
- turtle.select(1)
- turtle.equipLeft()
- local details = turtle.getItemDetail()
- if(details and details.name == "minecraft:diamond_hoe") then
- goTo(BASE.x - 1, BASE.y, BASE.z)
- elseif(details and details.name == "minecraft:crafting_table") then
- goTo(BASE.x - 1, BASE.y + 1, BASE.z)
- end
- turnTo(0)
- turtle.drop()
- end
- function equip(type)
- unequip()
- if(type == "hoe") then
- goTo(BASE.x - 1, BASE.y, BASE.z)
- elseif(type == "craft") then
- goTo(BASE.x - 1, BASE.y + 1, BASE.z)
- end
- turnTo(0)
- turtle.suck(1)
- turtle.equipLeft()
- end
- function craft()
- turtle.select(16)
- local crafting = true
- while(crafting) do
- goTo(BASE.x, BASE.y + 1, BASE.z)
- turnTo(0)
- turtle.suck()
- local items = turtle.getItemCount()
- if(items >= 3) then
- local toCraft = math.floor(items/3)
- turtle.transferTo(5, toCraft)
- turtle.transferTo(6, toCraft)
- turtle.transferTo(7, toCraft)
- turtle.drop()
- turtle.craft()
- goTo(BASE.x, BASE.y, BASE.z)
- turnTo(0)
- turtle.drop()
- else
- turtle.drop()
- crafting = false
- end
- end
- end
- findFacing()
- getToBase()
- deposit()
- while(true) do
- equip("hoe")
- refuel()
- refurbish()
- harvest()
- deposit()
- equip("craft")
- craft()
- deposit()
- goTo(BASE.x, BASE.y, BASE.z)
- turnTo(2)
- sleep(600)
- end
Advertisement
Add Comment
Please, Sign In to add comment