1+ --- @class Builder_Lib
2+ local Builder_Lib = {
3+ movementDirection = {
4+ height = " bottom" ,
5+ width = " right"
6+ }
7+ }
8+
9+
10+ --- @class SCM
11+ local scm = require (" scm" )
12+
13+ --- @class turtleController
14+ local turtleController = scm :load (" turtleController" )
15+
16+ turtleController .canBreakBlocks = true
17+
18+ local function selectItemToPlace (itemname )
19+ local item = turtle .getItemDetail ()
20+ if item == nil or item .name ~= itemname then
21+ local slot = turtleController :findItemInInventory (itemname )
22+ if slot == nil then
23+ error (" No more blocks available to build" )
24+ end
25+ turtle .select (slot )
26+ end
27+ end
28+
29+ local function placeDownItem (itemname )
30+ selectItemToPlace (itemname )
31+ if turtle .detectDown () then
32+ local _ , down = turtle .inspectDown ()
33+ print (" Fond block to replace: " , down .name )
34+ turtleController :tryAction (" digD" )
35+ end
36+ local succ , txt = turtle .placeDown ()
37+ if not succ then error (txt ) end
38+ end
39+
40+ local function returnToStartingPos ()
41+
42+ end
43+
44+ --- builds the floor with the given size
45+ --- @param length number
46+ --- @param width number
47+ function Builder_Lib :floor (length , width )
48+
49+ local t
50+ if self .movementDirection .width == " right" then
51+ t = function (modulo )
52+ if modulo == 1 then
53+ turtle .turnRight ()
54+ else
55+ turtle .turnLeft ()
56+ end
57+ end
58+ else
59+ t = function (modulo )
60+ if modulo == 1 then
61+ turtle .turnLeft ()
62+ else
63+ turtle .turnRight ()
64+ end
65+ end
66+ end
67+
68+ turtle .select (1 )
69+ local block = turtle .getItemDetail ()
70+ if block == nil then error (" No block at item slot 1" ) end
71+ for j = 1 , width , 1 do
72+ for i = 1 , length - 1 , 1 do
73+ placeDownItem (block .name )
74+ turtleController :goStraight (1 )
75+ end
76+ placeDownItem (block .name )
77+ if (j < width ) then
78+ t (j % 2 )
79+ turtleController :goStraight (1 )
80+ t (j % 2 )
81+ end
82+ end
83+ returnToStartingPos ()
84+ end
85+ return Builder_Lib
0 commit comments