Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- INIT ---
- --- CONFIG ---
- local wantedChestSide = "top"
- local wantedChestSlot = 2
- local interfaceSide = "left"
- local direction = "up" -- direction from interface to output container
- --- GLOBAL VARIABLES ---
- local wantedChest = peripheral.wrap(wantedChestSide)
- if wantedChest == nil then
- error("Wanted chest not found on side : " .. wantedChestSide)
- end
- local interface = peripheral.wrap(interfaceSide)
- if interface == nil then
- error("interface not found on side : " .. interfaceSide)
- end
- --- UTILS ---
- local function displayPercentage(currentPercentage, total, itemSent)
- local p = math.floor((itemSent/total) * 100, 1)
- p = p - p % 10
- if currentPercentage < p then
- print(tostring(p) .. " %")
- return p
- else
- return currentPercentage
- end
- end
- local function equals(tab1, tab2)
- local equal = true
- for k,v in pairs(tab1) do
- if tab2[k] ~= nil then
- if tab1[k] ~= tab2[k] then
- return false
- end
- end
- end
- return equal
- end
- --- FUNCTIONS ---
- -- check output container pressence
- local function checkOutputContainer()
- if not interface.canExport(direction) then
- print("\nIl manque le container d'output !")
- print("Ajoutez le sur la face [" .. direction .. "] de l'interface...")
- end
- while not interface.canExport(direction) do
- sleep(1)
- end
- end
- -- returns true if the item is craftable
- local function isCraftable(item)
- local allItemsStored = interface.getAvailableItems("ALL")
- for i=1,#allItemsStored do
- if allItemsStored[i].fingerprint.id == item.id then
- if equals(item, allItemsStored[i].fingerprint) then
- return allItemsStored[i].is_craftable
- end
- end
- end
- return false
- end
- local function processItem(item)
- local details = interface.getItemDetail(item) -- details about the item in the AE
- print("\nEntrez le nombre d'items voulus :")
- if details == nil then
- print("\nAucun item en stock et autocraft de " .. " [" .. item.display_name .. "] dans l'AE.")
- print("\nArret !")
- return
- end
- local n = tonumber(io.read()) -- quantity of items to move
- local nbItemsInAE = details.all().qty -- quantity of items in AE
- local toCraft = n - nbItemsInAE -- quantity of items to craft
- -- autocraft if needed
- if toCraft > 0 then
- print("\nNecessite le craft de " .. tostring(toCraft) .. " [" .. item.display_name .. "].")
- if isCraftable(item) then
- print("Autocraft de " .. tostring(toCraft) .. " [" .. item.display_name .. "] en cours...")
- interface.requestCrafting(item, toCraft)
- else
- print("Aucun autocraft autocraft de [" .. item.display_name .. "].")
- print("\nArret !")
- return
- end
- end
- -- sending items
- print("\nEnvoie des items :")
- local itemSent = 0
- local currentPercentage = 0
- local maxSize = item.max_size
- while itemSent < n and wantedChest.getStackInSlot(wantedChestSlot) ~= nil do
- checkOutputContainer()
- local exportResult = interface.exportItem(item, direction, math.min(maxSize, (n - itemSent)))
- if exportResult == nil then
- nbExportedItems = 0
- else
- nbExportedItems = exportResult.size
- end
- itemSent = itemSent + nbExportedItems
- currentPercentage = displayPercentage(currentPercentage, n, itemSent)
- sleep(0)
- end
- print("\nFini !")
- end
- --- MAIN CALL ---
- local function main()
- local item
- local nbExportedItems
- while true do
- term.clear()
- item = nil
- print("Inserez un item dans la cache...")
- while item == nil do
- sleep(2)
- item = wantedChest.getStackInSlot(wantedChestSlot)
- end
- processItem(item)
- -- finishing
- print("\nRetirez l'item de la cache...")
- while wantedChest.getStackInSlot(wantedChestSlot) ~= nil do
- sleep(1)
- end
- sleep(0)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement