Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not turtle then
- error( "Cannot load turtle API on computer" )
- end
- local function placeNext(face, sn, slots)
- sTurtle.place(face)
- local n = turtle.getItemCount(slots[sn])
- if n == 0 then
- sn = sn + 1
- sTurtle.select(slots[sn])
- end
- return sn
- end
- function platformDown(v1, v2, pos, s, ignoreRCount)
- --Sterilize
- print('Preparing to build platform')
- v1 = sUtil.vForm(v1)
- v2 = sUtil.vForm(v2)
- if v1 == v2 then error('Cannot build between identical points') end
- if v1[2] ~= v2[2] then error('Platform corners must be on same y level') end
- s = sUtil.slotForm(s, true)
- pos = sUtil.posForm(pos)
- sFuel = sUtil.slotForm(s, false, 16)
- --Calculate
- local dir = 0
- local depth = 0
- local width = 0
- if v1[1] >= v2[1] and v1[3] >= v2[3] then
- dir = 1
- depth = v2[1] - v1[1]
- width = v2[3] - v1[3]
- elseif v1[1] >= v2[1] and v1[3] < v2[3] then
- dir = 0
- depth = v2[3] - v1[3]
- width = v1[1] - v2[1]
- elseif v1[1] < v2[1] and v1[3] >= v2[3] then
- dir = 2
- depth = v1[3] - v2[3]
- width = v2[1] - v1[1]
- elseif v1[1] < v2[1] and v1[3] < v2[3] then
- dir = 3
- depth = v2[1] - v1[1]
- width = v2[3] - v1[3]
- end
- depth = depth + 1
- width = width + 1
- print('Platform depth: ' .. depth)
- print('Platform width: ' .. width)
- local slots = sTurtle.findSlots(s)
- if not ignoreRCount then
- local rCount = sTurtle.sumCount(slots)
- if rCount < (depth * width) then
- error('Platform requires too many resources.')
- else
- print('Turtle has enough resources.')
- end
- else print('Ignoring resource count.')
- end
- local sn = 1
- --Align
- print('Travelling to start')
- pos = sTurtle.mineTo({v1[1], v1[2]+1, v1[3], dir}, pos)
- --Build
- local forwards = true
- turtle.select(slots[sn])
- print('Building platform')
- for j=1,width do
- for i=1,depth-1 do
- sn = placeNext('down', sn, slots)
- pos = sTurtle.mine(1, pos)
- end
- sn = placeNext('down', sn, slots)
- if j ~= width then
- if forwards then
- pos = sTurtle.turn('right', pos)
- pos = sTurtle.mine(1, pos)
- pos = sTurtle.turn('right', pos)
- forwards = false
- else
- pos = sTurtle.turn('left', pos)
- pos = sTurtle.mine(1, pos)
- pos = sTurtle.turn('left', pos)
- forwards = true
- end
- end
- end
- print('Platform finished')
- return pos
- end
- function platformUp(v1, v2, pos, s, ignoreRCount)
- --Sterilize
- print('Preparing to build ceiling')
- v1 = sUtil.vForm(v1)
- v2 = sUtil.vForm(v2)
- if v1 == v2 then error('Cannot build ceiling between identical points') end
- if v1[2] ~= v2[2] then error('Ceiling corners must be on same y level') end
- s = sUtil.slotForm(s, true)
- pos = sUtil.posForm(pos)
- sFuel = sUtil.slotForm(s, false, 16)
- --Calculate
- local dir = 0
- local depth = 0
- local width = 0
- if v1[1] >= v2[1] and v1[3] >= v2[3] then
- dir = 1
- depth = v2[1] - v1[1]
- width = v2[3] - v1[3]
- elseif v1[1] >= v2[1] and v1[3] < v2[3] then
- dir = 0
- depth = v2[3] - v1[3]
- width = v1[1] - v2[1]
- elseif v1[1] < v2[1] and v1[3] >= v2[3] then
- dir = 2
- depth = v1[3] - v2[3]
- width = v2[1] - v1[1]
- elseif v1[1] < v2[1] and v1[3] < v2[3] then
- dir = 3
- depth = v2[1] - v1[1]
- width = v2[3] - v1[3]
- end
- depth = depth + 1
- width = width + 1
- print('Ceiling depth: ' .. depth)
- print('Ceiling width: ' .. width)
- local slots = sTurtle.findSlots(s)
- if not ignoreRCount then
- local rCount = sTurtle.sumCount(slots)
- if rCount < (depth * width) then
- error('Ceiling requires too many resources.')
- else
- print('Turtle has enough resources.')
- end
- else print('Ignoring resource count.')
- end
- local sn = 1
- --Align
- print('Travelling to start')
- pos = sTurtle.mineTo({v1[1], v1[2]-1, v1[3], dir}, pos)
- --Build
- local forwards = true
- turtle.select(slots[sn])
- print('Building ceiling')
- for j=1,width do
- for i=1,depth-1 do
- sn = placeNext('up', sn, slots)
- pos = sTurtle.mine(1, pos)
- end
- sn = placeNext('up', sn, slots)
- if j ~= width then
- if forwards then
- pos = sTurtle.turn('right', pos)
- pos = sTurtle.mine(1, pos)
- pos = sTurtle.turn('right', pos)
- forwards = false
- else
- pos = sTurtle.turn('left', pos)
- pos = sTurtle.mine(1, pos)
- pos = sTurtle.turn('left', pos)
- forwards = true
- end
- end
- end
- print('Ceiling finished')
- return pos
- end
- function wall(v1, v2, pos, s, ignoreRCount)
- --Sterilize
- print('Preparing to build wall')
- v1 = sUtil.vForm(v1)
- v2 = sUtil.vForm(v2)
- if v1 == v2 then error('Cannot wall build between identical points') end
- if v1[1] ~= v2[1] and v1[3] ~= v2[3] then
- error('Wall corners must be equal in either x or z.')
- end
- s = sUtil.slotForm(s, true)
- pos = sUtil.posForm(pos)
- sFuel = sUtil.slotForm(s, false, 16)
- --Calculate
- local dir = 0
- local length = math.abs(v2[1] - v1[1])
- if length == 0 then
- length = math.abs(v2[3] - v1[3])
- end
- length = length + 1
- local height = math.abs(v2[2] - v1[2]) + 1
- if v1[1] > v2[1] then
- dir = 1
- elseif v1[1] < v2[1] then
- dir = 3
- elseif v1[3] > v2[3] then
- dir = 2
- elseif v1[3] < v2[3] then
- dir = 0
- end
- print('Wall length: ' .. length)
- print('Wall height: ' .. height)
- --Register building materials
- local slots = sTurtle.findSlots(s)
- if not ignoreRCount then
- local rCount = sTurtle.sumCount(slots)
- if rCount < (length * height) then
- error('Wall requires too many resources.')
- else
- print('Turtle has enough resources.')
- end
- else print('Ignoring resource count.')
- end
- local sn = 1
- --Build
- turtle.select(slots[sn])
- print('Building wall')
- for h=1,height do
- for i=1,length-1 do
- sn = placeNext('down', sn, slots)
- pos = sTurtle.mine(1, pos)
- end
- sn = placeNext('down', sn, slots)
- if h ~= height then
- pos = sTurtle.mineUp(1, pos)
- pos = sTurtle.turn('back', pos)
- end
- end
- print('Wall finished')
- return pos
- end
- function stripDown(length, pos, s, ignoreRCount)
- --Sterilization
- length = sUtil.nForm(length, 1)
- if length <= 0 then
- error('Build must have positive dimensions')
- end
- pos = sUtil.posForm(pos)
- --Resources
- local slots = sTurtle.findSlots(s)
- if not ignoreRCount then
- local rCount = sTurtle.sumCount(slots)
- if rCount < (length) then
- error('Strip requires too many resources.')
- else
- print('Turtle has enough resources.')
- end
- else print('Ignoring resource count.')
- end
- local sn = slots[1]
- for i=1,length do
- sn = placeNext('down', sn, slots)
- if i < length then
- pos = sTurtle.mine(1, pos)
- end
- end
- return pos
- end
- function tunnel(length, height, pos, inc)
- length = sUtil.nForm(length, 8)
- height = sUtil.nForm(height, 2)
- pos = sUtil.posForm(pos)
- print('Cutting tunnel '..length..' long and '..height..' high.')
- if inc ~= true then
- pos = sTurtle.mine(1, pos)
- end
- pos = sTurtle.mineUp(height-1, pos)
- while height > 0 do
- for i=1,length-1 do
- pos = sTurtle.mine(1, pos)
- if height > 1 then sTurtle.dig('down') end
- end
- if height > 2 then
- height = height - 2
- pos = sTurtle.turn('back', pos)
- pos = sTurtle.mineDown(2, pos)
- if height > 1 then sTurtle.dig('down') end
- else
- height = 0
- end
- end
- return pos
- end
- function excavate(v1, v2, pos, s, depo)
- print('Preparing to excavate')
- --Sterilize
- v1 = sUtil.vForm(v1)
- v2 = sUtil.vForm(v2)
- pos = sUtil.posForm(pos)
- s = sUtil.slotForm(s, true)
- if depo ~= nil then
- depo = sUtil.vForm(depo)
- depo[4] = sUtil.faceForm(depo[4], 'down')
- end
- --Compute
- local corners = sUtil.corners(v1, v2)
- local length = 0
- if (corners[1][2] - corners[1][1]) >= (corners[3][2] - corners[3][1]) then
- dir = 3
- length = corners[1][2] - corners[1][1] + 1
- else
- dir = 0
- length = corners[3][2] - corners[3][1] + 1
- end
- local height = corners[2][2] - corners[2][1] + 1
- local vol = 1
- for i = 1,3 do
- vol = vol * (corners[i][2] - corners[i][1] + 1)
- end
- --Excavate
- print('Excavating '..vol..'blocks.')
- local target = {0, corners[2][1], 0, dir}
- if dir == 3 then
- target[1] = corners[1][1]
- for i=corners[3][1],corners[3][2] do
- target[3] = i
- print(pos[1]..' '..pos[2]..' '..pos[3]..' '..pos[4])
- pos = sTurtle.mineTo(target, pos)
- print(pos[1]..' '..pos[2]..' '..pos[3]..' '..pos[4])
- pos = tunnel(length, height, pos, true)
- print(pos[1]..' '..pos[2]..' '..pos[3]..' '..pos[4])
- end
- else
- target[3] = corners[3][1]
- for i=corners[1][1],corners[1][2] do
- target[1] = i
- pos = sTurtle.mineTo(target, pos)
- pos = tunnel(length, height, pos, true)
- end
- end
- print('Excavation finished')
- return pos
- end
Advertisement
Add Comment
Please, Sign In to add comment