Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --### Program Config
- local turtleFromAEDirection = "down"
- local programRestartInterval = 1.00 -- Program run interval
- --### ONLY MODFIY BELOW IF YOU KNOW WHAT YOU ARE DOING
- ---------------------------------------------------------------------------------------------------------------
- --### Recipe functions
- local woolStock = 100
- local woolName = "minecraft:wool"
- local cottonName = "Natura:barleyFood:3"
- local dyeStock = 100
- local dyeName = "Botania:dye"
- local petalName = "Botania:petal"
- local mortarName = "Botania:pestleAndMortar"
- local recipe = {
- {name = "minecraft:chest", stock = 10, ingredient = {"minecraft:planks","minecraft:planks","minecraft:planks","minecraft:planks",nil,"minecraft:planks","minecraft:planks","minecraft:planks","minecraft:planks"}}
- }
- function addNaturaWoolRecipe()
- local whiteWool = {name = woolName, stock = woolStock, ingredient = {cottonName,cottonName,cottonName,cottonName,cottonName,cottonName,cottonName,cottonName,cottonName}}
- table.insert(recipe, whiteWool)
- end
- function generateWoolRecipes()
- for c=1,16 do
- local r = {}
- r.name = woolName..":"..c
- r.stock = woolStock
- r.ingredient = {dyeName..":"..c, woolName}
- table.insert(recipe, r)
- end
- end
- function generateDyeRecipes()
- table.insert(recipe, {name = dyeName, stock = dyeStock, ingredient = {petalName,mortarName}})
- for c=1,16 do
- local r = {}
- r.name = dyeName..":"..c
- r.stock = dyeStock
- r.ingredient = {petalName..":"..c, mortarName}
- table.insert(recipe, r)
- end
- end
- generateDyeRecipes()
- addNaturaWoolRecipe()
- generateWoolRecipes()
- function getRecipe()
- for _,r in pairs(recipe) do
- if r.stock > getAmountInAE(r.name) then
- return r
- end
- end
- return nil
- end
- --### Recipe functions
- ---------------------------------------------------------------------------------------------------------------
- --### Crafting functions
- local c = peripheral.find("workbench")
- if not c then
- error("\n\nNo Crafting Table equiped")
- return
- end
- --### Crafting functions
- ---------------------------------------------------------------------------------------------------------------
- --### Helper Functions
- local gridSlotToTurtleSlot = {
- [1] = 1,
- [2] = 2,
- [3] = 3,
- [4] = 5,
- [5] = 6,
- [6] = 7,
- [7] = 9,
- [8] = 10,
- [9] = 11,
- }
- function debug(text)
- local debug = true
- if text ~= nil and debug then
- term.setTextColor(colors.blue)
- print(">>> "..text)
- term.setTextColor(colors.white)
- end
- end
- function status(text)
- if text ~= nil then
- term.setTextColor(colors.yellow)
- print(" "..text)
- term.setTextColor(colors.white)
- end
- end
- function getItemId(stack)
- if stack then
- if stack.dmg ~= nil and stack.dmg ~= 0 then
- return stack.id .. ":" .. stack.dmg
- else
- return stack.id
- end
- else
- return nil
- end
- end
- function getFingerprint(itemString)
- itemString = itemString..":"
- local tbl = {}
- for v in itemString:gmatch("(.-):") do
- table.insert(tbl,v)
- end
- local id = tbl[1]..":"..tbl[2]
- local dmg = tbl[3] or 0
- return {["id"] = id, ["dmg"] = tostring(dmg)}
- end
- function resetTerminal()
- term.clear()
- term.setCursorPos(1,1)
- end
- function printTable(tbl)
- for i,v in pairs(tbl) do
- write(i)
- write(":")
- write(type(v))
- write(":")
- print(v)
- end
- end
- --### Helper Functions
- ---------------------------------------------------------------------------------------------------------------
- --### AE Functions
- local ae = peripheral.find("tileinterface")
- if not ae then
- error("\n\nNo AE Interface found.\nAttack to any side.")
- return
- end
- function checkAE()
- if not ae.canExport(turtleFromAEDirection) then
- error("\nWrong AE Setup.\n\nInterface can not export to: "..turtleFromAEDirection)
- end
- end
- function getAmountInAE(itemString)
- local fp = getFingerprint(itemString)
- printTable(fp)
- local info = ae.getItemDetail(fp)
- return info.basic()["qty"] or 0
- end
- function clearTurtle()
- for i=1,16 do
- ae.pullItem(turtleFromAEDirection,i)
- end
- end
- --### AE Functions
- ---------------------------------------------------------------------------------------------------------------
- --### Program Functions
- function craft(r)
- for cslot,i in pairs(r.ingredient) do
- local fingerprint = getFingerprint(i)
- local toSlot = gridSlotToTurtleSlot[cslot]
- local success = ae.exportItem(fingerprint, turtleFromAEDirection, 1, toSlot)
- --print("exported "..success.fingerprint.id.. " to slot "..toSlot)
- if not success then
- status("Not enough resources: "..i)
- return
- end
- end
- local cSuccess, msg = c.craft()
- if cSuccess then
- print("Crafting done")
- else
- print(msg)
- end
- end
- --### Program Functions
- ---------------------------------------------------------------------------------------------------------------
- --### Default Main Program Functions
- function preRunProgram()
- end
- function runProgram()
- checkAE()
- local r = getRecipe()
- if r ~= nil then
- status("Crafting: "..r.name)
- status("("..getAmountInAE(r.name).."/"..r.stock..")")
- craft(r)
- clearTurtle()
- else
- status("No further recipe")
- end
- --resetTerminal()
- end
- function postRunProgram()
- end
- local STOP = false
- local PROGRAM_RUN_TIMER = nil
- function handleEvent(event)
- if event[1] == "timer" and event[2] == PROGRAM_RUN_TIMER then
- preRunProgram()
- runProgram()
- postRunProgram()
- PROGRAM_RUN_TIMER = os.startTimer(programRestartInterval)
- return
- end
- if event[1] == "char" and event[2] == "t" then
- STOP = true
- print("Termination Key detected.\n!!! Terminating the program !!!")
- return
- end
- local ignoreList = {"char", "key", "key_up", "mouse_click", "mouse_up", "mouse_drag", "mouse_scroll", "rednet", "turtle_inventory"}
- for i,v in pairs(ignoreList) do
- if event[1] == v then
- return
- end
- end
- print("unhandeled event:")
- for i,v in pairs(event) do
- write(i)
- write(":")
- print(v)
- end
- end
- function preLoop()
- resetTerminal()
- print(shell.getRunningProgram().." started")
- clearTurtle()
- PROGRAM_RUN_TIMER = os.startTimer(0)
- end
- function loop()
- while not STOP do
- handleEvent({os.pullEvent()})
- end
- end
- function postLoop()
- end
- --### Default Main Program Functions
- ---------------------------------------------------------------------------------------------------------------
- preLoop()
- loop()
- postLoop()
Advertisement
Add Comment
Please, Sign In to add comment