Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin:Sg9BVwcS
- local tArgs = { ... }
- os.loadAPI("movement")
- local m = movement
- local torchDist = 6
- if #tArgs ~= 3 then
- print("Usage: cave <width> <height> <length>")
- print("Slot 1: floor")
- print("Slot 2: ceiling")
- print("Slot 3: sides")
- print("Slot 4: torches")
- print("Slot 5: front")
- print("Slot 6: back")
- return
- end
- local width = tonumber(tArgs[1])
- if width < 1 then
- print("Cave width must be positive")
- return
- end
- local height = tonumber(tArgs[2])
- if height < 1 then
- print("Cave height must be positive")
- return
- end
- local length = tonumber(tArgs[3])
- if length < 1 then
- print("Cave length must be positive")
- return
- end
- local floorSlot = 1
- local ceilingSlot = 2
- local sideSlot = 3
- local torchSlot = 4
- local frontSlot = 5
- local backSlot = 6
- m.reservedslots = 6
- local paintFloor = turtle.getItemCount(floorSlot) > 0
- local paintCeiling = turtle.getItemCount(ceilingSlot) > 0
- local paintSides = turtle.getItemCount(sideSlot) > 0
- local placeTorches = turtle.getItemCount(torchSlot) > 0
- local paintFront = turtle.getItemCount(frontSlot) > 0
- local paintBack = turtle.getItemCount(backSlot) > 0
- local fuelLevel = turtle.getFuelLevel()
- print("Fuel level: " .. fuelLevel)
- if fuelLevel < 1 then
- return
- end
- print("caving " .. width .. " x " .. height .. " x " .. length)
- local function doPaintSide()
- if paintSides then
- m.paintForward(sideSlot)
- end
- end
- local function doPaintFloor()
- if paintFloor then
- m.paintDown(floorSlot)
- end
- end
- local function doPaintCeiling()
- if paintCeiling then
- m.paintUp(ceilingSlot)
- end
- end
- local goRight = true
- for i = 1, length do
- if ((i - 1) % torchDist == 0) then
- if placeTorches then
- if height > 2 then
- m.turtleUp()
- end
- m.turtleUp()
- turtle.dig()
- m.turtleDown()
- if (m.selectMaterial(torchSlot)) then
- turtle.turnLeft()
- turtle.placeUp()
- turtle.turnRight()
- end
- if height > 2 then
- m.turtleDown()
- end
- end
- end
- -- prepare for next slice
- m.turtleForward()
- m.turn( not goRight )
- doPaintSide()
- m.turn( goRight )
- m.turn( goRight )
- for h = 1, height do
- for w = 1, width do
- if (h == 1) then
- doPaintFloor()
- end
- if (h == height) then
- doPaintCeiling()
- end
- if (paintFront and i == 1) then
- m.turn(goRight)
- m.paintForward(frontSlot)
- m.turn(not goRight)
- end
- if (paintBack and i == length) then
- m.turn(not goRight)
- m.paintForward(backSlot)
- m.turn(goRight)
- end
- if (w < width) then
- m.turtleForward()
- end
- end
- doPaintSide()
- if h < height then
- m.turtleUp()
- doPaintSide()
- turtle.turnRight()
- turtle.turnRight()
- goRight = not goRight
- end
- end
- for h = 1, height - 1 do
- m.turtleDown()
- end
- m.turn( not goRight )
- goRight = not goRight
- end
- -- return to start position.
- if (not goRight) then
- -- turtle is to the right, move back to left side
- m.turn( false )
- for i=1,width-1 do
- m.turtleForward(width)
- end
- m.turn( false )
- else
- -- else just turn around
- m.turn( false )
- m.turn( false )
- end
- for i=1, length-1 do
- m.turtleForward()
- end
- m.turn( false )
- m.turn( false )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement