Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CHEST_NAME = "EnderSTorage:enderChest"
- local function is_facing_name(str, matching_chars)
- local success, data = turtle.inspect()
- if not success then
- return false
- end
- if not matching_chars then
- if data.name == str then
- return true
- end
- else
- if string.sub(str, matching_chars) == string.sub(data.name, matching_chars) then
- return true
- end
- end
- return false
- end
- local function orient()
- local turned = 0
- while not is_facing_name(CHEST_NAME) do
- turtle.turnLeft()
- turned = turned + 1
- if turned >= 4 then
- print("Could not find orientation")
- return false
- end
- end
- return true
- end
- local function is_facing_turtle()
- return is_facing_name("ComputerCraft", 13)
- end
- local function get_bucket()
- while true do
- turtle.select(1)
- turtle.suck(1)
- if turtle.getItemCount() > 0 then
- return
- end
- sleep(1)
- end
- end
- local function on_found_turtle()
- sleep(60)
- if not is_facing_turtle() then
- return
- end
- -- Get rid of the old one
- turtle.suck(1)
- turtle.turnLeft()
- turtle.drop(1)
- turtle.turnLeft()
- -- Grab the new one
- get_bucket()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.drop(1)
- end
- local function find_turtles()
- while true do
- sleep(1)
- os.pullEvent("turtle")
- if is_facing_turtle() then
- end
- end
- end
- local function init()
- if orient() then
- find_turtles()
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement