Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CHEST_NAME = "EnderStorage:enderChest"
- local went_up = false
- 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, 1, matching_chars) == string.sub(data.name, 1, 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 -1
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- return turned
- end
- local function is_facing_turtle()
- return is_facing_name("ComputerCraft", 13)
- end
- local function up()
- if turtle.getFuelLevel() < 2 then
- -- Needs to go down eventually, resupply yourself first
- local turned = orient()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.suck(1)
- turtle.refuel()
- turtle.drop(1)
- -- Wait for the bucket to be filled
- sleep(60)
- for t = 0, turned do
- turtle.turnRight()
- end
- end
- turtle.up()
- end
- local function down()
- turtle.down()
- end
- local function get_bucket()
- if went_up then
- down()
- end
- while true do
- turtle.select(1)
- turtle.suck(1)
- if turtle.getItemCount() > 0 then
- if went_up then
- up()
- end
- return
- end
- sleep(1)
- end
- end
- local function on_found_turtle()
- sleep(60)
- if not is_facing_turtle() then
- print("Turtle not there anymore")
- return
- else
- print("Turtle is still there")
- 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)
- -- Put the old one in the chest
- if went_up then
- down()
- end
- turtle.turnLeft()
- turtle.suck(1)
- turtle.turnLeft()
- turtle.drop(1)
- turtle.turnLeft()
- turtle.turnLeft()
- if went_up then
- up()
- end
- end
- local function find_turtles()
- while true do
- sleep(1)
- if is_facing_turtle() then
- print("Found a turtle")
- on_found_turtle()
- end
- if went_up then
- went_up = false
- up()
- else
- went_up = true
- down()
- end
- end
- end
- local function init()
- if orient() > -1 then
- find_turtles()
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement