Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions builder-lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ local Builder_Lib = {
movementDirection = {
height = "up",
width = "right"
}
},
placeDirection = "down"
}


Expand All @@ -23,19 +24,33 @@ local function selectItemToPlace(itemname)
if item == nil or item.name ~= itemname then
local slot = turtleController:findItemInInventory(itemname)
if slot == nil then
error("No more blocks available to build")
error("No more blocks available to build" .. tostring(turtle.getItemCount()))
end
turtle.select(slot)
end
end

local function placeDownItem(itemname)
---
---@param self Builder_Lib
---@param itemname string
local function placeItem(self, itemname)
selectItemToPlace(itemname)
if turtle.detectDown() then
local _, down = turtle.inspectDown()
turtleController:tryAction("digD")
local function action()
if (self.placeDirection == "down") then
if turtle.detectDown() then
local _, down = turtle.inspectDown()
turtleController:tryAction("digD")
end
return turtle.placeDown()
else
if turtle.detectUp() then
local _, down = turtle.inspectUp()
turtleController:tryAction("digU")
end
return turtle.placeUp()
end
end
local succ, txt = turtle.placeDown()
local succ, txt = action()
if not succ then error(txt) end
end

Expand Down Expand Up @@ -82,10 +97,10 @@ function Builder_Lib:floor(length, width)
if block == nil then error("No block at item slot 1") end
for j = 1, width, 1 do
for i = 1, length - 1, 1 do
placeDownItem(block.name)
placeItem(self, block.name)
turtleController:goStraight(1)
end
placeDownItem(block.name)
placeItem(self, block.name)
if (j < width) then
getTurningDirection(self, j)
turtleController:goStraight(1)
Expand Down
9 changes: 5 additions & 4 deletions builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ local function help()
print("Options:")
print("-mH[movementDir. Horizon] <'left'|'right'> [default: right]")
print("-mV[movementDir. Vertical] <'down'|'up'> [default: up]")
print("-p (place) up | down")
print("-w[width] <number>")
print("-l[length] <number>")
print("-h[height] <number>")
print("-help")
print("help")
end
if #arg == 0 then
help()
Expand Down Expand Up @@ -58,9 +59,9 @@ local argsSwitch = {
end
size["height"] = tonumber(arg[no[1]])
end,
["-help"] = function()
help()
stopExec = true
["-p"] = function(no)
no[1] = no[1] + 1
builder.placeDirection = arg[no[1]]
end,
["help"] = function()
help()
Expand Down
22 changes: 22 additions & 0 deletions tests/floor_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ describe("Testing placing Floor", function ()
assert.are.equal(100, blocksTested)
end)

it("Create 10x10 floor - to Left - above", function()
assert.are.equal(0, countTableLength(turtleEmulator.blocks))
local succ, err = xpcall(function ()
builder.movementDirection.width = "left"
builder.placeDirection = "up"
builder:floor(10, 10)
end, debug.traceback)
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
assert.is.truthy(
turtleEmulator:getBlock(vector.new(i, 1, j))
)
end
end
assert.are.equal(100, blocksTested)
end)


it("Error on too few Blocks", function()
local blocksToTest = blockAmount * 2 + 1
Expand Down
Loading