gunny576

Disassemble .01

Apr 7th, 2022 (edited)
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. --Turtle Disassemble
  2. --input paramaters
  3. --1 range
  4.  
  5. local function printUsage()
  6.     print( "Usages:" )
  7.     print( "Disassemble  <distance>" )
  8. end
  9. --array of items dugup
  10. local items = {}
  11. local tArgs = { ... }
  12. local slots = {}
  13. local activeslot = 1
  14. --fills the slot array with junk data
  15. for i=1,16 do
  16.     for j=1, 4 do
  17.         slots[(i..':'..j)] =64
  18.     end
  19. end
  20. if #tArgs < 1 then
  21.     printUsage()
  22.     return
  23. end
  24.  
  25. --fuction to find the item we just dug up
  26. local function checkItem(row, i)
  27.     a=turtle.getItemDetail()
  28.     items[row..i]=a
  29.     print(row..i)
  30.     print(items[row..i].name)
  31. end
  32. --post dig, find the item added to the turtles inventory
  33. local function findItem(row, i)
  34.     for k=1,activeslot+1 do
  35.         --function only worked with these statements unnessted in an if statement
  36.         --no fucking idea why
  37.         space = turtle.getItemSpace(k)
  38.     --  print(space)
  39.         spaceleft = slots[(k..':'..1)]
  40.     --  print(spaceleft)
  41.     --if this metric changed we know that slot added an item to it
  42.         if (space==spaceleft-1) then
  43.             turtle.select(k)
  44.             slots[(k..':'..1)]=slots[(k..':'..1)]-1
  45.             checkItem(row,i)
  46.             turtle.select(1)
  47.             if (k==activeslot+1)then
  48.             activeslot=activeslot+1
  49.             --overflow check for slot 17 here
  50.             end
  51.                
  52.         end    
  53.     end
  54.    
  55. end
  56.  
  57. --main dig loop
  58. i=0
  59. local items = {}
  60. tArgs[1]=tArgs[1]+0
  61. while i<tArgs[1] do
  62.     while(not turtle.forward()) do
  63.     --if the selected slot is full on space, move the selected slot up
  64.         turtle.dig()
  65.         findItem('F',i)
  66.         --step 1 find the slot that took in the item
  67. --      if (foo -1 == turtle.getItemSpace(activeslot)) then
  68. --          checkItem(f, i)
  69. --      else
  70. --          activeslot = activeslot+1
  71. --          turtle.select(activeslot)
  72. --          checkItem(f, i)
  73. --      end
  74.         os.sleep(1)
  75.     end
  76.     turtle.digUp()
  77.     findItem('U',i)
  78.     turtle.digDown()
  79.     findItem('D',i)
  80.     i=i+1
  81. end
  82.    
  83. file = fs.open("output.txt","w")
  84. row1=""
  85. row2=""
  86. row3=""
  87. for(i=0, i<tArgs[1]) do
  88.     row1=row1..items['U'..i]..', '
  89.     row2=row2..items['F'..i]..', '
  90.     row3=row3..items['D'..i]..', '
  91. end
  92. file.write(row1)
  93. file.write(row2)
  94. file.write(row3)
  95.    
  96. turtle.turnLeft()
  97. turtle.turnLeft()
  98. while i>1 do
  99.     while (not turtle.forward()) do
  100.         turtle.dig()
  101.         os.sleep(1)
  102.     end
  103.     i = i-1
  104. end
Add Comment
Please, Sign In to add comment