HandieAndy

Pylon Builder

Aug 5th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local ms = require("movescript")
  2. local robot = require("robot")
  3. local component = require("component")
  4. local sides = require("sides")
  5.  
  6. local ic = component.inventory_controller
  7.  
  8. local BLOCK = {
  9.   name = "immersiveengineering:metal_decoration1",
  10.   damage = 5
  11. }
  12. local SLAB = {
  13.   name = "immersiveengineering:metal_decoration1_slab",
  14.   damage = 5
  15. }
  16. local STAIR = {
  17.   name = "immersiveengineering:aluminum_scaffolding_stairs0",
  18.   damage = 0
  19. }
  20. local STEEL_FENCE = {
  21.   name = "immersiveengineering:metal_decoration1",
  22.   damage = 0
  23. }
  24. local ALU_FENCE = {
  25.   name = "immersiveengineering:metal_decoration1",
  26.   damage = 4
  27. }
  28. local AF_CONN = {
  29.   name = "alternatingflux:connector",
  30.   damage = 0
  31. }
  32. local RS_TORCH = {
  33.   name = "minecraft:redstone_torch",
  34.   damage = 0
  35. }
  36.  
  37. local function getItem(item)
  38.   repeat
  39.     local success = false
  40.     for i=1, robot.inventorySize() do
  41.       local stack = ic.getStackInInternalSlot(i)
  42.       if stack ~= nil and stack.name == item.name and stack.damage == item.damage then
  43.         robot.select(i)
  44.         success = true
  45.         break
  46.       end
  47.     end
  48.     if not success then
  49.       print("Could not select "..item.name..":"..item.damage..", please add more and press enter.")
  50.       io.read()
  51.     end
  52.   until success
  53. end
  54.  
  55. local function buildStdPost()
  56.   for i=1, 5 do
  57.     getItem(BLOCK)
  58.     ms.exec("UPd")
  59.   end
  60.   getItem(STAIR)
  61.   ms.exec("BPUF")
  62. end
  63.  
  64. local function placeInvertedStair()
  65.   getItem(STAIR)
  66.   robot.placeDown(sides.back)
  67. end
  68.  
  69. -- Builds an arm of the pylon, starting from in front of where the aluminum fence would be.
  70. -- Ends at where the aluminum fence should be.
  71. local function buildOrthogonalPylonArm()
  72.   getItem(SLAB) -- Start by placing the slabs at the end.
  73.   ms.exec("U2FPu")
  74.   getItem(SLAB)
  75.   ms.exec("FPu")
  76.   getItem(STEEL_FENCE)
  77.   ms.exec("BP")
  78.   getItem(BLOCK)
  79.   ms.exec("BP")
  80.   getItem(STAIR)
  81.   ms.exec("BPD2F")
  82.   for i=1, 2 do
  83.     getItem(STEEL_FENCE)
  84.     ms.exec("PB")
  85.   end
  86.   getItem(BLOCK)
  87.   ms.exec("PB")
  88.   getItem(STAIR)
  89.   ms.exec("PD3F")
  90.   for i=1, 3 do
  91.     getItem(AF_CONN)
  92.     robot.place(sides.up)
  93.     ms.exec("B")
  94.   end
  95.   ms.exec("F")
  96.   placeInvertedStair()
  97.   getItem(BLOCK)
  98.   ms.exec("BPU")
  99. end
  100.  
  101. -- Builds an orthogonal pylon, starting in front of the near-left post.
  102. local function buildOrthogonalPylon()
  103.   ms.exec("FR") -- Move to the first post's position.
  104.   buildStdPost()
  105.   ms.exec("L2FR6D")
  106.   buildStdPost()
  107.   ms.exec("4F2R6D")
  108.   buildStdPost()
  109.   ms.exec("L2FR6D")
  110.   buildStdPost()
  111.   ms.exec("FD") -- Place the first upside-down stair.
  112.   placeInvertedStair()
  113.   ms.exec("R2FL")
  114.   placeInvertedStair()
  115.   ms.exec("2F2R")
  116.   placeInvertedStair()
  117.   ms.exec("R2FL")
  118.   placeInvertedStair()
  119.   getItem(SLAB) -- Place the slabs on the first segment.
  120.   ms.exec("FDPu")
  121.   getItem(SLAB)
  122.   ms.exec("L2F2RPu")
  123.   getItem(SLAB)
  124.   ms.exec("FL2F2RPu")
  125.   getItem(SLAB)
  126.   ms.exec("4F2RPuFURFL")
  127.   buildStdPost() -- Build the next set of posts.
  128.   ms.exec("L2FR6D")
  129.   buildStdPost()
  130.   ms.exec("2F2R6D")
  131.   buildStdPost()
  132.   ms.exec("L2FR6D")
  133.   buildStdPost()
  134.   getItem(SLAB) -- Build the slabs on the second segment.
  135.   ms.exec("RF2DLPu")
  136.   getItem(SLAB)
  137.   ms.exec("2F2RPuFURF2R")
  138.   buildStdPost() -- Build the third set of posts.
  139.   ms.exec("2F2R6D")
  140.   buildStdPost()
  141.   ms.exec("FLF") -- Build the pylon arms.
  142.   buildOrthogonalPylonArm()
  143.   ms.exec("2RF")
  144.   buildOrthogonalPylonArm()
  145.   ms.exec("RD")
  146.   for i=1, 2 do
  147.     getItem(BLOCK)
  148.     ms.exec("PdU")
  149.   end
  150.   getItem(ALU_FENCE)
  151.   ms.exec("Pd")
  152.   getItem(RS_TORCH)
  153.   ms.exec("BP")
  154.   -- Return to origin.
  155.   ms.exec("BL2FR17D")
  156. end
  157.  
  158. buildOrthogonalPylon()
Add Comment
Please, Sign In to add comment