diff --git a/Rod_Quarry.lua b/Rod_Quarry.lua index 6e7f9557b84d40a10cf8bff8bb86855871280304..f7b1da58254d572820cb405f88c8be8f8545303d 100644 --- a/Rod_Quarry.lua +++ b/Rod_Quarry.lua @@ -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