blunderhund

track3

Mar 19th, 2021 (edited)
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 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. local PR = "minecraft:powered_rail"
  7. local RR = "minecraft:rail"
  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 layTrack(railType, railCount)
  16.     local curSlot = nextSlot(railType)
  17.     if curSlot ~= false then
  18.         turtle.select(curSlot)
  19.     else
  20.         return false
  21.     end
  22.     for i = 1, railCount do
  23.         local checkStatus = checkFront()
  24.         print(checkStatus)
  25.         if checkStatus ~= false then
  26.             if checkStatus == "minecraft:wall_torch" then
  27.                 print("Torch detected.")
  28.             else
  29.                 print("Block in the way")
  30.                 return false
  31.             end
  32.         else
  33.             turtle.forward()
  34.             if slotCount(curSlot) < 0 then
  35.                 if turtle.compareDown() then
  36.                     print("Already a rail here.")
  37.                 else
  38.                     turtle.placeDown(1)
  39.                 end
  40.             else
  41.                 curSlot = nextSlot(railType)
  42.                 if curSlot ~= false then
  43.                     turtle.select(curSlot)
  44.                     if turtle.compareDown() then
  45.                         print("Already a rail here.")
  46.                     else
  47.                         turtle.placeDown(1)
  48.                     end
  49.                 else
  50.                     return false
  51.                 end
  52.             end
  53.         end
  54.     end
  55.     return true
  56. end
  57.  
  58. function slotCount(s)
  59.         turtle.select(s)
  60.         return turtle.getItemCount(s)
  61. end
  62.  
  63. function nextSlot(t)
  64.     print(t)
  65.     for i = 1, 16 do
  66.         if turtle.getItemCount(i) > 0 then
  67.             if turtle.getItemDetail(i)["name"] == t then
  68.                 return i
  69.             end
  70.         end
  71.     end
  72.     return false
  73. end
  74.  
  75. function checkFront()
  76.     local success, data = turtle.inspect()
  77.     if success then
  78.         return data.name
  79.     else
  80.         return false
  81.     end
  82. end
  83.  
  84. turtle.up()
  85. for i=1, totalDistance do
  86.     if layTrack(RR, REG_TRACK_COUNT) == true then
  87.         --print("Layed reg track set.")
  88.         if layTrack(PR, POWER_TRACK_COUNT) == true then
  89.             --print("Layed power track set.")
  90.         else
  91.             print("Power track error.")
  92.         end
  93.     else
  94.         print("Reg track error.")
  95.     end
  96. end
Add Comment
Please, Sign In to add comment