perf(inferium-harvester): do not continue replant when inventory is empty
This commit is contained in:
parent
88d7b6dcc8
commit
4502db1ba1
@ -2,7 +2,7 @@ local net = require('libs/net')
|
||||
local utils = require('libs/utils')
|
||||
local turtleUtils = require('libs/turtle-utils')
|
||||
|
||||
local VERSION = "4.0.0"
|
||||
local VERSION = "4.0.1"
|
||||
local INFERIUM_SERVER = 'inferium.com'
|
||||
local IDLE_TIME = 2
|
||||
local WAIT_ITEM_IDLE_TIME = 5
|
||||
@ -364,6 +364,7 @@ local function removeSeeds(seeds, config)
|
||||
print('> remove ' .. utils.sizeof(seeds) .. ' seed(s)')
|
||||
local stateSeeds = seeds -- warning: do not mutate the data (only the ref)
|
||||
|
||||
local nbBlockTraveled = 0
|
||||
for i=1, config.length, 1 do
|
||||
local ok, block = turtle.inspectDown()
|
||||
local blockName = block and block.name
|
||||
@ -372,6 +373,7 @@ local function removeSeeds(seeds, config)
|
||||
|
||||
if found then
|
||||
local digOk = turtle.digDown()
|
||||
|
||||
compactIfNeeded()
|
||||
|
||||
if not digOk then
|
||||
@ -383,16 +385,15 @@ local function removeSeeds(seeds, config)
|
||||
|
||||
if i ~= config.length then
|
||||
forward()
|
||||
nbBlockTraveled = nbBlockTraveled + 1
|
||||
end
|
||||
end
|
||||
|
||||
turtle.turnLeft()
|
||||
turtle.turnLeft()
|
||||
|
||||
for i=1, config.length, 1 do
|
||||
if i ~= config.length then
|
||||
forward()
|
||||
end
|
||||
for i=1, nbBlockTraveled, 1 do
|
||||
forward()
|
||||
end
|
||||
|
||||
goBackToHome(config)
|
||||
@ -467,6 +468,7 @@ local function replantSeeds(config)
|
||||
|
||||
print('> replant seeds')
|
||||
|
||||
local nbBlockTraveled = 0
|
||||
for i=1, config.length, 1 do
|
||||
local ok, block = turtle.inspectDown()
|
||||
|
||||
@ -477,20 +479,23 @@ local function replantSeeds(config)
|
||||
end)
|
||||
|
||||
turtle.placeDown()
|
||||
|
||||
if turtleUtils.isInventoryEmpty() then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if i ~= config.length then
|
||||
forward()
|
||||
nbBlockTraveled = nbBlockTraveled + 1
|
||||
end
|
||||
end
|
||||
|
||||
turtle.turnLeft()
|
||||
turtle.turnLeft()
|
||||
|
||||
for i=1, config.length, 1 do
|
||||
if i ~= config.length then
|
||||
forward()
|
||||
end
|
||||
for i=1, nbBlockTraveled, 1 do
|
||||
forward()
|
||||
end
|
||||
|
||||
goBackToHome(config)
|
||||
|
||||
@ -25,6 +25,16 @@ turtleUtils.getInventory = function(side)
|
||||
return nil
|
||||
end
|
||||
|
||||
turtleUtils.isInventoryEmpty = function()
|
||||
for i=1, 16, 1 do
|
||||
if turtle.getItemCount(i) > 0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
turtleUtils.getItemName = function(slotIndex)
|
||||
local item = turtle.getItemDetail(slotIndex)
|
||||
return item and item.name
|
||||
|
||||
Loading…
Reference in New Issue
Block a user