feat: add simple-harvester
This commit is contained in:
parent
e8ce29bad6
commit
6b8cec89e8
@ -1,5 +1,6 @@
|
|||||||
local LIST_FILES = {
|
local LIST_FILES = {
|
||||||
'miner.lua',
|
'miner.lua',
|
||||||
|
'simple-harvester.lua',
|
||||||
'libs/turtle-utils.lua',
|
'libs/turtle-utils.lua',
|
||||||
'libs/robot.lua'
|
'libs/robot.lua'
|
||||||
};
|
};
|
||||||
|
|||||||
99
simple-harvester.lua
Normal file
99
simple-harvester.lua
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
local VERSION = "0.1.0"
|
||||||
|
local IDLE_TIME = 2
|
||||||
|
|
||||||
|
function isMatureCrop()
|
||||||
|
local isBlock, block = turtle.inspect()
|
||||||
|
|
||||||
|
local blockStateAge = block and block.state and block.state.age
|
||||||
|
return blockStateAge == 7
|
||||||
|
end
|
||||||
|
|
||||||
|
function isInventory()
|
||||||
|
local periph = peripheral.wrap('front')
|
||||||
|
|
||||||
|
if not periph then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return peripheral.hasType(periph, 'inventory')
|
||||||
|
end
|
||||||
|
|
||||||
|
function isSeed(item)
|
||||||
|
local tags = item.tags or {}
|
||||||
|
return tags['forge:seeds'] or tags['mysticalagriculture:seeds'] or false
|
||||||
|
end
|
||||||
|
|
||||||
|
function selectSeed()
|
||||||
|
for i=1, 16,1 do
|
||||||
|
local details = turtle.getItemDetail(i, true)
|
||||||
|
|
||||||
|
if details and isSeed(details) then
|
||||||
|
turtle.select(i)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
error("selectSeed error: seed not found")
|
||||||
|
end
|
||||||
|
|
||||||
|
function strictDrop(idx)
|
||||||
|
if turtle.getSelectedSlot() ~= idx then
|
||||||
|
turtle.select(idx)
|
||||||
|
end
|
||||||
|
|
||||||
|
local ok, err = turtle.drop()
|
||||||
|
|
||||||
|
if not ok then
|
||||||
|
error('strictDrop error: ' .. err)
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function dropAll()
|
||||||
|
for i=1, 16, 1 do
|
||||||
|
local count = turtle.getItemCount(i)
|
||||||
|
|
||||||
|
if count > 0 then
|
||||||
|
strictDrop(i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function waitFor(predicate, sleepTime)
|
||||||
|
while true do
|
||||||
|
local result = predicate()
|
||||||
|
|
||||||
|
if result ~= nil and result ~= false then
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
os.sleep(sleepTime)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function emptyInventory()
|
||||||
|
turtle.turnLeft()
|
||||||
|
turtle.turnLeft()
|
||||||
|
|
||||||
|
waitFor(isInventory, IDLE_TIME)
|
||||||
|
dropAll()
|
||||||
|
|
||||||
|
turtle.turnLeft()
|
||||||
|
turtle.turnLeft()
|
||||||
|
end
|
||||||
|
|
||||||
|
function main()
|
||||||
|
while true do
|
||||||
|
waitFor(isMatureCrop, IDLE_TIME)
|
||||||
|
turtle.dig()
|
||||||
|
selectSeed()
|
||||||
|
turtle.place()
|
||||||
|
emptyInventory()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
print("Starting Trap's simple harvester v" .. VERSION)
|
||||||
|
print("=========================")
|
||||||
|
print()
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user