Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Created by Stekeblad 3/2016
- -- This program is made to automate the inscriber from Applied Energetics
- local pressChest = peripheral.wrap("chest_1")
- local resourceChest = peripheral.wrap("chest_2")
- local insc = peripheral.wrap("left") -- network name is tileinscriber_x there x is a number
- local siliChest = peripheral.wrap("chest_0")
- local pressChestDir = "east"
- local resourceChestDir = "north"
- local siliChestDir = "west"
- local printDBG = false
- local sleepDBG = false
- -- Do not make any changes below
- --this line if you do not know
- --what you are doing
- -----------------------------------------
- if not insc then
- error("Could not find inscriber")
- end
- local curPress, slot = nil
- local nrSilicon = 0
- local pressGold, pressSilicon, pressPure, pressDiamond = nil
- if (insc.getStackInSlot(1) and string.find(insc.getStackInSlot(1).display_name, "Press")) then
- insc.pushItemIntoSlot(pressChestDir, 1, 1, 1)
- else
- insc.pushItemIntoSlot(siliChestDir, 1, 64, 27)
- insc.pushItemIntoSlot(siliChestDir, 2, 64, 26)
- insc.pushItemIntoSlot(resourceChestDir, 3, 64, 25)
- insc.pushItemIntoSlot(siliChestDir, 4, 64, 1)
- end
- pressChest.condenseItems()
- if printDBG then print("finding presses...") end
- for i = 1, pressChest.getInventorySize() do
- slot = pressChest.getStackInSlot(i)
- if slot then
- if (string.sub(slot.raw_name, 39) == "siliconpress") then
- pressSilicon = i
- elseif (string.sub(slot.raw_name, 39) == "logicprocessorpress") then
- pressGold = i
- elseif (string.sub(slot.raw_name, 39) == "engprocessorpress") then
- pressDiamond = i
- elseif (string.sub(slot.raw_name, 39) == "calcprocessorpress") then
- pressPure = i
- end
- end
- end
- --if printDBG then print(pressGold .. " " .. pressSilicon .. " " .. pressPure .. " " .. pressDiamond) end
- -----------------
- function inscribeWithPress(press, slotNr, amount)
- success = 0
- if printDBG then print("inscribeWithPress") end
- success = insc.pullItemIntoSlot(pressChestDir, press, 1, 1)
- if success == 0 then error("Failed to place press in inscriber") end
- for i = 1, amount do
- sleep(0.5)
- success = insc.pullItemIntoSlot(resourceChestDir, slotNr, 1, 3)
- if success == 0 then error("Failed to move item from resourceChest slot " .. slotNr) end
- local clogged = true
- while clogged do
- sleep(0.2)
- if not insc.getStackInSlot(3) then
- clogged = false
- end
- end
- end
- sleep(0.75)
- if (string.find(insc.getStackInSlot(1).display_name, "Silicon")) then
- insc.pushItemIntoSlot(siliChestDir, 4, 64, siliChest.getInventorySize())
- else
- insc.pushItemIntoSlot(pressChestDir, 4, 64, pressChest.getInventorySize())
- end
- insc.pushItemIntoSlot(pressChestDir, 1, 1, press)
- resourceChest.condenseItems()
- pressChest.condenseItems()
- siliChest.condenseItems()
- end
- function inscribeNoPress(resourceChestDir, printedType, redstone, silic)
- local ok1 = 0
- local ok2 = 0
- local ok3 = 0
- if printDBG then print("inscribeNoPress, " .. printedType) end
- ok1 = insc.pullItemIntoSlot(pressChestDir, printedType, 1, 1)
- ok2 = insc.pullItemIntoSlot(siliChestDir, silic, 1, 2)
- ok3 = insc.pullItemIntoSlot(resourceChestDir, redstone, 1, 3)
- if (ok1 == 0 or ok2 == 0 or ok3 == 0) then error("inscribeNoPress error moving: " .. ok1 .. " " .. ok2 .. " " .. ok3) end
- if (not pressChest.getStackInSlot(printedType)) then
- printedType = nil
- elseif (not resourceChest.getStackInSlot(redstone)) then
- redstone = nil
- elseif (not siliChest.getStackInSlot(silic)) then
- silic = nil
- end
- local clogged = true
- while clogged do
- sleep(0.2)
- if not insc.getStackInSlot(2) then
- clogged = false
- end
- end
- sleep(0.5)
- insc.pushItemIntoSlot(resourceChestDir, 4, 1, resourceChest.getInventorySize())
- resourceChest.condenseItems()
- return printedType, redstone, silic
- end
- -----------------
- resourceChest.condenseItems()
- local didJob = false
- local slotNr = 1
- local logic = nil
- local calcu = nil
- local enginer = nil
- local redstone = nil
- local silic = nil
- while true do
- if printDBG then print("main loop start") end
- resourceChest.condenseItems()
- slotNr = 1
- slot = resourceChest.getStackInSlot(slotNr)
- if sleepDBG then sleep(1) end
- while (slot ~= nil) and (slotNr < resourceChest.getInventorySize()) do
- if printDBG then print("looping resources: " .. slotNr) end
- didJob = false
- if printDBG then print(slot.display_name) end
- if slot.display_name == "Gold Ingot" then
- if printDBG then print("gold") end
- inscribeWithPress(pressGold, slotNr, slot.qty)
- didJob = true
- elseif slot.display_name == "Silicon" then
- if printDBG then print("silicon") end
- inscribeWithPress(pressSilicon, slotNr, slot.qty)
- didJob = true
- elseif slot.display_name == "Pure Certus Quartz Crystal" then
- if printDBG then print("pure") end
- inscribeWithPress(pressPure, slotNr, slot.qty)
- didJob = true
- elseif slot.display_name == "Diamond" then
- if printDBG then print("diamond") end
- inscribeWithPress(pressDiamond, slotNr, slot.qty)
- didJob = true
- end
- if not didJob then
- if printDBG then print("did no job") end
- slotNr = slotNr + 1
- end
- slot = resourceChest.getStackInSlot(slotNr)
- if sleepDBG then sleep(1) end
- end
- -- And now to the processors!
- -- 1) Find materials slot number
- for i = 1, siliChest.getInventorySize() do
- if printDBG then print("finding printed parts: " .. i) end
- invSlot = siliChest.getStackInSlot(i)
- if (invSlot and string.find(invSlot.display_name, "Silicon")) then
- silic = i
- end
- invSlot = pressChest.getStackInSlot(i)
- if(invSlot and invSlot.display_name) then
- if string.find(invSlot.display_name, "Printed") then
- if (string.find(invSlot.display_name, "Calculation")) then
- calcu = i
- end
- if (string.find(invSlot.display_name, "Engineering")) then
- enginer = i
- end
- if (string.find(invSlot.display_name, "Logic")) then
- logic = i
- end
- end
- invSlot = resourceChest.getStackInSlot(i)
- if(invSlot and invSlot.display_name == "Redstone") then
- redstone = i
- end
- end
- if sleepDBG then sleep(0.3) end
- end
- --if printDBG then print(calcu .. " " .. enginer .. " " .. logic) end
- -- 2) make Circuits
- while true do
- if (not redstone or not silic or (not logic and not enginer and not calcu)) then
- if printDBG then print("broke") end
- break
- else
- if(logic) then
- logic, redstone, silic = inscribeNoPress(resourceChestDir, logic, redstone, silic)
- elseif(enginer) then
- enginer, redstone, silic = inscribeNoPress(resourceChestDir, enginer, redstone, silic)
- elseif (calcu) then
- calcu, redstone, silic = inscribeNoPress(resourceChestDir, calcu, redstone, silic)
- end
- end
- if sleepDBG then sleep(1) end
- end
- if printDBG then print("sleeping...") end
- sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement