feat(coal-crafter): stop crafting coal when a certain threshold is reached
This commit is contained in:
parent
d971f0acf3
commit
694a23fb68
@ -1,9 +1,26 @@
|
|||||||
local turtleUtils = require('libs/turtle-utils')
|
local turtleUtils = require('libs/turtle-utils')
|
||||||
|
|
||||||
|
local NB_NEEDED_COAL = 256
|
||||||
local WAIT_INVENTORY_TIME = 3
|
local WAIT_INVENTORY_TIME = 3
|
||||||
local IDLE_TIME = 10
|
local IDLE_TIME = 30
|
||||||
|
local IDLE_TIME_ENOUGH_COAL = 120
|
||||||
local MIN_ESSENCE_NEEDED = 8
|
local MIN_ESSENCE_NEEDED = 8
|
||||||
local COAL_ESSENCE_NAME = 'mysticalagriculture:coal_essence'
|
local COAL_ESSENCE_NAME = 'mysticalagriculture:coal_essence'
|
||||||
|
local COAL_NAME = 'minecraft:coal'
|
||||||
|
|
||||||
|
local function waitForNotEnoughCoal(inventory)
|
||||||
|
while true do
|
||||||
|
for slot, item in pairs(inventory.list()) do
|
||||||
|
local enoughCoal = item.name == COAL_NAME and item.count >= NB_NEEDED_COAL
|
||||||
|
|
||||||
|
if not enoughCoal then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
os.sleep(IDLE_TIME_ENOUGH_COAL)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- the slot of the coal essence is returned
|
-- the slot of the coal essence is returned
|
||||||
local function waitForCoalEssence(inventory)
|
local function waitForCoalEssence(inventory)
|
||||||
@ -89,6 +106,7 @@ local function main()
|
|||||||
storageInventory = turtleUtils.waitForInventory('back', WAIT_INVENTORY_TIME)
|
storageInventory = turtleUtils.waitForInventory('back', WAIT_INVENTORY_TIME)
|
||||||
bufferInventory = turtleUtils.waitForInventory('front', WAIT_INVENTORY_TIME)
|
bufferInventory = turtleUtils.waitForInventory('front', WAIT_INVENTORY_TIME)
|
||||||
|
|
||||||
|
waitForNotEnoughCoal(storageInventory)
|
||||||
local coalEssenceSlot = waitForCoalEssence(storageInventory)
|
local coalEssenceSlot = waitForCoalEssence(storageInventory)
|
||||||
local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), coalEssenceSlot, MIN_ESSENCE_NEEDED)
|
local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), coalEssenceSlot, MIN_ESSENCE_NEEDED)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user