feat: add coal-crafter
This commit is contained in:
parent
e5e63f4223
commit
115ffd2e78
78
coal-crafter.lua
Normal file
78
coal-crafter.lua
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
local turtleUtils = require('turtle-utils')
|
||||||
|
|
||||||
|
local WAIT_INVENTORY_TIME = 3
|
||||||
|
local IDLE_TIME = 10
|
||||||
|
local MIN_ESSENCE_NEEDED = 8
|
||||||
|
local COAL_ESSENCE_NAME = 'mysticalagriculture:essence_coal'
|
||||||
|
|
||||||
|
-- the slot of the coal essence is returned
|
||||||
|
local function waitForCoalEssence(inventory)
|
||||||
|
|
||||||
|
while true do
|
||||||
|
for slot, item in pairs(inventory.list()) do
|
||||||
|
if item.name == COAL_ESSENCE_NAME and item.count >= MIN_ESSENCE_NEEDED then
|
||||||
|
return slot
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
os.sleep(IDLE_TIME)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function prepareCraftShape()
|
||||||
|
turtle.transferTo(2, 1)
|
||||||
|
turtle.transferTo(3, 1)
|
||||||
|
|
||||||
|
turtle.transferTo(5, 1)
|
||||||
|
turtle.transferTo(7, 1)
|
||||||
|
|
||||||
|
turtle.transferTo(9, 1)
|
||||||
|
turtle.transferTo(10, 1)
|
||||||
|
turtle.transferTo(11, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function craft()
|
||||||
|
local craftOk = turtle.craft()
|
||||||
|
|
||||||
|
if not craftOk then
|
||||||
|
error('cannot craft')
|
||||||
|
end
|
||||||
|
|
||||||
|
return craftOk
|
||||||
|
end
|
||||||
|
|
||||||
|
local functin dropSelected()
|
||||||
|
turtle.turnLeft()
|
||||||
|
turtle.drop()
|
||||||
|
turtle.turnRight()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function main()
|
||||||
|
turtle.select(1)
|
||||||
|
|
||||||
|
print('> Waiting for left inventory (storage)')
|
||||||
|
local storageInventory = turtleUtils.waitForInventory('left', WAIT_INVENTORY_TIME)
|
||||||
|
|
||||||
|
print('> Waiting for the front inventory (buffer chest)')
|
||||||
|
local bufferInventory = turtleUtils.waitForInventory('front', WAIT_INVENTORY_TIME)
|
||||||
|
|
||||||
|
print('> coal-crafter process started')
|
||||||
|
|
||||||
|
while true do
|
||||||
|
storageInventory = turtleUtils.waitForInventory('left', WAIT_INVENTORY_TIME)
|
||||||
|
bufferInventory = turtleUtils.waitForInventory('front', WAIT_INVENTORY_TIME)
|
||||||
|
|
||||||
|
local coalEssenceSlot = waitForCoalEssence(storageInventory)
|
||||||
|
local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), coalEssenceSlot)
|
||||||
|
|
||||||
|
if not pushOk then
|
||||||
|
error('cannot pushItems from storage to buffer')
|
||||||
|
end
|
||||||
|
|
||||||
|
prepareCraftShape()
|
||||||
|
craft()
|
||||||
|
dropSelected()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
main()
|
||||||
@ -1,6 +1,7 @@
|
|||||||
local LIST_FILES = {
|
local LIST_FILES = {
|
||||||
'old/simple-harvester.lua',
|
'old/simple-harvester.lua',
|
||||||
'miner.lua',
|
'miner.lua',
|
||||||
|
'coal-crafter.lua',
|
||||||
'inferium-upgrader.lua',
|
'inferium-upgrader.lua',
|
||||||
'inferium-harvester.lua'
|
'inferium-harvester.lua'
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user