Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin get nAZejNMM enchanter
- --shell.run("enchanter t d rback 10 30")
- --shell.run("enchanter t b")
- --shell.run("enchanter t rf")
- local tArgs = { ... }
- local sXPInput, sInput, sOutput, nDelay, nLevel = tArgs[1], tArgs[2], tArgs[3], tArgs[4], tArgs[5]
- local filename = shell.getRunningProgram()
- local function fixSide(aSide)
- if aSide == nil then
- aSide = ""
- end
- aSide = string.lower(aSide)
- if aSide == "top" or aSide == "t" or aSide == "up" or aSide == "u"then
- aSide = "t"
- elseif aSide == "front" or aSide == "f" then
- aSide = "f"
- elseif aSide == "bottom" or aSide == "b" or aSide == "down" or aSide == "d" then
- aSide = "b"
- elseif aSide == "none" or aSide == "n" then
- aSide = "n"
- elseif aSide == "rtop" or aSide == "rt" or aSide == "rup" or aSide == "ru"then
- aSide = "rt"
- elseif aSide == "rfront" or aSide == "rf" then
- aSide = "rf"
- elseif aSide == "rbottom" or aSide == "rb" or aSide == "rdown" or aSide == "rd" then
- aSide = "rd"
- elseif aSide == "rright" or aSide == "rr" then
- aSide = "rr"
- elseif aSide == "rleft" or aSide == "rl" then
- aSide = "rl"
- elseif aSide == "rback" or aSide == "rbk" then
- aSide = "rb"
- else
- aSide = nil
- end
- return aSide
- end
- sXPInput = fixSide(sXPInput)
- sInput = fixSide(sInput)
- sOutput = fixSide(sOutput)
- if sXPInput == nil or sInput == nil or sOutput == nil then
- print( "Usage: " .. filename .. " <input XP side> <input side> <output side> [Delay Time] [Enchant Level]" )
- print( "Side values are Top, Bottom, Front, and None" )
- print( "The turtle will pull from the input side and push into the output side." )
- print( "None can be specified if the turtle is expected to deal with items moving on their own." )
- return
- end
- if nDelay ~= nil then
- nDelay = tonumber(nDelay)
- end
- if nLevel ~= nil then
- nLevel = tonumber(nLevel)
- end
- if nDelay == nil then
- nDelay = 0.5
- end
- if nLevel == nil then
- nLevel = 30
- end
- if nLevel > 30 then
- nLevel = 30
- elseif nLevel < 1 then
- nLevel = 1
- end
- local function displaySide(aSide)
- if aSide == nil then
- aSide = ""
- end
- aSide = string.lower(aSide)
- if aSide == "t" then
- aSide = "top"
- elseif aSide == "f" then
- aSide = "front"
- elseif aSide == "b" then
- aSide = "bottom"
- elseif aSide == "n" then
- aSide = "none"
- elseif aSide == "rt" then
- aSide = "redstone pulse top"
- elseif aSide == "rf" then
- aSide = "redstone pulse front"
- elseif aSide == "rd" then
- aSide = "redstone pulse down"
- elseif aSide == "rr" then
- aSide = "redstone pulse right"
- elseif aSide == "rl" then
- aSide = "redstone pulse left"
- elseif aSide == "rb" then
- aSide = "redstone pulse back"
- else
- aSide = "unknown (" .. aSide .. ")"
- end
- return aSide
- end
- local function isEmpty()
- local bFull = true
- local nTotalItems = 0
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount == 0 then
- bFull = false
- end
- nTotalItems = nTotalItems + nCount
- end
- if nCount == 0 then
- --print( "No more Items to drop." )
- return true
- end
- return false
- end
- local function flashSide(aSide)
- --print("Flash " .. aSide .. " On ")
- redstone.setOutput(aSide, true)
- sleep(0.2)
- --print("Flash " .. aSide .. " Off ")
- redstone.setOutput(aSide, false)
- sleep(0.2)
- end
- local function unload()
- if sOutput == "n" then
- return
- end
- --print( "Unloading items..." )
- for n=1,1 do
- --unloaded = unloaded + turtle.getItemCount(n)
- if (turtle.getItemCount(n) > 0) then
- turtle.select(n)
- if sOutput == "t" then
- turtle.dropUp()
- elseif sOutput == "f" then
- turtle.drop()
- elseif sOutput == "b" then
- turtle.dropDown()
- elseif sOutput == "rt" then
- flashSide("top")
- elseif sOutput == "rd" then
- flashSide("bottom")
- elseif sOutput == "rf" then
- flashSide("front")
- elseif sOutput == "rb" then
- flashSide("back")
- elseif sOutput == "rl" then
- flashSide("left")
- elseif sOutput == "rf" then
- flashSide("right")
- end
- end
- end
- end
- local function load()
- if sInput == "n" then
- return
- end
- --print( "Loading items..." )
- turtle.select(1)
- n=1
- --unloaded = unloaded + turtle.getItemCount(n)
- if (turtle.getItemCount(n) == 0) then
- if sInput == "t" then
- res = turtle.suckUp(1)
- elseif sInput == "f" then
- res = turtle.suck(1)
- elseif sInput == "b" then
- res = turtle.suckDown(1)
- elseif sInput == "rt" then
- flashSide("top")
- turtle.select(n)
- res = (turtle.getItemCount(n) ~= 0)
- elseif sInput == "rd" then
- turtle.select(n)
- flashSide("bottom")
- res = (turtle.getItemCount(n) ~= 0)
- elseif sInput == "rf" then
- turtle.select(n)
- flashSide("front")
- res = (turtle.getItemCount(n) ~= 0)
- elseif sInput == "rb" then
- turtle.select(n)
- flashSide("back")
- res = (turtle.getItemCount(n) ~= 0)
- elseif sInput == "rl" then
- turtle.select(n)
- flashSide("left")
- res = (turtle.getItemCount(n) ~= 0)
- elseif sInput == "rf" then
- turtle.select(n)
- flashSide("right")
- res = (turtle.getItemCount(n) ~= 0)
- end
- if res == false then
- --print( "No more Items to get." )
- return false
- end
- --sleep(60)
- end
- return true
- end
- print( "Enchanting using XP from " .. displaySide(sXPInput) .. " and items from " .. displaySide(sInput) .. " at level " .. nLevel .. " sending to " .. displaySide(sOutput) .. " with a delay of " .. nDelay .. " seconds." )
- --print("Left: " .. peripheral.getType("left"))
- --print("Right: " .. peripheral.getType("right"))
- local xp
- if peripheral.getType("left") == "xp" then
- xp = peripheral.wrap("left")
- elseif peripheral.getType("right") == "xp" then
- xp = peripheral.wrap("right")
- end
- local function getXP()
- if sXPInput == "f" then
- xp.get()
- elseif sXPInput == "t" then
- xp.getUp()
- elseif xpInput == "b" then
- xp.getDown()
- end
- end
- while true do
- getXP()
- xp.collect()
- print("Levels: " .. xp.getLevels())
- if xp.getLevels() >= nLevel then
- if turtle.getItemCount(1) + turtle.getItemCount(2) == 0 then
- load()
- end
- if turtle.getItemCount(1) > 1 then
- turtle.select(1)
- turtle.transferTo(2, turtle.getItemCount(1) - 1)
- end
- if turtle.getItemCount(1) == 0 and turtle.getItemCount(2) > 0 then
- turtle.select(2)
- turtle.transferTo(1, 1)
- end
- turtle.select(1)
- xp.enchant(nLevel)
- unload()
- end
- sleep(nDelay)
- end
Advertisement
Add Comment
Please, Sign In to add comment