Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- heading = 1
- rHeading = 1
- pos = vector.new(0,0,0)
- lPos = vector.new(0,0,0)
- tgted = false
- unloading = false
- tgt = vector.new(0,0,0)
- waypoints = {}
- waypoints['dockUnl'] = vector.new(-2,0,2)
- waypoints['unload'] = vector.new(-2,0,1)
- waypoints['retP'] = vector.new(0,0,1)
- function chkInv()
- if unloading ~= true then
- itmQ = 0
- for a = 2, 16 do
- itmQ = itmQ + turtle.getItemCount(a)
- end
- print(' item count = ', itmQ)
- if itmQ > 600 then
- print(' returning to unload')
- lPos = vector.new(pos.x, pos.y, pos.z)
- rHeading = heading
- unloadTime()
- end
- end
- end
- function unloadTime()
- unloading = true
- moveToTgt(waypoints['dockUnl'])
- moveToTgt(waypoints['unload'])
- for a = 2, 16 do
- turtle.select(a)
- turtle.drop()
- end
- moveToTgt(waypoints['dockUnl'])
- print('returning to ', lPos.x, "x",lPos.y, "x",lPos.z)
- moveToTgt(lPos)
- rot(rHeading)
- unloading = false
- end
- function moveToTgt(Vector)
- tgt = Vector
- tgted = true
- while (pos.x ~= tgt.x) or (pos.y ~= tgt.y) or (pos.z ~= tgt.z) do
- if pos.x > tgt.x then
- move(4)
- elseif pos.x < tgt.x then
- move(2)
- end
- if pos.y > tgt.y then
- move(5)
- elseif pos.y < tgt.y then
- move(6)
- end
- if pos.z > tgt.z then
- move(3)
- elseif pos.z < tgt.z then
- move(1)
- end
- end
- end
- function move(Int)
- if (Int > 0) and (Int < 5) then
- rot(Int)
- Fwd(1)
- elseif Int == 5 then
- chkInv()
- ChkFuel()
- turtle.digDown()
- turtle.down()
- chngCoord(5)
- elseif Int == 6 then
- chkInv()
- ChkFuel()
- turtle.digUp()
- turtle.up()
- chngCoord(6)
- end
- end
- function rotB(Bool)
- if Bool then
- turtle.turnRight()
- heading = heading + 1
- else
- turtle.turnLeft()
- heading = heading - 1
- end
- if heading > 4 then
- heading = 1
- elseif heading < 1 then
- heading = 4
- end
- end
- function rot(Int)
- a = heading - 1
- if a < 1 then
- a = 4
- end
- if a == int then
- turtle.turnLeft()
- heading = heading - 1
- end
- a = heading + 1
- if a > 4 then
- a = 1
- end
- if a == int then
- turtle.turnRight()
- heading = heading + 1
- end
- if heading > 4 then
- heading = 1
- elseif heading < 1 then
- heading = 4
- end
- while Int ~= heading do
- turtle.turnRight()
- heading = heading + 1
- if heading > 4 then
- heading = 1
- elseif heading < 1 then
- heading = 4
- end
- end
- end
- function swapBool(Bool)
- if Bool then
- return false
- else
- return true
- end
- end
- function chngCoord(Int)
- if Int == 1 then
- pos.z = pos.z + 1
- elseif Int == 2 then
- pos.x = pos.x + 1
- elseif Int == 3 then
- pos.z = pos.z - 1
- elseif Int == 4 then
- pos.x = pos.x - 1
- elseif Int == 5 then
- pos.y = pos.y - 1
- elseif Int == 6 then
- pos.y = pos.y + 1
- end
- end
- function ChkFuel()
- if turtle.getFuelLevel() == 0 then
- turtle.select(1)
- if turtle.refuel(1) == true then
- print('Dozapravke na ',pos.x, "x",pos.y, "x",pos.z)
- end
- end
- end
- function Fwd(Int)
- for a = 1, Int do
- chkInv()
- turtle.dig()
- ChkFuel()
- if turtle.forward() then
- chngCoord(heading)
- end
- end
- end
- function Turn(Bool)
- if Bool then
- rotB(true)
- Fwd(1)
- rotB(true)
- return false
- else
- rotB(false)
- Fwd(1)
- rotB(false)
- return true
- end
- end
- function down()
- move(5)
- rotB(false)
- rotB(false)
- end
- print('Vvedite Shiriny')
- mX = tonumber(read())
- print('Vvedite glubinu')
- mY = tonumber(read())
- print(' Starting at ',pos.x, "x",pos.y, "x",pos.z)
- Fwd(1)
- rotB(false)
- Fwd(mX/2)
- rotB(true)
- for c=1, 2 do
- move(6)
- end
- print(' Dig down at ',pos.x, "x",pos.y, "x",pos.z)
- turn = true
- for y = 1, mY+3 do
- if y > 1 then
- down()
- end
- for x = 1, mX do
- if mX > 1 then
- Fwd(mX - 1)
- else
- Fwd(mX)
- end
- if x ~= mX then
- turn = Turn(turn)
- end
- end
- end
- print('Begin dig up, steps up = ', mY, "\n ", pos.x, "x",pos.y, "x",pos.z)
- for b=1, mY do
- move(6)
- end
- unloadTime()
- moveToTgt(waypoints['retP'])
- moveToTgt(vector.new(0,0,0))
- print('Ending operation ', pos.x, "x",pos.y, "x",pos.z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement