Advertisement
Thanateros

Mob Farm

Nov 28th, 2020 (edited)
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.11 KB | None | 0 0
  1. -- fuels up the turtle as much as it can
  2. function fuelUp()
  3.     print("Current Fuel Level: ",   turtle.getFuelLevel())
  4.     if turtle.getFuelLevel() == turtle.getFuelLimit() then
  5.         return
  6.     end
  7.    
  8.     for i = 1, 16 do
  9.         turtle.select(i)
  10.         turtle.refuel(turtle.getItemCount(i))
  11.         if turtle.getFuelLevel() == turtle.getFuelLimit() then
  12.             break
  13.         end
  14.     end
  15.     print("Current Fuel Level: ",   turtle.getFuelLevel())
  16. end
  17.  
  18. -- checks if the turtle can hold more fuel
  19. function checkFuel()
  20.     if turtle.getFuelLevel() <= 0 then
  21.         fuelUp()
  22.     end
  23. end
  24.  
  25. --[[14 - full block
  26.     15 - slab
  27.     16 - water bucket]]
  28. function findBlock(block)
  29.     for i = 1, 13 do
  30.         turtle.select(i)
  31.         if turtle.compareTo(block) then
  32.             return i
  33.         end
  34.     end
  35.     print("no more blocks, need a fillup")
  36. end
  37.  
  38. --checks if there are any more blocks left in the stack, if not the find a new stack
  39. function checkRemaining(block)
  40.     if turtle.getItemCount() > 0 then
  41.         return
  42.     end
  43.     findBlock(block)
  44. end
  45.  
  46. --move the turtle forward a distance of dist
  47. function forward(dist)
  48.     for i = 1, dist do
  49.         turtle.forward()
  50.         checkFuel()
  51.     end
  52. end
  53.  
  54. --move the turtle forward a distance of dist placeing a block below it after each move
  55. function placeForward(dist, block)
  56.     for i = 1, dist do
  57.         turtle.forward()
  58.         turtle.placeDown()
  59.         checkFuel()
  60.         checkRemaining(block)
  61.     end
  62. end
  63.  
  64. function perimeter()
  65.     findBlock(14)
  66.     for i = 1, 4 do
  67.         placeForward(19, 14)
  68.         turtle.turnRight()
  69.     end
  70. end
  71.  
  72. --layer 1 functions
  73.  
  74. function funnels()
  75.     --get to first block
  76.     turtle.forward()
  77.     turtle.turnRight()
  78.     forward(8)
  79.     turtle.turnLeft()
  80.  
  81.     --build the funnels
  82.     findBlock(14)
  83.     for i = 1, 4 do
  84.         turtle.placeDown()
  85.         for j = 1, 2 do
  86.    findBlock(14)
  87.             placeForward(7, 14)
  88.             turtle.turnLeft()
  89.         end
  90.   turtle.turnRight()
  91.   turtle.turnRight()
  92.         for j = 1, 2 do
  93.             turtle.forward()
  94.             findBlock(16)
  95.             turtle.placeDown()
  96.         end
  97.         turtle.forward()
  98.         turtle.turnRight()
  99.   findBlock(14)
  100.   turtle.placeDown()
  101.     end
  102.  
  103.     --get back to the initial location
  104.     turtle.turnLeft()
  105.     forward(8)
  106.     turtle.turnLeft()
  107.     turtle.forward()
  108.     turtle.turnLeft()
  109.     turtle.turnLeft()
  110. end
  111.  
  112. --layer 2 functions
  113.  
  114. function placeSquare(num)
  115.     checkRemaining(14)
  116.     for i = 1, 8 do
  117.         for j = 1, 8 do
  118.             turtle.placeDown()
  119.             checkFuel()
  120.             checkRemaining(14)
  121.             turtle.forward()
  122.         end
  123.         if i%2 == num then
  124.             turtle.turnLeft()
  125.             turtle.forward()
  126.             turtle.turnLeft()
  127.         else
  128.             turtle.turnRight()
  129.             turtle.forward()
  130.             turtle.turnRight()
  131.         end
  132.   turtle.forward()
  133.     end
  134. end
  135.  
  136. function layer2()
  137.     --get inside the wall
  138.     turtle.forward()
  139.     turtle.turnRight()
  140.     turtle.forward()
  141.     placeSquare(1)
  142.  
  143.     turtle.turnLeft()
  144.     turtle.forward()
  145.     turtle.forward()
  146.     placeSquare(0)
  147.  
  148.     turtle.turnRight()
  149.     turtle.forward()
  150.     turtle.forward()
  151.     placeSquare(1)
  152.  
  153.     turtle.turnRight()
  154.     for i = 1, 11 do
  155.         turtle.forward()
  156.     end
  157.     placeSquare(1)
  158.  
  159.     --return to start
  160.     for i = 1, 9 do
  161.         turtle.forward()
  162.     end
  163.     turtle.turnRight()
  164.     for i = 1, 19 do
  165.         turtle.forward()
  166.     end
  167.     turtle.turnRight()
  168.  turtle.forward()
  169. end
  170.  
  171. --layer 3 functions
  172.  
  173. function placeSlabs(turn)
  174.     --row 1
  175.     findBlock(15)
  176.     for x = 1, 3 do
  177.         turtle.placeDown()
  178.         checkFuel()
  179.         checkRemaining(15)
  180.         forward(3)
  181.     end
  182.  
  183.     --move to next row
  184.     if turn == 0 then
  185.         turtle.turnRight()
  186.         forward(3)
  187.         turtle.turnRight()
  188.     else
  189.         turtle.turnLeft()
  190.         forward(3)
  191.         turtle.turnLeft()
  192.     end
  193.  
  194.     --row 2
  195.     for i = 1, 3 do
  196.         forward(3)
  197.         turtle.placeDown()
  198.         checkFuel()
  199.         checkRemaining(15)
  200.     end
  201.  
  202.     --move to next row
  203.     if turn == 0 then
  204.         turtle.turnLeft()
  205.         forward(3)
  206.         turtle.turnLeft()
  207.     else
  208.         turtle.turnRight()
  209.         forward(3)
  210.         turtle.turnRight()
  211.     end
  212.  
  213.     --row 3
  214.     for x = 1, 3 do
  215.         turtle.placeDown()
  216.         checkFuel()
  217.         checkRemaining(15)
  218.         forward(3)
  219.     end
  220. end
  221.  
  222. function slabs()
  223.    
  224.     --get inside the wall
  225.     turtle.forward()
  226.     turtle.turnRight()
  227.     turtle.forward()
  228.     turtle.turnLeft()
  229.  
  230.     placeSlabs(0)
  231.    
  232.     turtle.turnRight()
  233.     forward(5)
  234.     turtle.turnRight()
  235.     forward(3)
  236.  
  237.     placeSlabs(1)
  238.     turtle.turnRight()
  239.     turtle.turnRight()
  240.  
  241.     forward(14)
  242.     turtle.turnLeft()
  243.  
  244.     placeSlabs(0)
  245.  
  246.     turtle.turnLeft()
  247.     forward(6)
  248.     turtle.turnRight()
  249.     forward(2)
  250.  
  251.     placeSlabs(0)
  252.  
  253.     --return to start
  254.     turtle.turnLeft()
  255.     forward(18)
  256.     turtle.turnRight()
  257.     turtle.forward()
  258.     turtle.turnLeft()
  259.     turtle.forward()
  260.     turtle.turnLeft()
  261.     turtle.turnLeft()
  262. end
  263.  
  264. --layer 4 functions
  265. function roof()
  266.     checkRemaining(14)
  267.     for i = 1, 19 do
  268.         for j = 1, 19 do
  269.             turtle.placeDown()
  270.             checkFuel()
  271.             checkRemaining(14)
  272.             turtle.forward()
  273.         end
  274.         if i%2 == 0 then
  275.             turtle.turnLeft()
  276.             turtle.forward()
  277.             turtle.turnLeft()
  278.         else
  279.             turtle.turnRight()
  280.             turtle.forward()
  281.             turtle.turnRight()
  282.         end
  283.     end
  284.  
  285.     --return to start
  286.     for i = 1, 19 do
  287.         turtle.forward()
  288.     end
  289.     turtle.turnRight()
  290.     for i = 1, 19 do
  291.         turtle.forward()
  292.     end
  293.     turtle.turnRight()
  294. end
  295.  
  296. -- main function
  297. function run()
  298.     --1st layer of blocks
  299. --  turtle.up()
  300. --  perimeter()
  301. --  funnels()
  302.  
  303.     --2nd layer of blocks
  304. --  turtle.up()
  305. --  perimeter()
  306. --  layer2()
  307.  
  308.     --slab it up
  309. --  turtle.up()
  310. --  perimeter()
  311.     slabs()
  312.  
  313.     --top it off
  314. --  turtle.up()
  315. --  roof()
  316. end
  317. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement