soulgriever

Untitled

Oct 11th, 2021 (edited)
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. -- Clears the generated .blacklist file before start equivilant to "delete .blacklist" and loads default values
  2. --  OreQuarry REDUX by default uses a dynamic .blacklist file that is updated every time the program starts but saves previous values
  3. clearBlacklist = false
  4.  
  5. -- Default blacklist values ***This is ignored after a .blacklist file has been generated unless "clearBlacklist = true"***
  6. local blacklistArray = {
  7.     ["minecraft:air"] = true,
  8.     ["minecraft:bedrock"] = true,
  9.     ["minecraft:cobblestone"] = true,
  10.     ["minecraft:dirt"] = true,
  11.     ["minecraft:ice"] = true,
  12.     ["minecraft:ladder"] = true,
  13.     ["minecraft:snow"] = true,
  14.     ["minecraft:snow_layer"] = true,
  15.     ["minecraft:stone"] = true,
  16.     ["minecraft:grass"] = true,
  17.     ["minecraft:torch"] = true
  18. }
  19.  
  20.  
  21.  
  22. --Checks to see if a blacklist file has been generated, imports current blacklist, adds items in slots 1-14 to blacklist
  23. function checkBlacklist()
  24.     if clearBlacklist == false then
  25.         if fs.exists(".blacklist") then
  26.             --Opens the .blacklist file and loads contents to blacklistArray
  27.             local file = fs.open(".blacklist","r")
  28.             local data = file.readAll()
  29.             file.close()
  30.             blacklistArray = textutils.unserialize(data)
  31.         end
  32.         --Compares items in slots 1-14 with blacklistArray adds item to blacklistArray if not already specified
  33.         for i=1,14 do
  34.             turtle.select(i)
  35.             local item = turtle.getItemDetail()
  36.             if item then
  37.                 if blacklistArray[item.name] then
  38.                 else
  39.                 print("Added "..item.name.." to the blacklist!")
  40.                 blacklistArray[item.name] = true
  41.                 end
  42.             end
  43.         end
  44.         --Writes the updated blacklistArray to .blacklist for next run
  45.         local file = fs.open(".blacklist","w")
  46.         file.write(textutils.serialize(blacklistArray))
  47.         file.close()
  48.     else
  49.         --if clearBlacklist = true deletes previous .blacklist and generates fresh list from table and turtle inventory
  50.         fs.delete(".blacklist")
  51.         clearBlacklist = false
  52.         checkBlacklist()
  53.     end
  54. end
Add Comment
Please, Sign In to add comment