milo: quad cooker
This commit is contained in:
@@ -57,6 +57,7 @@ equip('right', 'plethora:sensor', 'plethora:module:3')
|
|||||||
local sensor = device['plethora:sensor']
|
local sensor = device['plethora:sensor']
|
||||||
|
|
||||||
turtle.setMovementStrategy('goto')
|
turtle.setMovementStrategy('goto')
|
||||||
|
turtle.setPolicy(turtle.policies.attack)
|
||||||
|
|
||||||
function Point.iterateClosest(spt, ipts)
|
function Point.iterateClosest(spt, ipts)
|
||||||
local pts = Util.shallowCopy(ipts)
|
local pts = Util.shallowCopy(ipts)
|
||||||
|
|||||||
@@ -1,54 +1,120 @@
|
|||||||
--[[
|
--[[
|
||||||
Use 4 furnaces at once to smelt items.
|
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.
|
CONFIGURATION:
|
||||||
Export coal to slot 2 of each furnace and import from slot 3.
|
Set turtle as a "Generic Inventory"
|
||||||
|
export coal to slot 2
|
||||||
|
import from slot 3
|
||||||
|
|
||||||
|
Use this turtle for machine crafting.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
_G.requireInjector(_ENV)
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local Util = require('util')
|
local Peripheral = require('peripheral')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
local turtle = _G.turtle
|
local peripheral = _G.peripheral
|
||||||
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local intro =
|
local function equip(side, item, rawName)
|
||||||
device['plethora:introspection']
|
local equipped = Peripheral.lookup('side/' .. side)
|
||||||
local inv = intro.getInventory()
|
|
||||||
|
|
||||||
Event.on('turtle_inventory', function()
|
if equipped and equipped.type == item then
|
||||||
while true do
|
return true
|
||||||
local list = inv.list()
|
end
|
||||||
local sleepTime = 10
|
|
||||||
if Util.empty(list) then
|
if not turtle.equip(side, rawName or item) then
|
||||||
break
|
if not turtle.selectSlotWithQuantity(0) then
|
||||||
|
error('No slots available')
|
||||||
end
|
end
|
||||||
for k,slot in pairs(list) do
|
turtle.equip(side)
|
||||||
for _ = 1, 4 do
|
if not turtle.equip(side, item) then
|
||||||
local count = 0
|
error('Unable to equip ' .. item)
|
||||||
local s, m = pcall(function()
|
end
|
||||||
count = inv.pushItems('front', k, 8, 1)
|
end
|
||||||
end)
|
|
||||||
if not s then
|
turtle.select(1)
|
||||||
_G.printError(m)
|
end
|
||||||
end
|
|
||||||
if count > 0 then
|
equip('left', 'plethora:introspection', 'plethora:module:0')
|
||||||
sleepTime = 0
|
local intro = device['plethora:introspection']
|
||||||
end
|
local inv = intro.getInventory()
|
||||||
turtle.turnRight()
|
local sides = { 'front', 'back', 'right', 'top' }
|
||||||
slot.count = slot.count - count
|
|
||||||
if slot.count <= 0 then
|
-- slot 1: item to cook
|
||||||
break
|
-- 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
|
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
|
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)
|
end)
|
||||||
|
|
||||||
os.queueEvent('turtle_inventory')
|
os.queueEvent('turtle_inventory')
|
||||||
Event.pullEvents()
|
Event.pullEvents()
|
||||||
|
|||||||
Reference in New Issue
Block a user