Skip to content
Snippets Groups Projects
Commit 5dd8ace2 authored by Rodrigo Amaral's avatar Rodrigo Amaral
Browse files

V1.5

parent 6fe5b6e2
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,8 @@ local N_COLS = 4
local FUEL_LOW_LIMIT = 2096
-- Amount of fuel items consumed on a single refuel
local REFUEL_AMOUNT = 4
-- Minimum stack size for fuel item (on slot 1)
local N_FUEL_STOCK = 8
-- Amount of layers of N_ROWS by N_COLS wide to be dug, if 0 then infinite amount of layers
-- Relative to what? Layer (y) at which turtle starts, buddy
......@@ -28,19 +30,6 @@ function Is_Even(num)
end
end
-- Performs a fuel check and attempts to refuel from slot 1
function Fuel_Check()
local fuel_level = turtle.getFuelLevel()
if fuel_level < FUEL_LOW_LIMIT then
turtle.select(1)
if(not turtle.refuel(REFUEL_AMOUNT)) then
print("Couldn't Refuel Turtle!'")
return false
end
end
return true
end
-- Checks if slot 16 has an item, returns true if so
function Check_FullInv()
if (turtle.getItemCount(16) == 0) then
......@@ -57,19 +46,46 @@ function Place_Items()
turtle.select(i)
turtle.drop()
end
turtle.select(1)
end
function Restock_Fuel()
turtle.turnRight()
turtle.suck(turtle.getItemSpace(1))
turtle.turnLeft()
end
function Inventory_Routine()
-- Goes home, unloads items and goes back
function Home_Routine()
--Check if Last Inventory spot is used, if so unload
if(Check_FullInv()) then
Go_Home()
Place_Items()
Restock_Fuel()
turtle.turnLeft()
turtle.turnLeft()
Go_Back()
end
end
-- Performs a fuel check and attempts to refuel from slot 1
function Fuel_Check()
local fuel_level = turtle.getFuelLevel()
if fuel_level < FUEL_LOW_LIMIT then
turtle.select(1)
-- Restock Fuel if fuel stock below N_FUEL_STOCK
if(turtle.getItemCount(1) < N_FUEL_STOCK) then
Home_Routine()
end
if(not turtle.refuel(REFUEL_AMOUNT)) then
print("Couldn't Refuel Turtle!'")
return false
end
end
return true
end
-- Tries to dig in front of turtle, if inventory is full empties the inventory at home and then returns
function Dig_Infront()
local r, err = turtle.dig()
......@@ -349,7 +365,7 @@ function Mine_1Layer()
Count_Row()
-- Check if inventory is full
Inventory_Routine()
Home_Routine()
end
-- turn
......@@ -381,7 +397,7 @@ function Mine_1Layer()
turtle.turnRight()
end
Inventory_Routine()
Home_Routine()
Fuel_Check()
end
......@@ -395,7 +411,7 @@ function Mine_1Layer()
Count_Row()
-- Check if inventory is full
Inventory_Routine()
Home_Routine()
end
return 0
......@@ -429,6 +445,8 @@ function Main()
end
CURRENT_LAYER = CURRENT_LAYER + 1
Home_Routine()
end
return 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment