Keine Ahnung was hier los ist
This commit is contained in:
Sascha Martens 2020-11-14 13:47:40 +01:00
commit 68fa543ca7
4 changed files with 1818 additions and 0 deletions

812
Modules/circles.lua Normal file
View File

@ -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_circle_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_row(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_triangle(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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_setup(material, 28)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.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
circles.initial_circle_setup(material, 28)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.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
circles.initial_circle_setup(material, 32)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.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
circles.initial_circle_setup(material, 36)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.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
circles.initial_circle_setup(material, 36)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.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
circles.initial_circle_setup(material, 36)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_diagonal(1, material)
circles.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
circles.initial_circle_setup(material, 44)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_diagonal(1, material)
circles.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
circles.initial_circle_setup(material, 48)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_triangle(material)
circles.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
circles.initial_circle_setup(material, 48)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_diagonal(2, material)
circles.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
circles.initial_circle_setup(material, 52)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_diagonal(2, material)
circles.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
circles.initial_circle_setup(material, 56)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_row(2, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 56)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_diagonal(3, material)
circles.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
circles.initial_circle_setup(material, 60)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_diagonal(3, material)
circles.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
circles.initial_circle_setup(material, 64)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_row(2, material)
circles.place_diagonal(1, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 64)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_diagonal(4, material)
circles.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
circles.initial_circle_setup(material, 68)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_row(2, material)
circles.place_diagonal(2, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 72)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_row(2, material)
circles.place_diagonal(2, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 76)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_diagonal(1, material)
circles.place_row(2, material)
circles.place_column(2, material)
circles.place_diagonal(1, material)
circles.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
circles.initial_circle_setup(material, 76)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_row(2, material)
circles.place_diagonal(3, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 80)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_row(2, material)
circles.place_diagonal(3, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 84)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_diagonal(1, material)
circles.place_row(2, material)
circles.place_diagonal(1, material)
circles.place_column(2, material)
circles.place_diagonal(1, material)
circles.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
circles.initial_circle_setup(material, 84)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_row(2, material)
circles.place_diagonal(4, material)
circles.place_column(2, material)
circles.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

784
Modules/fcircles.lua Normal file
View File

@ -0,0 +1,784 @@
--[[ Modules for generation or building circles in various forms
--filled with another sort of block - 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_circle_setup() checks if there is enough
--material and sets the turtle to the start
--position.
--All circles uses this function
--omaterial = Outer Material
--imaterial = Inner Material
function initial_circle_setup(omaterial, imaterial, omaterial_count, imaterial_count)
-- Check if we have enough material
if modules.count_inventory(omaterial) < omaterial_count then
print('Error! Not enough blocks of ' .. omaterial)
return false
end
if modules.count_inventory(imaterial) < imaterial_count then
print('Error! Not enough blocks of ' .. imaterial)
return false
end
turtle.up()
end
-- go_to_start() brings the turtle back to the starting point
function go_to_start(moving_forward, diameter)
if moving_forward then
-- turtle is on the left position
for i = 1, finished_left do
turtle.forward()
end
turtle.turnLeft()
else
-- turtle is on the right position
for i = 1, finished_right do
turtle.back()
end
turtle.turnLeft()
end
for i = 1, diameter do
turtle.back()
end
--circle3 builds a 3 by 3 wide circle
function circle3(omaterial, imaterial)
-- Definition of the diameter of the circle
local diameter = 3
local moving_forward = true
-- Define the blocks you have to go from left and right,
-- when building is finished, to go back to start
local finished_left = 0
local finished_right = 2
-- Start the initial Setup and place the turtle in
-- the right position
circles.initial_circle_setup(omaterial, imaterial, 8, 1)
turtle.turnLeft()
for i = 1, diameter do
modules.select_and_place_down(material)
for j = 1, diameter -1 do
if moving_forward then
turtle.forward()
elseif not moving_forward then
turtle.back()
modules.select_and_place_down(material)
end
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
moving_forward = not moving_forward
-- Done building, go back to start
go_to_start(moving_forward, diameter)
end
print('Done building a filled 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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_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
circles.initial_circle_setup(material, 28)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.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
circles.initial_circle_setup(material, 28)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.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
circles.initial_circle_setup(material, 32)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.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
circles.initial_circle_setup(material, 36)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.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
circles.initial_circle_setup(material, 36)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.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
circles.initial_circle_setup(material, 36)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_diagonal(1, material)
circles.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
circles.initial_circle_setup(material, 44)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_diagonal(1, material)
circles.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
circles.initial_circle_setup(material, 48)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_triangle(material)
circles.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
circles.initial_circle_setup(material, 48)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_diagonal(2, material)
circles.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
circles.initial_circle_setup(material, 52)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_diagonal(2, material)
circles.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
circles.initial_circle_setup(material, 56)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_row(2, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 56)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_diagonal(3, material)
circles.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
circles.initial_circle_setup(material, 60)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_diagonal(3, material)
circles.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
circles.initial_circle_setup(material, 64)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_row(2, material)
circles.place_diagonal(1, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 64)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_diagonal(4, material)
circles.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
circles.initial_circle_setup(material, 68)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_row(2, material)
circles.place_diagonal(2, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 72)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_row(2, material)
circles.place_diagonal(2, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 76)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_diagonal(1, material)
circles.place_row(2, material)
circles.place_column(2, material)
circles.place_diagonal(1, material)
circles.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
circles.initial_circle_setup(material, 76)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(2, material)
circles.place_row(2, material)
circles.place_diagonal(3, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 80)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_row(2, material)
circles.place_diagonal(3, material)
circles.place_column(2, material)
circles.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
circles.initial_circle_setup(material, 84)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_diagonal(1, material)
circles.place_row(2, material)
circles.place_diagonal(1, material)
circles.place_column(2, material)
circles.place_diagonal(1, material)
circles.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
circles.initial_circle_setup(material, 84)
turtle.turnLeft()
turtle.forward()
for i = 1, 4 do
circles.place_row(3, material)
circles.place_row(2, material)
circles.place_diagonal(4, material)
circles.place_column(2, material)
circles.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

View File

@ -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

131
Modules/modules.lua Normal file
View File

@ -0,0 +1,131 @@
--[[Function Module program by Al Sweigart
Provides useful utility functions.]]
-- selectItem() selects the inventory
-- slot with the named item, returns
-- true if found and false if not
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
end
return false -- couldn't find item
end
-- selectEmptySlot() selects inventory
-- slot that is empty, returns true if
-- found, false if no empty spaces
function select_emptySlot()
-- loop through all slots
for slot = 1, 16 do
if turtle.getItemCount(slot) == 0 then
turtle.select(slot)
return true
end
end
return false -- couldn't find empty space
end
-- countInventory() returns the total
-- numer of a given minecraft id item in the inventory
function count_inventory(minecraft_id)
local total = 0
for slot = 1, 16 do
item = turtle.getItemDetail(slot)
if item ~= nil and item['name'] == 'minecraft:' .. minecraft_id then
total = total + turtle.getItem(slot)
end
end
return total
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
-- build_wall() creates a wall stretching
-- in front of the turtle
function build_wall(length, height)
if modules.count_inventory() > length * height then
return false --not enough block
end
turtle.up()
local movingForward = true
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
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
-- 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