Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Coded by HPWebcamAble --
- -- Simple API that lets ComputerCraft turtle accept sides in most functions
- -- See the forum post for more:
- -- http://www.computercraft.info/forums2/index.php?/topic/24030-turtle-tweaks-api/
- if not turtle then error("Can only load on turtles") end
- local sideConversion = {
- ["right"] = "Right",
- ["left"] = "Left",
- ["top"] = "Up",
- ["bottom"] = "Down",
- ["back"] = "back",
- ["front"] = ""
- }
- local directionConversions = {
- top = "up", bottom = "down", right = "turnRight",
- left = "turnLeft", back = "back", front = "forward"
- }
- local oldFuncs = {}
- local toReplace = {
- ["detect"] = true,
- ["inspect"] = true,
- ["place"] = true,
- ["suck"] = true,
- ["compare"] = true,
- ["attack"] = true,
- ["dig"] = true,
- ["drop"] = true
- }
- local directionsToReplace = {"up","down","turnRight","turnLeft","forward","back"}
- for a,b in pairs(turtle) do
- if toReplace[a] then
- oldFuncs[a] = b
- _G["turtle"][a] = function(side)
- if not side then return oldFuncs[a]() end
- if _G["turtle"][a..tostring(sideConversion[side])] then
- return _G["turtle"][a..sideConversion[side]]()
- else
- error(side.." is not a valid side",2)
- end
- end
- end
- end
- turtle.move = function(sideOrDirection)
- if _G["turtle"][directionConversions[sideOrDirection]] then
- return _G["turtle"][directionConversions[sideOrDirection]]()
- elseif _G["turtle"][sideOrDirection] then
- return _G["turtle"][sideOrDirection]()
- else
- error("Not a valid side or direction",2)
- end
- end
- turtle.equip = function(side)
- side = string.lower(tostring(side))
- if side == "left" then return turtle.equipLeft()
- elseif side == "right" then return turtle.equipRight()
- else error(tostring(side).." is not a valid side",2) end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement