Advertisement
VADemon

MysteriousItem

Nov 16th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. monitorSide = "top"
  2. redstoneSide = "left"
  3. outputSide = "back"
  4. inputSide = "Down"  -- suckDown/Up
  5.  
  6. mon = peripheral.wrap("top")
  7. f = io.open("items.txt", "w")
  8.  
  9. function show()
  10.     for s = 1, 16 do
  11.         local item = turtle.getItemDetail(s)
  12.        
  13.         local line = ""
  14.        
  15.         for k,v in pairs(item) do
  16.             if k == "count" then
  17.                 k = "x"
  18.                 v = string.format("%02d", v)
  19.             end
  20.             if k == "name" then
  21.                 line = line .. "\"".. v .."\", "
  22.             else
  23.                 line = line .. "[".. k .."]=".. v ..", "
  24.             end
  25.         end
  26.        
  27.         print(line)
  28.         f:write(line)
  29.        
  30.         f:write("\n")
  31.         --term.setCursorPos(1, s)
  32.     end
  33.    
  34.     f:flush()
  35.     --term.setCursorPos(1,1)
  36. end
  37.  
  38. function outputItems()
  39.     repeat
  40.         for i = 1, 16 do
  41.             turtle.select(i)
  42.             turtle.drop(64)        
  43.         end
  44.         turtle.select(1)
  45.        
  46.         sleep(1)
  47.         local hasItems = 0
  48.        
  49.         for s = 1, 16 do
  50.             hasItems = hasItems + turtle.getItemCount(s)
  51.         end
  52.        
  53.         sleep(1)
  54.     until hasItems == 0
  55.    
  56.     redstone.setOutput(outputSide, false)
  57. end
  58.  
  59. function inputItems()
  60.     for i = 1, 16 do
  61.         turtle["suck" .. inputSide](64)
  62.     end
  63. end
  64.  
  65. while true do
  66.     if redstone.getInput(redstoneSide) then
  67.         print("Redstone Signal Received!")
  68.         show()
  69.         sleep(1)
  70.         --
  71.        
  72.        
  73.         print("Waiting for repeated Redstone Input to output Items!")
  74.        
  75.         local wait = true
  76.        
  77.         while wait do
  78.             if redstone.getInput(redstoneSide) then
  79.                 wait = false
  80.                 print("Outputting Items!")
  81.                 outputItems()
  82.             end
  83.             sleep(0.1)
  84.         end
  85.        
  86.         sleep(1)
  87.         print("Inputting items!")
  88.         inputItems()
  89.         print("Done!")
  90.         sleep(1)
  91.        
  92.     else
  93.         sleep(0.1)
  94.     end
  95.    
  96.     if redstone.getInput("front") then
  97.         f:close()
  98.         print("Stop Signal received!")
  99.         mon.write("Stop Signal received!")
  100.         break
  101.     end
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement