milo: quad cooker
This commit is contained in:
@@ -57,6 +57,7 @@ equip('right', 'plethora:sensor', 'plethora:module:3')
|
||||
local sensor = device['plethora:sensor']
|
||||
|
||||
turtle.setMovementStrategy('goto')
|
||||
turtle.setPolicy(turtle.policies.attack)
|
||||
|
||||
function Point.iterateClosest(spt, ipts)
|
||||
local pts = Util.shallowCopy(ipts)
|
||||
|
||||
@@ -1,54 +1,120 @@
|
||||
--[[
|
||||
Use 4 furnaces at once to smelt items.
|
||||
|
||||
Set up a turtle with a hopper on top and surrounded by furnaces.
|
||||
SETUP:
|
||||
Place an introspection module into the turtles inventory.
|
||||
Connect with wired modem at bottom of turtle.
|
||||
Place furnaces on each side EXCEPT for bottom and right.
|
||||
|
||||
Set the hopper as a machine used for crafting.
|
||||
Export coal to slot 2 of each furnace and import from slot 3.
|
||||
CONFIGURATION:
|
||||
Set turtle as a "Generic Inventory"
|
||||
export coal to slot 2
|
||||
import from slot 3
|
||||
|
||||
Use this turtle for machine crafting.
|
||||
--]]
|
||||
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local Event = require('event')
|
||||
local Util = require('util')
|
||||
local Event = require('event')
|
||||
local Peripheral = require('peripheral')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
local turtle = _G.turtle
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
local turtle = _G.turtle
|
||||
|
||||
local intro =
|
||||
device['plethora:introspection']
|
||||
local inv = intro.getInventory()
|
||||
local function equip(side, item, rawName)
|
||||
local equipped = Peripheral.lookup('side/' .. side)
|
||||
|
||||
Event.on('turtle_inventory', function()
|
||||
while true do
|
||||
local list = inv.list()
|
||||
local sleepTime = 10
|
||||
if Util.empty(list) then
|
||||
break
|
||||
if equipped and equipped.type == item then
|
||||
return true
|
||||
end
|
||||
|
||||
if not turtle.equip(side, rawName or item) then
|
||||
if not turtle.selectSlotWithQuantity(0) then
|
||||
error('No slots available')
|
||||
end
|
||||
for k,slot in pairs(list) do
|
||||
for _ = 1, 4 do
|
||||
local count = 0
|
||||
local s, m = pcall(function()
|
||||
count = inv.pushItems('front', k, 8, 1)
|
||||
end)
|
||||
if not s then
|
||||
_G.printError(m)
|
||||
end
|
||||
if count > 0 then
|
||||
sleepTime = 0
|
||||
end
|
||||
turtle.turnRight()
|
||||
slot.count = slot.count - count
|
||||
if slot.count <= 0 then
|
||||
break
|
||||
turtle.equip(side)
|
||||
if not turtle.equip(side, item) then
|
||||
error('Unable to equip ' .. item)
|
||||
end
|
||||
end
|
||||
|
||||
turtle.select(1)
|
||||
end
|
||||
|
||||
equip('left', 'plethora:introspection', 'plethora:module:0')
|
||||
local intro = device['plethora:introspection']
|
||||
local inv = intro.getInventory()
|
||||
local sides = { 'front', 'back', 'right', 'top' }
|
||||
|
||||
-- slot 1: item to cook
|
||||
-- slot 2: fuel
|
||||
-- slot 3: return
|
||||
|
||||
local active = false
|
||||
|
||||
local function process(list)
|
||||
active = false
|
||||
|
||||
for _, side in ipairs(Util.shallowCopy(sides)) do
|
||||
local f = peripheral.call(side, 'list')
|
||||
|
||||
-- items to cook
|
||||
local item = list[1]
|
||||
local cooking = f[1]
|
||||
|
||||
if cooking or item then
|
||||
active = true
|
||||
end
|
||||
|
||||
if item and item.count > 0 then
|
||||
if not cooking or cooking.name == item.name then
|
||||
local count = cooking and cooking.count or 0
|
||||
if count < 64 then
|
||||
print('cooking : ' .. side)
|
||||
count = inv.pushItems(side, 1, 8, 1)
|
||||
item.count = item.count - count
|
||||
Util.removeByValue(sides, side)
|
||||
table.insert(sides, side)
|
||||
end
|
||||
end
|
||||
end
|
||||
os.sleep(sleepTime)
|
||||
|
||||
-- fuel
|
||||
local fuel = f[2] or { count = 0 }
|
||||
if fuel.count < 8 then
|
||||
print('fueling ' ..side)
|
||||
inv.pushItems(side, 2, 8 - fuel.count, 2)
|
||||
end
|
||||
|
||||
local result = f[3]
|
||||
if result then
|
||||
if not list[3] or result.name == list[3].name then
|
||||
print('pulling from : ' .. side)
|
||||
inv.pullItems(side, 3, result.count, 3)
|
||||
list[3] = result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return active
|
||||
end
|
||||
|
||||
Event.on('turtle_inventory', function()
|
||||
print('processing')
|
||||
while true do
|
||||
-- furnace block updates can cause errors
|
||||
local s = pcall(process, inv.list())
|
||||
if s and not active then
|
||||
break
|
||||
end
|
||||
os.sleep(3)
|
||||
end
|
||||
print('idle')
|
||||
end)
|
||||
|
||||
os.queueEvent('turtle_inventory')
|
||||
Event.pullEvents()
|
||||
Event.pullEvents()
|
||||
|
||||
Reference in New Issue
Block a user