Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- status: 1: Digs up area,
- 2: Digs up area + side walls
- 3: Waterproof + side walls
- 4: Waterproof + all walls
- else: input settings
- dF: length in forward direction
- dR: length in right direction
- dU: hight of area
- ]]
- local status, dF, dR, dU = ...
- local mode = 0
- if status then
- mode = tonumber(status)
- end
- local move = require("move")
- information1 = [[
- This program digs up a specified area.
- You can select between three different modi:
- 1. Dig up area
- 2. Dig up area + build side walls
- 3. Dig up area + all walls
- Otherwise the default mode is selected.
- Type something to continue]]
- information2 = [[
- You can choose the mode in the first argument when starting the programm or by adjusting the settings.
- The second to fourth argument define the size of the area:
- second: forward length
- third: right width (side)
- fourth: height
- Type something to continue]]
- local function getSettings()
- local y_n_toBoolean = { ["y"] = true, ["n"] = false }
- local numDecision = 1
- print("Type 1 to run the default code")
- print("Type 2 to adjust the settings")
- print("Type 3 to exit")
- print("Type 4 for further information")
- numDecision = tonumber(io.read())
- print("")
- if numDecision == 4 then
- print(information1)
- io.read()
- print(information2)
- io.read()
- print("Type 1 to run the default code")
- print("Type 2 to adjust the settings")
- print("Type 3 to exit")
- numDecision = tonumber(io.read())
- end
- if ((numDecision >= 3) or (numDecision < 1)) then
- return 0, nil, nil, nil
- elseif numDecision == 1 then
- return 1, 50, 3, 3
- else
- print("")
- print("Enter in which modus you want to dig up the area (1/2/3)")
- local modus_A = tonumber(io.read())
- print("")
- print("Enter the length of the area")
- local length_F = tonumber(io.read())
- print("")
- print("Enter the width of the area")
- local width_R = tonumber(io.read())
- print("")
- print("Enter the height of the area")
- local height_H = tonumber(io.read())
- return modus_A, length_F, width_R, height_H
- end
- end
- if mode == 0 then
- mode, dF, dR, dU = getSettings()
- end
- if mode == 0 or mode > 4 then
- print("Exiting the programm")
- return
- end
- local deltaForward = 50
- if dF then
- deltaForward = tonumber(dF)
- end
- local deltaRight = 3
- if dR then
- deltaRight = tonumber(dR)
- end
- local deltaUp = 3
- if dU then
- deltaUp = tonumber(dU)
- end
- print("Arguments")
- print(mode, deltaForward, deltaRight, deltaUp)
- -- forward, right, up
- turtlePos = {0, 0, 0}
- turtleLastPos = {0, 0, 0}
- -- {1, 0} = forward, {0, 1} = right, {-1, 0} = back, {0, -1} = left
- turtleVec = {1, 0}
- turtleLastVec = {1, 0}
- local function loc_MoveForward(t_pos, t_direct)
- move.Forward()
- t_pos[1] = t_pos[1] + t_direct[1]
- t_pos[2] = t_pos[2] + t_direct[2]
- end
- local function loc_MoveUp(t_pos, t_direct)
- move.Up()
- t_pos[3] = t_pos[3] + 1
- end
- local function loc_MoveDown(t_pos, t_direct)
- move.Down()
- t_pos[3] = t_pos[3] - 1
- end
- local function loc_TurnLeft(t_direct)
- turtle.turnLeft()
- t_direct[1] = t_direct[2]
- t_direct[2] = -t_direct[1]
- end
- local function loc_TurnRight(t_direct)
- turtle.turnRight()
- t_direct[1] = -t_direct[2]
- t_direct[2] = t_direct[1]
- end
- local function selectItemSlot(itemName)
- local itemA = turtle.getItemDetail()
- if itemA then
- if not(itemA.name == itemName) then
- for i=1, 16, 1 do
- turtle.select(i)
- local itemB = turtle.getItemDetail()
- if itemB then
- if item.name == itemName then
- return true
- end
- end
- end
- end
- else
- for i=1, 16, 1 do
- turtle.select(i)
- local itemB = turtle.getItemDetail()
- if itemB then
- if itemB.name == itemName then
- return true
- end
- end
- end
- end
- return false
- end
- local function fluidProofForward()
- selectItemSlot("minecraft:cobbled_deepslate")
- if not (turtle.detect()) then
- turtle.place()
- end
- end
- local function fluidProofUp()
- selectItemSlot("minecraft:cobbled_deepslate")
- if not (turtle.detectUp()) then
- turtle.placeUp()
- end
- end
- local function fluidProofDown()
- selectItemSlot("minecraft:cobbled_deepslate")
- if not (turtle.detectDown()) then
- turtle.placeDown()
- end
- end
- -- Digs up the given area
- function digArea(modus, lenForward, lenRight, lenUp)
- local rowCnt = 1
- local bOutside = false
- -- Go forward
- for i=1, lenForward, 1 do
- if modus == 1 then
- if i % 2 == 1 then
- loc_TurnRight(turtleVec)
- else
- loc_TurnLeft(turtleVec)
- end
- end
- -- Go sideways
- for j=1, lenRight, 1 do
- -- Go up/down
- for k=1, lenUp - 1, 1 do
- -- Odd rows (starting with 1) up, even rows down
- local condition_1 = (j == 1 and modus >= 2)
- local condition_2 = (j == lenRight and modus >= 2)
- local condition_3 = (i == 1 and modus == 4)
- local condition_4 = (i == lenForward and modus == 4)
- -- bottom or top of side wall: place block if there is none
- if (k == 1 and condition_1) then
- if i % 2 == 1 then
- loc_TurnLeft(turtleVec)
- else
- loc_TurnRight(turtleVec)
- end
- fluidProofForward()
- end
- if (k == 1 and condition_2) then
- fluidProofForward()
- if condition_3 then
- loc_TurnRight(turtleVec)
- fluidProofForward()
- loc_TurnLeft(turtleVec)
- end
- end
- -- place up/down block if k starts
- if (k == 1 and modus > 1) then
- if rowCnt % 2 == 1 then
- fluidProofDown()
- else
- fluidProofUp()
- end
- if condition_3 and (not(j == 1)) then
- loc_TurnRight(turtleVec)
- fluidProofForward()
- loc_TurnLeft(turtleVec)
- elseif condition_4 then
- if i % 2 == 1 then
- if j == 1 then
- loc_TurnRight(turtleVec)
- fluidProofForward()
- loc_TurnLeft(turtleVec)
- else
- loc_TurnLeft(turtleVec)
- fluidProofForward()
- loc_TurnRight(turtleVec)
- end
- else
- if j == 1 then
- loc_TurnLeft(turtleVec)
- fluidProofForward()
- loc_TurnRight(turtleVec)
- else
- loc_TurnRight(turtleVec)
- fluidProofForward()
- loc_TurnLeft(turtleVec)
- end
- end
- end
- end
- if rowCnt % 2 == 1 then
- loc_MoveUp(turtlePos, turtleVec)
- else
- loc_MoveDown(turtlePos, turtleVec)
- end
- -- places block if on side
- if (condition_1 or condition_2) then
- fluidProofForward()
- if condition_3 and condition_1 then
- if k > 1 then
- loc_TurnLeft(turtleVec)
- fluidProofForward()
- loc_TurnRight(turtleVec)
- end
- end
- if condition_3 and condition_2 then
- loc_TurnRight(turtleVec)
- fluidProofForward()
- loc_TurnLeft(turtleVec)
- end
- if condition_4 and condition_1 then
- if i % 2 == 1 then
- loc_TurnRight(turtleVec)
- fluidProofForward()
- loc_TurnLeft(turtleVec)
- else
- loc_TurnLeft(turtleVec)
- fluidProofForward()
- loc_TurnRight(turtleVec)
- end
- end
- if condition_4 and condition_2 then
- if i % 2 == 1 then
- loc_TurnLeft(turtleVec)
- fluidProofForward()
- loc_TurnRight(turtleVec)
- else
- loc_TurnRight(turtleVec)
- fluidProofForward()
- loc_TurnLeft(turtleVec)
- end
- end
- elseif condition_3 then
- loc_TurnRight(turtleVec)
- fluidProofForward()
- loc_TurnLeft(turtleVec)
- elseif condition_4 then
- if i % 2 == 1 then
- loc_TurnLeft(turtleVec)
- fluidProofForward()
- loc_TurnRight(turtleVec)
- else
- loc_TurnRight(turtleVec)
- fluidProofForward()
- loc_TurnLeft(turtleVec)
- end
- end
- -- place up/down block if k starts
- if (k == lenUp - 1 and modus > 1) then
- if rowCnt % 2 == 1 then
- fluidProofUp()
- else
- fluidProofDown()
- end
- end
- -- turns back in right direction
- if (k == lenUp - 1 and condition_1) then
- loc_TurnLeft(turtleVec)
- loc_TurnLeft(turtleVec)
- end
- end
- -- After odd planes (y-z plane) turn left, after even ones right
- if j == lenRight then
- if i % 2 == 1 then
- loc_TurnLeft(turtleVec)
- else
- loc_TurnRight(turtleVec)
- end
- end
- if not (j == lenRight and i == lenForward) then
- loc_MoveForward(turtlePos, turtleVec)
- rowCnt = rowCnt + 1
- end
- end
- end
- end
- digArea(mode, deltaForward, deltaRight, deltaUp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement