blunderhund

track4

Mar 19th, 2021 (edited)
803
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_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.     if curSlot ~= false then
  20.         turtle.select(curSlot)
  21.     else
  22.         return false
  23.     end
  24.     for i = 1, blockCount do
  25.         local checkStatus = checkFront()
  26.         print(checkStatus)
  27.         if checkStatus ~= false then
  28.             if checkStatus == "minecraft:wall_torch" then
  29.                 print("Torch detected.")
  30.             else
  31.                 print("Block in the way")
  32.                 return false
  33.             end
  34.         else
  35.             turtle.forward()
  36.             if slotCount(curSlot) < 0 then
  37.                 if turtle.compareDown() then
  38.                     print(blockType, " already here")
  39.                 else
  40.                     turtle.placeDown(1)
  41.                 end
  42.             else
  43.                 curSlot = nextSlot(blockType)
  44.                 if curSlot ~= false then
  45.                     turtle.select(curSlot)
  46.                     if turtle.compareDown() then
  47.                         print(blockType, " already here")
  48.                     else
  49.                         turtle.placeDown(1)
  50.                     end
  51.                 else
  52.                     if turtle.compareDown() then
  53.                         print(blockType, " already here")
  54.                     else
  55.                         return false
  56.                     end
  57.                 end
  58.             end
  59.         end
  60.     end
  61.     return true
  62. end
  63.  
  64. function slotCount(s)
  65.         turtle.select(s)
  66.         return turtle.getItemCount(s)
  67. end
  68.  
  69. function nextSlot(t)
  70.     print(t)
  71.     for i = 1, 16 do
  72.         if turtle.getItemCount(i) > 0 then
  73.             if turtle.getItemDetail(i)["name"] == t then
  74.                 return i
  75.             end
  76.         end
  77.     end
  78.     return false
  79. end
  80.  
  81. function checkFront()
  82.     local success, data = turtle.inspect()
  83.     if success then
  84.         return data.name
  85.     else
  86.         return false
  87.     end
  88. end
  89.  
  90. function redTorch()
  91.     local retVal = false
  92.     turtle.turnLeft()
  93.     if layBlock(RT, RT_COUNT) == true then
  94.         retVal = true
  95.     end
  96.     turtle.back()
  97.     turtle.turnRight()
  98.     return retVal
  99. end
  100.  
  101. turtle.up()
  102. for i=1, totalDistance do
  103.     if layBlock(RR, REG_TRACK_COUNT) == true then
  104.         --print("Layed reg track set.")
  105.         if layBlock(PR, POWER_TRACK_COUNT) == true then
  106.             --print("Layed power track set.")
  107.             if redTorch() == true then
  108.                 print("Layed a red stone torch.")
  109.             else
  110.                 print("Red stone torch error.")
  111.             end
  112.         else
  113.             print("Power track error.")
  114.         end
  115.     else
  116.         print("Reg track error.")
  117.     end
  118. end
Advertisement
Add Comment
Please, Sign In to add comment