Advertisement
Testman696969

Sorter

Dec 12th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. x,y,z=1,1,0
  2. dir=0
  3. smeltables={
  4. "minecraft:iron_ore",
  5. "minecraft:gold_ore",
  6. "thermalfoundation:ore",
  7. "railcraft:ore_metal",
  8. "railcraft:ore_metal_poor"
  9. }
  10. barrels={
  11. "minecraft:cobblestone",
  12. "minecraft:stone",
  13. "minecraft:dirt",
  14. "minecraft:gravel"
  15. }
  16. furnaces=5
  17.  
  18. function Forward()
  19. while not turtle.forward() do end
  20. if (dir%2)==0 then y=y-1+(dir%4)
  21. else x=x+2-(dir%4)
  22. end
  23. end
  24.  
  25. function Up()
  26. while not turtle.up() do end
  27. z=z+1
  28. end
  29.  
  30. function Down()
  31. while not turtle.down() do end
  32. z=z-1
  33. end
  34.  
  35. function Right()
  36. turtle.turnRight()
  37. dir=(dir+1)%4
  38. end
  39.  
  40. function Left()
  41. turtle.turnLeft()
  42. dir=(dir-1)%4
  43. end
  44.  
  45. function CheckSmeltable(num)
  46. local data=turtle.getItemDetail(num)
  47. if data then
  48. for i=1,#smeltables do
  49. if data.name==smeltables[i] then return true end
  50. end
  51. end
  52. return false
  53. end
  54.  
  55. function CheckBarrel(num)
  56. local data=turtle.getItemDetail(num)
  57. if data then
  58. for i=1,#barrels do
  59. if data.name==barrels[i] then return true end
  60. end
  61. end
  62. return false
  63. end
  64.  
  65. function MoveToFurnace(list)
  66. if #list==0 then return end
  67. turtle.select(list[1])
  68. Right() Right() Forward() Left()
  69. local tries,dropped=0,0
  70. while dropped<#list do
  71. for n=1,#list do
  72. turtle.select(list[n])
  73. if turtle.dropDown() then dropped=dropped+1 end
  74. end
  75. if dropped==#list then break
  76. elseif tries<furnaces-1 then
  77. Forward()
  78. tries=tries+1
  79. else break
  80. end
  81. end
  82. Right() Right()
  83. for i=1,tries do Forward() end
  84. Right() Forward()
  85. end
  86.  
  87. function MoveToChest(list)
  88. if #list==0 then return end
  89. Right() Forward()
  90. local tries,dropped=0,0
  91. while dropped<#list do
  92. for n=1,#list do
  93. turtle.select(list[n])
  94. if turtle.drop() then dropped=dropped+1 end
  95. end
  96. if dropped==#list then break
  97. else
  98. Up()
  99. tries=tries+1
  100. end
  101. end
  102. for i=1,tries do Down() end
  103. Right() Right() Forward() Right()
  104. end
  105.  
  106. function MoveToBarrel(list)
  107. if #list==0 then return end
  108. Right() Forward() Left()
  109. local tries,dropped=0,0
  110. while dropped<#list do
  111. for n=1,#list do
  112. turtle.select(list[n])
  113. if turtle.drop() then dropped=dropped+1 end
  114. end
  115. if dropped==#list then break
  116. else
  117. Up()
  118. tries=tries+1
  119. end
  120. end
  121. for i=1,tries do Down() end
  122. Left() Forward() Right()
  123. end
  124.  
  125. while true do
  126. while turtle.suckDown() do end
  127. local toChests,toSmelts,toBarrels={},{},{}
  128. for i=1,16 do
  129. turtle.select(i)
  130. if turtle.getItemCount(i)>0 then
  131. if CheckSmeltable(i) then table.insert(toSmelts,i)
  132. elseif CheckBarrel(i) then table.insert(toBarrels,i)
  133. else table.insert(toChests,i)
  134. end
  135. end
  136. end
  137. turtle.select(1)
  138. MoveToBarrel(toBarrels)
  139. MoveToChest(toChests)
  140. MoveToFurnace(toSmelts)
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement