Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define a list of waypoints with their coordinates and optional functions
- local waypoints = {
- {x = 620, y = 160, z = -588},
- {x = 620, y = 160, z = -586},
- {x = 620, y = 164, z = -586},
- {x = 616, y = 164, z = -586},
- {x = 616, y = 170, z = -586},
- {x = 616, y = 170, z = -582},
- {x = 610, y = 170, z = -582},
- {x = 616, y = 170, z = -579},
- {x = 623, y = 170, z = -577},
- {x = 623, y = 170, z = -574},
- {x = 630, y = 170, z = -574},
- {x = 636, y = 170, z = -570},
- {x = 640, y = 170, z = -566},
- {x = 642, y = 170, z = -564},
- {x = 647, y = 170, z = -564},
- {x = 649, y = 170, z = -566},
- {x = 649, y = 170, z = -571},
- {x = 649, y = 170, z = -578},
- {x = 646, y = 173, z = -578},
- {x = 639, y = 173, z = -582},
- {x = 638, y = 173, z = -588},
- {x = 634, y = 173, z = -591},
- {x = 627, y = 173, z = -592},
- {x = 627, y = 172, z = -592},
- {x = 627, y = 172, z = -591},
- {x = 621, y = 170, z = -591},
- {x = 620, y = 160, z = -586},
- {x = 620, y = 164, z = -586},
- {x = 616, y = 164, z = -586},
- {x = 616, y = 170, z = -586},
- {x = 620, y = 160, z = -588}
- }
- function checkAndReplaceLantern()
- -- Select slot 2
- turtle.select(2)
- -- Check if the block beneath the turtle is a lantern or soul lantern
- local success, block = turtle.inspectDown()
- if success then
- local blockName = block.name
- if blockName == "minecraft:lantern" or blockName == "minecraft:soul_lantern" then
- print("Replacing Lantern")
- -- Replace the lantern with the item in slot 2
- turtle.digDown()
- turtle.placeDown()
- else
- print("No Lantern")
- end
- end
- turtle.select(1)
- end
- function moveTo(targetX, targetZ, targetY)
- local currentX, currentZ, currentY = gps.locate()
- -- Calculate the differences between current and target coordinates
- local deltaX = targetX - currentX
- local deltaY = targetY - currentY
- local deltaZ = targetZ - currentZ
- print(targetZ)
- print(currentZ)
- print(deltaZ)
- -- Move along the Z-axis
- if deltaZ > 0 then
- print("Up")
- for i = 1, math.abs(deltaZ) do
- turtle.up()
- end
- elseif deltaZ < 0 then
- print("Down")
- for i = 1, math.abs(deltaZ) do
- turtle.down()
- end
- end
- -- Move along the X-axis
- if deltaX > 0 then
- for i = 1, deltaX do
- turtle.forward()
- end
- elseif deltaX < 0 then
- for i = 1, math.abs(deltaX) do
- turtle.back()
- end
- end
- -- Move along the Y-axis
- if deltaY > 0 then
- turtle.turnRight()
- for i = 1, deltaY do
- turtle.forward()
- end
- turtle.turnLeft()
- elseif deltaY < 0 then
- turtle.turnLeft()
- for i = 1, math.abs(deltaY) do
- turtle.forward()
- end
- turtle.turnRight()
- end
- end
- -- Function to move to each waypoint and optionally execute a function
- function moveThroughWaypoints()
- for i, waypoint in ipairs(waypoints) do
- -- Move to the waypoint
- moveTo(waypoint.x, waypoint.y, waypoint.z)
- checkAndReplaceLantern()
- end
- end
- -- Call the function to move through the waypoints
- moveThroughWaypoints()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement