FarmingTurtle/Turtle/Wheat.lua
2023-01-08 16:19:12 +00:00

86 lines
2.0 KiB
Lua

require("Turtle")
Wheat = Turtle:new()
function Wheat:getStatusDown()
local bd, data = turtle.inspectDown()
if(bd == true) then
if(data.state.age == nil) then
return -1
end
return data.state.age
end
if(turtle.digDown() == true) then
return -2
end
if(self:selectPlantable(true)) then
if(turtle.placeDown() == true) then
turtle.digDown()
return -2
end
return -1
end
return false
end
function Wheat:isPlantable(slot, update)
self:assertInvUpdate(update)
if(type(self.inv[slot]) ~= "table") then
return false
end
if(type(self.inv[slot].tags) ~= "table") then
return false
end
return self.inv[slot].tags["forge:seeds"] == true
end
function Wheat:getPlantable(update)
self:assertInvUpdate(update)
for i = 1, 16 do
if(self:isPlantable(i, false)) then
return i
end
end
return false
end
function Wheat:selectPlantable(update)
self:assertInvUpdate(update)
local slot = self:getPlantable(false)
if(slot == false) then
return false
else
turtle.select(slot)
return true
end
end
function Wheat:readConfig(path)
-- reading configFile into a table
if (path == nil) then
term.write("init must have a path for the config file as argument")
return -1
end
if (type(path) ~= "string") then
term.write("invalid argument")
return -1
end
if (not fs.exists(path)) then
term.write("could not find config file \n please make sure it exists and the path is correct")
return -1
end
local file = fs.open(path, "r")
local config = {}
while true do
local line = file.readLine()
if not line then
break
end
local numLine = tonumber(line)
config[#config+1] = numLine
end
file.close()
self.homePos = {config[1], config[2], config[3], config[4]}
self.length = config[5]
self.width = config[6]
end