Advertisement
demon012

Minecraft - Item Sorter - Item Command

Feb 27th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.22 KB | None | 0 0
  1. args = {...}
  2. ItemDB = {
  3.     itemdb_path = 'itemdb',
  4. }
  5. ItemDB_mt = {__index = Item}
  6.  
  7. function ItemDB:create()--{{{
  8.     local new_ItemDB = {}
  9.     setmetatable(new_ItemDB, ItemDB_mt)
  10.     return new_ItemDB
  11. end--}}}
  12. function ItemDB:loadItemDB()--{{{
  13.     if fs.exists(self.itemdb_path) then
  14.         f = fs.open(self.itemdb_path, 'r')
  15.         self.itemDB = textutils.unserialize(f.readAll())
  16.         f.close()
  17.         f = nil
  18.     else
  19.         self.itemDB = {}
  20.     end
  21. end--}}}
  22. function ItemDB:saveItemDB()--{{{
  23.     f = fs.open(self.itemdb_path, 'w')
  24.     f.write(textutils.serialize(self.itemDB))
  25.     f.close()
  26.     f = nil
  27. end--}}}
  28.  
  29. db = ItemDB
  30. db:loadItemDB()
  31. itemuuid = args[2] .. ":" .. args[3]
  32. -- find item id and damage combo
  33. item = db.itemDB[itemuuid]
  34. if item then
  35.     if args[1] == 'smelt' then
  36.         item.action = 'smelt'
  37.     elseif args[1] == 'macerate' then
  38.         item.action = 'macerate'
  39.     elseif args[1] == 'action' then
  40.         if item.action then
  41.             print(item.action)
  42.         else
  43.             print("item action not set so it would be stored")
  44.         end
  45.     end
  46.     db.itemDB[itemuuid] = item
  47.     db:saveItemDB()
  48. else
  49.     print("Item " .. itemuuid .. " not in the database")
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement