Advertisement
Guest User

farminer

a guest
Jan 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. -- hello!
  2. -- 15 szeles
  3. -- 4 magas
  4. -- kezdes: baloldalt legszelen
  5. -- nem a dirt szinten, hanem felette
  6. -- asas iranyaba nezve
  7. -- arg: len floor_item lamp_item
  8.  
  9. tArgs = { ... }
  10.  
  11. if (#tArgs ~= 1) then
  12.   print("Usage: farminer [length]")
  13.   return
  14. end
  15.  
  16. print("Running xXx EpiC F4rmIn3r 9000!!!")
  17.  
  18. target_length = tArgs[1]
  19. target_floor = "minecraft:dirt"
  20.  
  21. function check_shit()
  22.  
  23.   if turtle.getFuelLevel() < 10 then
  24.    local stash = turtle.getSelectedSlot()
  25.    select_block("minecraft:coal")
  26.  
  27.    if not turtle.refuel() then
  28.      error("failed to refuel")
  29.    else
  30.      print("Refueld")
  31.    end
  32.  
  33.    turtle.select(stash)
  34.  
  35.   end
  36.  
  37. end
  38.  
  39. function select_block(_name)
  40.  
  41.   for i=1,16 do
  42.  
  43.     local slot_data = turtle.getItemDetail(i)
  44.  
  45.     if slot_data then
  46.    
  47.       if (slot_data.name == _name) then
  48.         turtle.select(i)
  49.         return
  50.       end
  51.    
  52.     end
  53.      
  54.   end
  55.  
  56.   error("out of: " .. _name)
  57.      
  58. end
  59.  
  60.  
  61. function lamp_place(pos,depth)
  62.  
  63.   if math.fmod(depth,4) == 0 then -- negyesevel
  64.     if math.fmod(pos,4) == 0 then
  65.  
  66.         -- lamp must be placed
  67.         turtle.up()
  68.         turtle.digUp()
  69.         check_shit()
  70.         select_block("minecraft:torch")
  71.        
  72.         if not turtle.placeUp() then
  73.           error("Failed to lamp")
  74.         end
  75.        
  76.         turtle.down()
  77.         check_shit()
  78.  
  79.     end
  80.   end  
  81.  
  82. end
  83.  
  84. function do_line_up(len,depth)
  85.  
  86.   for i=1,len do
  87.     local digged = false
  88.  
  89.     if i < len then
  90.      if turtle.detect() then
  91.        turtle.dig()
  92.        digged = true
  93.      end
  94.     end
  95.    
  96.     if turtle.detectUp() then
  97.       turtle.digUp()
  98.       digged = true
  99.     end
  100.  
  101.     lamp_place(i,depth) -- check b4
  102.  
  103.     if i < len then            
  104.      turtle.forward()
  105.     end
  106.    
  107.     check_shit()
  108.        
  109.     if digged then
  110.       sleep(0.1)  
  111.     end
  112.   end
  113.  
  114. end
  115.  
  116.  
  117. function do_line_down(len)
  118.  
  119.   for i=1,len do
  120.  
  121.     if i < len then
  122.      if turtle.detect() then  
  123.       turtle.dig()
  124.      end
  125.     end
  126.  
  127.     local skip_floor = false
  128.  
  129.     local is_down,down_data = turtle.inspectDown()
  130.  
  131.     if is_down then
  132.  
  133.      if (down_data) and (down_data.name == target_floor) then
  134.       skip_floor = true
  135.      else
  136.       turtle.digDown()
  137.      end
  138.  
  139.     end
  140.    
  141.     if (not skip_floor) then  
  142.       select_block(target_floor)
  143.       turtle.placeDown()    
  144.     end
  145.    
  146.     if i < len then
  147.      turtle.forward()
  148.     end
  149.  
  150.     sleep(0.1)  
  151.   end
  152.  
  153.  
  154. end
  155.  
  156.  
  157. -- Main
  158.  
  159. turtle.turnRight()
  160.  
  161. for j=1,target_length do
  162.  
  163.  
  164.   do_line_down(15)
  165.   -- arrived right
  166.   turtle.digUp()
  167.   turtle.up()
  168.    check_shit()
  169.   turtle.turnLeft()
  170.   turtle.turnLeft()
  171.   do_line_up(15,j)
  172.   -- arrived left
  173.   turtle.digUp()
  174.   turtle.down()
  175.    check_shit()
  176.   turtle.turnRight()
  177.   turtle.dig()
  178.   turtle.forward()
  179.    check_shit()  
  180.   turtle.turnRight()
  181.  
  182. end
  183.  
  184. turtle.turnLeft()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement