Advertisement
Guest User

farminer2

a guest
Jan 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.51 KB | None | 0 0
  1. -- hello!
  2. -- 15 szeles
  3. -- 4 magas
  4. -- ez mar epit is, nem csak as
  5. -- kezdes: baloldalt legszelen
  6. -- nem a dirt szinten, hanem felette
  7. -- asas iranyaba nezve
  8. -- arg: len
  9.  
  10. tArgs = { ... }
  11.  
  12. if (#tArgs ~= 1) then
  13.   print("Usage: farminer [length]")
  14.   return
  15. end
  16.  
  17. print("Running xXx EpiC F4rmIn3r xXx 18000!!!")
  18.  
  19. target_length = tArgs[1]
  20. target_floor = "minecraft:dirt"
  21. target_wall = "minecraft:cobblestone"
  22. target_roof = "minecraft:glass"
  23.  
  24. function check_refuel()
  25.  
  26.   if turtle.getFuelLevel() < 10 then
  27.    local stash = turtle.getSelectedSlot()
  28.    select_block("minecraft:coal")
  29.  
  30.    if not turtle.refuel(1) then
  31.      error("failed to refuel")
  32.    else
  33.      print("Refueld")
  34.    end
  35.  
  36.    turtle.select(stash)
  37.  
  38.   end
  39.  
  40. end
  41.  
  42. function select_block(_name)
  43.  
  44.   for i=1,16 do
  45.  
  46.     local slot_data = turtle.getItemDetail(i)
  47.  
  48.     if slot_data then
  49.    
  50.       if (slot_data.name == _name) then
  51.         turtle.select(i)
  52.         return
  53.       end
  54.    
  55.     end
  56.      
  57.   end
  58.  
  59.   error("out of: " .. _name)
  60.      
  61. end
  62.  
  63.  
  64. function do_line_down(len,top)
  65.  
  66.   for i=1,len do
  67.  
  68.     if i < len then
  69.      if turtle.detect() then  
  70.       turtle.dig()
  71.      end
  72.     end
  73.  
  74.     if top then
  75.  
  76.       local skip_roof = false    
  77.       local is_top,top_data = turtle.inspectUp()
  78.  
  79.       if is_top then
  80.  
  81.         if top_data and top_data.name == target_roof then
  82.           skip_roof = true
  83.         else
  84.           turtle.digUp()
  85.         end
  86.      
  87.                  
  88.       end
  89.      
  90.       if not skip_roof then
  91.         select_block(target_roof)
  92.         turtle.placeUp()      
  93.       end
  94.            
  95.    
  96.     else -- top
  97.     -- this is bottom
  98.  
  99.       local water_hole = ((i == 5) or (i == 11))
  100.  
  101.       local skip_floor = false
  102.  
  103.       local is_down,down_data = turtle.inspectDown()
  104.  
  105.       if is_down then
  106.  
  107.        if (down_data) and (down_data.name == target_floor) then
  108.         skip_floor = true
  109.        else
  110.         turtle.digDown()
  111.        end
  112.  
  113.       end
  114.  
  115.       if not water_hole then
  116.                            
  117.        if (not skip_floor) then  
  118.          select_block(target_floor)
  119.          turtle.placeDown()    
  120.        end
  121.  
  122.       else -- put cobblestone
  123.      
  124.        turtle.digDown()
  125.        turtle.down()
  126.        check_refuel()
  127.        select_block(target_wall)
  128.        turtle.placeDown()      
  129.        turtle.up()
  130.        check_refuel()      
  131.  
  132.       end
  133.  
  134.  
  135.     end -- not top
  136.            
  137.     if i < len then
  138.      turtle.forward()
  139.     end
  140.  
  141.     check_refuel()
  142.  
  143.     sleep(0.1)  
  144.   end
  145.  
  146.  
  147. end
  148.  
  149. function do_wall()
  150.   select_block(target_wall)
  151.   turtle.dig()
  152.   turtle.place()
  153. end
  154.  
  155. -- Main
  156.  
  157. turtle.turnRight()
  158.  
  159. for j=1,target_length do
  160.  
  161.  
  162.   do_line_down(15,false) -- bottom
  163.   -- arrived right
  164.  
  165.   -- wall elemet
  166.   do_wall()
  167.  
  168.   -- go up
  169.    
  170.   turtle.digUp()
  171.   turtle.up()
  172.    check_refuel()
  173.  
  174.   -- another wall element
  175.  
  176.   do_wall()
  177.    
  178.   -- move up
  179.  
  180.   turtle.digUp()
  181.   turtle.up()
  182.    check_refuel()
  183.  
  184.   -- wall
  185.   do_wall()
  186.  
  187.   -- turn around
  188.   turtle.turnLeft()
  189.   turtle.turnLeft()
  190.  
  191.   -- roof
  192.   do_line_down(15,true) -- top
  193.   -- arrived left
  194.  
  195.   --wall
  196.   do_wall()
  197.  
  198.   -- go down
  199.   turtle.digDown()
  200.   turtle.down()
  201.    check_refuel()
  202.  
  203.   -- wall
  204.   do_wall()
  205.  
  206.   -- down    
  207.   turtle.digDown()
  208.   turtle.down()
  209.    check_refuel()
  210.  
  211.   -- last wall piece
  212.    do_wall()
  213.  
  214.   -- next layer  
  215.   turtle.turnRight()
  216.   turtle.dig()
  217.   turtle.forward()
  218.    check_refuel()  
  219.   turtle.turnRight()
  220.  
  221. end
  222.  
  223. turtle.turnLeft()
  224.  
  225. print("Done farmining")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement