Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- loc = {x=0, y=0, z=0, b=0}
- a=10
- p=0
- function oblom()
- fx = fs.open('locX','r')
- loc.x = tonumber(fx.readLine())
- fx.close()
- fy = fs.open('locY','r')
- loc.y = tonumber(fy.readLine())
- fy.close()
- fz = fs.open('locZ','r')
- loc.z = tonumber(fz.readLine())
- fz.close()
- fb = fs.open('locB','r')
- loc.b = tonumber(fb.readLine())
- fb.close()
- fp = fs.open('locP','r')
- p = tonumber(fp.readLine())
- fp.close()
- fa = fs.open('pecA','r')
- a = tonumber(fa.readLine())
- fa.close()
- if a>10 then
- while turtle.getFuelLevel()<11000 do
- turtle.select(1)
- if a<11 then
- while loc.b~=1 do
- turnRight()
- end
- turtle.suck(64 - turtle.getItemCount())
- a=11
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- end
- if a<12 then
- while loc.b ~= 0 do
- turnLeft()
- end
- if loc.z<2 then
- while loc.y < 1 do
- forward()
- end
- while loc.z < 2 do
- up()
- end
- end
- while loc.y>0 do
- back()
- end
- turtle.dropDown()
- a=12
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- end
- if a<13 then
- if loc.z > 0 then
- while loc.y < 1 do
- forward()
- end
- while loc.z>0 do
- down()
- end
- end
- while loc.y>0 do
- back()
- end
- a=13
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- end
- if a<14 then
- while turtle.getItemCount()<64 do
- turtle.suckUp()
- sleep(8)
- end
- turtle.dropUp()
- a=14
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- end
- if a<15 then
- turtle.refuel()
- a=15
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- end
- a=10
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- end
- end
- if (loc.y ~= 4) or (loc.x ~= 0) or (loc.b ~= 2)
- then
- if ((loc.b == 1) or (loc.b == 3)) and (loc.z >= 2)
- then
- if p == 1 then
- forward()
- p=0
- fp=fs.open('locP','w')
- fp.write(p)
- fp.close()
- end
- if (loc.z > 2) or ((loc.x+2)%2 == 1)
- then
- up()
- while turtle.compareUp() == true do
- turtle.digUp()
- up()
- end
- while loc.z>2 do
- turtle.digDown()
- down()
- end
- turtle.digDown()
- turtle.select(16)
- turtle.placeDown()
- turtle.select(1)
- back()
- end
- end
- if a ~= 1 then
- dom(true)
- end
- a=1
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- while loc.b~=0 do
- turnLeft()
- end
- while loc.y < 1 do
- forward()
- end
- while loc.z<2 do
- up()
- end
- while loc.y < 4 do
- forward()
- end
- a=10
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- end
- end
- function forward()
- if turtle.forward() then
- if loc.b == 0 then loc.y = loc.y+1
- elseif loc.b == 1 then loc.x = loc.x+1
- elseif loc.b == 2 then loc.y = loc.y-1
- else loc.x = loc.x-1 end
- fx=fs.open('locX','w')
- fx.write(loc.x)
- fx.close()
- fy=fs.open('locY','w')
- fy.write(loc.y)
- fy.close()
- return true
- else
- return false
- end
- end
- function back()
- if turtle.back() then
- if loc.b == 0 then loc.y = loc.y-1
- elseif loc.b == 1 then loc.x = loc.x-1
- elseif loc.b == 2 then loc.y = loc.y+1
- else loc.x = loc.x+1 end
- fx=fs.open('locX','w')
- fx.write(loc.x)
- fx.close()
- fy=fs.open('locY','w')
- fy.write(loc.y)
- fy.close()
- return true
- else
- return false
- end
- end
- function up()
- if turtle.up() then
- loc.z = loc.z+1
- fz=fs.open('locZ','w')
- fz.write(loc.z)
- fz.close()
- return true
- else
- return false
- end
- end
- function down()
- if turtle.down() then
- loc.z = loc.z-1
- fz=fs.open('locZ','w')
- fz.write(loc.z)
- fz.close()
- return true
- else
- return false
- end
- end
- function turnRight()
- turtle.turnRight()
- loc.b = (loc.b+1)%4
- fb=fs.open('locB','w')
- fb.write(loc.b)
- fb.close()
- end
- function turnLeft()
- turtle.turnLeft()
- loc.b = (loc.b+3)%4
- fb=fs.open('locB','w')
- fb.write(loc.b)
- fb.close()
- end
- function dom(noreturn)
- -- двигаемся домой
- local d = loc.b
- local p = loc.x
- local t = loc.y
- if loc.b ~= 2 then
- while loc.b ~= 2 do
- turnRight()
- end
- end
- if loc.x > 0 then
- turnRight()
- if turtle.detect()==true then
- while loc.b ~= 2 do
- turnLeft()
- end
- forward()
- turnRight()
- end
- while loc.x ~= 0 do
- forward()
- end
- turnLeft()
- end
- if loc.x < 0 then
- turnLeft()
- while loc.x ~= 0 do
- forward()
- end
- turnRight()
- end
- while loc.y > 1 do
- forward()
- end
- while loc.z>0 do
- down()
- end
- forward()
- -- выгрузка дерева
- if turtle.getItemCount(1)>1 then
- while loc.b ~=1 do
- turnLeft()
- end
- for i=1,15 do
- turtle.select(i)
- if turtle.compareTo(16)==true then
- turtle.dropDown()
- else
- turtle.drop()
- end
- end
- while loc.b ~= 2 do
- turnRight()
- end
- for i=1,15 do
- turtle.select(i)
- if turtle.compareTo(16)==true then
- turtle.dropDown()
- else
- turtle.drop()
- end
- end
- end
- while loc.b ~= 2 do
- turnLeft()
- end
- -- забираем саженцы
- turtle.select(16)
- turtle.suckDown(64-turtle.getItemCount(16))
- -- зарядка
- while turtle.getFuelLevel()<11000 do
- turtle.select(1)
- turnRight()
- turtle.suck(64 - turtle.getItemCount())
- a=11
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- turnLeft()
- forward()
- for i=1,2 do
- up()
- end
- back()
- turtle.dropDown()
- a=12
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- forward()
- for i=1,2 do
- down()
- end
- back()
- a=13
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- while turtle.getItemCount()<64 do
- turtle.suckUp()
- sleep(8)
- end
- turtle.dropUp()
- a=14
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- turtle.refuel()
- a=15
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- end
- a=10
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- turtle.select(1)
- -- возвращаемся если нет флага "в один конец"
- if not noreturn then
- forward()
- while loc.z<2 do
- up()
- end
- while loc.y < t do
- forward()
- end
- if loc.x ~= p then
- turnRight()
- while loc.x ~=p do
- forward()
- end
- end
- if loc.b ~= d then
- while loc.b ~= d do
- turnLeft()
- end
- end
- end
- end
- function usl()
- if turtle.getItemCount(15)>32
- then
- dom()
- end
- if turtle.getItemCount(16)<8
- then
- dom()
- end
- if turtle.getFuelLevel()<5000
- then
- dom()
- end
- end
- function axe()
- if turtle.detect()==true
- then
- turtle.dig()
- p=1
- fp=fs.open('locP','w')
- fp.write(p)
- fp.close()
- forward()
- p=0
- fp=fs.open('locP','w')
- fp.write(p)
- fp.close()
- turtle.digDown()
- while turtle.compareUp() == true do
- turtle.digUp()
- up()
- end
- while loc.z>2 do
- turtle.digDown()
- down()
- end
- turtle.select(16)
- turtle.placeDown()
- turtle.select(1)
- back()
- end
- end
- if fs.exists('locX') == false then
- fx=fs.open('locX','w')
- fx.write(loc.x)
- fx.close()
- end
- if fs.exists('locY') == false then
- fy=fs.open('locY','w')
- fy.write(loc.y)
- fy.close()
- end
- if fs.exists('locZ') == false then
- fx=fs.open('locZ','w')
- fx.write(loc.x)
- fx.close()
- end
- if fs.exists('locB') == false then
- fb=fs.open('locB','w')
- fb.write(loc.b)
- fb.close()
- end
- if fs.exists('locP') == false then
- fp=fs.open('locP','w')
- fp.write(p)
- fp.close()
- end
- if fs.exists('pecA') == false then
- fa=fs.open('pecA','w')
- fa.write(a)
- fa.close()
- end
- oblom()
- while true do
- for i=1, 8 do
- usl()
- forward()
- turnLeft()
- axe()
- for t=1,2 do
- turnRight()
- end
- axe()
- turnLeft()
- forward()
- if (i == 4) or (i==8) then
- turnRight()
- for c=1, 4 do forward() end
- turnRight()
- end
- end
- for i=1,10 do
- sleep(72)
- print(i*10,' %')
- end
- term.clear()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement