blunderhund

track2

Mar 17th, 2021 (edited)
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | None | 0 0
  1. local REG_TRACK_COUNT = 37
  2. local POWER_TRACK_COUNT = 1
  3. local rt = 1
  4. local pt = 2
  5. local totalDistance = 0
  6.  
  7.  
  8.  
  9. if #arg == 1 then
  10.     totalDistance = tonumber(arg[1])
  11. else
  12.     print("Please give total count of track iterations to lay so I don't go on forever.")
  13. end
  14.    
  15. function regTrack()
  16.     local curSlot = nextSlot("minecraft:rail")
  17.     if curSlot ~= false then
  18.         turtle.select(curSlot)
  19.     else
  20.         return false
  21.     end
  22.     for i = 1, REG_TRACK_COUNT do
  23.         local checkStatus = checkFront()
  24.         print(checkStatus)
  25.         if checkStatus ~= false then
  26.             if checkStatus == "minecraft:wall_torch" then
  27.                 print("regTrack: Torch detected.")
  28.             else
  29.                 print("regTrack: Block in the way")
  30.                 return false
  31.             end
  32.         else
  33.             turtle.forward()
  34.             if slotCount(curSlot) < 0 then
  35.                 turtle.placeDown(1)
  36.             else
  37.                 curSlot = nextSlot("minecraft:rail")
  38.                 if curSlot ~= false then
  39.                     turtle.select(curSlot)
  40.                     turtle.placeDown(1)
  41.                 else
  42.                     return false
  43.                 end
  44.             end
  45.         end
  46.     end
  47.     return true
  48. end
  49.  
  50. function powTrack()
  51.     local curSlot = nextSlot("minecraft:powered_rail")
  52.     if curSlot ~= false then
  53.         turtle.select(curSlot)
  54.     else
  55.         return false
  56.     end
  57.     for i = 1, POWER_TRACK_COUNT do
  58.         local checkStatus = checkFront()
  59.         if checkStatus ~= false then
  60.             if checkStatus == "minecraft:wall_torch" then
  61.                 print("powTrack: Torch detected.")
  62.             else
  63.                 print("powTrack: Block in the way")
  64.                 return false
  65.             end
  66.         else
  67.             turtle.forward()
  68.             if slotCount(curSlot) < 0 then
  69.                 turtle.placeDown(1)
  70.             else
  71.                 curSlot = nextSlot("minecraft:powered_rail")
  72.                 if curSlot ~= false then
  73.                     turtle.select(curSlot)
  74.                     turtle.placeDown(1)
  75.                 else
  76.                     return false
  77.                 end
  78.             end
  79.         end
  80.     end
  81.     return true
  82. end
  83.  
  84. function slotCount(s)
  85.         turtle.select(s)
  86.         return turtle.getItemCount(s)
  87. end
  88.  
  89. function nextSlot(t)
  90.     print(t)
  91.     for i = 1, 16 do
  92.         if turtle.getItemCount(i) > 0 then
  93.             if turtle.getItemDetail(i)["name"] == t then
  94.                 return i
  95.             end
  96.         end
  97.     end
  98.     return false
  99. end
  100.  
  101. function checkFront()
  102.     local success, data = turtle.inspect()
  103.     if success then
  104.         return data.name
  105.     else
  106.         return false
  107.     end
  108. end
  109.  
  110. turtle.up()
  111. for i=1, totalDistance do
  112.     if regTrack() == true then
  113.         --print("Layed reg track set.")
  114.         if powTrack() == true then
  115.             --print("Layed power track set.")
  116.         else
  117.             print("Power track error.")
  118.         end
  119.     else
  120.         print("Reg track error.")
  121.     end
  122. end
Add Comment
Please, Sign In to add comment