Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function decimalToBinary(number)
- local binary = {}
- while number > 0 do
- table.insert(binary, 1, number % 2)
- number = math.floor(number / 2)
- end
- return binary
- end
- local function generateCombination(index)
- local binary = decimalToBinary(index)
- local combination = {}
- for i = 1, 9 do
- local bit = binary[i] or 0
- combination[i] = bit == 1 and "minecraft:uu_matter" or "minecraft:air"
- end
- return combination
- end
- local function clearCraftingGrid(usedSlots)
- for _, slotPair in ipairs(usedSlots) do
- turtle.select(slotPair.to)
- turtle.transferTo(slotPair.from, 1)
- end
- end
- local function testCombination(combination)
- local uuMatterSlot = 1
- local craftSlots = {1, 2, 3, 5, 6, 7, 9, 10, 11}
- local usedSlots = {}
- for i = 1, 9 do
- if combination[i] == "minecraft:uu_matter" then
- turtle.select(uuMatterSlot)
- turtle.suck(1)
- turtle.transferTo(craftSlots[i], 1)
- table.insert(usedSlots, {from = uuMatterSlot, to = craftSlots[i]})
- uuMatterSlot = uuMatterSlot + 1
- if uuMatterSlot > 27 then
- clearCraftingGrid(usedSlots)
- return false, nil -- not enough UU matter
- end
- else
- turtle.select(4) -- empty slot
- end
- end
- turtle.select(1)
- local success, result = turtle.craft()
- if success then
- for i = 1, 16 do
- local item = turtle.getItemDetail(i)
- if item and item.name ~= "minecraft:cobblestone" then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- clearCraftingGrid(usedSlots)
- return success, success and turtle.getItemDetail(1) or nil
- end
- local function logResult(file, combination, item)
- local recipe = "{ "
- for i = 1, 9 do
- recipe = recipe .. (i > 1 and ", " or "") .. "\"" .. combination[i] .. "\""
- end
- recipe = recipe .. " }"
- file.write("Recept: " .. recipe .. ", Item: " .. item.name .. ", Počet: " .. item.count .. "\n")
- end
- local totalCombinations = 2 ^ 9
- local logFile = fs.open("recepty.txt", "w")
- for i = 0, totalCombinations - 1 do
- local combination = generateCombination(i)
- local success, item = testCombination(combination)
- if success then
- logResult(logFile, combination, item)
- end
- end
- logFile.close()
- print("Testování receptů dokončeno")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement