Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x, y, z = ...
- local move = require("move1")
- local maxHeight = 0
- local turtlePos = {0, 0, 0}
- local turtleLastPos = {turtlePos[1], turtlePos[2], turtlePos[3]}
- local turtleVec = {1, 0}
- local turtleLastVec = {turtleVec[1], turtleVec[2]}
- local workMode = 1
- local function forward()
- move.Forward()
- turtlePos[1] = turtlePos[1] + turtleVec[1]
- turtlePos[2] = turtlePos[2] + turtleVec[2]
- end
- local function upward()
- move.Up()
- turtlePos[3] = turtlePos[3] + 1
- end
- local function downward()
- move.Down()
- turtlePos[3] = turtlePos[3] - 1
- end
- local function turnLeft()
- turtle.turnLeft()
- local buffer = turtleVec[1]
- turtleVec[1] = turtleVec[2]
- turtleVec[2] = -buffer
- end
- local function turnRight()
- turtle.turnRight()
- local buffer = turtleVec[1]
- turtleVec[1] = -turtleVec[2]
- turtleVec[2] = buffer
- end
- local function varInArr(var, arr)
- for i = 1, #arr, 1 do
- if var == arr[i] then
- return true
- end
- end
- return false
- end
- local function selectItemFromList(itemList)
- local itemA = turtle.getItemDetail()
- if itemA then
- if varInArr(itemA.name, itemList) then
- return true
- end
- end
- for i=1, 16, 1 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- local itemB = turtle.getItemDetail()
- if itemB then
- if varInArr(itemB.name, itemList) then
- return true
- end
- end
- end
- end
- return false
- end
- local function goToStart()
- if workMode == 1 then
- turtleLastPos = {turtlePos[1], turtlePos[2], turtlePos[3]}
- turtleLastVec = {turtleVec[1], turtleVec[2]}
- workMode = 2
- end
- while turtleVec[1] > -1 do
- turnRight()
- end
- if (turtlePos[1] + turtlePos[2] + math.abs(turtlePos[3])) > 0 then
- while turtlePos[3] < maxHeight do
- upward()
- end
- while turtlePos[1] > 0 do
- forward()
- end
- turnRight()
- while turtlePos[2] > 0 do
- forward()
- end
- turnLeft()
- while turtlePos[3] > 0 do
- downward()
- end
- while turtlePos[3] < 0 do
- upward()
- end
- end
- end
- local function goToLastPosition()
- workMode = 3
- while turtlePos[3] < math.max(maxHeight, turtleLastPos[3]) do
- upward()
- end
- turnLeft()
- while turtlePos[2] < turtleLastPos[2] do
- forward()
- end
- turnLeft()
- while turtlePos[1] < turtleLastPos[1] do
- forward()
- end
- while turtlePos[3] > turtleLastPos[3] do
- downward()
- end
- while not (turtleVec[1] == turtleLastVec[1] and turtleVec[2] == turtleLastVec[2]) do
- turnLeft()
- end
- workMode = 1
- end
- local function getItemFromList(itemList)
- local bItem = true
- while not selectItemFromList(itemList) do
- bItem = false
- goToStart()
- print("Item like ", itemList[1], " is needed. Pls input more of it.")
- io.read()
- end
- if not bItem then
- goToLastPosition()
- end
- end
- local height = 5
- local length = 9
- local width = 9
- if x then
- length = tonumber(x)
- end
- if y then
- height = tonumber(y)
- end
- if z then
- width = tonumber(z)
- end
- local bottomBlock = { "minecraft:dirt"}
- local sandBlock = { "minecraft:sand", "minecraft:red_sand" }
- local cactusBlock = { "minecraft:cactus" }
- local fenceBlock = { "minecraft:spruce_fence" }
- forward()
- forward()
- turnRight()
- forward()
- forward()
- turnLeft()
- upward()
- local cntZ = 0
- while cntZ < width do
- local cntX = 0
- while cntX < length do
- local cntY = 0
- while cntY < height do
- getItemFromList(bottomBlock)
- turtle.placeDown()
- upward()
- getItemFromList(sandBlock)
- turtle.placeDown()
- upward()
- getItemFromList(cactusBlock)
- turtle.placeDown()
- if cntX % 2 == 0 then
- getItemFromList(fenceBlock)
- turtle.place()
- end
- upward()
- upward()
- cntY = cntY + 1
- end
- if turtlePos[3] > maxHeight then
- maxHeight = turtlePos[3]
- end
- if not (cntX == length - 1) then
- forward()
- forward()
- while turtlePos[3] > 1 do
- downward()
- end
- end
- cntX = cntX + 1
- end
- if not (cntZ == width - 1) then
- if cntZ % 2 == 0 then
- turnRight()
- forward()
- forward()
- turnRight()
- else
- turnLeft()
- forward()
- forward()
- turnLeft()
- end
- while turtlePos[3] > 1 do
- downward()
- end
- end
- cntZ = cntZ + 1
- end
- goToStart()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement