alesandreo

lib/ale/turtle/blocklist.lua

Aug 11th, 2021 (edited)
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. -- https://pastebin.com/tnXQrtpQ
  2.  
  3. BlockList = {}
  4. BlockList.__index = BlockList
  5.  
  6. function BlockList:new()
  7.   local o = {}
  8.   setmetatable(o, BlockList)
  9.   o.blocks = {}
  10.   o.tags = {}
  11.   return o
  12. end
  13.  
  14. function BlockList:addBlock(block_name)
  15.   self.blocks[block_name] = true
  16. end
  17.  
  18. function BlockList:removeBlock(block_name)
  19.   self.blocks[block_name] = nil
  20. end
  21.  
  22. function BlockList:addTag(tag)
  23.   self.tags[tag] = true
  24. end
  25.  
  26. function BlockList:removeTag(tag)
  27.   self.tags[tag] = nil
  28. end
  29.  
  30. function BlockList: checkBlockName(block_name)
  31.   return self.blocks[block_name]
  32. end
  33.  
  34. function BlockList:checkBlockTag(block_tag)
  35.   return self.tags[block_tag]
  36. end
  37.  
  38. function BlockList:checkBlockTags(block_data)
  39.   if not block_data.tags then
  40.     return false
  41.   end
  42.   for tag, tagBool in pairs(block_data.tags) do
  43.     if  self:checkBlockTag(tag) then
  44.       return true
  45.     end
  46.   end
  47.   return false
  48. end
  49.  
  50. function BlockList:checkBlock(block_data)
  51.   local block_name
  52.   block_name = block_data.name
  53.   return (self:checkBlockName(block_name) or self:checkBlockTags(block_data))
  54. end
Add Comment
Please, Sign In to add comment