Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Current plan:
- -- Create somewhere the bot can access the network. (supply)
- -- Give it another inventory it can move things into, and from there suck into the turtle
- -- Have loop using the parallel api.
- -- Make it listen for chat. Format of "crafty <routine> <amount> <return to current>"
- -- "crafty stop" should make the bot immediately cease the program and, if possible, return to base station or wherever it started.
- -- first argument should accept stuff like fleshAuto, sourceGems, essence, etc.
- -- instead of running the actual files, these will set the the information that the computer has to use.
- -- Namely, target (the type of device to use), materials (a table of possible materials), and results
- -- If the last argument is true, then save the current location as tempHome.
- -- teleport to the access point, read through the network until you find the correct item id, move it to the other inventory in slot 1, then suck into turtle
- -- teleport to correct point ("imbuer" for source gems, "basin" for leather, etc), then execute normal program
- -- when done or stopped, check if that last argument was true. If not, return to the access point, deposit the result, send message to me, then either remain there or return to a default
- -- if true, then check how much fuel it takes to return. If it's too expensive, still return to base point and deposit the result
- -- otherwise, if argument is true and if there is enough fuel to return to starting location, do so
- -- Possibly set up "crafty echo"/"crafty say" program so that I can make crafty speak.
- -- preprogrammed responses? "Hey Crafty, say hello" could make crafty send a message to the whole server like "Hello, I'm Crafty! Ivy's autocrafting bot! Pleased to meet you all!"
- -- table of responses to the phrase "Hello Crafty" based on each user.
- local chatBox = peripheral.find("chatBox")
- local automata = peripheral.find("endAutomata")
- --important IDs
- local turtleStorageName = "turtle_2"
- local mainPoint = "supply"
- local ownerIGN="Gallent_Bristle"
- chatBox.sendMessageToPlayer("Good morning, I'm up and running!", ownerIGN, "Crafty")
- local programTable
- local storageNames={
- drawers="functionalstorage:storage_controller_0",
- mainStorage="occultism:storage_controller_1",
- -- apotheosis="sophisticatedstorage:controller_1",
- -- ironScrolls="entangled:tile_0"
- }
- local storageModems={}
- local function storageSync() if automata.distanceToPoint(mainPoint) == 0 then for k,v in pairs(storageNames) do storageModems[k]=peripheral.wrap(v) end end end
- --Variables for the crafting programs
- local queue={}
- local working=false
- local stopped=false
- local clearQueue=false
- local paused=false
- local pauseLoc
- local suck,drop
- local altReturn=false
- local fuelList = {
- ["minecraft:charcoal"]=80,
- ["minecraft:coal"]=80,
- ["modern_industrialization:lignite_coal"]=80
- }
- local sideSearch = function(peripheralName)
- local sideTable = {
- front=function()
- suck = turtle.suck
- drop = turtle.drop
- return true
- end,
- left=function()
- turtle.turnLeft()
- suck = turtle.suck
- drop = turtle.drop
- return true end,
- right=function()
- turtle.turnRight()
- suck = turtle.suck
- drop = turtle.drop
- return true end,
- back=function ()
- turtle.turnLeft()
- turtle.turnLeft()
- suck = turtle.suck
- drop = turtle.drop
- return true
- end,
- top=function ()
- suck=turtle.suckUp
- drop=turtle.dropUp
- end,
- bottom=function ()
- suck=turtle.suckDown
- drop=turtle.dropDown
- end
- }
- local target = peripheral.find(peripheralName)
- if target== nil then
- turtle.turnLeft()
- target = peripheral.find(peripheralName)
- if target == nil then
- local errorMessage = {
- {text="I'm sorry, I cannot find the block id "},
- {text=peripheralName, color="red"},
- {text=" at this location. Did you move it, perhaps?"}
- }
- for k,v in pairs(automata.points()) do
- if automa.distanceToPoint(v) == 0 then
- for _,locMessage in pairs({
- {"Be sure to update the point named "},
- {text=v, color="gold"},
- {text=" when you are able!"}
- }) do errorMessage[#errorMessage+1] = locMessage
- break
- end
- end
- end
- chatBox.sendFormattedMessageToPlayer(
- textutils.serialiseJSON(errorMessage), ownerIGN, "Crafty"
- )
- return false
- end
- end
- sideTable[peripheral.getName(target)]()
- return target
- end
- local responseTable = {
- --Flandre
- ["1784f778-5e6a-4154-9f19-da52687082af"] = {
- "Hello Flan!",
- "Hello Flan! Your wings are looking lovely today!",
- "Hello Flandre! I hope you're having fun!",
- "Hello Flan! How is your factory coming along?",
- "Hello Flan! Sadly, I cannot offer you any blood if you're hungry, but hopefully I can bring you other food soon!"
- },
- --Ruby
- ["ba192da4-c6a0-4815-8114-34ae8526574e"] = {
- "Hello Ruby!",
- "Hello Ruby, how is everything coming along? ^.^",
- "Hello Ruby, I hope your day is going well!",
- "Hello Ruby! Thank you for always offering to help Ivy! She doesn't like feeling reliant on others, but she does appreciate it!"
- },
- --Penny
- ["e7127dc1-70e3-4700-b28a-888be7464f8d"]={
- "Hello Penny!",
- "Hey Penny! Hope your mekanism is coming along well!",
- "Salutations Penny! Hope your mekanism is coming along well!",
- "Hey Penny! As a robot, I absolutely love your farm!",
- "Hello Penny! I hope everything is going well!",
- "Hello Penny! Nice skin!",
- "Salutations Penny! Nice skin!",
- "Nice to see you again, Penny! I hope your reactor is ok. I'm happy to give you supplies if you need them!",
- "Salutations friend Penny!",
- "It is great to see you again, Penny! I am in awe at your factory and growing skills!",
- "Hello again, Penny! Do you think you can teach me how to be as cute as you some day?",
- "Greetings, Friend Penny! Your mekasuit looks so cool!"
- },
- --Noire
- ["356a5e15-289b-4a7c-9373-f1c12209bdcd"]={
- "Hello Noire!",
- "Hello Vivid!",
- "Hello Server-Chan!",
- "Hello Noire! Thank you for running this server for everyone!",
- },
- ["35899282-36fc-4e45-819e-4e3cb14695c8"] = {
- "Hello Chris!",
- "Hello Chris, I hope you and your wives are doing well!"
- },
- general={
- "Hello! ^.^",
- "Hi there!",
- "Greetings!",
- "Nice to see you!",
- "Hello! I'm sorry I don't have specific dialogue for you!",
- "Oh hey!",
- "Wonderful to see you!"
- }
- }
- local acceptedGreetings ={
- "hello crafty",
- "hi crafty",
- "greetings crafty",
- "hello crafty-chan"
- }
- local function warpFuel(location)
- local targetNumber = automata.estimateWarpCost(location) - turtle.getFuelLevel()
- if targetNumber <= 0 then return true end
- local solution={}
- for k,v in pairs(fuelList) do
- if targetNumber <= 0 then break end
- for i=16,1,-1 do
- if turtle.getItemDetail(i) ~= nil and k == turtle.getItemDetail(i).name then
- if turtle.getItemDetail(i).count * v >= targetNumber then
- solution[#solution+1] = {i,math.ceil(targetNumber/v)}
- targetNumber=0
- break
- else
- solution[#solution+1] = {i,turtle.getItemDetail(i).count}
- targetNumber = targetNumber - (turtle.getItemDetail(i).count*v)
- end
- end
- os.sleep(0)
- end
- end
- if targetNumber > 0 then return false
- else
- for k,v in pairs(solution) do
- turtle.select(v[1])
- turtle.refuel(v[2])
- os.sleep(0)
- end
- return true
- end
- end
- local function deposit(itemIndex)
- local inDrawers=false
- for _,v2 in pairs(storageModems.drawers.list()) do
- if v2.name == turtle.getItemDetail(itemIndex).name then
- storageModems.drawers.pullItems(turtleStorageName,itemIndex)
- inDrawers=true
- break
- end
- end
- if not inDrawers then storageModems.mainStorage.pullItems(turtleStorageName,itemIndex) end
- end
- local function emptyCheck(id)
- local tempSlot
- for i=1,16 do
- if turtle.getItemDetail(i) == nil then
- if tempSlot==nil then tempSlot=i end
- elseif id ~= nil and turtle.getItemDetail(i).name == id and turtle.getItemDetail(i).count < turtle.getItemDetail(i,true).maxCount then
- return i
- end
- end
- return tempSlot
- end
- local function withdrawMats(materials, amount)
- if type(materials) =="string" then materials={[materials]=true} end
- --print("withdrawing")
- for k,v in pairs(materials) do print(k) end
- local startingMats={}
- for _,modem in pairs(storageModems) do
- for slot,item in pairs(modem.list()) do
- if materials[item.name] then
- --print(modem,slot,item.count)
- startingMats[#startingMats+1] = {modem,slot,item.count,item.name}
- end
- end
- end
- --sort the results
- --I'll just use insertion sort for now
- if #startingMats > 1 then
- for i=2,#startingMats do
- local key = i
- while key > 1 and (startingMats[key-1][3] < startingMats[key][3]) do
- local sortTemp = startingMats[key-1]
- startingMats[key-1] = startingMats[key]
- startingMats[key]=sortTemp
- key=key-1
- end
- end
- end
- print("-----")
- for k,v in pairs(startingMats) do print(k) end
- --withdraw the item
- local targetNumber = amount
- for i=1,#startingMats do
- if targetNumber<= 0 then break end
- --print("amount:", amount)
- --print("targetNumber:", targetNumber)
- --print(startingMats[i][3])
- local detail = startingMats[i][1].getItemDetail(startingMats[i][2])
- while (detail ~= nil and detail.count > 0) and targetNumber>0 do
- local moved = startingMats[i][1].pushItems(turtleStorageName,startingMats[i][2],targetNumber, emptyCheck(startingMats[i][4]))
- targetNumber = targetNumber-moved
- end
- end
- end
- local function refuelFromStorage(targetNum)
- local targetNumber = targetNum - turtle.getFuelLevel()
- local solution={}
- for fuel,fuelVal in pairs(fuelList) do
- if targetNumber <= 0 then break end
- for _,modem in pairs(storageModems) do
- if targetNumber <= 0 then break end
- for slot,item in pairs(modem.list()) do
- if item.name == fuel then
- if item.count*fuelVal >= targetNumber then
- targetNumber=0
- solution[#solution+1] = {modem,slot, math.ceil(targetNumber/fuelVal)}
- break
- else
- targetNumber=targetNumber-(item.count*fuelVal)
- solution[#solution+1] = {modem,slot, item.count}
- end
- end
- os.sleep(0)
- end
- end
- end
- if targetNumber<=0 then
- local fuelSlot
- for i=16,1,-1 do
- if turtle.getItemDetail(i) == nil then turtle.select(i)
- break end
- end
- for _,v in pairs(solution) do
- v[1].pushItems(turtleStorageName,v[2],v[3], fuelSlot)
- turtle.refuel()
- os.sleep(0)
- end
- return true
- else
- return false
- end
- end
- local function makeItem(details, target)
- local materials,results,input,output
- if details.material ~= nil then materials={[details.material]=true}
- elseif type(details.materials) =="string" then materials={[details.materials]=true}
- elseif details.materials ~= nil then materials = details.materials
- elseif type(details[1])== "string" then materials={[details[1]]=true} else materials=details[1]
- end
- if details.result ~= nil then results={[details.result]=true}
- elseif type(details.results) =="string" then results={[details.results]=true}
- elseif details.results ~= nil then results = details.results
- elseif type(details[2])== "string" then results={[details[2]]=true} else results=details[2]
- end
- if details.input ~= nil then input = details.input else input = 1 end
- if details.output ~= nil then output = details.output else output = target.size() end
- local matSlots = {}
- for i=1,16 do
- if turtle.getItemDetail(i) ~= nil and
- (materials[turtle.getItemDetail(i).name])
- then
- matSlots[#matSlots+1] = i
- end
- end
- local resultCell=0
- local function emptyCheck()
- for i=1,16 do
- if turtle.getItemDetail(i) == nil then
- if resultCell == 0 then resultCell=i end
- elseif (results[turtle.getItemDetail(i).name] and turtle.getItemDetail(i).count < turtle.getItemDetail(i,true).maxCount) then
- resultCell=i
- break
- end
- end
- end
- local pushSafe= (output==1)
- for _,v in pairs(matSlots) do
- emptyCheck()
- turtle.select(v)
- while not stopped do
- while paused do if stopped then return end os.sleep(0) end
- if output~=1 then pushSafe = (target.getItemDetail(1)==nil) end
- if target.getItemDetail(output) ~= nil and pushSafe and not materials[target.getItemDetail(1).name] then
- turtle.select(resultCell)
- target.pushItems(peripheral.getName(target),output,nil,1)
- suck()
- local itemDetail = turtle.getItemDetail(resultCell,true)
- if not results[itemDetail.name] or itemDetail.count==itemDetail.maxCount then emptyCheck() end
- turtle.select(v)
- end
- if target.getItemDetail(input) == nil and target.getItemDetail(1) == nil then
- local check = turtle.getItemDetail(v)
- if check ~= nil and materials[check.name] then
- drop()
- if input~= 1 then target.pushItems(peripheral.getName(target),1,nil,input) end
- else break
- end
- end
- os.sleep(0)
- end
- end
- end
- local function warp(location, forced)
- if automata.distanceToPoint(location) == 0 then if location==mainPoint then storageSync() end return true end
- local function tryWarp(destination)
- local success = automata.warpToPoint(destination)
- if not success then
- local nearestPoint
- for _,v in pairs(automata.points()) do
- if nearestPoint == nil or automata.distanceToPoint(v)<automata.distanceToPoint(nearestPoint) then nearestPoint=v end
- end
- chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON({
- {text="I'm sorry, but something went wrong when trying to warp! I'm closest to "},
- {text=nearestPoint,color="gold"},
- {", though. Please come pick me up!"}
- }), ownerIGN, "Crafty")
- os.sleep(0)
- return false
- else
- if destination==mainPoint then storageSync() end
- return true
- end
- end
- if stopped and not forced then return false end
- while paused and not forced do if stopped then return false end os.sleep(0) end
- if automata.estimateWarpCost(location) >= turtle.getFuelLevel() or warpFuel(location) then
- return tryWarp(location)
- elseif automata.estimateWarpCost(mainPoint) >= turtle.getFuelLevel() or warpFuel(mainPoint) then
- chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON({
- {text="Have to refuel before I can get to "},
- {text=location,color="gold"},
- {text=", but I'll be right there!"}
- }),ownerIGN, "Crafty")
- if not tryWarp(mainPoint) then
- return false
- end
- if refuelFromStorage(automata.estimateWarpCost(location)) then
- if refuelFromStorage(automata.estimateWarpCost(location)*2)then
- chatBox.sendMessageToPlayer("Alright, all fueled up and ready to go!", ownerIGN, "Crafty")
- else
- chatBox.sendMessageToPlayer("We don't have enough fuel for a return trip. Should I make the jump?", ownerIGN, "Crafty")
- local jumping = true
- parallel.waitForAny(
- function()
- while true do
- local _, username, message, uuid, isHidden = os.pullEvent("chat")
- if isHidden and uuid == "58b2110a-ceb4-4781-9359-1a764ac57edc" then
- lowerString = string.lower(message)
- if lowerString:find("deny") == 1 or lowerString:find("crafty deny") == 1
- or lowerString:find("no") == 1 or lowerString:find("crafty no") == 1
- or lowerString:find("cancel") == 1 then
- jumping = false
- chatBox.sendMessageToPlayer("Alright, I'll stay at the base!", ownerIGN, "Crafty")
- break
- elseif message:find("confirm") or message:find("yes") then
- chatBox.sendMessageToPlayer("Ok, warping now!", ownerIGN, "Crafty")
- break
- end
- end
- end
- end,
- function ()
- os.sleep(60)
- chatBox.sendMessageToPlayer("I didn't get a response, should I warp?", ownerIGN, "Crafty")
- os.sleep(60)
- chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON({
- {text="I'm going to warp now, but I'll be over by "},
- {text=location,color="gold"},
- {text=" so you can pick me up there."}
- }), ownerIGN, "Crafty")
- end
- )
- if jumping then return tryWarp(location) end
- end
- else
- chatBox.sendMessageToPlayer("I'm sorry, we don't have enough fuel to make it to the crafting station! Please bring more and try again.", ownerIGN, "Crafty")
- return false
- end
- else
- local nearestPoint
- for _,v in pairs(automata.points()) do
- if nearestPoint == nil or automata.distanceToPoint(v)<automata.distanceToPoint(nearestPoint) then nearestPoint=v end
- end
- chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON({
- {text="I'm sorry, but I can't warp right now! I don't have enough fuel! I'm closest to "},
- {text=nearestPoint,color="gold"},
- {", though. Please come pick me up, or at least refuel me."}
- }), ownerIGN, "Crafty")
- return false
- end
- end
- local function simpleProcessMats(args)
- if args[4] ~= nil and args[4]:lower()=="true" and not altReturn then
- altReturn=true
- automata.savePoint("tempHome")
- end
- --go to supply area
- if not warp(mainPoint) then return end
- local amount
- if tonumber(args[3]) ~= nil then amount = tonumber(args[3]) else amount = 64 end
- local details = programTable[args[2]]
- --Withdraw materials
- withdrawMats(details.materials,amount)
- -- go to area
- if not warp(details.location) then return end
- --find device
- local target = sideSearch(details.target)
- if not target then
- if warp(mainPoint) then
- for i=1,16 do
- if details.results[turtle.getItemDetail(i).name] then
- deposit(i)
- end
- end
- end
- if altReturn then warp("tempHome") end
- return
- end
- --start creating items
- makeItem(details,target)
- --return and deposit items, or if argument 4 is true, return to tempHome
- if (not altReturn) and warp(mainPoint) then
- for i=1,16 do
- if turtle.getItemDetail(i) ~= nil and details.results[turtle.getItemDetail(i).name] then
- deposit(i)
- end
- end
- warp(mainPoint)
- else
- warp("tempHome")
- end
- end
- local function makeEssence(args)
- local essenceList = {
- fire = "ars_nouveau:fire_essence",
- manipulation="ars_nouveau:manipulation_essence",
- manip="ars_nouveau:manipulation_essence",
- conjuration="ars_nouveau:conjuration_essence",
- conjure="ars_nouveau:conjuration_essence",
- abjuration="ars_nouveau:abjuration_essence",
- abjure="ars_nouveau:abjuration_essence",
- water="ars_nouveau:water_essence",
- air="ars_nouveau:air_essence",
- earth="ars_nouveau:earth_essence",
- anima="ars_nouveau:anima_essence"
- }
- local essence=nil
- if args[3] ~= nil then
- if essenceList[args[3]] ~= nil then essence = essenceList[args[3]]
- else
- for k,v in pairs(essenceList) do
- if args[3] == v then essence = v end
- end
- end
- end
- if essence == nil then
- chatBox.sendMessageToPlayer("I'm sorry, Ivy! I don't know what essence that is! As a reminder, the format is $crafty essence <essence type> <optional amount> <alternate return (true or false)>", ownerIGN, "Crafty")
- else
- if args[5] ~= nil and args[5]:lower()=="true" and not altReturn then
- altReturn=true
- automata.savePoint("tempHome")
- end
- --withdraw gems
- if not warp(mainPoint) then return end
- local amount=64
- if tonumber(args[4]) ~= nil then amount = tonumber(args[4]) end
- withdrawMats("ars_nouveau:source_gem",amount)
- --prepare pedestals
- if not warp("essenceMats") then return end
- local pedestals={}
- for i=0,2 do pedestals[#pedestals+1] = peripheral.wrap("ars_nouveau:arcane_pedestal_"..tostring(i)) end
- local chest=peripheral.wrap("sophisticatedstorage:chest_0")
- local pedestalRecipes = {
- --Insert desired results here
- ["ars_nouveau:abjuration_essence"] = {
- "minecraft:fermented_spider_eye",
- "minecraft:sugar",
- "minecraft:milk_bucket"
- },
- ["ars_nouveau:conjuration_essence"] = {
- "ars_nouveau:wilden_horn",
- "ars_nouveau:starbuncle_shards",
- "minecraft:book"
- },
- ["ars_nouveau:water_essence"] = {
- "minecraft:water_bucket",
- "minecraft:kelp",
- "minecraft:snow_block"
- },
- ["ars_nouveau:air_essence"] = {
- "minecraft:feather",
- "minecraft:arrow",
- "ars_nouveau:wilden_wing",
- },
- ["ars_nouveau:earth_essence"] = {
- "minecraft:iron_ingot",
- "minecraft:dirt",
- "minecraft:wheat_seeds"
- },
- ["ars_nouveau:fire_essence"] = {
- "minecraft:torch",
- "minecraft:gunpowder",
- "minecraft:flint_and_steel"
- },
- ["ars_nouveau:manipulation_essence"] = {
- "minecraft:stone_button",
- "minecraft:clock",
- "minecraft:redstone"
- },
- ["ars_elemental:anima_essence"] = {
- "minecraft:wither_skeleton_skull",
- "minecraft:bone_meal",
- "minecraft:golden_apple"
- }
- }
- for i=1,3 do
- if pedestals[i].getItemDetail(1) == nil or pedestals[i].getItemDetail(1).name ~= pedestalRecipes[essence][i] then
- pedestals[i].pushItems("sophisticatedstorage:chest_0", 1)
- for k,v in pairs(chest.list()) do
- if v.name == pedestalRecipes[essence][i] then
- pedestals[i].pullItems("sophisticatedstorage:chest_0",k)
- break
- end
- end
- end
- local failed = false
- if pedestals[i].getItemDetail(1) == nil then
- chatBox.sendMessageToPlayer("I'm sorry, but I couldn't find an item by the id of "..pedestalRecipes[essence],ownerIGN,"Crafty")
- failed=true
- elseif pedestals[i].getItemDetail(1).name ~= pedestalRecipes[essence][i] then
- chatBox.sendMessageToPlayer("I'm sorry, but something went wrong and I couldn't replace the essence material on pedestal".. tostring(i),ownerIGN,"Crafty")
- failed=true
- end
- if failed then
- if not altReturn and warp(mainPoint) then
- for i2=1,16 do
- if turtle.getItemDetail(i2) ~= nil and turtle.getItemDetail(i2).name == "ars_nouveau:source_gem" then deposit(i2) end
- end
- elseif altReturn then warp("tempHome")
- end
- return
- end
- end
- if not warp("imbuer") then return end
- local imbuer = sideSearch("ars_nouveau:imbuement_chamber")
- makeItem({material="ars_nouveau:source_gem",result=essence},imbuer)
- if not warp("essenceMats") then return end
- for i=1,3 do
- pedestals[i].pushItems("sophisticatedstorage:chest_0", 1)
- end
- if (not altReturn) and warp(mainPoint) then
- for i=1,16 do
- if turtle.getItemDetail(i) ~= nil and turtle.getItemDetail(i).name == essence then
- deposit(i)
- end
- end
- warp(mainPoint)
- else
- warp("tempHome")
- end
- end
- end
- programTable = {
- sourceGems={
- target="ars_nouveau:imbuement_chamber",
- materials = {
- --insert valid ingredients here
- ["minecraft:amethyst_shard"]=true,
- ["minecraft:lapis_lazuli"]=true
- },
- results = {
- --Insert desired results here
- ["ars_nouveau:source_gem"] = true
- },
- location="imbuer"
- },
- fleshAuto = {
- target="integrateddynamics:drying_basin",
- materials = {
- --insert valid ingredients here
- ["minecraft:rotten_flesh"]=true
- },
- results = {
- ["minecraft:leather"]=true
- },
- location="basin"
- },
- essence={func=makeEssence,acceptArgs=true},
- sort={func=function ()
- if not warp(mainPoint,true) then return end
- storageSync()
- local apotheosis = peripheral.wrap("sophisticatedstorage:controller_1")
- local ironsSpells = peripheral.wrap("entangled:tile_1")
- --First create a list for drawers to check names against
- local drawerList = {}
- for k,v in pairs(storageModems.drawers.list()) do
- drawerList[v.name] = k
- end
- --next sort the main chests, also storing a list
- local chestList = {}
- for k,v in pairs(storageModems.mainStorage.list()) do
- while paused do sleep(0) end
- if stopped then
- chatBox.sendMessageToPlayer("Sorry, I had to stop sorting early!",ownerIGN,"Crafty")
- return end
- if drawerList[v.name] ~= nil then
- local sortAmount = v.count
- while sortAmount > 0 do
- local sentItems = storageModems.mainStorage.pushItems(storageNames.drawers, k, nil, drawerList[v.name])
- sortAmount = sortAmount-sentItems
- if sentItems==0 then break end
- end
- elseif v.name:find("irons_spellbooks:") ~= nil then
- local sortAmount = v.count
- while sortAmount > 0 do
- local sentItems = ironsSpells.pullItems(storageNames.mainStorage,k)
- sortAmount = sortAmount-sentItems
- if sentItems==0 then break end
- end
- elseif v.name:find("apotheosis:") ~= nil then
- local sortAmount = v.count
- while sortAmount > 0 do
- local sentItems = apotheosis.pullItems(storageNames.mainStorage,k)
- sortAmount = sortAmount-sentItems
- if sentItems==0 then break end
- end
- elseif chestList[v.name] ~= nil then
- local sortAmount = v.count
- while sortAmount > 0 do
- local sentItems = storageModems.mainStorage.pushItems(storageNames.mainStorage,k,nil,chestList[v.name])
- sortAmount = sortAmount-sentItems
- if sentItems==0 then break end
- end
- else chestList[v.name] = k
- end
- -- os.sleep(0)
- end
- --sort other things back into chests and drawers
- for k,v in pairs(ironsSpells.list()) do
- while paused do sleep(0) end
- if stopped then
- chatBox.sendMessageToPlayer("Sorry, I had to stop sorting early!",ownerIGN,"Crafty")
- return end
- if drawerList[v.name] ~= nil then
- local sortAmount = v.count
- while sortAmount > 0 do
- local sentItems = ironsSpells.pushItems(storageNames.drawers,k,nil,drawerList[v.name])
- sortAmount = sortAmount-sentItems
- if sentItems==0 then break end
- end
- elseif chestList[v.name] ~= nil and (v.name:find("irons_spellbooks:") == nil) then
- local sortAmount = v.count
- while sortAmount > 0 do
- local sentItems = ironsSpells.pushItems(storageNames.mainStorage,k,nil,chestList[v.name])
- sortAmount = sortAmount-sentItems
- if sentItems==0 then break end
- end
- end
- end
- for k,v in pairs(apotheosis.list()) do
- while paused do sleep(0) end
- if stopped then
- chatBox.sendMessageToPlayer("Sorry, I had to stop sorting early!",ownerIGN,"Crafty")
- return end
- if drawerList[v.name] ~= nil then
- local sortAmount = v.count
- while sortAmount > 0 do
- local sentItems = apotheosis.pushItems(storageNames.drawers,k,nil,drawerList[v.name])
- sortAmount = sortAmount-sentItems
- if sentItems==0 then break end
- end
- end
- end
- chatBox.sendMessageToPlayer("I have finished sorting!",ownerIGN,"Crafty")
- end},
- update = {
- func=function ()
- chatBox.sendMessageToPlayer("Alright, updating now!",ownerIGN,"Crafty")
- if shell.run("pastebin get ZQbBNLkB tempCrafty") then
- shell.run("rm crafty")
- shell.run("rename tempCrafty crafty")
- chatBox.sendMessageToPlayer("Restarting now, see you soon!", ownerIGN, "Crafty")
- os.reboot()
- else
- return false
- end
- end
- },
- --Powah Energizing
- energize={
- func=function(args)
- local recipeList = {
- hardened = {
- id="powah:steel_energized",
- "minecraft:iron_ingot",
- "minecraft:gold_ingot"
- },
- blazing={
- id="powah:crystal_blazing",
- "minecraft:blaze_powder",
- "minecraft:blaze_powder",
- "minecraft:blaze_powder",
- "minecraft:blaze_powder",
- altRecipe={
- "minecraft:blaze_rod",
- }
- },
- niotic={
- id="powah:crystal_niotic",
- "minecraft:diamond"
- },
- spirited={
- id="powah:crystal_spirited",
- "minecraft:emerald"
- },
- nitro={
- id="powah:crystal_nitro",
- "minecraft:nether_star",
- "minecraft:redstone_block",
- "minecraft:redstone_block",
- "powah:blazing_crystal_block",
- }
- }
- recipeList.esteel=recipeList.hardened
- recipeList.energized=recipeList.hardened
- local result=nil
- if args[3] ~= nil then
- if recipeList[args[3]] ~= nil then result = recipeList[args[3]]
- else
- for k,v in pairs(recipeList) do
- if args[3] == v.id then result = v
- end
- end
- end
- end
- if result == nil then
- chatBox.sendMessageToPlayer("I'm sorry, Ivy! I don't know what that is! As a reminder, the format is $crafty energize <powah material> <optional amount> <alternate return (true or false)>",ownerIGN,"Crafty")
- else
- local amount
- if tonumber(args[4]) ~= nil then amount=tonumber(args[4]) else amount = 64 end
- if args[5] ~= nil and args[5]:lower()=="true" and not altReturn then
- altReturn=true
- automata.savePoint("tempHome")
- end
- if not warp(mainPoint) then return false end
- local itemTable={}
- local withdrawTable = {}
- for i=1,#result do
- if itemTable[result[i]] == nil then itemTable[result[i]]=true end
- if withdrawTable[result[i]] == nil then withdrawTable[result[i]] = amount else withdrawTable[result[i]] = withdrawTable[result[i]]+amount end
- end
- for k,v in pairs(withdrawTable) do withdrawMats(k,v) end
- if not warp("energizer") then
- for i=1,16 do
- if itemTable[turtle.getItemDetail(i).name] then
- deposit(i)
- end
- return false
- end
- end
- local energizer=peripheral.find("powah:energizing_orb")
- local matSlots = {}
- local blipTest=false
- while not stopped do
- while paused do if stopped then return end os.sleep(0) end
- if energizer.getItemDetail(1) ~= nil then
- energizer.pushItems("turtle_6",1,nil,emptyCheck(energizer.getItemDetail(1).name))
- end
- for i=1,#result do
- if matSlots[i] == nil or turtle.getItemDetail(matSlots[i]) == nil or turtle.getItemDetail(matSlots[i]).name ~= result[i] then
- for i2=1,16 do
- if turtle.getItemDetail(i2)~=nil and turtle.getItemDetail(i2).name == result[i] then matSlots[i]=i2 end
- end
- end
- local itemDetails = energizer.getItemDetail(i+1)
- if itemDetails ~= nil and itemDetails.name ~= result[i] then
- energizer.pushItems("turtle_6",i+1,nil,emptyCheck(energizer.getItemDetail(i+1).name))
- end
- itemDetails=energizer.getItemDetail(i+1)
- if itemDetails == nil and turtle.getItemDetail(matSlots[i])~= nil and turtle.getItemDetail(matSlots[i]).name == result[i] then
- energizer.pullItems("turtle_6",matSlots[i],nil,i+1)
- end
- end
- local continue=false
- for i=1,energizer.size() do
- if energizer.getItemDetail(i)~= nil then
- continue=true
- end
- end
- if not continue then
- if blipTest==false then blipTest=true
- else break end
- end
- end
- if (not altReturn) and warp(mainPoint) then
- for i=1,16 do
- if turtle.getItemDetail(i) ~= nil and (turtle.getItemDetail(i).name == result.id or itemTable[turtle.getItemDetail(i).name]) then
- deposit(i)
- end
- end
- warp(mainPoint)
- else
- warp("tempHome")
- end
- end
- end,
- acceptArgs=true
- }
- }
- local simpleCommands
- simpleCommands = {
- echo=function (message, args)
- local sayThis = message:gsub(args[1].." "..args[2].." ","")
- chatBox.sendMessageToPlayer(sayThis, ownerIGN, "Crafty")
- end,
- say=function (message, args)
- local sayThis = message:gsub(args[1].." "..args[2].." ","")
- chatBox.sendMessage(sayThis, "Crafty")
- end,
- sayrange=function (message, args)
- local sayThis = message:gsub(args[1].." "..args[2].." "..args[3].." ","")
- local range = tonumber(args[3])
- chatBox.sendMessage(sayThis, "Crafty",nil,nil, range)
- end,
- save=function (message, args)
- local saveThis = message:gsub(args[1].." "..args[2].." ","")
- automata.savePoint(saveThis)
- end,
- warp=function (message, args)
- local warpPoint = message:gsub(args[1].." "..args[2].." ","")
- for _,v in pairs(automata.points()) do
- if warpPoint:lower() == v:lower() then warp(v,true) end
- end
- end,
- stop=function ()
- if working then
- local tempLoc
- for _,v in pairs(automata.points()) do
- if automata.distanceToPoint(v) == 0 then tempLoc = v end
- end
- if tempLoc==nil then
- automata.savePoint("pauseLoc")
- tempLoc="tempLoc"
- end
- pauseLoc=tempLoc
- end
- paused=true stopped=true
- end,
- pause=function ()
- if working and not paused then
- local tempLoc
- for _,v in pairs(automata.points()) do
- if automata.distanceToPoint(v) == 0 then tempLoc = v end
- end
- if tempLoc==nil then
- automata.savePoint("pauseLoc")
- tempLoc="tempLoc"
- end
- pauseLoc=tempLoc
- end
- paused=true
- end,
- skip = function ()
- stopped=true
- end,
- clear = function ()
- clearQueue=true
- queue={}
- end,
- resume=function ()
- if pauseLoc ~= nil then warp(pauseLoc, true) end
- paused=false
- end,
- fuel=function (_, args)
- local reply = {
- {text="I currently have "},
- {text=tostring(turtle.getFuelLevel()), color="gold"},
- {text=" fuel remaining."}
- }
- if args[3] ~= nil then
- for _,v in pairs(automata.points()) do
- if args[3]:lower() == v:lower() then
- reply[#reply+1] = {text=" Getting to "..v.." will take "}
- reply[#reply+1] = {text=tostring(automata.estimateWarpCost(v)), color="gold"}
- reply[#reply+1] = {text=" fuel."}
- end
- end
- end
- chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(reply), ownerIGN, "Crafty")
- end,
- points=function ()
- local reply = {
- {text="I have memorized the following points: "},
- }
- for _,v in pairs(automata.points()) do
- reply[#reply+1] = {text="\n"..v, color="gold"}
- end
- chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(reply), ownerIGN, "Crafty")
- end,
- move=function(_,args)
- moveTable={
- forward=turtle.forward,
- back=turtle.back,
- left=turtle.turnLeft,
- right=turtle.turnRight,
- up=turtle.up,
- down=turtle.down,
- scan=function()
- local scannedBlock, scanned = turtle.inspect()
- local scanText
- if not scannedBlock then scanText={{text="There is nothing there!"}}
- else
- scanText={{text="I currently see: "}}
- scanText[#scanText+1] = {text=scanned.name,hoverEvent={
- action="show_item",
- contents={id=scanned.name}
- }}
- end
- chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(scanText),ownerIGN,"Crafty")
- end,
- scanup=function()
- local scannedBlock, scanned = turtle.inspectUp()
- local scanText
- if not scannedBlock then scanText={{text="There is nothing there!"}}
- else
- scanText={{text="I currently see: "}}
- scanText[#scanText+1] = {text=scanned.name,hoverEvent={
- action="show_item",
- contents={id=scanned.name}
- }}
- end
- chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(scanText),ownerIGN,"Crafty")
- end,
- scandown=function()
- local scannedBlock, scanned = turtle.inspectDown()
- local scanText
- if not scannedBlock then scanText={{text="There is nothing there!"}}
- else
- scanText={{text="I currently see: "}}
- scanText[#scanText+1] = {text=scanned.name,hoverEvent={
- action="show_item",
- contents={id=scanned.name}
- }}
- end
- chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(scanText),ownerIGN,"Crafty")
- end
- }
- for i=3,#args do
- if moveTable[args[i]] then moveTable[args[i]]() end
- end
- end,
- invcheck=function ()
- local invText = {{text="My inventory currently is:\n"}}
- for i=1,16 do
- local invSlotString ={
- text="["..tostring(i).."]"
- }
- if turtle.getItemDetail(i) ~= nil then
- invSlotString.hoverEvent={
- action="show_item",
- contents={}
- }
- invSlotString.bold=true
- invSlotString.hoverEvent.contents.id=turtle.getItemDetail(i).name
- end
- if i%4 == 0 then invSlotString.text = invSlotString.text.."\n"
- else invSlotString.text=invSlotString.text.." " end
- invText[#invText+1] = invSlotString
- end
- chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(invText),ownerIGN,"Crafty")
- end,
- select=function (_,args)
- if tonumber(args[3])~= nil then turtle.select() end
- end
- }
- --aliases
- simpleCommands["warpto"] = simpleCommands.warp
- simpleCommands.clearqueue = simpleCommands.clear
- --MAIN BRAINS
- parallel.waitForAny(
- function()
- local username, message, uuid, isHidden
- while true do
- _, username, message, uuid, isHidden = os.pullEvent("chat")
- if isHidden and uuid == "58b2110a-ceb4-4781-9359-1a764ac57edc" then
- local args = {}
- for word in message:gmatch("%S+") do args[#args+1] = word end
- if args[1]:lower() == "crafty" and args[2] ~= nil then
- if args[2]:lower() == "quit" or args[2]:lower()=="forcequit" then return
- elseif simpleCommands[args[2]:lower()] ~= nil then simpleCommands[args[2]:lower()](message, args)
- else
- for k,v in pairs(programTable) do
- if args[2]:lower() == k:lower() then
- local funcArgs = {}
- if type(v) == "function" then funcArgs= {name=k,func=v, args=message}
- elseif v.func ~= nil then
- if v.acceptArgs then funcArgs = {name=k, func=v.func,args=args}
- elseif v.acceptMessage then funcArgs = {name=k, func=v.func, args=message}
- else funcArgs={name=k, func=v.func} end
- else
- funcArgs= {name=k,func=simpleProcessMats,args=args}
- end
- queue[#queue+1] = funcArgs
- end
- end
- end
- end
- elseif message:lower():gsub("[^%w%s]+", ""):find("crafty say hello") and uuid == "58b2110a-ceb4-4781-9359-1a764ac57edc" then
- chatBox.sendMessage("Hello, I'm Crafty! Ivy's new robot meant to assist with many tasks and automation! It's a huge pleasure to meet you all! ^.^", "Crafty")
- elseif message:lower():find("crafty") then
- for k,v in pairs(acceptedGreetings) do
- if message:lower():gsub("[^%w%s]+", ""):find(v) then
- if responseTable[uuid] ~= nil then chatBox.sendMessage(responseTable[uuid][math.random(#responseTable[uuid])],"Crafty")
- else chatBox.sendMessage(responseTable.general[math.random(#responseTable.general)])
- end
- end
- end
- end
- end end,
- function() while true do
- local tasks = {}
- if next(queue) ~= nil then
- tasks=queue
- queue={}
- end
- if next(tasks) ~= nil then
- working=true
- for k,v in pairs(tasks) do
- if not clearQueue then
- if v.args ~= nil then v.func(v.args) else v.func() end
- end
- stopped=false
- end
- else working=false
- end
- stopped = false
- clearQueue=false
- os.sleep(0)
- end end
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement