This commit is contained in:
Julian Brammer 2024-06-15 00:34:53 +02:00
parent 35bcf0200d
commit 36dce7eff9

View File

@ -61,6 +61,32 @@ local function itemInInventory()
end end
local function countBlocks(matrix)
local counter = 0
for i=1, #matrix do
for j=1, #matrix[i] do
if matrix[i][j] == 1 then
counter = counter + 1
end
end
end
return counter
end
local function confirmationDialog(input)
if input == "y" or input == "yes" then
return true
elseif input == "n" or input == "no" then
return false
else
print("confirmationDialogError")
return "Error"
end
end
local function printLayer(matrix, withChest) local function printLayer(matrix, withChest)
--for i=1, #matrix do --for i=1, #matrix do
for i=#matrix, 1, -1 do for i=#matrix, 1, -1 do
@ -80,50 +106,22 @@ local function printLayer(matrix, withChest)
turtle.forward() turtle.forward()
turtle.turnLeft() turtle.turnLeft()
end end
turtle.turnLeft()
-- go back to start
for i=#matrix, 1, -1 do
turtle.back()
end
turtle.turnLeft()
end end
local function printLayers(matrix, withChest, height)
local function printAwesome(matrix, withChest, height) for i=1, height do
printLayer(matrix, withChest)
end turtle.up()
local function countBlocks(matrix)
local counter = 0
for i=1, #matrix do
for j=1, #matrix[i] do
if matrix[i][j] == 1 then
counter = counter + 1
end
end
end
return counter
end
local function confirmationDialog(input)
if input == "y" or input == "yes" then
return true
elseif input == "n" or input == "no" then
return false
else
print("confirmationDialogError")
return "Error"
end end
end end
function main() function main()
print("Print with Chest? [yn]") print("Print with Chest? [yn]")
local withChest = confirmationDialog(read()) local withChest = confirmationDialog(read())
@ -136,15 +134,22 @@ function main()
matrix = createMatrix(filePath, dim) matrix = createMatrix(filePath, dim)
blockCounter = countBlocks(matrix) local blocksPerLayer = countBlocks(matrix)
print("One Layer would need " .. blockCounter .. " Blocks.") print("How many Layers?")
local height = read()
local blocksForAllLayers = blocksPerLayer * height
print("One Layer would need " .. blocksPerLayer .. " Blocks.")
print(height .. " Layers would need " .. blocksForAllLayers .. " Blocks (" .. blocksForAllLayers/64 .. " Stacks)")
print("Continue? [yn]") print("Continue? [yn]")
local startPrinting = confirmationDialog(read()) local startPrinting = confirmationDialog(read())
if startPrinting then if startPrinting then
printLayer(matrix, withChest) printLayers(matrix, withChest, height)
--printLayer(matrix, withChest)
end end
end end