Advertisement
Le_JuiceBOX

[App] flooring.lua

Mar 29th, 2024 (edited)
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. -- Gj6pAfrP
  2.  
  3. local Brain = require("/turtleBrain"):new()
  4. local Terminal = require("/terminal"):new()
  5.  
  6. local Params = {
  7.     RoomWidth = nil,
  8.     RoomDepth = nil,
  9.     OnLeftWall = nil,
  10. }
  11.  
  12. local materials = {} -- slot index
  13. local totalMaterials = 0
  14.  
  15.  
  16. function Main()
  17.     repeat
  18.         Terminal:reset()
  19.         Params.RoomWidth = Terminal:promptNum("Enter room width:")
  20.         print()
  21.         Params.RoomDepth = Terminal:promptNum("Enter room depth:")
  22.         print()
  23.         print("Is the turtle placed next")
  24.         Params.OnLeftWall = Terminal:promptBool("to the LEFT wall? (1 or 0)")
  25.         print()
  26.     until Terminal:promptBool("Does everything look correct? (1 or 0)")
  27.     Terminal:reset()
  28.  
  29.     UpdateMaterials()
  30.  
  31.     local area = (Params.RoomWidth * Params.RoomDepth)
  32.     if totalMaterials < area then
  33.         repeat
  34.             print("You dont have enough blocks for this job.\n\nYou have... x"..totalMaterials.." Blocks\n\nYou need... x"..area.." Blocks (x"..math.ceil(area/64).." stacks")
  35.             print()
  36.             local inputNum = Terminal:promptNum("Retry, Continue Anyway, or Quit? (1, 2, or 3)")
  37.             if inputNum == 1 then
  38.                 Terminal:reset()
  39.             elseif inputNum == 2 then
  40.                 break
  41.             elseif inputNum == 3 then
  42.                 return
  43.             else
  44.                 return
  45.             end
  46.         until (totalMaterials < area)
  47.     end
  48.  
  49.     if Brain:hasEnoughFuel(area) == false then -- if there isnt enough fuel
  50.         if Terminal:promptBool("You dont have fuel this job.\nHave: "..turtle.getFuelLevel().."\nNeeded: "..area.."\nContinue anyway? (1 or 0)") == false then
  51.             return
  52.         end
  53.     end
  54.  
  55.  
  56.     Brain.CurrentDir = 1
  57.     local turnToDir = (Params.OnLeftWall and Brain.Dir.E) or Brain.Dir.W
  58.     for x = 1, Params.RoomWidth do
  59.         -- move down the room
  60.         for z = 1, Params.RoomDepth do
  61.             turtle.select(1)
  62.             turtle.digDown()
  63.             turtle.dropUp()
  64.             turtle.select(math.random(2,#materials+1))
  65.             turtle.placeDown()
  66.             if turtle.getItemCount() == 0 then
  67.                 UpdateMaterials()
  68.             end
  69.             if z < Params.RoomDepth then
  70.                 turtle.select(#materials+2)
  71.                 Brain:forceForward()
  72.                 turtle.dropUp()
  73.             end
  74.         end
  75.         -- set up for next row
  76.         Brain:turnToFace(Brain.Dir.E)
  77.         Brain:forceForward()
  78.         -- point turtle down the next row
  79.         if (x % 2) > 0 then -- if x is ODD
  80.             Brain:turnRight()
  81.         else
  82.             Brain:turnLeft()
  83.         end
  84.  
  85.     end
  86.     Terminal:reset()
  87.     print("Floor complete!")
  88. end
  89.  
  90. function UpdateMaterials()
  91.     totalMaterials = 0
  92.     for k,_ in pairs(materials) do materials[k] = nil; end
  93.     for i = 1, 16 do
  94.         turtle.select(i)
  95.         local ct = turtle.getItemCount()
  96.         if ct > 0 then
  97.             table.insert(materials,i)
  98.             totalMaterials = totalMaterials + ct
  99.         end
  100.     end
  101. end
  102.  
  103. Main()
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement