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