Advertisement
npexception

CC TurtleQuarry Ignore List Generator

Dec 19th, 2014
1,971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local version = 1.1
  2. if _UD and _UD.su(version, "fw5C7u8t", {...}) then return end
  3.  
  4. local IGNOREFILE = "ignore.list"
  5. local editWhenDone = false
  6.  
  7. local ignore = {
  8.   ["minecraft:stone"] = true,
  9.   ["minecraft:cobblestone"] = true,
  10.   ["minecraft:dirt"] = true
  11. }
  12.  
  13. if fs.exists(IGNOREFILE) then
  14.   local file = fs.open(IGNOREFILE, "r")
  15.   local content = file.readAll()
  16.   local list = textutils.unserialize(content)
  17.   ignore = {}
  18.   for _,name in pairs(list) do
  19.     ignore[name] = true
  20.   end
  21. end
  22.  
  23. local function inspect()
  24.   local previous = nil
  25.   while true do
  26.     local ok, data = turtle.inspect()
  27.     if ok then
  28.       local block = data.name
  29.       if block ~= previous then
  30.         previous = block
  31.         if ignore[block] then
  32.           print("Already known "..block)
  33.         else
  34.           print("Added "..block)
  35.           ignore[block] = true
  36.         end
  37.       end
  38.     end
  39.     sleep(0.1)
  40.   end
  41. end
  42.  
  43. local function waitForKey()
  44.   local event, char = os.pullEvent("char")
  45.   if char == "e" then
  46.     editWhenDone = true
  47.   end
  48. end
  49.  
  50. local function storeToFile()
  51.   -- convert to list
  52.   local list = {}
  53.   for name,_ in pairs(ignore) do
  54.     list[#list+1] = name
  55.   end
  56.   -- write to file
  57.   local file = fs.open(IGNOREFILE,"w")
  58.   file.write(textutils.serialize(list))
  59.   file.close()
  60. end
  61.  
  62.  
  63. --- main part
  64. print("Place Blocks that should be ignored by")
  65. print("the quarry in front of the turtle.")
  66. print("Press any alphanumeric key to stop the")
  67. print(" program and store the ignore list.")
  68. print("Regular stone, cobble, and dirt are")
  69. print(" added by default.")
  70. print("Press 'e' if you want to open the file")
  71. print("for editing afterwards.")
  72. print()
  73.  
  74. parallel.waitForAny(inspect, waitForKey)
  75.  
  76. storeToFile()
  77.  
  78. if editWhenDone then
  79.   shell.run("edit "..IGNOREFILE)
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement