Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pars = {}
- parsNames = {"position", "width", "height", "depth", "fuelType" }
- fuelArray = { 6, 18, 96, 1000 }
- fuelNames = { "sticks", "wood/Planks", "coal", "lava" }
- mM = { {true, true},{false, true}, {true, false}, {false, false} }
- -- {1( isToRight, isToDown ),2,3,4} movingModificators
- function hM(isFromPoint, count) --heightMove
- if isFromPoint == mM[pars[1]][2] then
- turtlex.down(count, "dig")
- else
- turtlex.up(count, "dig")
- end
- end
- function hD(isFromPoint) --heightDig
- if isFromPoint == mM[pars[1]][2] then
- turtlex.digDown()
- else
- turtlex.digUp()
- end
- end
- function forward(count, onBlocked, isDigFrom, isDigTo)
- for i=1,count do
- turtlex.forward(1, onBlocked)
- if isDigFrom then hD(true) end
- if isDigTo then hD(false) end
- end
- end
- function turn(isRight)
- if isRight == mM[pars[1]][1] then
- turtlex.turnRight()
- else
- turtlex.turnLeft()
- end
- end
- function fuelNeeded(width, height, depth)
- aLevels = height % 3 --additional levels
- mLevels = height - aLevels --main levels
- Levels = mLevels / 3
- count = Levels * ( width * depth + 2 ) + height + 1
- if aLevels ~= 0 then
- count = count + width * depth + aLevels - 1
- Levels = Levels + 1
- end
- if depth % 2 ~= 0 then
- count = count + width
- end
- if Levels % 2 ~= 0 then
- count = count + depth
- end
- return count
- end
- function dig1e(w, RorL, isDigFrom, isDigTo) --dig one horizontal element of the level
- forward(w - 1, "dig", isDigFrom, isDigTo)
- turn(RorL)
- end
- function dig1l(w, d, isRight, isDigFrom, isDigTo)
- for i = 1, d do
- dig1e(w, not isRight, isDigFrom, isDigTo)
- if i ~= d then
- forward(1, "dig", isDigFrom, isDigTo)
- end
- turn(not isRight)
- isRight = not isRight
- end
- end
- function dig(w, h, d)
- turtlex.pushPos()
- isRight = true
- isDigFrom = false
- isDigTo = false
- aLevels = h % 3 --additional levels
- mLevels = (h - aLevels)/3 --main levels
- turtlex.forward(1, "dig")
- turn(true)
- if aLevels ~= 0 then --need to correct
- if aLevels == 2 then
- hD(true)
- hM(true, 1)
- isDigTo = true
- end
- dig1l(w, d, isRight, isDigFrom, isDigTo)
- if (d % 2 == 0) then
- isRight = not isRight
- end
- if mLevels ~= 0 then
- hM(true, 1)
- end
- end
- isDigFrom = true
- isDigTo = true
- for i = 1,mLevels do
- hM(true, 1)
- hD(true)
- dig1l(w, d, isRight, isDigFrom, isDigTo)
- if (d % 2 == 0) then
- isRight = not isRight
- end
- if i ~= mLevels then
- hM(true, 2)
- end
- end
- turtlex.popPos()
- end
- -- main code --
- term.clear()
- term.setCursorPos(1,1)
- print[[Enter the 1)position:
- 1--2
- | |
- 3--4
- 2)width, 3)height, 4)depth, 5)fuelType:
- 1-stick,2-wood/Planks,3-coal,4-lavaBucket
- e.g. "1 2 3 4 1"]]
- repeat
- iHasPars = true
- k = 0
- errorStr = ""
- input = read()
- pars = {}
- for v in string.gmatch(input, '%w+') do
- k = k + 1
- if k <= table.getn(parsNames) then --check it
- pars[k] = tonumber(v)
- if pars[k] == nil then
- iHasPars = false
- errorStr = parsNames[k] .. " is sets to \"" .. v .. "\", it must be a number"
- break
- elseif pars[1] > 4 or pars[1] < 1 then
- iHasPars = false
- errorStr = parsNames[1] .. " must be 0<pos<5"
- break
- elseif k == 5 then
- if pars[5] > table.getn(fuelArray) or pars[5] < 1 then
- iHasPars = false
- errorStr = parsNames[5] .. " must be 0<fuelType<" .. table.getn(fuelArray) + 1
- break
- end
- end
- else
- break
- end
- --print("k=" .. k .. ", iHasPars = " .. tostring(iHasPars) .. " " .. errorStr)
- end
- if iHasPars == true and table.getn(pars) < table.getn(parsNames) then
- iHasPars = false
- errorStr = parsNames[table.getn(pars) + 1] .. " is missing"
- end
- if iHasPars == false then
- print(errorStr)
- end
- until iHasPars == true
- fuelN = fuelNeeded(pars[2], pars[3], pars[4])
- if fuelN > turtle.getFuelLevel() then
- print("put " .. math.ceil(( fuelN - turtle.getFuelLevel() ) / fuelArray[pars[5]]) .. " " .. fuelNames[pars[5]] .. " into my 1st slot plz" )
- print("press Enter to refuel")
- read()
- turtle.refuel()
- while fuelN > turtle.getFuelLevel() do
- print("error, i hasnt enough fuel. Type the number of new fuelType or press Enter if you want'nt change it")
- repeat
- iHasPars = true
- input = read()
- if input ~= "" then
- pars[5] = tonumber(input)
- if pars[5] ~= nil then
- if pars[5] > table.getn(fuelArray) or pars[5] < 1 then
- iHasPars = false
- print("fuelType must be 0<fuelType<" .. table.getn(fuelArray) + 1)
- end
- else
- print("fuelType must be the number")
- iHasPars = false
- end
- end
- until iHasPars == true
- print("put " .. math.ceil(( fuelN - turtle.getFuelLevel() ) / fuelArray[pars[5]]) .. " " .. fuelNames[pars[5]] .. " into my 1st slot plz" )
- print("press Enter to refuel")
- read()
- turtle.refuel()
- end
- end
- dig(pars[2], pars[3], pars[4])
- print(turtle.getFuelLevel() .. " fuel remaining")
Add Comment
Please, Sign In to add comment