From 651378647ee762dd3905fd8a5099f4cae1603b0e Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Tue, 3 Jun 2025 12:13:29 +0200 Subject: [PATCH 1/5] refactor: :wastebasket: removed submodules --- .github/workflows/test.yml | 6 ++--- .gitignore | 1 + .gitmodules | 8 ------ README.md | 7 +---- ccPackage.lua | 6 ----- fetch-deps.sh | 54 ++++++++++++++++++++++++++++++++++++++ tests/test_spec.lua | 10 +++---- turtleController-lib | 1 - turtleEmulator-lib | 1 - 9 files changed, 64 insertions(+), 30 deletions(-) create mode 100644 .gitignore delete mode 100644 .gitmodules delete mode 100644 ccPackage.lua create mode 100755 fetch-deps.sh delete mode 160000 turtleController-lib delete mode 160000 turtleEmulator-lib diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5347502..6d0ab4a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,10 +30,10 @@ jobs: luarocks install luasocket luarocks install luasec - - name: Git Submodule Update + - name: fetch dependencies run: | - git pull --recurse-submodules - git submodule update --init --remote --recursive + chmod +x ./fetch-deps.sh + ./fetch-deps.sh - name: test run: | diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73df968 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/libs \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 4e65a3d..0000000 --- a/.gitmodules +++ /dev/null @@ -1,8 +0,0 @@ -[submodule "turtleController-lib"] - path = turtleController-lib - url = https://github.com/mc-cc-scripts/turtleController-lib.git - branch = master -[submodule "turtleEmulator-lib"] - path = turtleEmulator-lib - url = https://github.com/mc-cc-scripts/turtleEmulator-lib.git - branch = master diff --git a/README.md b/README.md index 4394c6d..08c1651 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,4 @@ builder help builder floor -w -l -m <"left"|"right"> ``` -# Dev - Documentaion - -### Submodules used -- turtleControler-lib -- turtleEmulator-lib -- - plus submodules +# Dev - Documentaion \ No newline at end of file diff --git a/ccPackage.lua b/ccPackage.lua deleted file mode 100644 index 98d7cf4..0000000 --- a/ccPackage.lua +++ /dev/null @@ -1,6 +0,0 @@ -local spath = - debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$","") -package.path = spath.."?.lua;" - .. spath.."turtleController-lib/?.lua;" - .. package.path -require(spath.."turtleEmulator-lib/ccPackage") \ No newline at end of file diff --git a/fetch-deps.sh b/fetch-deps.sh new file mode 100755 index 0000000..921ddf9 --- /dev/null +++ b/fetch-deps.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# ---- Whats happening ---- # + +# This fetches the dependencies listed in the "libs" variable and saves them in the targetFolder + + + +set -e + +libs=( + "helperFunctions-lib" + "ccClass-lib" + "testSuite-lib" + "turtleEmulator-lib" + "turtleController-lib" + "eventHandler-lib" +) + +# Basic setup variables +repo="mc-cc-scripts" +branch="master" +targetFolderName=libs + + +# fetch files.txt and save each file into the targetFolder +fetch() { + files_txt=$(curl -fsSL "https://raw.githubusercontent.com/$repo/$1/$branch/files.txt") + if [ -z "$files_txt" ]; then + echo "Could not load files.txt for $1" + exit 1 + fi + while IFS= read -r FILE; do + url="https://raw.githubusercontent.com/$repo/$1/$branch/$FILE" + + mkdir -p "$(dirname "$targetFolderName/$FILE")" # create the folder (and subfolders specified in the files.txt) + rm -f $targetFolderName/$FILE.lua # rm existing file + if ! curl -s -o "$targetFolderName/$FILE" "$url"; then + echo "could not get / write the file $i: '$FILE' to the folder '$targetFolderName'" + exit 1 + fi + # echo "saved $1: '$FILE' in '$targetFolderName'" + done < <(echo "$files_txt") +} + +if [[ $# -eq 0 ]]; then + # No arguments given, fetch all + for i in "${libs[@]}"; do + fetch "$i" + done +else + # Argument given, fetch arguemt + fetch "$1" +fi \ No newline at end of file diff --git a/tests/test_spec.lua b/tests/test_spec.lua index 16edaf2..c68717e 100644 --- a/tests/test_spec.lua +++ b/tests/test_spec.lua @@ -28,11 +28,11 @@ ---@field equal function assert = assert -local spath = debug.getinfo(1,'S').source:sub(2):gsub("/+", "/"):gsub("[^/]*$",""):gsub("/tests", ""):gsub("tests","") -if spath == "" then - spath = "./" -end -require(spath.."ccPackage") +package.path = package.path .. ";" + .."libs/?.lua;" + .."libs/inventory/?.lua;" + .."libs/peripherals/?.lua;" + ---@class Vector _G.vector = require("vector") ---@class Builder_Lib diff --git a/turtleController-lib b/turtleController-lib deleted file mode 160000 index 8816bf4..0000000 --- a/turtleController-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8816bf4de67da590aa75c2a6ad7b537b63aca446 diff --git a/turtleEmulator-lib b/turtleEmulator-lib deleted file mode 160000 index 6c41199..0000000 --- a/turtleEmulator-lib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6c411996cd8ac7117def9ebcf67c91a9ea82d946 From 3cc75b2c3f7287b26497b708c7e4c2e95af2d2a3 Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Tue, 3 Jun 2025 17:50:10 +0200 Subject: [PATCH 2/5] feat: :construction: WIP clearArea integration --- builder-lib.lua | 92 +++++++++---- tests/clearArea_spec.lua | 165 ++++++++++++++++++++++++ tests/{test_spec.lua => floor_spec.lua} | 10 +- 3 files changed, 239 insertions(+), 28 deletions(-) create mode 100644 tests/clearArea_spec.lua rename tests/{test_spec.lua => floor_spec.lua} (98%) diff --git a/builder-lib.lua b/builder-lib.lua index 83a42b8..e55d92d 100644 --- a/builder-lib.lua +++ b/builder-lib.lua @@ -1,7 +1,7 @@ ---@class Builder_Lib local Builder_Lib = { movementDirection = { - height = "bottom", + height = "up", width = "right" } } @@ -36,6 +36,27 @@ local function placeDownItem(itemname) if not succ then error(txt) end end +local function getTurningDirection(builderRef ,cHorizontal, cVertical) + assert(type(builderRef) == "table", "needs self reference!") + cHorizontal = cHorizontal or 1 + cVertical = cVertical or 1 + local hModulo = cHorizontal % 2 + local vModulo = cVertical % 2 + if builderRef.movementDirection.width == "left" then + hModulo = 1 - hModulo -- toggle between 1 / 0 + end + if builderRef.movementDirection.height == "down" and cVertical ~= 0 then + vModulo = 1 - vModulo -- toggle between 1 / 0 + end + -- TODO Simplify + if (hModulo == 1 and vModulo == 1) or (hModulo == 0 and vModulo == 0) then + turtle.turnRight() + else + turtle.turnLeft() + end + +end + local function returnToStartingPos() end @@ -44,26 +65,8 @@ end ---@param length number ---@param width number function Builder_Lib:floor(length, width) - - local t - if self.movementDirection.width == "right" then - t = function(modulo) - if modulo == 1 then - turtle.turnRight() - else - turtle.turnLeft() - end - end - else - t = function(modulo) - if modulo == 1 then - turtle.turnLeft() - else - turtle.turnRight() - end - end - end - + length = length or 1 + width = width or 1 turtle.select(1) local block = turtle.getItemDetail() if block == nil then error("No block at item slot 1") end @@ -74,11 +77,54 @@ function Builder_Lib:floor(length, width) end placeDownItem(block.name) if (j < width) then - t(j % 2) + getTurningDirection(self, j) turtleController:goStraight(1) - t(j % 2) + getTurningDirection(self, j) end end returnToStartingPos() end + +function Builder_Lib:clearArea(length, width, height) + local upDownDig = function(cHeight, maxHeight) + if(cHeight < maxHeight) then + turtleController:tryAction("digU") + end + if(cHeight > 1) then + turtleController:tryAction("digD") + end + end + local currentHeight = 1 + local k = 1 + while true do + for j = 1, width, 1 do + for i = 1, length - 1, 1 do + upDownDig(currentHeight, height) + turtleController:goStraight(1) + end + upDownDig(currentHeight, height) + if (j < width) then + getTurningDirection(self, j, k) + turtleController:goStraight(1) + getTurningDirection(self, j, k) + end + end + upDownDig(currentHeight, height) + + -- go up 3 blocks + local u = height - currentHeight + if u > 3 then + u = 3 + end + if u == 0 then + break + end + currentHeight = currentHeight + u + k = k + 1 + turtleController:goUp(u) + turtleController:tryMove("tA") + end + + returnToStartingPos() +end return Builder_Lib \ No newline at end of file diff --git a/tests/clearArea_spec.lua b/tests/clearArea_spec.lua new file mode 100644 index 0000000..3dc4106 --- /dev/null +++ b/tests/clearArea_spec.lua @@ -0,0 +1,165 @@ +---@class are +---@field same function +---@field equal function +---@field equals function + +---@class is +---@field truthy function +---@field falsy function +---@field not_true function +---@field not_false function + +---@class has +---@field error function +---@field errors function + +---@class assert +---@field are are +---@field is is +---@field are_not are +---@field is_not is +---@field has has +---@field has_no has +---@field True function +---@field False function +---@field has_error function +---@field is_false function +---@field is_true function +---@field equal function +assert = assert + +package.path = package.path .. ";" + .."libs/?.lua;" + .."libs/inventory/?.lua;" + .."libs/peripherals/?.lua;" + +---@type TurtleEmulator +local turtleEmulator = require("turtleEmulator") + +---@type HelperFunctions +local helper = require("helperFunctions") + +---@type Vector +_G.vector = require("vector") + +---@type TextUtils +_G.textutils = require("textutils") + +---@type Builder_Lib +local builder + +local function beforeeach() + turtleEmulator:clearBlocks() + turtleEmulator:clearTurtles() + _G.turtle = turtleEmulator:createTurtle() + local peripheral = turtle.getPeripheralModule() + _G.peripheral = peripheral + if builder == nil then + builder = require("builder-lib") + end + builder.movementDirection.width = "right" + builder.movementDirection.height = "up" + + ---@type Item + local coal = {name = "minecraft:coal", count = 64, fuelgain = 8} + turtle.addItemToInventory(coal, 1) +end + +local function fillWorld() + local existingBlock = {item = {count = 1, name = "minecraft:stone", placeAble = true}} + local tmpBlock + local n = 0 + for y = 0, 9, 1 do + for x = 0, 9, 1 do + for z = 0, 9, 1 do + if x == 0 and y == 0 and z == 0 then + --skip + else + n = n + 1 + tmpBlock = helper.copyTable(existingBlock) --[[@as block]] + tmpBlock.position = vector.new(x, y, z) + turtleEmulator:createBlock(tmpBlock) + end + end + end + end +end + +---counts the length of a table +---@param t table +---@return number +local function countTableLength(t) + local length = 0 + for _, _ in pairs(t) do + length = length + 1 + end + return length +end + + + +---@param p1 Vector +---@param p2 Vector +---@return table +local function get_bounds(p1, p2) + return { + x_min = math.min(p1.x, p2.x), + x_max = math.max(p1.x, p2.x), + y_min = math.min(p1.y, p2.y), + y_max = math.max(p1.y, p2.y), + z_min = math.min(p1.z, p2.z), + z_max = math.max(p1.z, p2.z), + } +end + +---@param pos1 Vector +---@param pos2 Vector +---@return number +---@return table +local function checkEmptyFromTo(pos1, pos2) + local tmpBlock + local n = 0 + ---@type table + local blocks = {} + local bounds = get_bounds(pos1, pos2) + for x = bounds.x_min, bounds.x_max do + for y = bounds.y_min, bounds.y_max do + for z = bounds.z_min, bounds.z_max do + tmpBlock = turtleEmulator:getBlock(vector.new(x,y,z)) --[[@as block|TurtleEmulator]] + if tmpBlock ~= nil and not tmpBlock.item.name:find("turtle") then + n = n + 1 + table.insert(blocks, tmpBlock) + end + end + end + end + return n, blocks +end + +describe("Testing ClearArea Function", function() + ---@type block + + before_each(function () + beforeeach() + fillWorld() + end) + it("testing the basic Test setup", function() + -- pending("jup") + local n, _ = checkEmptyFromTo(vector.new(0,0,0),vector.new(3,3,3)) + assert.are.equal(63, n) + assert(998, countTableLength(turtleEmulator.blocks)) + end) + it("Clear 4 x 4 x 4 | Moving: left up", function() + builder.movementDirection.height = "up" + builder.movementDirection.height = "left" + builder:clearArea(4,4,4) + local filter = function(t) + return t.position.y == 3 + end + + local n = countTableLength(turtleEmulator.blocks) + assert(998 - (4*4*4), n) + local m, blocks = checkEmptyFromTo(vector.new(0,0,0),vector.new(3,3,3)) + assert.are.equal(0,m) + end) +end) \ No newline at end of file diff --git a/tests/test_spec.lua b/tests/floor_spec.lua similarity index 98% rename from tests/test_spec.lua rename to tests/floor_spec.lua index c68717e..9827204 100644 --- a/tests/test_spec.lua +++ b/tests/floor_spec.lua @@ -33,13 +33,13 @@ package.path = package.path .. ";" .."libs/inventory/?.lua;" .."libs/peripherals/?.lua;" ----@class Vector +---@type Vector _G.vector = require("vector") ----@class Builder_Lib +---@type Builder_Lib local builder ----@class TurtleEmulator +---@type TurtleEmulator local turtleEmulator = require("turtleEmulator") local function beforeeach() @@ -69,12 +69,12 @@ describe("Testing placing Floor", function () local blockAmount = 64 before_each(function () beforeeach() - ---@class Item + ---@type Item local itemToAdd = {name = "minecraft:cobblestone", count = blockAmount, placeAble = true} local itemToAdd2 = {name = "minecraft:cobblestone", count = blockAmount, placeAble = true} turtle.addItemToInventory(itemToAdd, 1) turtle.addItemToInventory(itemToAdd2, 3) - ---@class Item + ---@type Item local coal = {name = "minecraft:coal", count = 64, fuelgain = 8} turtle.addItemToInventory(coal, 2) end) From 1086aa4241704c300cfb233e9518c962c6b02e86 Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Wed, 4 Jun 2025 00:02:20 +0200 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=F0=9F=9A=A7=20WIP=20clearArea=20in?= =?UTF-8?q?tegration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builder-lib.lua | 42 ++++++++++++++++++++++++------------ builder.lua | 2 +- tests/clearArea_spec.lua | 46 ++++++++++++++++++++++++++++++++++++---- tests/floor_spec.lua | 2 ++ 4 files changed, 73 insertions(+), 19 deletions(-) diff --git a/builder-lib.lua b/builder-lib.lua index e55d92d..0d8da6d 100644 --- a/builder-lib.lua +++ b/builder-lib.lua @@ -36,20 +36,29 @@ local function placeDownItem(itemname) if not succ then error(txt) end end -local function getTurningDirection(builderRef ,cHorizontal, cVertical) +local function getTurningDirection(builderRef ,cHorizontal, cVertical, maxWidth) assert(type(builderRef) == "table", "needs self reference!") cHorizontal = cHorizontal or 1 cVertical = cVertical or 1 + maxWidth = maxWidth or 2 -- default is even + local even = maxWidth % 2 local hModulo = cHorizontal % 2 local vModulo = cVertical % 2 - if builderRef.movementDirection.width == "left" then + if builderRef.movementDirection.width == "right" then hModulo = 1 - hModulo -- toggle between 1 / 0 end - if builderRef.movementDirection.height == "down" and cVertical ~= 0 then - vModulo = 1 - vModulo -- toggle between 1 / 0 - end + -- TODO Simplify - if (hModulo == 1 and vModulo == 1) or (hModulo == 0 and vModulo == 0) then + -- with vModulo == hModulo xor even + if (even == 1 and vModulo == 0) then + if (hModulo ~= vModulo) then + turtle.turnRight() + else + turtle.turnLeft() + end + return + end + if (hModulo == vModulo) then turtle.turnRight() else turtle.turnLeft() @@ -104,24 +113,29 @@ function Builder_Lib:clearArea(length, width, height) end upDownDig(currentHeight, height) if (j < width) then - getTurningDirection(self, j, k) + getTurningDirection(self, j, k, width) turtleController:goStraight(1) - getTurningDirection(self, j, k) + getTurningDirection(self, j, k, width) end end upDownDig(currentHeight, height) -- go up 3 blocks - local u = height - currentHeight - if u > 3 then - u = 3 + local diff = height - currentHeight + if diff > 3 then + diff = 3 end - if u == 0 then + if diff == 0 then break end - currentHeight = currentHeight + u + if self.movementDirection.height == "up" then + turtleController:goUp(diff) + else + turtleController:goDown(diff) + end + currentHeight = currentHeight + diff + k = k + 1 - turtleController:goUp(u) turtleController:tryMove("tA") end diff --git a/builder.lua b/builder.lua index 52e8aaa..d7aa129 100644 --- a/builder.lua +++ b/builder.lua @@ -1,7 +1,7 @@ --- UI for Builder ---@class Builder_Lib -local builder = require("/progs/builder-prog/builder-lib") +local builder = require("builder-lib") local function help() diff --git a/tests/clearArea_spec.lua b/tests/clearArea_spec.lua index 3dc4106..df87cf3 100644 --- a/tests/clearArea_spec.lua +++ b/tests/clearArea_spec.lua @@ -143,23 +143,61 @@ describe("Testing ClearArea Function", function() beforeeach() fillWorld() end) + it("testing the basic Test setup", function() -- pending("jup") local n, _ = checkEmptyFromTo(vector.new(0,0,0),vector.new(3,3,3)) assert.are.equal(63, n) assert(998, countTableLength(turtleEmulator.blocks)) end) + it("Clear 4 x 4 x 4 | Moving: left up", function() + -- pending("pending") builder.movementDirection.height = "up" - builder.movementDirection.height = "left" + builder.movementDirection.width = "left" builder:clearArea(4,4,4) - local filter = function(t) - return t.position.y == 3 - end local n = countTableLength(turtleEmulator.blocks) assert(998 - (4*4*4), n) local m, blocks = checkEmptyFromTo(vector.new(0,0,0),vector.new(3,3,3)) assert.are.equal(0,m) end) + + it("Clear 4 x 4 x 4 | Moving: right up", function() + -- pending("pending") + builder.movementDirection.height = "up" + builder.movementDirection.width = "right" + ---position turtle at 0, 0, 3 + turtle.position = vector.new(-1, 0, 3) + turtle.refuel() + turtle.dig() + assert.is_true(turtle.forward()) + + builder:clearArea(4,4,4) + + local n = countTableLength(turtleEmulator.blocks) + assert(998 - (4*4*4), n) + local m, blocks = checkEmptyFromTo(vector.new(0,0,0),vector.new(3,3,3)) + assert.are.equal(0,m) + end) + + it("Clear 5 x 5 x 5 | Moving: left down", function() + pending("pending") + builder.movementDirection.height = "down" + builder.movementDirection.width = "left" + + ---position turtle at 0, 4, 0 + turtle.position = vector.new(-1, 4, 0) + turtle.refuel() + turtle.dig() + assert.is_true(turtle.forward()) + + builder:clearArea(5,5,5) + + local n = countTableLength(turtleEmulator.blocks) + assert(998 - (5*5*5), n) + local m, blocks = checkEmptyFromTo(vector.new(0,0,0),vector.new(4,4,4)) + print(textutils.serialize(blocks)) + assert.are.equal(0,m) + end) end) \ No newline at end of file diff --git a/tests/floor_spec.lua b/tests/floor_spec.lua index 9827204..8e55d4d 100644 --- a/tests/floor_spec.lua +++ b/tests/floor_spec.lua @@ -97,6 +97,7 @@ describe("Testing placing Floor", function () it("Create 9x9 floor", function() assert.are.equal(0, countTableLength(turtleEmulator.blocks)) local succ, err = xpcall(function () + builder.movementDirection.width = "right" builder:floor(9, 9) end, debug.traceback) if err then error(err) end @@ -137,6 +138,7 @@ describe("Testing placing Floor", function () it("Create 10x10 floor", function() assert.are.equal(0, countTableLength(turtleEmulator.blocks)) local succ, err = xpcall(function () + builder.movementDirection.width = "right" builder:floor(10, 10) end, debug.traceback) if err then error(err) end From 98eb24217ebcadfebe219a20b85b481cfd57f162 Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Wed, 4 Jun 2025 11:02:06 +0200 Subject: [PATCH 4/5] feat: clearArea Integration --- builder-lib.lua | 60 ++++++++++++++++++++++++++-------------- builder.lua | 37 ++++++++++++++++++------- tests/clearArea_spec.lua | 40 +++++++++++++++++++++------ tests/floor_spec.lua | 3 ++ 4 files changed, 101 insertions(+), 39 deletions(-) diff --git a/builder-lib.lua b/builder-lib.lua index 0d8da6d..ff81bbd 100644 --- a/builder-lib.lua +++ b/builder-lib.lua @@ -41,23 +41,20 @@ local function getTurningDirection(builderRef ,cHorizontal, cVertical, maxWidth) cHorizontal = cHorizontal or 1 cVertical = cVertical or 1 maxWidth = maxWidth or 2 -- default is even - local even = maxWidth % 2 + local hModulo = cHorizontal % 2 local vModulo = cVertical % 2 - if builderRef.movementDirection.width == "right" then - hModulo = 1 - hModulo -- toggle between 1 / 0 + + -- if odd, pretent to always be at base y-level and CONTINUE the left / right toggle + -- making vModulo static + if (maxWidth % 2 == 1) then + vModulo = 1 end - -- TODO Simplify - -- with vModulo == hModulo xor even - if (even == 1 and vModulo == 0) then - if (hModulo ~= vModulo) then - turtle.turnRight() - else - turtle.turnLeft() - end - return + if builderRef.movementDirection.width == "left" then + hModulo = 1 - hModulo -- invert 1 <=> 0 end + if (hModulo == vModulo) then turtle.turnRight() else @@ -71,8 +68,9 @@ local function returnToStartingPos() end ---builds the floor with the given size ----@param length number ----@param width number +---@param length number | nil +---@param width number | nil +---@return boolean success function Builder_Lib:floor(length, width) length = length or 1 width = width or 1 @@ -92,17 +90,37 @@ function Builder_Lib:floor(length, width) end end returnToStartingPos() + return true end +---clears an area with of specified size +---@param length number | nil +---@param width number | nil +---@param height number | nil +---@return boolean success function Builder_Lib:clearArea(length, width, height) local upDownDig = function(cHeight, maxHeight) - if(cHeight < maxHeight) then - turtleController:tryAction("digU") - end - if(cHeight > 1) then - turtleController:tryAction("digD") + if Builder_Lib.movementDirection.height == "up" then + if(cHeight < maxHeight) then + turtleController:tryAction("digU") + end + if(cHeight > 1) then + turtleController:tryAction("digD") + end + else + if(cHeight < maxHeight) then + turtleController:tryAction("digD") + end + if(cHeight > 1) then + turtleController:tryAction("digU") + end end end + length = length or 1 + width = width or 1 + height = height or 1 + + local currentHeight = 1 local k = 1 while true do @@ -116,6 +134,7 @@ function Builder_Lib:clearArea(length, width, height) getTurningDirection(self, j, k, width) turtleController:goStraight(1) getTurningDirection(self, j, k, width) + else end end upDownDig(currentHeight, height) @@ -125,7 +144,7 @@ function Builder_Lib:clearArea(length, width, height) if diff > 3 then diff = 3 end - if diff == 0 then + if diff <= 1 then break end if self.movementDirection.height == "up" then @@ -140,5 +159,6 @@ function Builder_Lib:clearArea(length, width, height) end returnToStartingPos() + return true end return Builder_Lib \ No newline at end of file diff --git a/builder.lua b/builder.lua index d7aa129..1a76e47 100644 --- a/builder.lua +++ b/builder.lua @@ -7,15 +7,16 @@ local builder = require("builder-lib") local function help() print("Usage:") print("builder ") - print("") print("Commands: ") - print("- 'floor'") - print("") + print("'floor'") + print("'clearArea'") print("Options:") - print("-m[movementDirection] <'left'|'right'> [default: right]") + print("-mH[movementDir. Horizon] <'left'|'right'> [default: right]") + print("-mV[movementDir. Vertical] <'left'|'right'> [default: right]") print("-w[width] ") print("-l[length] ") - print("-h[help]") + print("-h[height] ") + print("-help") end if #arg == 0 then help() @@ -26,16 +27,20 @@ end local stopExec = false local size = { - ["length"] = 0, - ["width"] = 0, - ["height"] = 0 + ["length"] = nil, + ["width"] = nil, + ["height"] = nil } local argsSwitch = { - ["-m"] = function(no) + ["-mH"] = function(no) no[1] = no[1] + 1 builder.movementDirection.width = arg[no[1]] end, + ["-mV"] = function (no) + no[1] = no[1] + 1 + builder.movementDirection.height = arg[no[1]] + end, ["-l"] = function(no) no[1] = no[1] + 1 size["length"] = tonumber(arg[no[1]]) or error("length not valid") @@ -44,7 +49,16 @@ local argsSwitch = { no[1] = no[1] + 1 size["width"] = tonumber(arg[no[1]]) or error("width not valid") end, - ["-h"] = function() + ["-h"] = function(no) + no[1] = no[1] + 1 + if not tonumber(arg[no[1]]) then + help() + stopExec = true + return + end + size["height"] = tonumber(arg[no[1]]) + end, + ["-help"] = function() help() stopExec = true end, @@ -56,6 +70,9 @@ local argsSwitch = { local commands = { ["floor"] = function() builder:floor(size["length"], size["width"]) + end, + ["clearArea"] = function() + builder:clearArea(size["length"], size["width"], size["height"]) end } diff --git a/tests/clearArea_spec.lua b/tests/clearArea_spec.lua index df87cf3..68a3632 100644 --- a/tests/clearArea_spec.lua +++ b/tests/clearArea_spec.lua @@ -151,10 +151,12 @@ describe("Testing ClearArea Function", function() assert(998, countTableLength(turtleEmulator.blocks)) end) - it("Clear 4 x 4 x 4 | Moving: left up", function() + it("Clear 4 x 4 x 4 | Moving: right up", function() -- pending("pending") builder.movementDirection.height = "up" - builder.movementDirection.width = "left" + builder.movementDirection.width = "right" + + builder:clearArea(4,4,4) local n = countTableLength(turtleEmulator.blocks) @@ -163,16 +165,17 @@ describe("Testing ClearArea Function", function() assert.are.equal(0,m) end) - it("Clear 4 x 4 x 4 | Moving: right up", function() + it("Clear 4 x 4 x 4 | Moving: left up", function() -- pending("pending") builder.movementDirection.height = "up" - builder.movementDirection.width = "right" + builder.movementDirection.width = "left" + ---position turtle at 0, 0, 3 turtle.position = vector.new(-1, 0, 3) turtle.refuel() turtle.dig() assert.is_true(turtle.forward()) - + builder:clearArea(4,4,4) local n = countTableLength(turtleEmulator.blocks) @@ -181,10 +184,10 @@ describe("Testing ClearArea Function", function() assert.are.equal(0,m) end) - it("Clear 5 x 5 x 5 | Moving: left down", function() - pending("pending") + it("Clear 5 x 5 x 5 | Moving: right down", function() + -- pending("pending") builder.movementDirection.height = "down" - builder.movementDirection.width = "left" + builder.movementDirection.width = "right" ---position turtle at 0, 4, 0 turtle.position = vector.new(-1, 4, 0) @@ -197,7 +200,26 @@ describe("Testing ClearArea Function", function() local n = countTableLength(turtleEmulator.blocks) assert(998 - (5*5*5), n) local m, blocks = checkEmptyFromTo(vector.new(0,0,0),vector.new(4,4,4)) - print(textutils.serialize(blocks)) assert.are.equal(0,m) end) + + it("Clear 5 x 5 x 5 | Moving: left down", function() + -- pending("pending") + builder.movementDirection.height = "down" + builder.movementDirection.width = "left" + + ---position turtle at 0, 4, 0 + turtle.position = vector.new(-1, 4, 4) + turtle.refuel() + turtle.dig() + assert.is_true(turtle.forward()) + + builder:clearArea(5,5,5) + + local n = countTableLength(turtleEmulator.blocks) + assert(998 - (5*5*5), n) + local m, blocks = checkEmptyFromTo(vector.new(0,0,0),vector.new(4,4,4)) + assert.are.equal(0,m) + end) + end) \ No newline at end of file diff --git a/tests/floor_spec.lua b/tests/floor_spec.lua index 8e55d4d..c1fe056 100644 --- a/tests/floor_spec.lua +++ b/tests/floor_spec.lua @@ -38,6 +38,8 @@ _G.vector = require("vector") ---@type Builder_Lib local builder +_G.textutils = require("textutils") + ---@type TurtleEmulator local turtleEmulator = require("turtleEmulator") @@ -164,6 +166,7 @@ describe("Testing placing Floor", function () if err then error(err) end assert.are.equal(100, countTableLength(turtleEmulator.blocks)) local blocksTested = 0 + -- print("Blocks placed", textutils.serialize(turtleEmulator.blocks)) for j = -9, 0, 1 do for i = 0, 9, 1 do blocksTested = blocksTested + 1 From 05ee370d1f450d8d82b942c7b88d4738cd8d995c Mon Sep 17 00:00:00 2001 From: ChristophLHR <11349102+ChristophLHR@users.noreply.github.com> Date: Wed, 4 Jun 2025 11:05:27 +0200 Subject: [PATCH 5/5] clearArea: Updated ReadMe --- README.md | 9 +++++++-- builder.lua | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 08c1651..d1703d9 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,12 @@ builder help ```lua -- Builds a floor with the specified size. -- Uses the Item in Slot 1 as Buildingblock! -builder floor -w -l -m <"left"|"right"> +builder floor -w -l -mH <"left"|"right"> ``` -# Dev - Documentaion \ No newline at end of file +### clearArea + +```lua +-- clears an Area of the specifed size +builder clearArea -w -l -h -mH <"left"|"right"> -mV <"up"|"down"> +``` diff --git a/builder.lua b/builder.lua index 1a76e47..f129a28 100644 --- a/builder.lua +++ b/builder.lua @@ -12,7 +12,7 @@ local function help() print("'clearArea'") print("Options:") print("-mH[movementDir. Horizon] <'left'|'right'> [default: right]") - print("-mV[movementDir. Vertical] <'left'|'right'> [default: right]") + print("-mV[movementDir. Vertical] <'down'|'up'> [default: up]") print("-w[width] ") print("-l[length] ") print("-h[height] ")