Skip to content

Commit 5de58dc

Browse files
committed
added InventoryManagement for clearArea
1 parent 5ecc1a6 commit 5de58dc

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

builder-lib.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ local Builder_Lib = {
77
}
88

99

10-
---@class SCM
10+
---@type SCM
1111
local scm = require("./scm")
1212

13-
---@class turtleController
13+
---@type turtleController
1414
local turtleController = scm:load("turtleController")
1515

16+
---@type TurtleResourceManager
17+
local tResourceManager = scm:load("turtleResourceManager")
18+
1619
turtleController.canBreakBlocks = true
1720

1821
local function selectItemToPlace(itemname)
@@ -115,20 +118,31 @@ function Builder_Lib:clearArea(length, width, height)
115118
turtleController:tryAction("digU")
116119
end
117120
end
121+
end
122+
123+
local filterFunc = function(item)
124+
return string.find(item.name, "coal") == nil
118125
end
126+
119127
length = length or 1
120128
width = width or 1
121129
height = height or 1
122130

123131

124132
local currentHeight = 1
125133
local k = 1
134+
local manageSpace = tResourceManager:checkSetup()
126135
while true do
127136
for j = 1, width, 1 do
128137
for i = 1, length - 1, 1 do
129138
upDownDig(currentHeight, height)
130139
turtleController:goStraight(1)
131140
end
141+
if manageSpace then
142+
if tResourceManager:manageSpace(10, filterFunc) == 3 then
143+
error("Errorhandling not finished, cound not pickup Chest!")
144+
end
145+
end
132146
upDownDig(currentHeight, height)
133147
if (j < width) then
134148
getTurningDirection(self, j, k, width)

fetch-deps.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ libs=(
1515
"turtleEmulator-lib"
1616
"turtleController-lib"
1717
"eventHandler-lib"
18+
"turtleResourceManager-lib"
19+
"config-lib"
1820
)
1921

2022
# Basic setup variables

tests/clearArea_spec.lua

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ local helper = require("helperFunctions")
4242
---@type Vector
4343
_G.vector = require("vector")
4444

45-
---@type TextUtils
4645
_G.textutils = require("textutils")
4746

47+
---@type SettingsManager
48+
_G.settings = require("settings")
49+
50+
4851
---@type Builder_Lib
4952
local builder
5053

@@ -222,4 +225,26 @@ describe("Testing ClearArea Function", function()
222225
assert.are.equal(0,m)
223226
end)
224227

228+
it("Test ChestDumping", function()
229+
builder.movementDirection.height = "up"
230+
builder.movementDirection.width = "right"
231+
232+
for i = 2, 14, 1 do
233+
turtle.addItemToInventory({name = "minecraft:dirt", count = 64, maxcount = 64, placeAble = true}, i)
234+
end
235+
local tmpChest = {name = "enderstorage:ender_chest", count = 1, maxcount = 1, placeAble = true}
236+
turtle.addItemToInventory(tmpChest, 16)
237+
local enderCHest = turtleEmulator:addInventoryToItem(tmpChest)
238+
239+
builder:clearArea(5,5,5)
240+
local n = countTableLength(turtleEmulator.blocks)
241+
assert(998 - (5*5*5), n)
242+
local m, blocks = checkEmptyFromTo(vector.new(0,0,0),vector.new(4,4,4))
243+
assert.are.equal(0,m)
244+
assert.are.same("minecraft:coal", turtle.getItemDetail(1).name)
245+
assert.are.same("minecraft:stone", turtle.getItemDetail(2).name) -- only does the last Line without clearing inventory
246+
assert.are.same(nil, turtle.getItemDetail(3))
247+
assert.are.same("minecraft:dirt", turtle.getItemDetail(14).name)
248+
end)
249+
225250
end)

tests/floor_spec.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ local builder
4040

4141
_G.textutils = require("textutils")
4242

43+
---@type SettingsManager
44+
_G.settings = require("settings")
45+
4346

4447
---@type TurtleEmulator
4548
local turtleEmulator = require("turtleEmulator")

0 commit comments

Comments
 (0)