Robear9992

passage

Jul 4th, 2022 (edited)
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. --cc:Tweaked: Passage
  2. --pastebin get xzvapSjN passage.lua
  3. --passage 10
  4.  
  5. local nav = require("navigation")
  6. local inv = require("inventory")
  7. local timer = require("timer")
  8. local sides = require("sides")
  9.  
  10. local COBBLE = { name = "minecraft:cobblestone" }
  11. local GLASS= { name = "minecraft:glass" }
  12.  
  13.  
  14.  
  15. function place(item)
  16.     if turtle.detect() then turtle.dig() end
  17.     if not inv.findAndSelect(item) then return false end
  18.    
  19.     turtle.place()
  20.     return true
  21. end
  22.  
  23.  
  24. function placeDown(item)
  25.     if turtle.detectDown() then turtle.digDown() end
  26.     if not inv.findAndSelect(item) then return false end
  27.    
  28.     turtle.placeDown()
  29.     return true
  30. end
  31.  
  32. function placeUp(item)
  33.     if turtle.detectDown() then turtle.digDown() end
  34.     if not inv.findAndSelect(item) then return false end
  35.    
  36.     turtle.placeUp()
  37.     return true
  38. end
  39.  
  40. function placeLeft(item)
  41.     nav.turnTo(sides.left)
  42.     return place(item)
  43. end
  44.  
  45. function placeRight(item)
  46.     nav.turnTo(sides.right)
  47.     return place(item)
  48. end
  49.  
  50.  
  51. local length = 0
  52. local windowEvery = 5
  53.  
  54.  
  55.  
  56. local function checkParameters(length, windowEvery)
  57.     --local fuelNeeded = (length * 3) + 1  -- 1 for endcap
  58.     --checkFuel(fuelNeeded)
  59.    
  60.     local glassNeeded = math.ceil(length / windowEvery) * 2 + 1  -- plus one for endcap
  61.     local glassIHave = inv.count(GLASS)
  62.     if glassIHave < glassNeeded then
  63.         print("Please add "..(glassNeeded - glassIHave).." more glass")
  64.         return false
  65.     end
  66.    
  67.     local bricksNeeded = length * 6 - glassNeeded + 1 -- plus one for endcap
  68.     local bricksIHave = inv.count(COBBLE)
  69.     if bricksIHave < bricksNeeded then
  70.         print("Please add "..(bricksNeeded - bricksIHave).." more cobblestone")
  71.         return false
  72.     end
  73.    
  74.     return true
  75.    
  76. end
  77.  
  78. local function surround(window)
  79.     WINDOW = GLASS
  80.     if not window then WINDOW = COBBLE end
  81.  
  82.     placeDown(COBBLE)
  83.     placeLeft(COBBLE)
  84.     nav.up()
  85.     placeLeft(WINDOW)
  86.     placeUp(COBBLE)
  87.     placeRight(WINDOW)
  88.     nav.down()
  89.     placeRight(COBBLE)
  90. end
  91.  
  92.  
  93. ---- Main Loop
  94. local tArgs = { ... }
  95.  
  96. if #tArgs ~= 2 then
  97.         print( "Usage: passage <distance> <window every n>" )
  98.         return false
  99. end
  100.  
  101. -- Mine in a quarry pattern until we hit something we can't dig
  102. local length        = tonumber( tArgs[1] )
  103. local windowEvery   = tonumber( tArgs[2] )
  104.  
  105. if not checkParameters(length, windowEvery) then return end
  106.  
  107. timer.start()
  108.  
  109. for n=1,length do
  110.     nav.turnTo(sides.front)
  111.     nav.forward()
  112.     surround(n % windowEvery == 0)
  113. end
  114.  
  115. nav.turnTo(sides.front)
  116. place(COBBLE)
  117. nav.up()
  118. place(GLASS)
  119. nav.down()
  120.  
  121. print("Completed in "..timer.format())
Add Comment
Please, Sign In to add comment