blunderhund

track5

Mar 19th, 2021 (edited)
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. local REG_TRACK_COUNT = 37
  2. local POWER_TRACK_COUNT = 1
  3. local RT_COUNT = 1
  4. local rt = 1
  5. local pt = 2
  6. local totalDistance = 0
  7. local PR = "minecraft:powered_rail"
  8. local RR = "minecraft:rail"
  9. local RT = "minecraft:redstone_torch"
  10.  
  11. if #arg == 1 then
  12.     totalDistance = tonumber(arg[1])
  13. else
  14.     print("Please give total count of track iterations to lay so I don't go on forever.")
  15. end
  16.    
  17. function layBlock(blockType, blockCount)
  18.     local curSlot = nextSlot(blockType)
  19.     for i = 1, blockCount do
  20.         turtle.forward()
  21.         if turtle.compareDown() == false then
  22.             if curSlot ~= false then
  23.                 turtle.select(curSlot)
  24.                 if slotCount(curSlot) < 0 then
  25.                     turtle.placeDown(1)
  26.                 else
  27.                     curSlot = nextSlot(blockType)
  28.                     if curSlot ~= false then
  29.                         turtle.select(curSlot)
  30.                         turtle.placeDown(1)
  31.                     else
  32.                         print(blockType, " not found!")
  33.                     end
  34.                 end
  35.             else
  36.                 print(blockType, " not found!")
  37.             end
  38.         else
  39.             print(blockType, " already here")
  40.         end
  41.     end
  42.     return true
  43. end
  44.  
  45. function slotCount(s)
  46.         turtle.select(s)
  47.         return turtle.getItemCount(s)
  48. end
  49.  
  50. function nextSlot(t)
  51.     print(t)
  52.     for i = 1, 16 do
  53.         if turtle.getItemCount(i) > 0 then
  54.             if turtle.getItemDetail(i)["name"] == t then
  55.                 return i
  56.             end
  57.         end
  58.     end
  59.     return false
  60. end
  61.  
  62. function checkFront()
  63.     local success, data = turtle.inspect()
  64.     if success then
  65.         return data.name
  66.     else
  67.         return false
  68.     end
  69. end
  70.  
  71. function redTorch()
  72.     local retVal = false
  73.     turtle.turnLeft()
  74.     if layBlock(RT, RT_COUNT) == true then
  75.         retVal = true
  76.     end
  77.     turtle.back()
  78.     turtle.turnRight()
  79.     return retVal
  80. end
  81.  
  82. turtle.up()
  83. for i=1, totalDistance do
  84.     if layBlock(RR, REG_TRACK_COUNT) == true then
  85.         --print("Layed reg track set.")
  86.         if layBlock(PR, POWER_TRACK_COUNT) == true then
  87.             --print("Layed power track set.")
  88.             if redTorch() == true then
  89.                 print("Layed a red stone torch.")
  90.             else
  91.                 print("Red stone torch error.")
  92.             end
  93.         else
  94.             print("Power track error.")
  95.         end
  96.     else
  97.         print("Reg track error.")
  98.     end
  99. end
Add Comment
Please, Sign In to add comment