Advertisement
SolidSnake96AS

Serpens Quarry

Sep 2nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.20 KB | None | 0 0
  1. args={...};
  2.  
  3. local config, width, height, checkThread;
  4.  
  5. --[[
  6.     TODO:
  7.         Home when full
  8.             Enderchest when full
  9.         Send to diplay
  10.         Torches
  11.         Ladder
  12.         Auto refuel with lava
  13.         Drop useless items
  14. ]]
  15.  
  16. local function goHome() --Move the turtle to the start position
  17.     --Z pos
  18.     while(mov.getZ()~=0)
  19.     do
  20.         if (mov.getZ()<0)
  21.         then
  22.             mov.u(true);
  23.         elseif (mov.getZ()>0)
  24.         then
  25.             mov.d(true);
  26.         end
  27.     end
  28.  
  29.     --X pos
  30.     if (mov.getX()<0)
  31.     then
  32.         mov.pointTo(mov.LEFT);
  33.     elseif (mov.getY()>0)
  34.     then
  35.         mov.pointTo(mov.RIGHT);
  36.     end
  37.  
  38.     while(mov.getX()~=0)
  39.     do
  40.         mov.f(true);
  41.     end
  42.  
  43.     --Y pos
  44.     if (mov.getY()<0)
  45.     then
  46.         mov.pointTo(mov.UP);
  47.     elseif (mov.getY()>0)
  48.     then
  49.         mov.pointTo(mov.DOWN);
  50.     end
  51.  
  52.     while(mov.getY()~=0)
  53.     do
  54.         mov.f(true);
  55.     end
  56.  
  57.     mov.pointTo(mov.UP);
  58.    
  59.     mov.l();
  60.     --dropAll(false);
  61.     mov.r();
  62.     --returnBack(x, y, dir);
  63. end
  64.  
  65. local function returnBack(x, y, dir) --Go to coords
  66.    
  67.     --Y pos
  68.     if (mov.getY()<y)
  69.     then
  70.         mov.pointTo(mov.UP);
  71.     elseif (mov.getY()>y)
  72.     then   
  73.         mov.pointTo(mov.DOWN);
  74.     end
  75.  
  76.     while(mov.getY()~=y)
  77.     do
  78.         mov.f(true);
  79.     end
  80.  
  81.     --X pos
  82.     if (mov.getX()<x)
  83.     then
  84.         mov.pointTo(mov.RIGHT);
  85.     elseif (mov.getY()>y)
  86.     then
  87.         mov.pointTo(mov.LEFT);
  88.     end
  89.  
  90.     while(mov.getX()~=x)
  91.     do
  92.         mov.f(true);
  93.     end
  94.  
  95.     --Z pos
  96.     while(mov.getZ()~=z)
  97.     do
  98.         if (mov.getZ()<z)
  99.         then
  100.             mov.u(true);
  101.         elseif (mov.getZ()>z)
  102.         then
  103.             mov.d(true);
  104.         end
  105.     end
  106.  
  107.     mov.pointTo(dir);
  108. end
  109.  
  110. local function quarry() --Main function
  111.     local block, _;
  112.  
  113.     mov.f();
  114.    
  115.     --Columns
  116.     for x=1, width
  117.     do
  118.  
  119.         --Rows
  120.         for y=1, height, 2
  121.         do
  122.             _, block=turtle.inspectDown();
  123.  
  124.             --Depth
  125.             while (block.name~="minecraft:bedrock")
  126.             do
  127.                 mov.d(true);
  128.                
  129.                 if (y<height)
  130.                 then
  131.                     turtle.dig();
  132.                 end
  133.  
  134.                 local bool, ev=coroutine.resume(checkThread);
  135.  
  136.                 if (bool)
  137.                 then
  138.                     print(ev);
  139.                 end
  140.  
  141.                 _, block=turtle.inspectDown();
  142.             end
  143.  
  144.             --Bedrock Reached
  145.  
  146.             while (mov.getZ()<0)
  147.             do
  148.                 mov.u(true);
  149.             end
  150.  
  151.             --Top Reached
  152.  
  153.             --Moving forward
  154.             for i=1, 2
  155.             do
  156.                 if (mov.getY()<height-1)
  157.                 then
  158.                     mov.f(true);
  159.                 end
  160.             end
  161.         end
  162.  
  163.         while (mov.getY()>1)
  164.         do
  165.             mov.b();
  166.         end
  167.  
  168.         --Back to Y=1
  169.        
  170.         mov.r();
  171.         mov.f(true);
  172.         mov.l();
  173.         --Next column
  174.     end
  175.  
  176.     goHome();
  177. end
  178.  
  179. --Main code
  180.  
  181. width=tonumber(args[1]);
  182. height=tonumber(args[2]);
  183.  
  184. if (fs.exists("quarry.config"))
  185. then
  186.     local configFile=fs.open("quarry.config", "r");
  187.  
  188.     config=textutils.unserialize(configFile.readAll());
  189.  
  190. else
  191.     local configFile=fs.open("quarry.config", "w");
  192.  
  193.     config=
  194.     {
  195.         enderChest=true;
  196.         returnHome=true;
  197.         net=false;
  198.         placeTorches=false;
  199.         buildLadder=false;
  200.     };
  201.  
  202.     configFile.write(textutils.serialize(config));
  203.  
  204.     --TODO: Configuration program
  205. end
  206.  
  207. os.loadAPI("serpensAPI/mov");
  208.  
  209. mov.setPos(0, 0, 0);
  210. mov.setDir(1);
  211. mov.setWaitTime(0);
  212.  
  213. local function test()
  214.     while (true)
  215.     do
  216.         --[[for i=1, 15
  217.         do
  218.             if (turtle.getItemCount(i)==0)
  219.             then
  220.                 coroutine.yield(false);
  221.             end
  222.         end
  223.         coroutine.yield(true, "full");]]
  224.         print(textutils.serialize(turtle.getItemDetail()));
  225.     end
  226. end
  227.  
  228. checkThread=coroutine.create(test);
  229. coroutine.resume(checkThread);
  230.  
  231. quarry();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement