Advertisement
TheProdigy22

Untitled

Mar 13th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. local args = {...}
  2.  
  3. local blueprint = {}
  4. blueprint.x = tonumber(args[1])
  5. blueprint.y = tonumber(args[2])
  6. blueprint.h = tonumber(args[3])
  7. blueprint.slots = {}
  8. blueprint.tcode = {}
  9.  
  10. local userFile = shell.resolve(args[4])
  11.  
  12. if fs.exists(userFile) then
  13. print("Error: A file by that name already exists")
  14. return
  15. end
  16.  
  17. local bpFile = fs.open(userFile,"w")
  18.  
  19. --returns whatever slot the block was put into
  20. function scan(up)
  21. local slotCounts = {}
  22. for i=1,16 do
  23. slotCounts[i] = turtle.getItemCount(i)
  24. end
  25. if up then
  26. turtle.digUp()
  27. else
  28. turtle.dig()
  29. end
  30. local slot = 0
  31. for i=1,16 do
  32. if turtle.getItemCount(i) > slotCounts[i] then
  33. slot = i
  34. end
  35. end
  36. if slot > 0 then
  37. --if slot hasn't been used yet
  38. if not blueprint.slots[slot] then
  39. --get item name for slot
  40. local item = turtle.getItemDetail(slot).name
  41. blueprint.slots[slot] = {name = item, count = 0}
  42. end
  43. --add 1 to the slot count
  44. blueprint.slots[slot].count = turtle.getItemCount(slot)
  45. end
  46. --add the slot number to the tcode
  47. return slot
  48. end
  49. local i = 1
  50. local right = true
  51. blueprint.tcode[i] = scan()
  52. i = i + 1
  53. turtle.forward()
  54. for h=1,blueprint.h do
  55. for y=1,blueprint.y do
  56. for x=1,blueprint.x do
  57. blueprint.tcode[i] = scan()
  58. if x < blueprint.x then
  59. turtle.forward()
  60. end
  61. i = i + 1
  62. end
  63. if y < blueprint.y then
  64. if right then
  65. turtle.turnRight()
  66. blueprint.tcode[i] = scan()
  67. i = i + 1
  68. turtle.forward()
  69. turtle.turnRight()
  70. right = false
  71. else
  72. turtle.turnLeft()
  73. blueprint.tcode[i] = scan()
  74. i = i + 1
  75. turtle.forward()
  76. turtle.turnLeft()
  77. right = true
  78. end
  79. end
  80. end
  81. blueprint.tcode[i] = scan(true)
  82. i = i + 1
  83. turtle.turnRight()
  84. turtle.turnRight()
  85. end
  86.  
  87. local output = textutils.serialize(blueprint)
  88. bpFile.write(output)
  89. bpFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement