Advertisement
Alexr360

Lantern Replacement Program

Feb 24th, 2024 (edited)
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. -- Define a list of waypoints with their coordinates and optional functions
  2. local waypoints = {
  3.     {x = 620, y = 160, z = -588},
  4.     {x = 620, y = 160, z = -586},
  5.     {x = 620, y = 164, z = -586},
  6.     {x = 616, y = 164, z = -586},
  7.     {x = 616, y = 170, z = -586},
  8.  
  9.     {x = 616, y = 170, z = -582},
  10.  
  11.     {x = 610, y = 170, z = -582},
  12.     {x = 616, y = 170, z = -579},
  13.     {x = 623, y = 170, z = -577},
  14.     {x = 623, y = 170, z = -574},
  15.     {x = 630, y = 170, z = -574},
  16.     {x = 636, y = 170, z = -570},
  17.     {x = 640, y = 170, z = -566},
  18.     {x = 642, y = 170, z = -564},
  19.     {x = 647, y = 170, z = -564},
  20.     {x = 649, y = 170, z = -566},
  21.     {x = 649, y = 170, z = -571},
  22.  
  23.     {x = 649, y = 170, z = -578},
  24.  
  25.     {x = 646, y = 173, z = -578},
  26.     {x = 639, y = 173, z = -582},
  27.     {x = 638, y = 173, z = -588},
  28.     {x = 634, y = 173, z = -591},
  29.    
  30.     {x = 627, y = 173, z = -592},
  31.     {x = 627, y = 172, z = -592},
  32.     {x = 627, y = 172, z = -591},
  33.    
  34.     {x = 621, y = 170, z = -591},
  35.  
  36.     {x = 620, y = 160, z = -586},
  37.     {x = 620, y = 164, z = -586},
  38.     {x = 616, y = 164, z = -586},
  39.     {x = 616, y = 170, z = -586},
  40.     {x = 620, y = 160, z = -588}
  41. }
  42.  
  43. function checkAndReplaceLantern()
  44.     -- Select slot 2
  45.     turtle.select(2)
  46.    
  47.     -- Check if the block beneath the turtle is a lantern or soul lantern
  48.     local success, block = turtle.inspectDown()
  49.     if success then
  50.         local blockName = block.name
  51.         if blockName == "minecraft:lantern" or blockName == "minecraft:soul_lantern" then
  52.             print("Replacing Lantern")
  53.             -- Replace the lantern with the item in slot 2
  54.             turtle.digDown()
  55.             turtle.placeDown()
  56.         else    
  57.             print("No Lantern")
  58.         end
  59.     end
  60.     turtle.select(1)
  61. end
  62.  
  63. function moveTo(targetX, targetZ, targetY)
  64.     local currentX, currentZ, currentY = gps.locate()
  65.    
  66.     -- Calculate the differences between current and target coordinates
  67.     local deltaX = targetX - currentX
  68.     local deltaY = targetY - currentY
  69.     local deltaZ = targetZ - currentZ
  70.    
  71.     print(targetZ)
  72.     print(currentZ)
  73.     print(deltaZ)
  74.  
  75.     -- Move along the Z-axis
  76.     if deltaZ > 0 then
  77.         print("Up")
  78.         for i = 1, math.abs(deltaZ) do
  79.             turtle.up()
  80.         end
  81.     elseif deltaZ < 0 then
  82.         print("Down")
  83.         for i = 1, math.abs(deltaZ) do
  84.             turtle.down()
  85.         end
  86.     end
  87.  
  88.     -- Move along the X-axis
  89.     if deltaX > 0 then
  90.         for i = 1, deltaX do
  91.             turtle.forward()
  92.         end
  93.     elseif deltaX < 0 then
  94.         for i = 1, math.abs(deltaX) do
  95.             turtle.back()
  96.         end
  97.     end
  98.    
  99.     -- Move along the Y-axis
  100.     if deltaY > 0 then
  101.         turtle.turnRight()
  102.         for i = 1, deltaY do
  103.             turtle.forward()
  104.         end
  105.         turtle.turnLeft()
  106.     elseif deltaY < 0 then
  107.         turtle.turnLeft()
  108.         for i = 1, math.abs(deltaY) do
  109.             turtle.forward()
  110.         end
  111.         turtle.turnRight()
  112.     end
  113. end
  114.  
  115. -- Function to move to each waypoint and optionally execute a function
  116. function moveThroughWaypoints()
  117.     for i, waypoint in ipairs(waypoints) do
  118.         -- Move to the waypoint
  119.         moveTo(waypoint.x, waypoint.y, waypoint.z)
  120.        
  121.         checkAndReplaceLantern()
  122.     end
  123. end
  124.  
  125. -- Call the function to move through the waypoints
  126. moveThroughWaypoints()
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement