Advertisement
skypop

CC-UUMatter recipes

Jul 22nd, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. -- UU-Matter recipes
  2. -- by SukaiPoppuGo
  3. -- https://github.com/absolument/CC-UUMatter-recipes
  4. -- Credits for integer to binary function :
  5. -- https://stackoverflow.com/a/26702880
  6.  
  7. assert(turtle and turtle.craft, "Require crafty turtle")
  8.  
  9. local saveFile = "UU.lua"
  10.  
  11. local function _select(slot)
  12.     if turtle.getSelectedSlot() ~= slot then
  13.         turtle.select(slot)
  14.     end
  15. end
  16.  
  17. local function toBits(num, bits)
  18.     -- returns a table of bits
  19.     local t={} -- will contain the bits
  20.     for b=bits,1,-1 do
  21.         rest=math.floor(math.fmod(num,2))
  22.         t[b]=rest
  23.         num=(num-rest)/2
  24.     end
  25.     if num==0 then return t else return {'Not enough bits to represent this number'}end
  26. end
  27.  
  28. local grid = {
  29.     1,  2,  3,  --4,
  30.     5,  6,  7,  --8,
  31.     9,  10, 11, --12,
  32. --  13, 14, 15, 16,
  33. }
  34.  
  35. for i=1,2^9-1 do
  36.     --iterate pattern
  37.     local _pattern = toBits(i, 9)
  38.     --Sum of items
  39.     local _cost = 0
  40.     for slot,v in ipairs(_pattern) do
  41.         _cost = _cost + v
  42.     end
  43.     print(i, "Pattern:", unpack(_pattern))
  44.    
  45.     --Place items
  46.     _select(1)
  47.     turtle.suckUp(_cost)
  48.     for pos=2, 9 do
  49.         local slot = grid[pos]
  50.         if _pattern[pos] == 1 then
  51.             turtle.transferTo(slot,1)
  52.         end
  53.     end
  54.    
  55.     --test craft
  56.     local success = turtle.craft()
  57.     local data = turtle.getItemDetail(1)
  58.     if success and data and data.name then
  59.         print("Get", data.count, data.name)
  60.         local r = {}
  61.         data.i = i
  62.         data.cost = _cost
  63.         data.pattern = _pattern
  64.         if data.damage then
  65.             r["damage"] = data.damage
  66.         end
  67.         --save craft
  68.         settings.load(saveFile)
  69.         local tRecipes = settings.get("UURecipes",{})
  70.         table.insert(tRecipes, data)
  71.         settings.set("UURecipes", tRecipes)
  72.         settings.save(saveFile)
  73.     end
  74.    
  75.     --Clear grid
  76.     for slot=1,16 do
  77.         local data = turtle.getItemDetail(slot)
  78.         if data and data.count > 0 then
  79.             _select(slot)
  80.             if data.damage and data.damage == 202 and data.name == "ic2:itemmisc" then
  81.                 turtle.dropUp()
  82.             else
  83.                 turtle.dropDown()
  84.             end
  85.         end
  86.     end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement