largeNumberGoeshere

makepathway.lua

Apr 21st, 2021 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1. -- build a pathway
  2. --rednet.open("left")
  3.  
  4. function waitForRednet()
  5.     while c == nil do
  6.         a,b = rednet.receive()
  7.         if b == "beginpath" then
  8.             c="begun"
  9.             print(c)
  10.             return
  11.         end
  12.     end
  13. end
  14.  
  15.  
  16. blockToBuildWith = "minecraft:netherrack"
  17. magmaBlock = "minecraft:magma_block"
  18. fuelBuffer = 100
  19. refuelSlot = 11
  20.  
  21. forwardCount = 0
  22.  
  23. function waitUntilNextMoment()
  24.     -- while not (os.time()*1000 %70 == 0) do
  25.         -- sleep(0.05)
  26.     -- end
  27.  
  28. end
  29.  
  30. function ifLava()
  31.  
  32.    
  33.     function goBack(b)
  34.         b = b or "nothing"
  35.         if b.name == "minecraft:lava" then
  36.             turtle.place()
  37.             turtle.placeUp()
  38.             turtle.placeDown()
  39.        
  40.             turtle.turnLeft()
  41.             turtle.turnLeft()
  42.             for i=1, 15 do
  43.                 turtle.forward()
  44.             end
  45.             turtle.turnLeft()
  46.             turtle.turnLeft()
  47.             error("Ran into lava")
  48.         end
  49.     end
  50.    
  51.     local a,b = turtle.inspectUp()
  52.     goBack(b)
  53.    
  54.     local a,b turtle.inspect()
  55.     goBack(b)
  56.    
  57.    
  58.    
  59. end
  60.  
  61. function searchSlotsFor(blockId)
  62.     for slot = 1,16 do
  63.         turtle.select(slot)
  64.         local i = turtle.getItemDetail() or "nothing"
  65.         if i ~= "nothing" then
  66.             if i.name == blockId then
  67.                 return slot
  68.             else
  69.             end
  70.         end
  71.     end
  72.     return "nothing found"
  73. end
  74.  
  75. function findBlock(blockId)
  76.         local i = turtle.getItemDetail() or "nothing"
  77.         if i ~= "nothing" and i.name == blockId then
  78.             return true
  79.         else
  80.             slot = searchSlotsFor(blockToBuildWith)
  81.             if slot ~= "nothing found" then
  82.                 return true
  83.             else
  84.                 print("Nothing found to build with")
  85.                
  86.                 while searchSlotsFor(blockToBuildWith) == "nothing found" do
  87.                         sleep(2)
  88.                         write(".")
  89.                 end
  90.             end
  91.            
  92.         end
  93. end
  94.  
  95.  
  96.  
  97. function build()
  98.             if findBlock(blockToBuildWith) == true then
  99.                 turtle.placeDown()
  100.             end
  101. end
  102.  
  103. function dig()
  104.     while turtle.detect() == true do
  105.         turtle.dig()
  106.     end
  107. end
  108.  
  109. function digUp()
  110.     while turtle.detectUp() == true do
  111.         turtle.digUp()
  112.     end
  113. end
  114.  
  115. function digAll()
  116.         dig()
  117.         digUp()
  118.        
  119. end
  120.  
  121. function forward()
  122.         turtle.forward()
  123. end
  124.  
  125. function refuel()
  126.     if turtle.getFuelLevel() <= fuelBuffer then
  127.         turtle.select(refuelSlot)
  128.         fuelInSlot = turtle.refuel(0)
  129.         if fuelInSlot then
  130.            
  131.            
  132.                 turtle.refuel(1)
  133.            
  134.         else
  135.             print("please refuel to slot "..refuelSlot)
  136.             while turtle.refuel(0) == false do
  137.                 sleep(2)
  138.                 write(".")
  139.             end
  140.             turtle.refuel(1)
  141.         end
  142.     end
  143. end
  144.  
  145. rednetSide = "left"
  146. function checkRedent()
  147.     rednet.open(rednetSide)
  148.     parallel.waitForAny(
  149.         function()
  150.             sleep(0.2)
  151.         end,
  152.         function()
  153.             a,b = rednet.receive()
  154.             a=nil
  155.         end
  156.     )
  157.     rednet.close()
  158.    
  159.     print(a)
  160.     print(b)
  161.    
  162.     if b ~= nil then
  163.    
  164.         if b == "endpath" then
  165.        
  166.             print("stopped by rednet")
  167.             error()
  168.         end
  169.     else
  170.         return false
  171.     end
  172.    
  173. end
  174.  
  175. function removeMagma()
  176.         local a,b = turtle.inspectDown()
  177.         if b~= nil then
  178.                 local name = b.name or "nothing"
  179.                 if name == magmaBlock then
  180.                     turtle.digDown()
  181.                 end
  182.         end
  183.  
  184.  
  185. end
  186.  
  187. --waitForRednet()
  188. while true do
  189.     refuel()
  190.     removeMagma()
  191.     build()
  192.     digAll()
  193.     forward()
  194.     ifLava()
  195.  
  196.     --waitUntilNextMoment()
  197.     --checkRedent()
  198. end
  199.        
Add Comment
Please, Sign In to add comment