Advertisement
Descaii

Untitled

Feb 2nd, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.46 KB | None | 0 0
  1. Blacklist = {}
  2. function Black(...)
  3.     local stuff = {...}
  4.     for i,v in pairs(stuff) do Blacklist[tostring(v):lower()]=true end
  5. end
  6. Black("Copper","Dirt","Stone","Limestone","Gravel")
  7. Position = {x=0,y=0,z=0}
  8. Forward = {x=1,y=0,z=0}
  9. function OnBlack(tx)
  10.     for i,v in pairs(Blacklist) do
  11.         if tx:find(i) then
  12.             return true
  13.         end
  14.     end
  15. end
  16. function ShiftOffsetForward()
  17.     Position.x=Position.x+Forward.x
  18.     Position.y=Position.y+Forward.y
  19.     Position.z=Position.z+Forward.z
  20. end
  21. function shift(direction)
  22.     local x,z = Forward.x,Forward.z
  23.     if direction=="right" then
  24.         Forward.x = (z == 1 and -1) or (z == -1 and 1) or (x ~= 0 and 0)
  25.         Forward.z = (x == 1 and 1) or (x == -1 and -1) or (z ~= 0 and 0)
  26.     end
  27.     if direction=="left" then
  28.         Forward.z = (x == 1 and -1) or (x == -1 and 1) or (z ~= 0 and 0)
  29.         Forward.x = (z == 1 and 1) or (z == -1 and -1) or (x ~= 0 and 0)
  30.     end
  31. end
  32. function GetDirection()
  33.     if Forward.x==1 then
  34.         return "forward"
  35.     elseif Forward.x==-1 then
  36.         return "backwards"
  37.     elseif Forward.z==1 then
  38.         return "right"
  39.     elseif Forward.z==-1 then
  40.         return "left"
  41.     end
  42. end
  43. function IsFull()
  44.     local f = true
  45.     for i = 1,16 do
  46.         if turtle.getItemCount(i) == 0 then
  47.             f=false
  48.         end
  49.     end
  50.     return f
  51. end
  52. function SetDirection(dir)
  53.     local DIR = GetDirection()
  54.     if DIR~=dir:lower() then
  55.         local l,r = 0,0
  56.         if DIR == "left" then
  57.             l,r = ((dir=="backwards"and 1)or 0),((dir=="forward"and 1)or(dir=="right"and 2)or 0)
  58.         elseif DIR == "right" then
  59.             l,r = ((dir=="forward"and 1)or 0),((dir=="backwards"and 1)or(dir=="left"and 2)or 0)
  60.         elseif DIR == "backwards" then
  61.             l,r = ((dir=="right"and 1)or 0),((dir=="left"and 1)or(dir=="forward"and 2)or 0)
  62.         elseif DIR == "forward" then
  63.             l,r = ((dir=="left"and 1)or 0),((dir=="right"and 1)or(dir=="backwards"and 2)or 0)
  64.         end
  65.         for i = 1,r do shift("right") turtle.turnRight() end
  66.         for i = 1,l do shift("left") turtle.turnLeft() end
  67.     end
  68. end
  69. function Move(direction)
  70.     CheckFuel()
  71.     if direction =="up" then
  72.         repeat if turtle.detectUp() then turtle.digUp() end until not turtle.detectUp()
  73.         turtle.up()
  74.         Position.y=Position.y+1
  75.     elseif direction == "down" then
  76.         repeat if turtle.detectDown() then turtle.digDown() end until not turtle.detectDown()
  77.         turtle.down()
  78.         Position.y=Position.y-1
  79.     else
  80.         SetDirection(direction)
  81.         if GetDirection()==direction then
  82.             repeat if turtle.detect() then turtle.dig() end until not turtle.detect()
  83.             turtle.forward()
  84.             ShiftOffsetForward()
  85.         end
  86.     end
  87. end
  88. function GoTo(x,y,z)
  89.     local x,y,z = x,y,z
  90.     repeat
  91.         if Position.x>x then
  92.             Move("backwards")
  93.         elseif Position.x<x then
  94.             Move("forward")
  95.         end
  96.     until Position.x == x
  97.     repeat
  98.         if Position.z<z then
  99.             Move("right")
  100.         elseif Position.z>z then
  101.             Move("left")
  102.         end
  103.     until Position.z == z
  104.     repeat
  105.         if Position.y<y then
  106.             Move("up")
  107.         elseif Position.y>y then
  108.             Move("down")
  109.         end
  110.     until Position.y == y
  111. end
  112. function DepositAll()
  113.     for i = 1,16 do
  114.         turtle.select(i)
  115.         turtle.drop(turtle.getItemCount(i))
  116.     end
  117. end
  118. function DepositExtras()
  119.     local f = true
  120.     for i = 1,16 do
  121.         if turtle.getItemCount(i)>0 and OnBlack(turtle.getItemDetail(i).name:lower()) then
  122.             f = false
  123.             turtle.select(i)
  124.             turtle.drop(turtle.getItemCount(i))
  125.         end
  126.     end
  127.     return f
  128. end
  129. function Display(tab)
  130.     local n = 0
  131.     term.clear()
  132.     for i,v in pairs(tab) do
  133.         n = n+1
  134.         term.setCursorPos(1,n)
  135.         print(v)
  136.     end
  137. end
  138. function CheckFuel()
  139.     if turtle.getFuelLevel()==0 then
  140.         repeat
  141.             sleep(1)
  142.             Display("Place fuel in selected slot.")
  143.         until
  144.             turtle.getItemCount(turtle.getSelectedSlot()) and turtle.getItemDetail(turtle.getSelectedSlot()).name:find("coal")
  145.             turtle.refuel(turtle.getItemCount(turtle.getSelectedSlot()))
  146.     end
  147. end
  148. function Quarry(x,y,z)
  149.     local StartPos = {x=Position.x,y=Position.y,z=Position.z}
  150.     local TDirection = ""
  151.     local TPos = {x=0,y=0,z=0}
  152.     local ax,ay,az = x,y,z
  153.     local Progress = 0
  154.  
  155.     for y = 1,y/3 do
  156.         if y ~= ay/3 then
  157.             for i = 1,(y~=1 and 3 or 2) do
  158.                 Progress = Progress+1
  159.                 Move("down")
  160.             end
  161.         end
  162.         for x = 1,x/2 do
  163.             for z = 1,z-1 do
  164.                 Progress = Progress+3
  165.                 Display({"Creating Quarry","Progress: "..math.ceil(Progress/(ax*ay*az)).."%","Fuel: "..turtle.getFuelLevel().."/"..turtle.getFuelLimit()})
  166.                 turtle.digUp()
  167.                 turtle.digDown()
  168.                 Move("right")
  169.                 if IsFull() and DepositExtras() then
  170.                     TPos = {x=Position.x,y=Position.y,z=Position.z}
  171.                     TDirection = GetDirection()
  172.                     GoTo(0,0,0)
  173.                     SetDirection("backwards")
  174.                     DepositAll()
  175.                     GoTo(TPos.x,TPos.y,TPos.z)
  176.                     SetDirection(TDirection)
  177.                 end
  178.             end
  179.             turtle.digUp()
  180.             turtle.digDown()
  181.             if Position.x~=ax-1 then
  182.                 Progress = Progress+1
  183.                 Move("forward")
  184.             end
  185.             for z = 1,z-1 do
  186.                 Progress = Progress+3
  187.                 Display({"Creating Quarry","Progress: "..math.ceil(Progress/(ax*ay*az)).."%","Fuel: "..turtle.getFuelLevel().."/"..turtle.getFuelLimit()})
  188.                 turtle.digUp()
  189.                 turtle.digDown()
  190.                 Move("left")
  191.                 if IsFull() and DepositExtras() then
  192.                     TPos = {x=Position.x,y=Position.y,z=Position.z}
  193.                     TDirection = GetDirection()
  194.                     GoTo(0,0,0)
  195.                     SetDirection("backwards")
  196.                     DepositAll()
  197.                     GoTo(TPos.x,TPos.y,TPos.z)
  198.                     SetDirection(TDirection)
  199.                 end
  200.             end
  201.             turtle.digUp()
  202.             turtle.digDown()
  203.             if Position.x~=ax-1 then
  204.                 Progress = Progress+1
  205.                 Move("forward")
  206.             end
  207.         end
  208.         GoTo(StartPos.x,Position.y,StartPos.z)
  209.     end
  210.     GoTo(0,0,0)
  211.     SetDirection("backwards")
  212.     DepositAll()
  213.     SetDirection("forward")
  214. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement