Added a build_pipe app, which builds pipes. Additionally the fvcircles

module checks for n iterations of building a circle
This commit is contained in:
Sascha Martens 2020-11-20 22:35:04 +01:00
parent 33043a6d56
commit e68905578f
3 changed files with 21 additions and 9 deletions

View File

@ -17,12 +17,12 @@ end
function initial_full_circle_setup(omaterial, omaterial_count, imaterial, imaterial_count) function initial_full_circle_setup(omaterial, omaterial_count, imaterial, imaterial_count)
-- Check if we have enough material -- Check if we have enough material
if modules.count_inventory(omaterial) < omaterial_count then if modules.count_inventory(omaterial) < omaterial_count then
error('Error! Not enough blocks of ' .. omaterial) error('Error! Not enough blocks of ' .. omaterial .. '. You need ' .. omaterial_count .. omaterial)
return false return false
end end
if modules.count_inventory(imaterial) < imaterial_count then if modules.count_inventory(imaterial) < imaterial_count then
error('Error! Not enough blocks of ' .. imaterial) error('Error! Not enough blocks of ' .. imaterial .. '. You need ' .. imaterial_count .. imaterial)
return false return false
end end
@ -31,10 +31,19 @@ end
--fvcircle5 builds a vertical 5 by 5 circle --fvcircle5 builds a vertical 5 by 5 circle
--which are filled with another material --which are filled with another material
function fvcircle5(omaterial, imaterial) function fvcircle5(omaterial, imaterial, times)
-- times checks how often this function should be called
-- this is only for checking, if we have enough blocks in
-- our inventory
times = times or 1
omatcount = 12 * times
imatcount = 9 * times
-- Start the initial Setup and place the turtle in -- Start the initial Setup and place the turtle in
-- the right position -- the right position
fvcircles.initial_full_circle_setup(omaterial, 12, imaterial, 9) fvcircles.initial_full_circle_setup(omaterial, omatcount, imaterial, imatcount)
-- First Row -- First Row
turtle.turnLeft() turtle.turnLeft()
@ -55,6 +64,8 @@ function fvcircle5(omaterial, imaterial)
turtle.forward() turtle.forward()
modules.select_and_place_down(imaterial) modules.select_and_place_down(imaterial)
turtle.forward() turtle.forward()
modules.select_and_place_down(imaterial)
turtle.forward()
modules.select_and_place_down(omaterial) modules.select_and_place_down(omaterial)
turtle.up() turtle.up()
end end

View File

@ -35,14 +35,14 @@ function select_emptySlot()
end end
-- countInventory() returns the total -- countInventory() returns the total
-- numer of a given minecraft id item in the inventory -- number of a given minecraft id item in the inventory
function count_inventory(minecraft_id) function count_inventory(minecraft_id, times)
local total = 0 local total = 0
for slot = 1, 16 do for slot = 1, 16 do
item = turtle.getItemDetail(slot) item = turtle.getItemDetail(slot)
if item ~= nil and item['name'] == 'minecraft:' .. minecraft_id then if item ~= nil and item['name'] == 'minecraft:' .. minecraft_id then
total = total + turtle.getItem(slot) total = total + turtle.getItemCount(slot)
end end
end end
return total return total
@ -52,7 +52,8 @@ end
-- minecraft id and places a block from it under the turtle -- minecraft id and places a block from it under the turtle
function select_and_place_down(minecraft_id) function select_and_place_down(minecraft_id)
for slot = 1, 16 do for slot = 1, 16 do
if turtle.getItemDetail(slot) == 'minecraft:' .. minecraft_id then item = turtle.getItemDetail(slot)
if item ~= nil and item['name'] == 'minecraft:' .. minecraft_id then
turtle.select(slot) turtle.select(slot)
turtle.placeDown() turtle.placeDown()
return return

View File

@ -21,7 +21,7 @@ local imaterial = read()
print("Building a " .. pipes .. " blocks long tunnel") print("Building a " .. pipes .. " blocks long tunnel")
for i = 1, pipes do for i = 1, pipes do
turtle.down() turtle.down()
fvcircles.fvcircle5(omaterial, imaterial) fvcircles.fvcircle5(omaterial, imaterial, pipes)
end end
print("Done build the tunnel") print("Done build the tunnel")