renzo009

Turtle recycle counter

Jul 31st, 2021 (edited)
530
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. --- %%% enable this for initializing(this will reset all stats)
  3. -- also enable save_stats , below the save_stats function
  4. --scrap = 0
  5. --gold_ore = 0
  6. --gold_dust = 0
  7. --emerald = 0
  8. --ender_pearl = 0
  9. --glowstone_dust = 0
  10. --slime_ball = 0
  11. --rubber = 0
  12. --diamond = 0
  13. --cake = 0
  14. --- %%%
  15.  
  16. function load_stats()
  17.     file = io.open('scrap', 'r')
  18.     scrap = file:read()
  19.     file:close()
  20.     file = io.open('gold_ore', 'r')
  21.     gold_ore = file:read()
  22.     file:close()
  23.     file = io.open('gold_dust', 'r')
  24.     gold_dust = file:read()
  25.     file:close()
  26.     file = io.open('emerald', 'r')
  27.     emerald = file:read()
  28.     file:close()
  29.     file = io.open('ender_pearl', 'r')
  30.     ender_pearl = file:read()
  31.     file:close()
  32.     file = io.open('glowstone_dust', 'r')
  33.     glowstone_dust = file:read()
  34.     file:close()
  35.     file = io.open('slime_ball', 'r')
  36.     slime_ball = file:read()
  37.     file:close()
  38.     file = io.open('rubber', 'r')
  39.     rubber = file:read()
  40.     file:close()
  41.     file = io.open('diamond', 'r')
  42.     diamond = file:read()
  43.     file:close()
  44.     file = io.open('cake', 'r')
  45.     cake = file:read()
  46.     file:close()
  47. end
  48.  
  49. function save_stats()
  50.     file = io.open('scrap', 'w')
  51.     file:write(scrap)
  52.     file:close()
  53.     file = io.open('gold_ore', 'w')
  54.     file:write(gold_ore)
  55.     file:close()
  56.     file = io.open('gold_dust', 'w')
  57.     file:write(gold_dust)
  58.     file:close()
  59.     file = io.open('emerald', 'w')
  60.     file:write(emerald)
  61.     file:close()
  62.     file = io.open('ender_pearl', 'w')
  63.     file:write(ender_pearl)
  64.     file:close()
  65.     file = io.open('glowstone_dust', 'w')
  66.     file:write(glowstone_dust)
  67.     file:close()
  68.     file = io.open('slime_ball', 'w')
  69.     file:write(slime_ball)
  70.     file:close()
  71.     file = io.open('rubber', 'w')
  72.     file:write(rubber)
  73.     file:close()
  74.     file = io.open('diamond', 'w')
  75.     file:write(diamond)
  76.     file:close()
  77.     file = io.open('cake', 'w')
  78.     file:write(cake)
  79.     file:close()
  80. end
  81.  
  82. -- for initializing
  83.  
  84. --save_stats() -- for initializing
  85.  
  86. -- start code
  87. print('loading stats')
  88. load_stats()
  89. sleep(1)
  90. term.clear()
  91.  
  92. -- show start stats
  93. term.setCursorPos(1,1)
  94. term.write('scrap unboxed: ')
  95. term.setCursorPos(16,1)
  96. write(math.floor(scrap))
  97.  
  98. term.setCursorPos(1,2)
  99. term.write('ender_pearls: ')
  100. term.setCursorPos(15,2)
  101. term.write(math.floor(ender_pearl))
  102. term.setCursorPos(20,2)
  103. term.write('avg scrap: ')
  104. term.setCursorPos(30,2)
  105. term.write(math.floor(scrap / ender_pearl))
  106.  
  107. term.setCursorPos(1,3)
  108. term.write('Diamonds: ')
  109. term.setCursorPos(11,3)
  110. term.write(math.floor(diamond))
  111. term.setCursorPos(16,3)
  112. term.write('avg scrap: ')
  113. term.setCursorPos(27,3)
  114. term.write(math.floor(scrap / diamond))
  115.  
  116. --checker infinite loop
  117. while true do
  118.     if redstone.getInput('right') == true then
  119.     scrap = scrap + 1
  120.     term.setCursorPos(1,1)
  121.     term.write('scrap unboxed: ')
  122.     term.setCursorPos(16,1)
  123.     write(math.floor(scrap))
  124.     save_stats()
  125.     sleep(0.25) -- time between 4 tick comparetor dispenser clock
  126.     else
  127.     sleep(.01) -- small cooldown between checking
  128.     end
  129.  
  130.     for i = 1,16 do
  131.        
  132.         if turtle.getItemDetail(i) then
  133.         check_item = turtle.getItemDetail(i)
  134.         item_name = check_item.name
  135.         term.setCursorPos(1,5)
  136.         term.write("Last item: ")
  137.         term.setCursorPos(12,5)
  138.         term.write(item_name)
  139.        
  140.             if item_name == 'minecraft:gold_ore' then
  141.             gold_ore = gold_ore + 1
  142.             turtle.select(i)
  143.             turtle.drop()
  144.             save_stats()
  145.             elseif item_name == 'minecraft:emerald' then
  146.             emerald = emerald + 1
  147.             turtle.select(i)
  148.             turtle.drop()
  149.             term.setCursorPos(1,6)
  150.             term.write("dropping: ")
  151.             term.setCursorPos(11,6)
  152.             term.write(item_name)
  153.             save_stats()
  154.             elseif item_name == 'minecraft:ender_pearl' then
  155.             ender_pearl = ender_pearl + 1
  156.             turtle.select(i)
  157.             turtle.drop()
  158.             save_stats()
  159.             term.setCursorPos(1,2)
  160.             term.write('ender_pearls: ')
  161.             term.setCursorPos(15,2)
  162.             term.write(math.floor(ender_pearl))
  163.             term.setCursorPos(20,2)
  164.             term.write('avg scrap: ')
  165.             term.setCursorPos(30,2)
  166.             term.write(math.floor(scrap / ender_pearl))
  167.             elseif item_name == 'minecraft:glowstone_dust' then
  168.             glowstone_dust = glowstone_dust + 1
  169.             turtle.select(i)
  170.             turtle.drop()
  171.             save_stats()
  172.             elseif item_name == 'minecraft:cake' then
  173.             cake = cake + 1
  174.             turtle.select(i)
  175.             turtle.drop()
  176.             save_stats()
  177.             elseif item_name == 'minecraft:slime_ball' then
  178.             slime_ball = slime_ball + 1
  179.             turtle.select(i)
  180.             turtle.drop()
  181.             save_stats()
  182.             elseif item_name == 'minecraft:diamond' then
  183.             diamond = diamond + 1
  184.             turtle.select(i)
  185.             turtle.drop()
  186.             save_stats()
  187.             term.setCursorPos(1,3)
  188.             term.write('Diamonds: ')
  189.             term.setCursorPos(11,3)
  190.             term.write(math.floor(diamond))
  191.             term.setCursorPos(16,3)
  192.             term.write('avg scrap: ')
  193.             term.setCursorPos(27,3)
  194.             term.write(math.floor(scrap / diamond))
  195.             elseif item_name == 'thermalfoundation:material' then
  196.             gold_dust = gold_dust + 1
  197.             turtle.select(i)
  198.             turtle.drop()
  199.             save_stats()
  200.             elseif item_name == 'ic2:crafting' then
  201.             rubber = rubber + 1
  202.             turtle.select(i)
  203.             turtle.drop()
  204.             save_stats()
  205.             end -- if statements
  206.         end -- if getItemDetail
  207.    
  208.     end -- end for loop
  209.  
  210. end -- end while loop
RAW Paste Data