Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if type(old) == "table" then
- return false
- else
- old = {}
- old.turtle = {}
- for i,v in pairs(turtle) do
- old.turtle[i] = v
- end
- end
- local function refuel()
- shell.run("refuel", "all")
- if turtle.getFuelLevel() == 0 then
- return false
- else
- return true
- end
- end
- local function doSide(f, direction, ...)
- local args = {...}
- if not old.turtle[f] then
- return false, "No such function as turtle." .. tostring(f)
- end
- if direction == "top" or direction == "up" then
- return old.turtle[f .. "Up"](unpack(args))
- elseif direction == "bottom" or direction == "down" then
- return old.turtle[f .. "Down"](unpack(args))
- elseif direction == nil or direction == "front" or direction == "forward" then
- return old.turtle[f](unpack(args))
- elseif direction == "right" then
- turtle.turnRight()
- local a = {old.turtle[f](unpack(args))}
- turtle.turnLeft()
- return unpack(a)
- elseif direction == "left" then
- turtle.turnLeft()
- local a = {old.turtle[f](unpack(args))}
- turtle.turnRight()
- return unpack(a)
- elseif direction == "back" then
- turtle.turnLeft()
- turtle.turnLeft()
- local a = {old.turtle[f](unpack(args))}
- turtle.turnLeft()
- turtle.turnLeft()
- return unpack(a)
- else
- return false, "Direction unrecognized"
- end
- end
- local function drop(n, side)
- if type(n) == "string" then
- side = n
- n = 1
- end
- return doSide("drop", side, n)
- end
- turtle.drop = drop
- local function suck(n, side)
- if type(n) == "string" then
- side = n
- n = 1
- end
- return doSide("suck", side, n)
- end
- turtle.suck = suck
- local function inspect(side)
- return doSide("inspect", side)
- end
- turtle.inspect = inspect
- local function dig(side)
- return doSide("dig", side)
- end
- turtle.dig = dig
- local function detect(side)
- return doSide("detect", side)
- end
- turtle.detect = detect
- local function place(side)
- return doSide("place", side)
- end
- turtle.place = place
- local function attack(side)
- return doSide("attack", side)
- end
- turtle.attack = attack
- local function forward()
- if turtle.getFuelLevel() > 0 then
- _, block = turtle.inspect("forward")
- if type(block) == "table" then
- if block.name == "minecraft:gravel" or block.name == "minecraft:sand" then
- while turtle.detect("forward") do
- turtle.dig("forward")
- sleep(0.5)
- end
- else
- while turtle.detect("forward") do turtle.dig("forward") end
- end
- end
- local walked = old.turtle.forward("forward")
- if not walked then
- print("ERROR : Unable to move forward")
- if turtle.detect("forward") then
- print("Block detected")
- while not forward() do
- sleep(0.5)
- end
- else
- print("ERROR : There must be a mob.")
- while true do
- turtle.attack("forward")
- walked = old.turtle.forward()
- if walked == true then break end
- end
- print("SUCCESS : Mob gone")
- end
- end
- else
- print("Lacking energy. Attempting to refuel.")
- if refuel() == false then
- print("ERROR : No more fuel.")
- shell.exit()
- end
- return false
- end
- return true
- end
- turtle.forward = forward
- local function go(direction)
- if direction == "top" or direction == "up" then
- return turtle.up()
- elseif direction == "bottom" or direction == "down" then
- return turtle.down()
- elseif direction == "front" or direction == "forward" then
- return turtle.forward()
- elseif direction == "right" then
- turtle.turnRight()
- return turtle.forward()
- elseif direction == "left" then
- turtle.turnLeft()
- return turtle.forward()
- elseif direction == "back" then
- return turtle.back()
- else
- return turtle.forward(), "Direction unrecognized"
- end
- end
- turtle.go = go
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement