Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Gj6pAfrP
- local Brain = require("/turtleBrain"):new()
- local Terminal = require("/terminal"):new()
- local Params = {
- RoomWidth = nil,
- RoomDepth = nil,
- OnLeftWall = nil,
- }
- local materials = {} -- slot index
- local totalMaterials = 0
- function Main()
- repeat
- Terminal:reset()
- Params.RoomWidth = Terminal:promptNum("Enter room width:")
- print()
- Params.RoomDepth = Terminal:promptNum("Enter room depth:")
- print()
- print("Is the turtle placed next")
- Params.OnLeftWall = Terminal:promptBool("to the LEFT wall? (1 or 0)")
- print()
- until Terminal:promptBool("Does everything look correct? (1 or 0)")
- Terminal:reset()
- UpdateMaterials()
- local area = (Params.RoomWidth * Params.RoomDepth)
- if totalMaterials < area then
- repeat
- 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")
- print()
- local inputNum = Terminal:promptNum("Retry, Continue Anyway, or Quit? (1, 2, or 3)")
- if inputNum == 1 then
- Terminal:reset()
- elseif inputNum == 2 then
- break
- elseif inputNum == 3 then
- return
- else
- return
- end
- until (totalMaterials < area)
- end
- if Brain:hasEnoughFuel(area) == false then -- if there isnt enough fuel
- if Terminal:promptBool("You dont have fuel this job.\nHave: "..turtle.getFuelLevel().."\nNeeded: "..area.."\nContinue anyway? (1 or 0)") == false then
- return
- end
- end
- Brain.CurrentDir = 1
- local turnToDir = (Params.OnLeftWall and Brain.Dir.E) or Brain.Dir.W
- for x = 1, Params.RoomWidth do
- -- move down the room
- for z = 1, Params.RoomDepth do
- turtle.select(1)
- turtle.digDown()
- turtle.dropUp()
- turtle.select(math.random(2,#materials+1))
- turtle.placeDown()
- if turtle.getItemCount() == 0 then
- UpdateMaterials()
- end
- if z < Params.RoomDepth then
- turtle.select(#materials+2)
- Brain:forceForward()
- turtle.dropUp()
- end
- end
- -- set up for next row
- Brain:turnToFace(Brain.Dir.E)
- Brain:forceForward()
- -- point turtle down the next row
- if (x % 2) > 0 then -- if x is ODD
- Brain:turnRight()
- else
- Brain:turnLeft()
- end
- end
- Terminal:reset()
- print("Floor complete!")
- end
- function UpdateMaterials()
- totalMaterials = 0
- for k,_ in pairs(materials) do materials[k] = nil; end
- for i = 1, 16 do
- turtle.select(i)
- local ct = turtle.getItemCount()
- if ct > 0 then
- table.insert(materials,i)
- totalMaterials = totalMaterials + ct
- end
- end
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement