From 49bfd155e2e50091aef4cde26c7315183cca438c Mon Sep 17 00:00:00 2001 From: TheLux83 Date: Thu, 12 Nov 2020 17:45:08 +0100 Subject: [PATCH] Changed functions in modules.lua and created circles.lua hare.lua contains now everything from Al Sweigarts book and modules is my interpretation from it with a few tweaks. Additionally I've created a circles.lua module. This module is used to build circles referenced from https://i.redd.it/swn3e9w8dyc31.jpg --- Modules/circles.lua | 812 ++++++++++++++++++++++++++++++++++++++++++++ Modules/hare.lua | 91 +++++ Modules/modules.lua | 142 ++++---- 3 files changed, 987 insertions(+), 58 deletions(-) create mode 100644 Modules/circles.lua diff --git a/Modules/circles.lua b/Modules/circles.lua new file mode 100644 index 0000000..4973a25 --- /dev/null +++ b/Modules/circles.lua @@ -0,0 +1,812 @@ +--[[ Modules for generation or building circles in various forms +--written by TheLux +--Check https://i.redd.it/swn3e9w8dyc31.jpg to see +--the references for the numbers]] + +-- Check if the modules API is present +-- and load it. We need it +if not os.loadAPI('modules.lua') then + error('Error! modules.lua is missing. Please insert it into turtle.') +end + +--initial_setup() checks if there is enough +--material and sets the turtle to the start +--position and places the first block. +--Alle circles uses this function +function initial_circle_setup(material, material_count) + -- Check if we have enough material + if modules.count_inventory(material) < material_count then + print('Error! Not enough blocks of ' .. material) + return false + end + + turtle.up() +end + + +--place_diagonal() places n blocks in a diagonal manner +function place_diagonal(amount, material) + for i = 1, amount do + turtle.turnRight() + turtle.forward() + modules.select_and_place_down(material) + turtle.turnLeft() + turtle.forward() + end +end + + +--place_column() places n block in a column +function place_column(amount, material) + turtle.turnRight() + for i = 1, amount do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.turnLeft() + turtle.forward() +end + + +--place_row() places n block in a row +function place_column(amount, material) + turtle.turnRight() + turtle.forward() + turtle.turnLeft() + for i = 1, amount do + modules.select_and_place_down(material) + turtle.forward() + end +end + + + +--place_triangle() places a trinagular block +function place_column(material) + turtle.turnRight() + turtle.forward() + turtle.turnLeft() + modules.select_and_place_down(material) + turtle.forward() + modules.select_and_place_down(material) + turtle.turnRight() + turtle.forward() + modules.select_and_place_down(material) + turtle.turnLeft() + turtle.forward() +end + + +--circle2 build a 2 by 2 circle +function circle2(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 4) + + modules.select_and_place_down(material) + turtle.forward() + modules.select_and_place_down(material) + turtle.turnRight() + turtle.forward() + turtle.turnRight() + modules.select_and_place_down(material) + turtle.forward() + turtle.turnRight() + modules.select_and_place_down(material) + turtle.forward() + turtle.turnRight() + print('Done building a 2 by 2 circle') +end + + +--circle3 builds a 3 by 3 wide circle +function circle3(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 8) + + for i = 1, 4 do + for j = 1, 2 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.turnRight() + end + print('Done building a 3 by 3 circle') +end + + +--circle4 builds a 4 by 4 wide circle +function circle4(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 8) + turtle.turnLeft() + turtle.forward() + turtle.turnRight() + for i = 1, 3 do + for j = 1, 2 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + turtle.turnRight() + end + turtle.forward() + modules.select_and_place_down(material) + turtle.forward() + modules.select_and_place_down(material) + turtle.turnRight() + print('Done building a 4 by 4 circle') +end + + +--circle5 builds a 5 by 5 wide circle +function circle5(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 12) + turtle.turnLeft() + turtle.forward() + turtle.turnRight() + for i = 1, 3 do + for j = 1, 3 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + turtle.turnRight() + end + + for i = 1, 3 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.turnRight() + print('Done building a 5 by 5 circle') +end + + +--circle6 builds a 6 by 6 wide circle +function circle6(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 16) + turtle.turnLeft() + turtle.forward() + turtle.turnRight() + for i = 1, 3 do + for j = 1, 4 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + turtle.turnRight() + end + + for i = 1, 4 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.turnRight() + print('Done building a 4 by 4 circle') +end + + +--circle7 builds a 7 by 7 wide circle +function circle7(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 16) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + turtle.turnRight() + turtle.forward() + modules.select_and_place_down(material) + turtle.turnLeft() + turtle.forward() + turtle.turnRight() + for j = 1, 3 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 7 by 7 circle') +end + + +--circle8 builds a 8 by 8 wide circle +function circle8(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 20) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + turtle.turnRight() + turtle.forward() + modules.select_and_place_down(material) + turtle.turnLeft() + turtle.forward() + turtle.turnRight() + for j = 1, 4 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 8 by 8 circle') +end + + +--circle9 builds a 9 by 9 wide circle +function circle9(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 24) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + turtle.turnRight() + turtle.forward() + modules.select_and_place_down(material) + turtle.turnLeft() + turtle.forward() + turtle.turnRight() + for j = 1, 5 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 9 by 9 circle') +end + + +--circle10 builds a 10 by 10 wide circle +function circle10(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 28) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_triangle(material) + turtle.turnRight() + for j = 1, 4 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 10 by 10 circle') +end + + +--circle11 builds a 11 by 11 wide circle +function circle11(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 28) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 5 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 11 by 11 circle') +end + + +--circle12 builds a 12 by 12 wide circle +function circle12(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 32) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 4 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 12 by 12 circle') +end + + +--circle13 builds a 13 by 13 wide circle +function circle13(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 36) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 5 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 13 by 13 circle') +end + + +--circle14 builds a 14 by 14 wide circle +function circle14(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 36) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_diagonal(3, material) + turtle.turnRight() + for j = 1, 6 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 14 by 14 circle') +end + + +--circle15 builds a 15 by 15 wide circle +function circle15(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 36) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_diagonal(1, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 5 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 15 by 15 circle') +end + + +--circle16 builds a 16 by 16 wide circle +function circle16(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 44) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_diagonal(1, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 6 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 16 by 16 circle') +end + + +--circle17 builds a 17 by 17 wide circle +function circle17(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 48) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_triangle(material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 5 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 17 by 17 circle') +end + + +--circle18 builds a 18 by 18 wide circle +function circle18(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 48) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_diagonal(2, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 6 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 18 by 18 circle') +end + + +--circle19 builds a 19 by 19 wide circle +function circle19(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 52) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_diagonal(2, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 7 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 19 by 19 circle') +end + + +--circle20 builds a 20 by 20 wide circle +function circle20(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 56) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_row(2, material) + modules.place_column(2, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 6 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 20 by 20 circle') +end + + +--circle21 builds a 21 by 21 wide circle +function circle21(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 56) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_diagonal(3, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 7 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 21 by 21 circle') +end + + +--circle22 builds a 22 by 22 wide circle +function circle22(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 60) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(3, material) + modules.place_diagonal(3, material) + modules.place_column(3, material) + turtle.turnRight() + for j = 1, 6 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 22 by 22 circle') +end + + +--circle23 builds a 23 by 23 wide circle +function circle23(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 64) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_row(2, material) + modules.place_diagonal(1, material) + modules.place_column(2, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 7 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 23 by 23 circle') +end + + +--circle24 builds a 24 by 24 wide circle +function circle24(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 64) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(3, material) + modules.place_diagonal(4, material) + modules.place_column(3, material) + turtle.turnRight() + for j = 1, 6 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 24 by 24 circle') +end + + +--circle25 builds a 25 by 25 wide circle +function circle25(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 68) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_row(2, material) + modules.place_diagonal(2, material) + modules.place_column(2, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 7 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 25 by 25 circle') +end + + +--circle26 builds a 26 by 26 wide circle +function circle26(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 72) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_row(2, material) + modules.place_diagonal(2, material) + modules.place_column(2, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 8 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 26 by 26 circle') +end + + +--circle27 builds a 27 by 27 wide circle +function circle27(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 76) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(3, material) + modules.place_diagonal(1, material) + modules.place_row(2, material) + modules.place_column(2, material) + modules.place_diagonal(1, material) + modules.place_column(3, material) + turtle.turnRight() + for j = 1, 7 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 27 by 27 circle') +end + + +--circle28 builds a 28 by 28 wide circle +function circle28(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 76) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(2, material) + modules.place_row(2, material) + modules.place_diagonal(3, material) + modules.place_column(2, material) + modules.place_column(2, material) + turtle.turnRight() + for j = 1, 7 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 28 by 28 circle') +end + + +--circle29 builds a 29 by 29 wide circle +function circle29(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 80) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(3, material) + modules.place_row(2, material) + modules.place_diagonal(3, material) + modules.place_column(2, material) + modules.place_column(3, material) + turtle.turnRight() + for j = 1, 7 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 29 by 29 circle') +end + + +--circle30 builds a 30 by 30 wide circle +function circle30(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 84) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(3, material) + modules.place_diagonal(1, material) + modules.place_row(2, material) + modules.place_diagonal(1, material) + modules.place_column(2, material) + modules.place_diagonal(1, material) + modules.place_column(3, material) + turtle.turnRight() + for j = 1, 8 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 30 by 30 circle') +end + + +--circle31 builds a 31 by 31 wide circle +function circle31(material) + -- Start the initial Setup and place the turtle in + -- the right position + modules.initial_setup(material, 84) + turtle.turnLeft() + turtle.forward() + for i = 1, 4 do + modules.place_row(3, material) + modules.place_row(2, material) + modules.place_diagonal(4, material) + modules.place_column(2, material) + modules.place_column(3, material) + turtle.turnRight() + for j = 1, 7 do + turtle.forward() + modules.select_and_place_down(material) + end + turtle.forward() + end + turtle.back() + turtle.turnRight() + print('Done building a 31 by 31 circle') +end + diff --git a/Modules/hare.lua b/Modules/hare.lua index 804826b..eac7f2e 100644 --- a/Modules/hare.lua +++ b/Modules/hare.lua @@ -34,4 +34,95 @@ function selectEmptySlot() return false -- couldn't find empty space end +-- countInventory() returns the total +-- numer of items in the inventory +function countInventory() + local total = 0 + for slot = 1, 16 do + total = total + turtle.getItem(slot) + end + return total +end + +-- selectAndPlaceDown() selects a nonempty slot +-- and places a block from it under the turtle +function selectAndPlaceDown() + for slot = 1, 16 do + if turtle.getItemCount(slot) > 0 then + turtle.select(slot) + turtle.placeDown() + return + end + end +end + + +-- buildWall() creates a wall stretching +-- in front of the turtle +function buildWall(length, height) + if modules.countInventory() > length * height then + return false --not enough block + end + + turtle.up() + + local movingForward = true + + for currentHeight = 1, height do + for currentLength = 1, length do + selectAndPlaceDown() -- Place the block + if movingForward and currentLength ~= length then + turtle.forward() + elseif not movingForward and currentLength ~= length then + turtle.back() + end + end + if currentHeight ~= height then + turtle.up() + end + movingForward = not movingForward + end + + -- done building wall; move to end position + if movingForward then + -- turtle is near the start position + for currentLength = 1, length do + turtle.forward() + end + else + -- turtle is near the end position + turtle.forward() + end + + -- move down to the ground + for currentHeight = 1, height do + turtle.down() + end + + return true +end + +-- buildRoom() constructs four walls +-- and a ceiling +function buildRoom(length, width, height) + if hare.countInventory() < (((length -1) * height * 2) + + ((width -1) * height * 2)) then + return false -- not enough blocks + end + + -- build the four walls + buildWall(length -1, height) + turtle.turnRight() + + buildWall(width - 1, height) + turtle.turnRight() + + buildWall(length - 1, height) + turtle.turnRight() + + buildWall(width - 1, height) + turtle.turnRight() + + return true +end diff --git a/Modules/modules.lua b/Modules/modules.lua index f6d31b3..2cfc220 100644 --- a/Modules/modules.lua +++ b/Modules/modules.lua @@ -4,15 +4,15 @@ Provides useful utility functions.]] -- selectItem() selects the inventory -- slot with the named item, returns -- true if found and false if not -function selectItem(name) +function select_item(name) -- check all inventory slots local item - for slot = 1, 16 do - item = turtle.getItemDetail(slot) - if item ~= nil and item['name'] == name then - turtle.select(slot) - return true - end + for slot = 1, 16 do + item = turtle.getItemDetail(slot) + if item ~= nil and item['name'] == name then + turtle.select(slot) + return true + end end return false -- couldn't find item @@ -22,7 +22,7 @@ end -- selectEmptySlot() selects inventory -- slot that is empty, returns true if -- found, false if no empty spaces -function selectEmptySlot() +function select_emptySlot() -- loop through all slots for slot = 1, 16 do @@ -35,70 +35,96 @@ function selectEmptySlot() end -- countInventory() returns the total --- numer of items in the inventory -function countInventory() - local total = 0 +-- numer of a given minecraft id item in the inventory +function count_inventory(minecraft_id) + local total = 0 - for slot = 1, 16 do - total = total + turtle.getItem(slot) + for slot = 1, 16 do + if turtle.getItemDetail(slot) == 'minecraft:' .. minecraft_id then + total = total + turtle.getItem(slot) end - return total + end + return total end --- selectAndPlaceDown() selects a nonempty slot --- and places a block from it under the turtle -function selectAndPlaceDown() - for slot = 1, 16 do - if turtle.getItemCount(slot) > 0 then - turtle.select(slot) - turtle.placeDown() - return - end +-- selectAndPlaceDown() selects a slot with given +-- minecraft id and places a block from it under the turtle +function select_and_place_down(minecraft_id) + for slot = 1, 16 do + if turtle.getItemDetail(slot) == 'minecraft:' .. minecraft_id then + turtle.select(slot) + turtle.placeDown() + return end + end end --- buildWall() creates a wall stretching +-- build_wall() creates a wall stretching -- in front of the turtle -function buildWall(length, height) - if modules.countInventory() > length * height then - return false --not enough block - end +function build_wall(length, height) + if modules.count_inventory() > length * height then + return false --not enough block + end - turtle.up() + turtle.up() - local movingForward = true + local movingForward = true - for currentHeight = 1, height do - for currentLength = 1, length do - selectAndPlaceDown() -- Place the block - if movingForward and currentLength ~= length then - turtle.forward() - elseif not movingForward and currentLength ~= length then - turtle.back() - end - end - if currentHeight ~= height then - turtle.up() - end - movingForward = not movingForward - end - - -- done building wall; move to end position - if movingForward then - -- turtle is near the start position - for currentLength = 1, length do - turtle.forward() - end - else - -- turtle is near the end position + for currentHeight = 1, height do + for currentLength = 1, length do + select_and_place_down() -- Place the block + if movingForward and currentLength ~= length then turtle.forward() + elseif not movingForward and currentLength ~= length then + turtle.back() + end end - - -- move down to the ground - for currentHeight = 1, height do - turtle.down() + if currentHeight ~= height then + turtle.up() end + movingForward = not movingForward + end - return true + -- done building wall; move to end position + if movingForward then + -- turtle is near the start position + for currentLength = 1, length do + turtle.forward() + end + else + -- turtle is near the end position + turtle.forward() + end + + -- move down to the ground + for currentHeight = 1, height do + turtle.down() + end + + return true +end + +-- build_room() constructs four walls +-- and a ceiling +function build_room(length, width, height) + if modules.count_inventory() < (((length -1) * height * 2) + + ((width -1) * height * 2)) then + return false -- not enough blocks + end + + -- build the four walls + build_wall(length -1, height) + turtle.turnRight() + + build_wall(width - 1, height) + turtle.turnRight() + + build_wall(length - 1, height) + turtle.turnRight() + + build_wall(width - 1, height) + turtle.turnRight() + + return true end