Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local gpu = component.gpu -- get primary gpu component
- local Robot = require("robotModule")
- --[[
- Class Farmer
- ]]--
- Farmer = Robot:new()
- function Farmer:new(x, y, z, f, invIgnore, size, wait, useItem)
- local o = Robot:new(x, y, z, f, invIgnore)
- setmetatable(o, self)
- self.__index = self
- self.size = size
- self.wait = wait
- self.placing = true
- self.useItem = useItem or false
- return o
- end
- function Farmer:selectSeed()
- local index = -1
- if not self.isTest then
- for i = 1, self.invIgnore do
- if self.robot.count(16 - i + 1) > 1 then
- index = 16 - i + 1
- break
- end
- end
- end
- return index
- end
- function Farmer:step()
- self:setLightColor("green")
- self:setState((self.placing and "Planting" or "Gathering") .. " : x = " .. self.x .. " / y = " .. self.y .. " / z = " .. self.z)
- if not self.isTest then
- if self.placing then
- local seedIndex = self:selectSeed()
- if seedIndex <= 0 then
- return false
- end
- self.robot.useDown()
- self.robot.select(seedIndex)
- self.robot.placeDown()
- else
- if self.useItem then
- self.robot.useDown()
- else
- self.robot.swingDown()
- end
- self.robot.suckDown()
- end
- else
- os.sleep(1)
- end
- return true
- end
- function Farmer:displayFarm()
- self:displayInfo()
- local width, height = gpu.getViewport()
- for i = 0, self.size do
- local line = ""
- for j = 0, self.size do
- if i == self.x - self.startX and j == self.y - self.startY then
- line = line .. " X"
- elseif i ~= 0 and j ~= 0 then
- line = line .. " -"
- else
- line = line .. " "
- end
- end
- gpu.set((width / 2) - string.len(line) / 2, 4 + i, line)
- end
- end
- function Farmer:farm()
- self.goHome = false
- if self.f ~= self.startF then
- self:turnTowards(self.startF)
- end
- for i = 1, self.size do
- for j = 1, self.size do
- self:moveTo(self.startX + i, self.startY + ((i % 2 == 0) and (self.size - j + 1) or j), self.startZ + 1, false)
- if not self:step() then
- self.goHome = true
- self:setLightColor("yellow")
- self:setState("No more seed, going home")
- break
- end
- end
- if self.goHome then
- break
- end
- end
- self:dropInventory()
- if self.placing then
- for i = 1, self.wait do
- self:setLightColor("blue")
- self:setState("Waiting " .. tostring(self.wait - i) .. " minutes")
- os.sleep(60)
- end
- self:setState("Shit! Here we go again!")
- end
- self.placing = not self.placing
- return true
- end
- return Farmer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement