Advertisement
karelvysinka

UU mater combination

Apr 7th, 2023 (edited)
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. local function decimalToBinary(number)
  2.     local binary = {}
  3.     while number > 0 do
  4.         table.insert(binary, 1, number % 2)
  5.         number = math.floor(number / 2)
  6.     end
  7.     return binary
  8. end
  9.  
  10. local function generateCombination(index)
  11.     local binary = decimalToBinary(index)
  12.     local combination = {}
  13.     for i = 1, 9 do
  14.         local bit = binary[i] or 0
  15.         combination[i] = bit == 1 and "minecraft:uu_matter" or "minecraft:air"
  16.     end
  17.     return combination
  18. end
  19.  
  20. local function clearCraftingGrid(usedSlots)
  21.     for _, slotPair in ipairs(usedSlots) do
  22.         turtle.select(slotPair.to)
  23.         turtle.transferTo(slotPair.from, 1)
  24.     end
  25. end
  26.  
  27. local function testCombination(combination)
  28.     local uuMatterSlot = 1
  29.     local craftSlots = {1, 2, 3, 5, 6, 7, 9, 10, 11}
  30.     local usedSlots = {}
  31.     for i = 1, 9 do
  32.         if combination[i] == "minecraft:uu_matter" then
  33.             turtle.select(uuMatterSlot)
  34.             turtle.suck(1)
  35.             turtle.transferTo(craftSlots[i], 1)
  36.             table.insert(usedSlots, {from = uuMatterSlot, to = craftSlots[i]})
  37.             uuMatterSlot = uuMatterSlot + 1
  38.             if uuMatterSlot > 27 then
  39.                 clearCraftingGrid(usedSlots)
  40.                 return false, nil -- not enough UU matter
  41.             end
  42.         else
  43.             turtle.select(4) -- empty slot
  44.         end
  45.     end
  46.     turtle.select(1)
  47.     local success, result = turtle.craft()
  48.     if success then
  49.         for i = 1, 16 do
  50.             local item = turtle.getItemDetail(i)
  51.             if item and item.name ~= "minecraft:cobblestone" then
  52.                 turtle.select(i)
  53.                 turtle.drop()
  54.             end
  55.         end
  56.     end
  57.     clearCraftingGrid(usedSlots)
  58.     return success, success and turtle.getItemDetail(1) or nil
  59. end
  60.  
  61. local function logResult(file, combination, item)
  62.     local recipe = "{ "
  63.     for i = 1, 9 do
  64.         recipe = recipe .. (i > 1 and ", " or "") .. "\"" .. combination[i] .. "\""
  65.     end
  66.     recipe = recipe .. " }"
  67.     file.write("Recept: " .. recipe .. ", Item: " .. item.name .. ", Počet: " .. item.count .. "\n")
  68. end
  69.  
  70. local totalCombinations = 2 ^ 9
  71. local logFile = fs.open("recepty.txt", "w")
  72.  
  73. for i = 0, totalCombinations - 1 do
  74.     local combination = generateCombination(i)
  75.     local success, item = testCombination(combination)
  76.     if success then
  77.         logResult(logFile, combination, item)
  78.     end
  79. end
  80.  
  81. logFile.close()
  82. print("Testování receptů dokončeno")
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement