Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- currentPositionx = 0
- currentPositiony = 0
- currentPositionz = 0
- currentFacing = 0
- currentlySelectedSlot = 1
- fuelLevelToRefuelAt = 5
- function main()
- pillarToZ(1, 3)
- lineToY(1, currentPositiony + 2)
- turnZero()
- safeForward()
- pillarToZ(1, 3)
- lineToY(1, currentPositiony + 2)
- turnZero()
- safeForward()
- pillarToZ(1, 3)
- end
- function lineToY(item, y)
- turnZero()
- while currentPositiony ~= y do
- if not turtle.detectDown() then
- safePlaceDown(item)
- end
- if y > currentPositiony then
- turnFacing(0)
- safeForward()
- safePlaceDown(item)
- elseif y < currentPositiony then
- turnFacing(2)
- safeForward()
- safePlaceDown(item)
- end
- end
- end
- function pillarToZ(item, z)
- goGround(128)
- safeUp()
- while currentPositionz < z do
- safePlaceDown(item)
- safeUp()
- end
- end
- function goGround(maximum)
- local current = 0;
- while not turtle.detectDown() do
- safeDown()
- current = current + 1
- if current >= maximum then
- return true
- end
- end
- return true
- end
- function getItemPlace(item)
- while true do
- turtle.select(item)
- local skip = true
- for i = 1, 15 do
- if skip then
- if turtle.getItemCount(i)==0 then
- skip = false
- end
- else
- if turtle.getItemCount(i)~=0 then
- if turtle.compareTo(i) then
- print("Found material in "..tostring(i))
- return i
- end
- end
- end
- end
- awaitFix("No building materials! Refill with same as selected slot!")
- end
- end
- function ensureFuel()
- -- Determine whether a refuel is required
- local fuelLevel = turtle.getFuelLevel()
- if (fuelLevel ~= "unlimited") then
- if (fuelLevel < fuelLevelToRefuelAt) then
- -- Need to refuel
- turtle.select(16)
- currentlySelectedSlot = 16
- local fuelItems = turtle.getItemCount(16)
- -- Do we need to impact the emergency fuel to continue? (always
- -- keep one fuel item in slot 16)
- if (fuelItems == 0) then
- print("I want more fuel!")
- else
- turtle.refuel(1)
- end
- end
- end
- end
- function awaitFix(message)
- print("I have problem: " .. message)
- print("Please fix it and press Enter to continue")
- io.read()
- end
- function safePlaceFront(itemTest)
- item = getItemPlace(itemTest)
- ensureFuel()
- turtle.select(item)
- success = false
- while not success do
- success = turtle.place()
- if not success then
- awaitFix("Can't place in front")
- end
- end
- end
- function safePlaceDown(itemTest)
- item = getItemPlace(itemTest)
- ensureFuel()
- turtle.select(item)
- success = false
- while not success do
- success = turtle.placeDown()
- if not success then
- awaitFix("Can't place down")
- end
- end
- end
- function safePlaceUp(itemTest)
- item = getItemPlace(itemTest)
- ensureFuel()
- turtle.select(item)
- success = false
- while not success do
- success = turtle.placeUp()
- if not success then
- awaitFix("Can't place up")
- end
- end
- end
- function safeDigFront(item)
- ensureFuel()
- turtle.select(item)
- success = false
- while not success do
- success = turtle.dig()
- if not success then
- awaitFix("Can't dig in front")
- end
- end
- end
- function safeDigDown(item)
- ensureFuel()
- turtle.select(item)
- success = false
- while not success do
- success = turtle.digDown()
- if not success then
- awaitFix("Can't dig down")
- end
- end
- end
- function safeDigUp(item)
- ensureFuel()
- turtle.select(item)
- success = false
- while not success do
- success = turtle.digUp()
- if not success then
- awaitFix("Can't dig up")
- end
- end
- end
- function turnZero()
- while currentFacing ~= 0 do
- turnRightTrack()
- end
- end
- function turnFacing(facing)
- --todo: faster it
- while facing ~= currentFacing do
- turnRightTrack()
- end
- end
- function turnRightTrack()
- ensureFuel()
- turtle.turnRight()
- currentFacing = currentFacing + 1
- if currentFacing >= 4 then
- currentFacing = 0
- end
- end
- function turnLeftTrack()
- ensureFuel()
- turtle.turnLeft()
- currentFacing = currentFacing - 1
- if currentFacing < 0 then
- currentFacing = 3
- end
- end
- function safeForward()
- ensureFuel()
- success = false
- while not success do
- success = turtle.forward()
- if not success then
- awaitFix("Blocked attempting to move forward")
- end
- end
- if (currentFacing == 0) then
- currentPositiony = currentPositiony + 1
- elseif (currentFacing == 1) then
- currentPositionx = currentPositionx + 1
- elseif (currentFacing == 2) then
- currentPositiony = currentPositiony - 1
- elseif (currentFacing == 3) then
- currentPositionx = currentPositionx - 1
- else
- awaitFix("Oy we gotta into 101010022..")
- end
- end
- function safeBack()
- ensureFuel()
- success = false
- while not success do
- success = turtle.back()
- if not success then
- awaitFix("Blocked attempting to move back")
- end
- end
- if (currentFacing == 0) then
- currentPositiony = currentPositiony - 1
- elseif (currentFacing == 1) then
- currentPositionx = currentPositionx - 1
- elseif (currentFacing == 2) then
- currentPositiony = currentPositiony + 1
- elseif (currentFacing == 3) then
- currentPositionx = currentPositionx + 1
- else
- awaitFix("Oy we gotta into 101010022..")
- end
- end
- function safeUp()
- ensureFuel()
- success = false
- while not success do
- success = turtle.up()
- if not success then
- awaitFix("Blocked attempting to move up")
- end
- end
- currentPositionz = currentPositionz + 1
- end
- function safeDown()
- ensureFuel()
- success = false
- while not success do
- success = turtle.down()
- if not success then
- awaitFix("Blocked attempting to move down")
- end
- end
- currentPositionz = currentPositionz - 1
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment