Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = 0.3
- -- +------------------------+ --
- -- |--> INITIALIZATION <--| --
- -- +------------------------+ --
- if not turtle then
- print("This program can only be")
- print(" executed by a turtle!")
- return
- end
- local ARGS = {...}
- -- INITIALIZING NECESSARY FUNCTIONS
- local startswith = function(self, piece)
- return string.sub(self, 1, string.len(piece)) == piece
- end
- -- UPDATE HANDLING --
- if _UD and _UD.su(version, "g4Nr4qMA", {...}) then return end
- -- directions in relation to initial placement (which is 0, or front)
- local direction = {front=0, right=1, back=2, left=3, top=4, bottom=5 }
- -- INITIAL VARIABLE SETUP --
- local vars = {
- -- width and height of the quarry site
- dropside = direction.bottom,
- tempside = direction.top,
- fetchside = direction.front,
- facing = direction.front
- }
- -- READ OUT COMMAND LINE PARAMETERS --
- for _,par in pairs(ARGS) do
- if startswith(par, "d:") then
- vars.dropside = direction[string.sub(par, string.len("d:")+1)]
- elseif startswith(par, "t:") then
- vars.tempside = direction[string.sub(par, string.len("t:")+1)]
- elseif startswith(par, "f:") then
- vars.fetchside = direction[string.sub(par, string.len("f:")+1)]
- elseif par == "help" then
- print("The Turtle will suck ingots from the specified side (default: front) and craft them to nuggets which will be temporarily dropped to the \"temp\" side (default: top).")
- print("The nuggets will be crafted back to ingots and get dropped to the \"drop\" side (default: bottom).")
- print("Usage: "..shell.getRunningProgram().." [f:{fetch side}] [t:{temp side}] [d:{frop side}]")
- print(" For example: "..shell.getRunningProgram().." f:top t:back")
- return
- end
- end
- local function turnLeft()
- turtle.turnLeft()
- vars.facing = vars.facing-1
- if (vars.facing < 0) then
- vars.facing = 3
- end
- end
- -- drops to the designated side and returns whatever the turtle.drop returns.
- local function drop( side )
- if side == direction.top then
- return turtle.dropUp()
- elseif side == direction.bottom then
- return turtle.dropDown()
- else
- while vars.facing ~= side do
- turnLeft()
- end
- return turtle.drop()
- end
- end
- -- sucks from the designated side and returns whatever the turtle.suck returns.
- local function suck( side )
- if side == direction.top then
- return turtle.suckUp()
- elseif side == direction.bottom then
- return turtle.suckDown()
- else
- while vars.facing ~= side do
- turnLeft()
- end
- return turtle.suck()
- end
- end
- local function status(text)
- term.clear()
- term.setCursorPos(1,1)
- print(" Ingot-Recraft ")
- print("---------------")
- print()
- term.write("--> ")
- print(text)
- print()
- end
- local function main()
- status("Dropping Inventory...")
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- drop(vars.dropside)
- end
- end
- turtle.select(1)
- suck(vars.fetchside)
- while turtle.getItemCount(1) > 0 do
- local ingotCount = turtle.getItemCount(1)
- -- TODO: check if valid ingots
- status("Crafting ingots to nuggets...")
- turtle.select(2)
- while turtle.getItemCount(1) > 0 do
- turtle.craft()
- drop(vars.tempside)
- end
- status("Crafting back to ingots...")
- turtle.select(16)
- for i=1,11 do
- if (i%4) > 0 then
- -- always sucking to slot 16 and then evenly distributing to the 9 crafting slots
- turtle.transferTo(i, ingotCount)
- local nuggetsNeeded = ingotCount - turtle.getItemCount(i)
- if (nuggetsNeeded > 0) then
- suck(vars.tempside)
- turtle.transferTo(i,nuggetsNeeded)
- end
- end
- end
- turtle.craft()
- status("Dropping Inventory...")
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- drop(vars.dropside)
- end
- end
- turtle.select(1)
- suck(vars.fetchside)
- end
- status("Finished.")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement