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: Digs up area + all walls
- 5: 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("move1")
- local inspect = require("inspect1")
- local bWaterproof = false
- local bFull = false
- information1 = [[
- This program digs up a specified area.
- You can select between five different modi:
- 1. Dig up area
- 2. Dig up area + build side walls
- 3. Like 2 + waterproof
- 4. Dig up area + all walls
- 5. Like 4 + waterproof
- 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]]
- building_material = {
- "minecraft:cobblestone", "minecraft:cobbled_deepslate",
- "minecraft:tuff", "minecraft:andesite",
- "minecraft:diorite", "minecraft:granite"
- }
- waterlogged_blocks = {
- "minecraft:activator_rail", "1_dripleaf",
- "1_amethyst_bud", "amethyst_cluster",
- "minecraft:soul_campfire", "minecraft:campfire",
- "1_candle", "minecraft:calibrated_sculk_sensor",
- "minecraft:chain", "minecraft:chest",
- "minecraft:conduit", "1_grate",
- "minecraft:dead_horn_coral_fan", "minecraft:horn_coral_fan",
- "minecraft:dead_horn_coral", "minecraft:horn_coral",
- "minecraft:dead_fire_coral_fan", "minecraft:fire_coral_fan",
- "minecraft:dead_fire_coral", "minecraft:fire_coral",
- "minecraft:dead_bubble_coral_fan", "minecraft:bubble_coral_fan",
- "minecraft:dead_bubble_coral", "minecraft:bubble_coral",
- "minecraft:dead_brain_coral_fan", "minecraft:brain_coral_fan",
- "minecraft:dead_brain_coral", "minecraft:brain_coral",
- "minecraft:dead_tube_coral_fan", "minecraft:brain_tube_fan",
- "minecraft:dead_tube_coral", "minecraft:tube_coral",
- "minecraft:decorated_pot", "minecraft:detector_rail",
- "minecraft:ender_chest", "1_fence",
- "1_pane", "minecraft:glow_lichen",
- "minecraft:hanging_roots", "minecraft:heavy_core",
- "minecraft:iron_bars", "minecraft:",
- "minecraft:kelp", "minecraft:kelp_plant",
- "minecraft:ladder", "minecraft:lantern",
- "minecraft:soul_lantern", "1_leaves",
- "minecraft:lightning_rod", "minecraft:mangrove_propagule",
- "minecraft:mangrove_roots", "minecraft:pointed_dripstone",
- "minecraft:powered_rail", "minecraft:rail",
- "minecraft:scaffolding", "minecraft:sculk_vein",
- "minecraft:sculk_shrieker", "minecraft:sculk_sensor",
- "minecraft:sea_pickle", "minecraft:seagrass",
- "1_sign", "1_slab",
- "1_stairs", "minecraft:tall_seagrass",
- "1_trap", "1_wall",
- }
- falling_blocks = {
- "minecraft:gravel", "minecraft:red_sand",
- "minecraft:sand", "minecraft:suspicious_sand",
- "1_anvil", "1_concrete_powder",
- "minecraft:dragon_egg", "minecraft:pointed_dripstone",
- "minecraft:scaffolding", "minecraft:",
- "minecraft:suspicious_gravel"
- }
- 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/4/5)")
- 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 > 5 then
- print("Wrong input")
- print("Exiting the programm")
- return
- end
- if mode == 3 then
- mode = 2
- bWaterproof = true
- end
- if mode == 5 then
- mode = 4
- bWaterproof = true
- 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)
- print("Waterproof: "..tostring(bWaterproof))
- -- forward, right, up
- turtlePos = {0, 0, 0}
- turtleLastPos = {turtlePos[1], turtlePos[2], turtlePos[3]}
- -- {1, 0} = forward, {0, 1} = right, {-1, 0} = back, {0, -1} = left
- turtleVec = {1, 0}
- turtleLastVec = {turtleVec[1], turtleVec[2]}
- 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 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()
- local buffer = t_direct[1]
- t_direct[1] = t_direct[2]
- t_direct[2] = -buffer
- end
- local function loc_TurnRight(t_direct)
- turtle.turnRight()
- local buffer = t_direct[1]
- t_direct[1] = -t_direct[2]
- t_direct[2] = buffer
- 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 tryOffloadItems()
- local bChest = inspect.Forward({"minecraft:chest"})
- if bFull then
- for i=16, 1, -1 do
- if turtle.getItemCount(i) == 0 then
- bFull = false
- end
- end
- end
- if not bChest then
- if bFull then
- print("Pls take out items from inventory or place a chest")
- io.read()
- tryOffloadItems()
- end
- return
- end
- local arrStackSize = {}
- for i=1, 16, 1 do
- local numItems = turtle.getItemCount(i)
- if numItems > 0 then
- turtle.select(i)
- local itemDetail = turtle.getItemDetail()
- if itemDetail then
- if not varInArr(itemDetail.name, building_material) then
- if not turtle.drop() then
- if bFull then
- print("Pls take out items from inventory or from chest")
- io.read()
- tryOffloadItems()
- end
- else
- bFull = false
- end
- else
- table.insert(arrStackSize, {slot = i, stackSize = numItems})
- end
- end
- end
- end
- table.sort(arrStackSize, function(a, b) return a.stackSize > b.stackSize end)
- for i=5, #arrStackSize, 1 do
- local slotVar = arrStackSize[i].slot
- turtle.select(slotVar)
- if not turtle.drop() then
- if bFull then
- print("Pls take out items from inventory or from chest")
- io.read()
- tryOffloadItems()
- end
- else
- bFull = false
- end
- end
- end
- local function goToStart()
- if not(((turtlePos[1] + turtlePos[2] + turtlePos[3]) == 0) and (turtleVec[1] == -1)) then
- turtleLastPos = {turtlePos[1], turtlePos[2], turtlePos[3]}
- turtleLastVec = {turtleVec[1], turtleVec[2]}
- end
- while turtleVec[1] > -1 do
- loc_TurnRight(turtleVec)
- end
- if (turtlePos[1] + turtlePos[2] + turtlePos[3]) > 0 then
- while turtlePos[1] > 0 do
- loc_MoveForward(turtlePos, turtleVec)
- end
- loc_TurnRight(turtleVec)
- while turtlePos[2] > 0 do
- loc_MoveForward(turtlePos, turtleVec)
- end
- loc_TurnLeft(turtleVec)
- while turtlePos[3] > 0 do
- loc_MoveDown(turtlePos, turtleVec)
- end
- end
- tryOffloadItems()
- end
- local function goToLastPosition()
- while turtlePos[3] < turtleLastPos[3] do
- loc_MoveUp(turtlePos, turtleVec)
- end
- loc_TurnLeft(turtleVec)
- while turtlePos[2] < turtleLastPos[2] do
- loc_MoveForward(turtlePos, turtleVec)
- end
- loc_TurnLeft(turtleVec)
- while turtlePos[1] < turtleLastPos[1] do
- loc_MoveForward(turtlePos, turtleVec)
- end
- while not (turtleVec[1] == turtleLastVec[1] and turtleVec[2] == turtleLastVec[2]) do
- loc_TurnLeft(turtleVec)
- end
- end
- local function fluidProofForward()
- local bMovement_required = false
- while true do
- if selectItemFromList(building_material) then
- break
- else
- bMovement_required = true
- goToStart()
- print("Please put in new building material")
- io.read()
- end
- end
- if bMovement_required then
- print("Going back to work")
- goToLastPosition()
- end
- if not (turtle.detect()) then
- while not turtle.place() do
- turtle.dig()
- end
- elseif inspect.Forward(falling_blocks) then
- while not turtle.place() do
- turtle.dig()
- end
- elseif inspect.Forward(waterlogged_blocks) then
- while not turtle.place() do
- turtle.dig()
- end
- end
- end
- local function fluidProofUp()
- local bMovement_required = false
- while true do
- if selectItemFromList(building_material) then
- break
- else
- bMovement_required = true
- goToStart()
- print("Please put in new building material")
- io.read()
- end
- end
- if bMovement_required then
- print("Going back to work")
- goToLastPosition()
- end
- if not (turtle.detectUp()) then
- while not turtle.placeUp() do
- turtle.digUp()
- end
- elseif inspect.Up(falling_blocks) then
- while not turtle.placeUp() do
- turtle.digUp()
- end
- elseif inspect.Up(waterlogged_blocks) then
- while not turtle.placeUp() do
- turtle.digUp()
- end
- end
- end
- local function fluidProofDown()
- local bMovement_required = false
- while true do
- if selectItemFromList(building_material) then
- break
- else
- bMovement_required = true
- goToStart()
- print("Please put in new building material")
- io.read()
- end
- end
- if bMovement_required then
- print("Going back to work")
- goToLastPosition()
- end
- if not (turtle.detectDown()) then
- while not turtle.placeDown() do
- turtle.digDown()
- end
- elseif inspect.Down(falling_blocks) then
- while not turtle.placeDown() do
- turtle.digDown()
- end
- elseif inspect.Down(waterlogged_blocks) then
- while not turtle.placeDown() do
- turtle.digDown()
- end
- end
- end
- -- checks if turtle has enough fuel and refuels if not
- local function checkAndRefuel()
- local distance = turtlePos[1] + turtlePos[2] + turtlePos[3]
- local multiplier = 1
- if distance == 0 then
- distance = turtleLastPos[1] + turtleLastPos[2] + turtleLastPos[3]
- multiplier = 2
- end
- local fuelLevel = turtle.getFuelLevel()
- local fuelBuffer = 10
- if fuelLevel > multiplier * distance + fuelBuffer then
- return
- end
- goToStart()
- tryOffloadItems()
- multiplier = 2
- print("Pls add fuel to turtle")
- while true do
- io.read()
- move.refuelProcess()
- fuelLevel = turtle.getFuelLevel()
- if fuelLevel > 2 * distance + fuelBuffer then
- break
- else
- print("Not enough fuel was added, pls try again")
- end
- end
- goToLastPosition()
- end
- --checks if turtle has an empty slot and unloads if not
- local function checkAndUnload()
- for i=16, 1, -1 do
- if turtle.getItemCount(i) == 0 then
- bFull = false
- return
- end
- end
- bFull = true
- goToStart()
- tryOffloadItems()
- checkAndRefuel()
- goToLastPosition()
- 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
- checkAndRefuel()
- checkAndUnload()
- -- 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
- -- Gets material to make it waterproof
- function checkAndGetMaterial(deltaF, deltaU)
- local neededMaterial = 2 * deltaF
- if deltaU == 2 then
- neededMaterial = deltaF
- elseif deltaU == 1 then
- neededMaterial = 0
- return
- end
- local numBuildMaterial = 0
- for i=1, 16, 1 do
- local numItems = turtle.getItemCount(i)
- if numItems > 0 then
- turtle.select(i)
- local itemDetail = turtle.getItemDetail()
- if itemDetail then
- if varInArr(itemDetail.name, building_material) then
- numBuildMaterial = numBuildMaterial + numItems
- end
- end
- end
- end
- if numBuildMaterial < neededMaterial then
- local difference = neededMaterial - numBuildMaterial
- print("More Material neede.")
- if difference == 1 then
- print("Pls put in 1 more block of building material.")
- elseif difference == neededMaterial then
- print("Pls put in ", difference, " blocks of building material.")
- else
- print("Pls put in ", difference, " more blocks of building material.")
- end
- io.read()
- checkAndGetMaterial(deltaF, deltaU)
- end
- end
- function placeUp()
- selectItemFromList(building_material)
- turtle.placeUp()
- end
- function placeDown()
- selectItemFromList(building_material)
- turtle.placeDown()
- end
- function topBottomRowProofer()
- for i=1, deltaForward, 1 do
- checkAndRefuel()
- placeUp()
- placeDown()
- if i < deltaForward then
- loc_MoveForward(turtlePos, turtleVec)
- end
- end
- loc_TurnLeft(turtleVec)
- loc_TurnLeft(turtleVec)
- for i=1, deltaForward, 1 do
- checkAndRefuel()
- turtle.digUp()
- turtle.digDown()
- if i < deltaForward then
- loc_MoveForward(turtlePos, turtleVec)
- end
- end
- end
- function topRowProofer()
- for i=1, deltaForward, 1 do
- checkAndRefuel()
- placeUp()
- if i < deltaForward then
- loc_MoveForward(turtlePos, turtleVec)
- end
- end
- loc_TurnLeft(turtleVec)
- loc_TurnLeft(turtleVec)
- for i=1, deltaForward, 1 do
- checkAndRefuel()
- turtle.digUp()
- if i < deltaForward then
- loc_MoveForward(turtlePos, turtleVec)
- end
- end
- end
- function bottomRowProofer()
- for i=1, deltaForward, 1 do
- checkAndRefuel()
- placeDown()
- if i < deltaForward then
- loc_MoveForward(turtlePos, turtleVec)
- end
- end
- loc_TurnLeft(turtleVec)
- loc_TurnLeft(turtleVec)
- for i=1, deltaForward, 1 do
- checkAndRefuel()
- turtle.digDown()
- if i < deltaForward then
- loc_MoveForward(turtlePos, turtleVec)
- end
- end
- end
- function proofForwardPlane()
- local remaining_height = deltaUp
- bStartPlane = true
- if remaining_height >= 1 then
- for i=1, remaining_height - 2, 1 do
- loc_MoveUp(turtlePos, turtleVec)
- end
- while remaining_height >= 2 do
- if not bStartPlane then
- loc_TurnLeft(turtleVec)
- end
- loc_TurnLeft(turtleVec)
- if remaining_height == 3 then
- topBottomRowProofer()
- elseif deltaUp == 2 then
- topRowProofer()
- loc_TurnLeft(turtleVec)
- loc_TurnLeft(turtleVec)
- loc_MoveUp(turtlePos, turtleVec)
- bottomRowProofer()
- loc_MoveDown(turtlePos, turtleVec)
- else
- topRowProofer()
- end
- remaining_height = remaining_height - 1
- if remaining_height > 1 then
- loc_MoveDown(turtlePos, turtleVec)
- end
- bStartPlane = false
- end
- end
- end
- digArea(mode, deltaForward, deltaRight, deltaUp)
- goToStart()
- tryOffloadItems()
- if bWaterproof then
- checkAndGetMaterial(deltaForward, deltaUp)
- loc_TurnLeft(turtleVec)
- for i=1, deltaRight, 1 do
- proofForwardPlane()
- if i < deltaRight then
- loc_TurnLeft(turtleVec)
- loc_MoveForward(turtlePos, turtleVec)
- end
- end
- print(turtlePos[1], turtlePos[2], turtlePos[3])
- goToStart()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement