Advertisement
danlemberg

placeblocks

Sep 17th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. print("Bridge build program")
  2.  
  3. print("")
  4. print("Place turtle facing away.")
  5. print("Turtle will build a 4x4 structure")
  6. print("using the blocks in the corresponding")
  7. print("square of its interface.  Put a torch")
  8. print("in the slot the corresponds to the")
  9. print("turtle's relative location.")
  10. print("Turtle will keep building until the")
  11. print("largest stack is out of blocks.")
  12.  
  13. -- find the turtle's relative location
  14.  
  15. local turtleslot = -1
  16. local maxstack = 0
  17.  
  18. for x=1,16 do
  19.   if turtle.getItemCount(x) > 0 then
  20.     if(turtle.getItemDetail(x).name == "minecraft:torch") then
  21.       turtleslot = x
  22.     end
  23.     if turtle.getItemCount(x) > maxstack then
  24.       maxstack = turtle.getItemCount(x)
  25.     end
  26.   end
  27. end
  28.  
  29. if turtleslot == -1 then
  30.   error("Must have a torch in the turtle's inventory")
  31. end
  32.  
  33. -- move turtle to the upper left
  34.  
  35. turtle.forward()
  36. turtle.forward()
  37. turtle.turnLeft()
  38.  
  39. turtle.select(turtleslot)
  40.  
  41. while turtle.getSelectedSlot() > 4 do
  42.   turtle.up()
  43.   turtle.select(turtle.getSelectedSlot() - 4)
  44. end
  45.  
  46. while turtle.getSelectedSlot() > 1 do
  47.   turtle.forward()
  48.   turtle.select(turtle.getSelectedSlot() - 1)
  49. end
  50.  
  51. turtle.turnLeft()
  52.  
  53. -- place blocks
  54.  
  55. for z=1,maxstack do
  56.  
  57.   if z ~= 1 then
  58.     turtle.turnRight()
  59.     turtle.turnRight()
  60.     turtle.forward()
  61.     turtle.turnLeft()
  62.     turtle.turnLeft()
  63.   end
  64.  
  65.   for x=1,4 do
  66.  
  67.     if x ~= 1 then
  68.       turtle.turnLeft()
  69.       turtle.forward()
  70.       turtle.turnRight()
  71.     end
  72.  
  73.     for y=1,4 do
  74.  
  75.       if y ~= 1 then
  76.         turtle.down()
  77.       end
  78.  
  79.       local blockslot = (x-1)+((y-1)*4)+1
  80.       if blockslot ~= turtleslot then
  81.         turtle.select(blockslot)
  82.         turtle.place()
  83.       end
  84.  
  85.     end
  86.  
  87.     -- return to top
  88.  
  89.     turtle.up()
  90.     turtle.up()
  91.     turtle.up()
  92.  
  93.   end
  94.  
  95.   -- return to left
  96.  
  97.   turtle.turnRight()
  98.   turtle.forward()
  99.   turtle.forward()
  100.   turtle.forward()
  101.   turtle.turnLeft()
  102.  
  103. end
  104.  
  105. -- move turtle back to starting spot
  106.  
  107. turtle.select(1)
  108.  
  109. while turtleslot - turtle.getSelectedSlot() >= 4 do
  110.   turtle.down()
  111.   turtle.select(turtle.getSelectedSlot() + 4)
  112. end
  113.  
  114. turtle.turnLeft()
  115.  
  116. while turtleslot - turtle.getSelectedSlot() >= 1 do
  117.   turtle.forward()
  118.   turtle.select(turtle.getSelectedSlot() + 1)
  119. end
  120.  
  121. turtle.turnRight()
  122. turtle.forward()
  123. turtle.turnRight()
  124. turtle.turnRight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement