Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Made by Stekeblad
- -- Last updated June 2016
- -- This is a computer craft program for automating the mod FluxedCrystals2 by Jaredlll08
- -- You will need the open peripherals mods to be able to use the program
- -- Build with the following mod versions:
- -- ComputerCraft 1.75
- -- OpenPeripheralsAddons 1.7.10 - 0.4
- -- OpenPeripheralsCore 1.7.10 - 1.2
- -- OpenPeripheralsIntegration 1.7.10 - 0.3
- -- First some variables...
- local args = {...}
- local SeedTable={}
- local settings = {}
- local x, y = term.getSize()
- local printDmgValues = false
- local invInput
- local invOutput
- if settings.outputType == "chest" then
- local nrOutSlots
- end
- local slot = nil
- local lastEmpty = 0
- local nrInpSlots -- two variables for the same thing? Don't want to look into that now....
- local inpChestSlots
- --Then some function in almost alphabetical order
- -- (It works, and not super 100% rubbish names!)
- function about() -- prints little about-information
- term.clear()
- term.setCursorPos(1,1)
- print("Your version is 2.5 of FluxedSeeds")
- print("For the program to work, you will need the openPeripherals mods in order to connect chests and refiners to your computer network.")
- print("\nFluxedSeeds is created by Stekeblad and is intended to be used together with the mod fluxedCrystals2 by Jaredlll08.")
- print("\n\tPress enter for more...")
- read()
- term.clear()
- term.setCursorPos(1,1)
- print("Things NOT made by Stekeblad in this program are two parts in the function for downloading default configurations,")
- print("\nThe download function downloads the seed information from the creator's gitHub.")
- print("The data is then passed to a JSON decoder made by ElvishJerricco.")
- print("This two things can I not take credits for!")
- print("\n\tPress enter for more...")
- read()
- term.clear()
- term.setCursorPos(1,1)
- print("The program is made to work in a computer or on a monitor, both on normal and advanced systems.")
- print("Beacuse FluxedCrystals supports adding, editing and removing seeds in its configuration file, FluxedSeeds is built so its easy to edit")
- print("what the program knows about the different seed types so it matches your configuration file.")
- print("\nFor more information I recommend you to find this programs thread on computercraft's forum")
- print("\n\tPress enter to finnish...")
- read()
- return
- end
- function checkIfInTable() --almost ignore-able
- return SeedTable[slot.dmg]["needed"]
- end
- --checkMove
- -- returns 0 if there is not enougth items in stack to move
- -- returns -1 if no free space in output inventory is found
- -- returns 1 on successful move
- -- returns 2 on non-fluxedCrystals-shards or shard not in SeedTable
- function checkMove(slot, i)
- if (slot.id ~= "fluxedCrystals:smoothShard"
- and slot.id ~= "fluxedCrystals:roughShard") then
- return 2
- end
- if not pcall(checkIfInTable) then
- return 2
- end
- if(SeedTable[slot.dmg]["needed"] <= slot.qty) then
- if settings.outputType == "chest" then
- local oldLastEmpty = lastEmpty
- local outSlot = "notARealSlot"
- while outSlot ~= nil do
- lastEmpty = lastEmpty + 1
- if lastEmpty == oldLastEmpty then return -1 end
- if lastEmpty > nrOutSlots then
- lastEmpty = lastEmpty - nrOutSlots
- end
- outSlot = invOutput.getStackInSlot(lastEmpty)
- sleep(0.05)
- end
- local status, error = pcall(invInput.pushItemIntoSlot(settings.outputDir,
- i, SeedTable[slot.dmg]["needed"], lastEmpty))
- if not status then error("Failed to move items, check connection to output chest") end
- return 1
- else
- --> settings.outputType == "refiner"
- if invOutput.getStackInSlot(1) == nil then
- invInput.pushItemIntoSlot(settings.outputDir,
- i, SeedTable[slot.dmg]["needed"], 1)
- return 1
- else
- return -1
- end
- end
- else
- return 0
- end
- end
- function editSeedTable() -- change the SeedtTble-file
- if settings.alwaysEditFile == "true" then
- shell.run("edit FluxedSeeds_SeedTable")
- return
- end
- local SeedSetup = true
- while SeedSetup do
- term.clear()
- print("Enter the input inventory slot number for the item to add, edit or remove, slot 1 is in top left corner")
- print("You can also write \"back\" to save and exit") -- add, edit, delete without the item? NO! (isInFile)
- print("or \"file\" if you are an advanced user to edit the seed table file directly" )
- term.write ("input?: ")
- local badInp = true, usrInp
- while badInp do
- usrInp = read()
- local numCheck = tonumber(usrInp)
- if numCheck ~= nil then
- if numCheck > invInput.getInventorySize() then -- To find witch one that errored, had bad luck guessing earlier
- print("Slot number must be a whole number between 1 and "..invInput.getInventorySize())
- elseif numCheck < 1 then
- print("Slot number must be a whole number between 1 and "..invInput.getInventorySize())
- elseif numCheck ~= math.floor(numCheck) then
- print("Slot number must be a whole number between 1 and "..invInput.getInventorySize())
- else
- if invInput.getStackInSlot(numCheck) == nil then
- print("No item in slot ".. numCheck)
- else
- if (invInput.getStackInSlot(numCheck).id ~= "fluxedCrystals:smoothShard"
- and invInput.getStackInSlot(numCheck).id ~= "fluxedCrystals:roughShard") then
- print("Item is not a smooth or rough shard from Fluxed Crystals!")
- else
- badInp = false
- print("")
- end
- end
- end
- elseif usrInp ~= "back" and usrInp ~= "file" then
- print("Invalid command!")
- else
- badInp = false
- print("")
- end -- if numCheck ~= nil then
- end -- while badInp do
- if tonumber(usrInp) then
- local slot = invInput.getStackInSlot(usrInp)
- if(SeedTable[slot.dmg]) then -- seed in table already
- while usrInp ~= "back" do
- print("\nFound: [".. slot.dmg .."] name: " .. SeedTable[slot.dmg]["name"] .. ", needed: " .. SeedTable[slot.dmg]["needed"])
- print("Name of item in selected slot: " .. slot.display_name)
- print("\nItem already in Seed Table. Type \"delete\", \"edit_name\", \"edit_needed\" or \"back\": ")
- usrInp = read()
- if usrInp ~= "back" and usrInp ~= "edit_name" and usrInp ~= "edit_needed" and usrInp ~= "delete" then
- term.write("Invalid command! Enter again: ")
- usrInp = read()
- elseif usrInp == "delete" then
- SeedTable[slot.dmg] = nil
- print("Deleted")
- usrInp = "back"
- elseif usrInp == "edit_name" then
- term.write("Enter new name: ")
- SeedTable[slot.dmg]["name"] = read()
- print("Name changed")
- usrInp = "back"
- elseif usrInp == "edit_needed" then
- term.write("Enter new amount needed: ")
- usrInp = tonumber(read())
- if (usrInp == nil) then
- print("Input not a number!")
- elseif (usrInp ~= math.floor(usrInp)) then
- print("Decimal number not allowed!")
- elseif (usrInp > 64 or usrInp < 1) then
- print ("Needed amount needs to be atleast one but not more then 64 !")
- else
- SeedTable[slot.dmg]["needed"] = usrInp
- print("Amount needed has been changed!")
- end
- end
- end -- while usrInp ~= "back" do
- print("Going back...")
- sleep(3)
- usrInp = "notBack"
- else -- a seed, but not in table
- print("Seed type not in table, type \"add\" or \"back\"")
- print("Name of item in selected slot: " .. slot.display_name)
- term.write("?: ")
- usrInp = read()
- while usrInp ~= "back" and usrInp ~= "add" do
- term.write("invalid command! Enter again: ")
- usrInp = read()
- end
- print("")
- if usrInp == "add" then
- print("What do you want to call this item? This will be displayed instead of its real name.")
- print("Suggesting something short, eg. \"iron\" instead of \"Smooth Iron Shard\"")
- term.write("Enter name: ")
- local name1 = read()
- print("How many \"".. name1 .. "\" is needed in the gem refiner for one refining operation? (a whole number in range 1-64)")
- term.write("Enter amount needed: ")
- local needed1 = tonumber(read())
- if needed1 ~= math.floor(needed1) or needed1 < 1 or needed1 > 64 then
- needed1 = nil
- end
- while needed1 == nil do
- print("Invalid amount!\n Enter a whole number in range 1-64")
- term.write("Enter amount: ")
- needed1 = read()
- if needed1 ~= math.floor(needed1) or needed1 < 1 or needed1 > 64 then
- needed1 = nil
- end
- end
- SeedTable[slot.dmg] = {name = name1, needed = tonumber(needed1)}
- print("New seed added to seed table")
- sleep(3)
- end
- usrInp = "notBack"
- end -- [else] if(SeedTable[slot.dmg]) then
- end -- if tonumber(usrInp) then (else already fixed in input loop)
- if usrInp == "file" then
- term.clear()
- print("Making changes in SeedTable file may break the program! Be careful.")
- print("The program will close then you have saved the changes and closed the file, changes will be applied next time the program starts")
- print("The format for the table is as follows:")
- print("[\'dmgValue\'] = {name = 'nameOnScreen', \"needed\" = 'nrItemsNeddedInRefiner'},")
- print("\tPress enter to open file...")
- read()
- shell.run("edit FluxedSeeds_SeedTable")
- error("Edit in seedTable, restart the program to apply changes!")
- end
- if usrInp == "back" then
- print("Saving changes to SeedTable file...")
- local file = fs.open("FluxedSeeds_SeedTable", "w")
- file.write(textutils.serialize(SeedTable))
- file.close()
- print("Saved")
- SeedSetup = false
- end
- end -- while SeedSetup do
- --print("I'm getting bored making it possible to make changes from inside the program...")
- --print("Make the changes on your own, heres the file\n\tpress enter to open...")
- --read()
- --shell.run("edit FluxedSeeds_SeedTable")
- end
- function printStack(slot, result) -- prints whats in a specific slot, used by 'main'
- if slot ~= nil then
- if result == 0 then
- print(slot.qty .." x " ..SeedTable[slot.dmg]["name"])
- elseif result == 1 then
- print(slot.qty .." x " ..SeedTable[slot.dmg]["name"]
- .. " moved " .. SeedTable[slot.dmg]["needed"])
- else -- not supported item in chest or a shard not in SeedTable
- if(term.isColor()) then term.setTextColor(colors.red)
- else term.setTextColor(colors.lightGray) end
- if (slot.id ~= "fluxedCrystals:smoothShard"
- and slot.id ~= "fluxedCrystals:roughShard") then
- print(slot.qty .. " x " .. slot.display_name .. " can't be processed!")
- else
- print(slot.qty .. " x " .. slot.display_name .. " not in table!")
- end
- term.setTextColor(colors.white)
- end
- end
- end
- function printTableIds() -- prints the dmgValue and name of the items in SeedTable to be compared with the in-game seeds
- local printed = 0
- local tableSize = table.maxn(SeedTable)
- print("\n\n")
- for i = 1, tableSize do
- if printed == 10 and i ~= tableSize then
- printed = 0
- print(" press enter for more...")
- read()
- print("\n\n")
- end
- if pcall(function() return SeedTable[i]["needed"] end) then -- index exists
- print("dmg: " .. i .. ", name: " .. SeedTable[i]["name"] .. "\t required: " .. SeedTable[i]["needed"])
- printed = printed + 1
- end
- end
- print("\nEverything printed, press enter to exit...")
- read()
- return
- end
- function runningMenu() -- shows little menu then pressing any key in normal running mode
- term.clear()
- term.setCursorPos(2,1)
- print("\t\tMENU")
- print("\n\"setup\" for settings menu")
- print("\"seeds\" for SeedTable menu")
- print("\"about\" to show about text")
- print("\"exit\" to terminate program (also ctrl+T)")
- print("anything else continues program")
- term.write("input: ")
- local usrInp = read()
- usrInp = string.lower(usrInp)
- if usrInp == "setup" then setup() end
- if usrInp == "seeds" then editSeedTable() end
- if usrInp == "about" then about() end
- if usrInp == "exit" then error("Program terminated by user") end
- end
- function setupMain() -- used by setup
- term.clear()
- term.setCursorPos(1,1)
- print("\tSetup menu")
- print("Type 1-5, \"file\" or \"back\"")
- term.write("1. Input")
- term.setCursorPos(x - #settings.input - 2, 3)
- term.write(settings.input .. " " .. testInventory(settings.input))
- term.setCursorPos(1, 4)
- term.write("2. Output")
- term.setCursorPos(x - #settings.output - 2, 4)
- term.write(settings.output .. " " .. testInventory(settings.output))
- term.setCursorPos(1,5)
- term.write("3. Output Type")
- term.setCursorPos(x - #settings.outputType - 2, 5)
- term.write(settings.outputType)
- term.setCursorPos(1,6)
- term.write("4. Output Direction")
- term.setCursorPos(x - #settings.outputDir - 2, 6)
- term.write(settings.outputDir)
- term.setCursorPos(1, 7)
- term.write("5. Sleep time (sec)")
- term.setCursorPos(x - 3, 7)
- term.write(settings.sleepTime)
- term.setCursorPos(1, 8)
- print("file. edit the settings file directly (only for advanced users)")
- print("back. exit settings configuration")
- term.write("Choose an alternative: ")
- local errInp = true
- while errInp do
- usrInp = read()
- if(usrInp ~= "1" and usrInp ~= "2" and usrInp ~= "3" and usrInp ~= "4"
- and usrInp ~= "5" and usrInp ~= "file" and usrInp ~= "back") then
- term.write("Bad input, try again: ")
- else
- errInp = false
- end
- end
- return usrInp
- end
- function setup() -- Changing the settings
- if (settings.alwaysEditFile == "true") then
- shell.run("edit FluxedSeeds_settings")
- return
- end
- local usrInp
- local inSetup = true
- while inSetup do
- usrInp = setupMain()
- term.clear()
- term.setCursorPos(1,2)
- if (usrInp == "1") then
- while usrInp ~= "back" do
- term.setCursorPos(1,2)
- term.write("1. Input")
- local strLen = tonumber(string.len(settings.input))
- term.setCursorPos((x - strLen - 2), 2)
- term.write(settings.input)
- term.setCursorPos(1,4)
- if testInventory(settings.input) == "!" then
- print ("THE CURRENT INVENTORY COULD NOT BE ACCESSED!!!")
- end
- local test1, test2 = peripheral.find("chest")
- if(test1 == nil) then
- print("No chest found on network, if you have a special type of chest you can enter its network name below")
- elseif(test2 == nil) then
- print("Only one normal chest found on network, type \"find\" or its name to set this one to input chest")
- print("Found chest: \""..test1.."\"")
- end
- print("Enter \"back\" or the network name of the input inventory (eg. \"chest_0\"): ")
- usrInp = read()
- if (usrInp ~= "find" and usrInp ~= "back") then
- local testRes = testInventory(usrInp)
- if testRes == "!" then
- print("Cant connect to that inventory!")
- print("...")
- read()
- else
- print("Inventory " .. usrInp .. " is OK, saving it!")
- settings.input = usrInp
- usrInp = "back"
- end
- if usrInp == "find" then
- settings.input = test1
- if not settings.outputType == "refiner" and test2 == nil then
- print("Changing output type to refiner beacuse only one chest was found, this is easy to change if needed")
- settings.outputType = "refiner"
- end
- usrInp = "back"
- end
- end
- sleep(3)
- term.clear()
- end -- while usrInp ~= "back" do
- usrInp = "1"
- end -- if usrInp == "1" then
- if (usrInp == "2") then
- while usrInp ~= "back" do
- term.setCursorPos(1,2)
- term.write("2. Output")
- local strLen = tonumber(string.len(settings.output))
- term.setCursorPos(x - strLen - 2, 2)
- term.write(settings.output .. " " .. testInventory(settings.output))
- term.setCursorPos(1,4)
- print("It's recommended to look at \"Output Type\" (alt 3) before changing \"Output\" (this one)")
- if testInventory(settings.output) == "!" then
- print ("THE CURRENT INVENTORY COULD NOT BE ACCESSED!!!")
- end
- local test1, test2 = peripheral.find("gem_refiner")
- if test1 and not test2 then
- print("one gem refiner was found on the network, type \"find\" or its name to set it as output")
- print("found refiner: \""..test1.."\"")
- end
- print("Enter \"back\" or the network name of the output inventory, a chest or a gem refiner (eg. \"chest_1\" or \"gem_refiner_0\")")
- usrInp = read()
- if (usrInp ~= "find" and usrInp ~= "back") then
- local testRes = testInventory(usrInp)
- if testRes == "!" then
- print("Cant connect to that inventory!")
- print("...")
- read()
- else
- print("Inventory " .. usrInp .. " is OK, saving it!")
- settings.output = usrInp
- usrInp = "back"
- end
- elseif usrInp == "find" then
- print("Finding a output, assuming input is configured to be a connected chest on this network...")
- if test1 then
- settings.output = test1
- print ("Found and saved " .. test1)
- settings.outputType = "refiner"
- usrInp = "back"
- else
- local ch1, ch2, ch3 = peripheral.find("chest")
- if ch3 then
- print("More then one possible output chest found, can not choose automaticly")
- elseif ch2 then
- if ch1 == settings.input then
- settings.output = ch2
- print("Found and saved ".. ch2)
- settings.outputType = "chest"
- usrInp = "back"
- end
- if ch2 == settings.input then
- settings.output = ch1
- print("Found and saved ".. ch1)
- settings.outputType = "chest"
- usrInp = "back"
- end
- end
- end
- if not usrInp == "back" then
- print("More then one possible output chest found, can not choose automaticly")
- end
- end
- sleep(3)
- term.clear()
- end -- while usrInp ~= "back" do
- usrInp = "2"
- end -- if (usrInp == "2") then
- if usrInp == "3" then
- while usrInp ~= "back" do
- term.setCursorPos(1,2)
- term.write("3. Output Type")
- local strLen = tonumber(string.len(settings.outputType))
- term.setCursorPos(x - strLen - 2, 2)
- term.write(settings.outputType)
- term.setCursorPos(1,4)
- print("type \"back\" to go back or select type of output inventory, \"refiner\" or \"chest\": ")
- usrInp = read()
- if usrInp == "refiner" then
- print("Setting type of output inventory to refiner")
- settings.outputType = "refiner"
- usrInp = "back"
- elseif usrInp == "chest" then
- print("Setting type of output inventory to chest")
- settings.outputType = "chest"
- usrInp = "back"
- elseif usrInp ~= "back" then
- print("Invalid choice!")
- end
- sleep(3)
- term.clear()
- end -- while usrInp ~= "back" do
- usrInp = "3"
- end -- if usrInp == "3" then
- if usrInp == "4" then
- while usrInp ~= "back" do
- term.setCursorPos(1,2)
- term.write("4. Output Direction")
- local strLen = tonumber(string.len(settings.outputDir))
- term.setCursorPos(x - strLen - 2, 2)
- term.write(settings.outputDir)
- term.setCursorPos(1, 4)
- print ("Looking from INPUT, in witch direction is OUTPUT?")
- print ("Type: \"down\", \"up\", \"north\", \"south\", \"west\", \"east\" or \"back\"")
- usrInp = read()
- if (usrInp == "down" or usrInp == "up" or usrInp == "north"
- or usrInp == "south" or usrInp == "west" or usrInp == "east") then
- settings.outputDir = usrInp
- print("Output Direction set to "..usrInp)
- usrInp = "back"
- elseif usrInp ~= "back" then
- print("Not a valid direction!")
- end
- sleep(3)
- term.clear()
- end -- while usrInp ~= "back" do
- usrInp = "4"
- end -- usrInp == "4" then
- if usrInp == "5" then
- while usrInp ~= "back" do
- term.setCursorPos(1,2)
- term.write("5. Sleep time (sec)")
- local strLen = string.len(tostring(settings.sleepTime))
- term.setCursorPos(x - strLen - 2, 2)
- term.write(settings.sleepTime)
- term.setCursorPos(1, 4)
- print("The time to wait (in seconds) between checks of the content in input chest (default 2)")
- term.write("Enter number of seconds to wait or \"back\": ")
- usrInp = read()
- if tonumber(usrInp) and tonumber(usrInp) > 0 then
- settings.sleepTime = tonumber(usrInp)
- print("waiting time changed to "..usrInp)
- usrInp = "back"
- elseif usrInp ~= "back" then
- print("Input not a number or smaller then zero")
- end
- sleep(3)
- term.clear()
- end -- while usrInp ~= "back" do
- usrInp = "5"
- end -- if usrInp == "5" then
- if usrInp == "file" then
- print("Making changes in settings file may break the program! Be careful.")
- print("The program will close then you have saved the changes and closed the file, changes will be applied next time the program starts")
- print("\tPress enter to open file...")
- read()
- shell.run("edit FluxedSeeds_settings")
- error("\nTerminated to reload settings, please restart the program")
- end
- if usrInp == "back" then
- print("Saving changes to settings file...")
- local file = fs.open("FluxedSeeds_settings", "w")
- file.write(textutils.serialize(settings))
- file.close()
- print("saved!")
- sleep(3)
- inSetup = false
- end
- end -- while inSetup do
- return
- end -- function setup()
- function testInventory(inv) -- used by testMovingItems
- if peripheral.isPresent(inv) then return "" else return "!" end
- end
- function testMovingItems() --Tests that the inventories are next to each other
- print("A test will be performed to verify that the configuration of input and output inventory is correctly made. Make sure to turn off everything that may add or remove items in this inventories!\n--Press any key then ready--")
- os.pullEvent("key")
- invInput.condenseItems() -- Sorts the chest
- sleep(0.1)
- if settings.output then
- invOutput.condenseItems()
- sleep(0.1)
- if (invInput.getStackInSlot(1) ~= nil
- and invOutput.getStackInSlot(invOutput.getInventorySize()) == nil) then --Chest not empty and other not full
- local pushedItem = invInput.getStackInSlot(1) -- saves info about the stack pushing from
- local nrPushed
- local status, err = pcall( function () nrPushed = invInput.pushItemIntoSlot(settings.outputDir, 1, 1, invOutput.getInventorySize()) end )--pushing
- sleep(0.1)
- if (err) then
- error("\nNo Inventory in specified direction off input inventory!\nCheck input chest name, direction or try swapping input/output inventory names")
- end
- if (nrPushed == 1) then -- push successful
- local recieveditem = invOutput.getStackInSlot(invOutput.getInventorySize()) --gets recieved item
- if (recieveditem.display_name == pushedItem.display_name) then --compares
- outInvType = "chest"
- invInput.pullItemIntoSlot(settings.outputDir,
- invOutput.getInventorySize(), 1, 1) -- Pull it back
- sleep(0.1)
- if (invInput.getStackInSlot(1).qty == pushedItem.qty
- and invInput.getStackInSlot(1).display_name == pushedItem.display_name) then
- -- The item got back to input chest again! All OK!
- print("\n\nNo problems with your setup found!\n--Continues in 5 seconds--")
- sleep(5)
- return
- else
- error("Test successful, but failed to return test item to input chest!")
- end
- else
- error("\nItem pushed but something else found in target inventory!\nTried to push one "
- .. pushedItem.display_name .. "\nbut found instead " .. recieveditem.display_name ..
- "\nReson: Outside disturbance")
- end -- if (recieveditem.display_name == pushedItem.display_name) then --compares
- else -- if (nrPushed == 1) --> nrPushed = 0
- error("\nSpace in target inventory was available but could not move anything!"..
- "\nTried to move: " .. pushedItem.display_name .. "\nReson: probably wrong name on input or output chest")
- end -- if (nrPushed == 1)
- else
- error("\nInput chest is empty or output chest is full, can't continue test!")
- end -- if (invInput.getStackInSlot(1) ~= nil --Chest not empty and other not full
- else -- Test as a refiner
- if gemRef.getStackInSlot(1) == nil then --test move to refiner
- local pushedItem = invInput.getStackInSlot(1)
- if (pushedItem ~= nil) then
- local nrPushed = invInput.pushItemIntoSlot(settings.outputDir, 1, 1, 1)
- sleep(0.1)
- if (nrPushed == 1) then
- local recieveditem = gemRef.getStackInSlot(1)
- if(recieveditem ~= nil and recieveditem.display_name == pushedItem.display_name) then
- outInvType = "refiner"
- invInput.pullItemIntoSlot(settings.outputDir, 1, 1, 1)
- sleep(0.1)
- if (invInput.getStackInSlot(1).qty == pushedItem.qty
- and invInput.getStackInSlot(1).display_name == pushedItem.display_name) then
- -- Test successful
- print("\n\nNo problems with your setup found!\n--Continues in 5 seconds--")
- sleep(5)
- return
- else
- error("Test successful, but failed to return test item to input chest!")
- end
- else
- if (recieveditem == nil) then
- error("\nItem pushed but not recieved by 'refiner'\nTried to move: "..pushedItem.display_name..
- "\nReson: Pushed to something else (check output chest direction and source inventory)!")
- else -- pushed item ~= recieved item
- error("\nItem pushed, but found something else in target inventory!\nTried to push one "
- .. pushedItem.display_name .. "\nbut found instead " .. recieveditem.display_name .."\nReson: Outside disturbance")
- end
- end
- else-- if (nrPushed == 1) --> nrPushed = 0
- error("\nSpace in target inventory was available but could not move anything!"..
- "\nTried to move: " .. pushedItem.display_name .. "\nReson: probably wrong input/output or item not a smooth shard!")
- end -- if (nrPushed == 1)
- else
- error("\nCan't test! No items in input chest to test on or testing on another chest, check name!")
- end --if (pushedItem ~= nil)
- else
- error("\nGem Refiner is not empty! Please move the shards to input chest and try again!")
- end -- if gemRef.getStackInSlot(1) == nil
- end -- if settings.output
- end -- function testMovingItems()
- function quickSettingsCheck()
- local invalidChestSetup = false
- if not pcall(function() return settings.input end) then
- print("Could not find the input inventory on the network!")
- invalidChestSetup = true
- elseif not peripheral.isPresent(settings.input) then
- print("Could not find the input inventory on the network!")
- invalidChestSetup = true
- end
- if not pcall(function() return settings.output end) then
- print("Could not find the output inventory on the network!")
- invalidChestSetup = true
- elseif not peripheral.isPresent(settings.output) then
- print("Could not find the output inventory on the network!")
- invalidChestSetup = true
- end
- if not pcall(function() return settings.outputType end) then
- print("Error in settings file, invalid outputType")
- invalidChestSetup = true
- elseif (settings.outputType ~= "chest" and settings.outputType ~= "refiner") then
- print("Error in settings file, invalid outputType")
- invalidChestSetup = true
- end
- if not pcall(function() return settings.sleepTime end) then
- print("Error in settings file, Invalid sleepTime!")
- invalidChestSetup = true
- elseif not tonumber(settings.sleepTime) then
- print("Error in settings file, Invalid sleepTime!")
- invalidChestSetup = true
- elseif settings.sleepTime < 0 then
- print("Error in settings file, Invalid sleepTime!")
- invalidChestSetup = true
- end
- if not pcall(function() return settings.outputDir end) then
- print("Error in settings file, Invalid output direction!")
- invalidChestSetup = true
- elseif(settings.outputDir ~= "up" and settings.outputDir ~= "down" and settings.outputDir ~= "north"
- and settings.outputDir ~= "south" and settings.outputDir ~= "west" and settings.outputDir ~= "east") then
- print("Error in settings file, Invalid output direction!")
- invalidChestSetup = true
- end
- if not pcall(function() return settings.alwaysEditFile end) then
- settings.alwaysEditFile = "false"
- end
- if invalidChestSetup then
- print("Redirecting to setup, press enter...")
- read()
- setup()
- end
- end
- --
- ----------------------------------
- -- Startup point
- for i, v in ipairs(args) do
- args[i] = v
- end
- if (fs.exists("FluxedSeeds_settings")) then -- loads settings, checks for errors in settings and creates default settings
- local settingsFile = fs.open("FluxedSeeds_settings", "r")
- settings = textutils.unserialize(settingsFile.readAll())
- -- print(textutils.serialize(settings)) -- Debug code
- settingsFile.close()
- quickSettingsCheck()
- else
- print("No settings file found, generating default...")
- settings = {
- outputDir = "down",
- input = "chest_0",
- output = "gem_refiner_0",
- outputType = "refiner",
- sleepTime = 2,
- alwaysEditFile = "false",
- }
- local settingsFile = fs.open("FluxedSeeds_settings", "w")
- settingsFile.write(textutils.serialize(settings))
- settingsFile.close()
- print("Press enter to start configuration...")
- read()
- setup()
- end
- -- should not be like this...
- invInput = peripheral.wrap(settings.input)
- if not invInput then error("Could not wrap input inventory as a peripheral, check your cables and program settings.") end
- invOutput = peripheral.wrap(settings.output)
- if not invOutput then error("Could not wrap output inventory as a peripheral, check your cables and program settings.") end
- if (fs.exists("FluxedSeeds_SeedTable")) then -- loads SeedTable, creates empty then none and can download default
- local seedFile = fs.open("FluxedSeeds_SeedTable", "r")
- local seedData = seedFile.readAll()
- SeedTable = textutils.unserialize(seedData)
- seedFile.close()
- else
- -- Download from gitHub?
- function getLatestDefaultSeedConfigs()
- print("No seed information found on your computer.\n")
- print("Do you want to download the newest seed files from the creators gitHub or maybe a custom one?")
- print("\nThis is recomended if your config file and default are the same or only slightly different or if your pack has a own seed file with a public link")
- print("This requires http to be enabled in computercraft config (enabled as default).")
- print("\nSeed information can be manually changed, added and removed by running the program with the argument \"SeedTable\"\n? ")
- local badAns = true, answer
- while badAns do
- answer = read()
- if string.lower(answer) == "yes" or answer == "no" then badAns = false
- else print ("Download seed information? Answer with \"yes\" or \"no\": ") end
- end
- if answer == "yes" then
- os.loadAPI("json")
- if not json then
- print("A needed api is not found!")
- term.write("Download Json API by ElvishJerricco?: ")
- badAns = true
- while badAns do
- answer = read()
- if string.lower(answer) == "yes" or answer == "no" then badAns = false
- else term.write ("Answer with \"yes\" or \"no\": ") end
- end
- if answer == "yes" then
- print("\nDownloading json API...")
- shell.run("pastebin get 4nRg9CHU json")
- os.loadAPI("json")
- print("json API has been downloaded")
- else
- print("API will not be downloaded, will not be able to download information. Creating empty seed table to be filled manually.")
- local seedFile = fs.open("FluxedSeeds_SeedTable", "w")
- seedFile.write("{}")
- seedFile.close()
- return
- end
- end
- print("\n\nWhat do you want to download?\n1. Latest GitHub version from the creator\n2. A custom file from pastebin \n3. A custom file from somewhere else")
- print("4. Nothing, terminate program")
- term.write("input your choise: ")
- badAns = true
- while badAns do
- answer = tonumber(read())
- if answer then
- if answer < 1 or answer > 4 or answer ~= math.floor(answer) then
- print("invalid input")
- else
- badAns = false
- end
- else
- print("Invalid input")
- end
- end
- local onlineSeeds = nil
- if answer == 1 then
- print("Downloading default...")
- onlineSeeds = http.get("https://raw.githubusercontent.com/jaredlll08/Fluxed-Crystals-Reborn/master/src/main/resources/assets/fluxedcrystals/misc/crystal.json")
- if not onlineSeeds then
- print ("\nDownload failed!")
- print("Try again later or skip this and add manually")
- return
- else
- print("Download Finished!")
- end
- elseif answer == 2 then
- print("\n\tDownload from pastebin.\nNote that the file needs to look like the one in your config-folder (name, seedId, refinerAmount)")
- term.write("Enter pastebin code: ")
- local code = read()
- print("Trying to download paste...")
- onlineSeeds = http.get("http://pastebin.com/raw/"..code)
- if not onlineSeeds then
- print("\nDownload failed!")
- print("Check your pastebin code")
- end
- elseif answer == 3 then
- print("\n\tDownload from somewhere else\nNote that the file needs to look like the one in your config-folder (name, seedId, refinerAmount)")
- print("The link needs to point to raw text, check your URL twice, no checks for where the link points will be made!")
- term.write("Enter full url to seed file: ")
- local url = read()
- print("Connecting to " .. url .. "...")
- onlineSeeds = http.get(url)
- if not onlineSeeds then
- print("Download failed!")
- print("Did you double-check the url?")
- end
- elseif answer == 4 then
- error("Terminated by user")
- else
- error("Unknown alternative selected")
- end
- print("Processing retrieved data...")
- onlineSeeds = onlineSeeds.readAll()
- onlineSeeds = json.decode(onlineSeeds)
- for i = 1, table.getn(onlineSeeds.seeds) do
- local status, err = pcall(function () SeedTable[onlineSeeds.seeds[i]["seedID"]] = {name = onlineSeeds.seeds[i]["name"], needed = onlineSeeds.seeds[i]["refinerAmount"]} end)
- if not status then
- error("error processing row " .. i .. " of " .. table.getn(onlineSeeds.seeds) .. " in downloaded seedtable, error msg: "..err)
- end
- end
- local seedFile = fs.open("FluxedSeeds_SeedTable", "w")
- seedFile.write(textutils.serialize(SeedTable))
- seedFile.close()
- print("SeedTable created, saved and ready to be used")
- print("press enter to exit")
- read()
- return
- else
- print("Don't dowloading\nCreating empty seed table to be filled manually")
- local seedFile = fs.open("FluxedSeeds_SeedTable", "w")
- seedFile.write("{}")
- seedFile.close()
- sleep(3)
- return
- end
- end
- getLatestDefaultSeedConfigs()
- end
- if settings.outputType == "chest" then
- nrOutSlots = invOutput.getInventorySize()
- end
- nrInpSlots = invInput.getInventorySize() -- two variables for the same thing? Don't want to look into that now....
- inpChestSlots = invInput.getInventorySize()
- if (#args>1) then
- print("FluxedSeeds takes one argument on startup, not more")
- args[1] = "nil"
- end
- if args[1] == "start" then args[1] = ":)"
- elseif (args[1] == "dmgValues") then printDmgValues = true
- elseif (args[1] == "setup") then setup()
- elseif (args[1] == "testSetup") then testMovingItems()
- elseif (args[1] == "SeedTable") then editSeedTable()
- elseif (args[1] == "about") then about(); return
- elseif (args[1] == "showTable") then printTableIds(); return
- else
- term.clear()
- print("Following program arguments are available:")
- print(" \"start\" starts the program")
- print(" \"dmgValues\" prints the name and damage value on all items in input inventory")
- print(" \"setup\" configure input/output etc")
- print(" \"testSetup\" will try to help you if input and output is not configured correctly")
- print(" \"SeedTable\" will take you to a menu for editing the SeedTable")
- print(" \"about\" will show more details about the program, how its used as well as credits")
- print(" \"showTable\" prints ID, number of items needed and name of items in SeedTable")
- return -1
- end
- if(printDmgValues) --triggered by one argument
- then
- local allEmpty = true
- for i=1, inpChestSlots, 1 do
- local slot = invInput.getStackInSlot(i)
- if(slot) then
- print(slot.display_name.. " has dmg value ".. slot.dmg)
- allEmpty = false
- end
- end
- if allEmpty then print("No items in inventory") end
- return
- end
- ----------------------------------------------------------
- -- 'main' It's here the program normally runs
- local result
- local allowMove
- print("\n\nStarting in ".. settings.sleepTime .. " second(s)")
- local event, timerIdOrKey, myTimerID, blocked = true
- while true do
- blocked = true
- myTimerID = os.startTimer(settings.sleepTime)
- while blocked do
- event, timerIdOrKey = os.pullEvent()
- if (event == "timer" and myTimerID == timerIdOrKey) then blocked = false end
- if(event == "key") then
- runningMenu()
- blocked = false
- end
- end
- invInput.condenseItems()
- if (settings.outputType == "chest") then invOutput.condenseItems() end
- term.clear()
- term.setCursorPos(1,1)
- local i = 1
- allowMove = true
- for i = 1, inpChestSlots, 1 do
- slot = invInput.getStackInSlot(i)
- if slot and allowMove then
- result = checkMove(slot, i)
- if result == -1 then
- allowMove = false
- result = 0
- end
- end
- printStack(slot, result)
- end
- end -- End of program loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement