cleanup + adv brewing
This commit is contained in:
@@ -2223,6 +2223,12 @@
|
||||
[ 6 ] = "minecraft:stone:0",
|
||||
},
|
||||
},
|
||||
[ "minecraft:blaze_powder:0" ] = {
|
||||
count = 2,
|
||||
ingredients = {
|
||||
"minecraft:blaze_rod:0",
|
||||
},
|
||||
},
|
||||
[ "minecraft:end_rod:0" ] = {
|
||||
count = 4,
|
||||
ingredients = {
|
||||
|
||||
@@ -7,14 +7,6 @@
|
||||
Turtle crafting:
|
||||
1. The turtle must have a crafting table equipped.
|
||||
2. Equip the turtle with an introspection module.
|
||||
|
||||
Configuration:
|
||||
Configuration file is usr/config/milo
|
||||
|
||||
monitor : valid options include:
|
||||
type/monitor - will use the first monitor found
|
||||
side/north - specify a direction (top/bottom/east/etc)
|
||||
name/monitor_1 - specify the exact name of the peripheral
|
||||
]]--
|
||||
|
||||
_G.requireInjector(_ENV)
|
||||
@@ -27,6 +19,7 @@ local Storage = require('storage')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
local fs = _G.fs
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
@@ -37,8 +30,6 @@ if multishell then
|
||||
end
|
||||
|
||||
local config = {
|
||||
monitor = 'type/monitor',
|
||||
activityMonitor = 'none',
|
||||
nodes = { },
|
||||
}
|
||||
Config.load('milo', config)
|
||||
@@ -54,7 +45,7 @@ if not modem or not modem.getNameLocal then
|
||||
error('Wired modem is not connected')
|
||||
end
|
||||
|
||||
local introspectionModule = Peripheral.get('plethora:introspection') or
|
||||
local introspection = Peripheral.get('plethora:introspection') or
|
||||
error('Introspection module not found')
|
||||
|
||||
local context = {
|
||||
@@ -62,16 +53,17 @@ local context = {
|
||||
resources = Util.readTable(Milo.RESOURCE_FILE) or { },
|
||||
|
||||
craftingQueue = { },
|
||||
|
||||
learnTypes = { },
|
||||
tasks = { },
|
||||
queue = { },
|
||||
|
||||
localName = modem.getNameLocal(),
|
||||
storage = Storage(config),
|
||||
introspectionModule = introspectionModule,
|
||||
turtleInventory = introspection.getInventory(),
|
||||
}
|
||||
|
||||
device[context.localName] = introspection.getInventory()
|
||||
|
||||
_G._p = context --debug
|
||||
|
||||
Event.on('storage_offline', function()
|
||||
|
||||
@@ -161,14 +161,13 @@ function Milo:getTurtleInventory()
|
||||
local list = { }
|
||||
|
||||
for i = 1,16 do
|
||||
local item = self.context.introspectionModule.getInventory().getItemMeta(i)
|
||||
if item then
|
||||
if not itemDB:get(item) then
|
||||
itemDB:add(item)
|
||||
end
|
||||
list[i] = item
|
||||
local item = self.context.turtleInventory.getItemMeta(i)
|
||||
if item and not itemDB:get(item) then
|
||||
itemDB:add(item)
|
||||
end
|
||||
list[i] = item
|
||||
end
|
||||
|
||||
itemDB:flush()
|
||||
return list
|
||||
end
|
||||
|
||||
@@ -225,7 +225,7 @@ function Storage:updateCache(adapter, key, count)
|
||||
entry.key = key
|
||||
adapter.cache[key] = entry
|
||||
else
|
||||
debug('STORAGE: item missing details')
|
||||
_G._debug('STORAGE: item missing details')
|
||||
-- TODO: somehow update itemdb with this maybe new item
|
||||
adapter.dirty = true
|
||||
self.dirty = true
|
||||
@@ -252,11 +252,11 @@ function Storage:export(target, slot, count, item)
|
||||
local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
|
||||
local function provide(adapter)
|
||||
local amount = adapter:provide(item, count, slot, target or self.localName)
|
||||
local amount = adapter:provide(item, count, slot, target)
|
||||
if amount > 0 then
|
||||
|
||||
_G._debug('EXT: %s(%d): %s -> %s%s',
|
||||
item.displayName or item.name, amount, sn(adapter.name), sn(target or self.localName),
|
||||
item.displayName or item.name, amount, sn(adapter.name), sn(target),
|
||||
slot and string.format('[%d]', slot) or '')
|
||||
|
||||
self:updateCache(adapter, key, -amount)
|
||||
@@ -301,12 +301,12 @@ function Storage:import(source, slot, count, item)
|
||||
end
|
||||
|
||||
local function insert(adapter)
|
||||
local amount = adapter:insert(slot, count, nil, source or self.localName)
|
||||
local amount = adapter:insert(slot, count, nil, source)
|
||||
if amount > 0 then
|
||||
|
||||
_G._debug('INS: %s(%d): %s[%d] -> %s',
|
||||
item.displayName or item.name, amount,
|
||||
sn(source or self.localName), slot, sn(adapter.name))
|
||||
sn(source), slot, sn(adapter.name))
|
||||
|
||||
self:updateCache(adapter, key, amount)
|
||||
self:updateCache(self, key, amount)
|
||||
@@ -341,6 +341,16 @@ _G._debug('INS: %s(%d): %s[%d] -> %s',
|
||||
end
|
||||
end
|
||||
|
||||
if not itemDB:get(item) then
|
||||
if not slot then
|
||||
_G._debug("IMPORT: NO SLOT")
|
||||
elseif not device[source] or not device[source].getItemMeta then
|
||||
_G._debug("IMPORT: DEVICE? : " .. source)
|
||||
else
|
||||
itemDB:add(device[source].getItemMeta(slot))
|
||||
end
|
||||
end
|
||||
|
||||
-- high to low priority
|
||||
for remote in self:onlineAdapters() do
|
||||
if count <= 0 then
|
||||
@@ -359,9 +369,9 @@ function Storage:trash(source, slot, count)
|
||||
local trashcan = Util.find(self.nodes, 'mtype', 'trashcan')
|
||||
if trashcan and trashcan.adapter and trashcan.adapter.online then
|
||||
|
||||
_G._debug('TRA: %s[%d] (%d)', sn(source or self.localName), slot, count or 64)
|
||||
_G._debug('TRA: %s[%d] (%d)', sn(source), slot, count or 64)
|
||||
|
||||
return trashcan.adapter.pullItems(source or self.localName, slot, count)
|
||||
return trashcan.adapter.pullItems(source, slot, count)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
@@ -4,7 +4,6 @@ local Util = require('util')
|
||||
local device = _G.device
|
||||
local fs = _G.fs
|
||||
local turtle = _G.turtle
|
||||
local intro = device['plethora:introspection']
|
||||
|
||||
local Craft = {
|
||||
STATUS_INFO = 'info',
|
||||
@@ -37,14 +36,7 @@ end
|
||||
|
||||
function Craft.clearGrid(storage)
|
||||
turtle.eachFilledSlot(function(slot)
|
||||
local item = slot
|
||||
if intro then
|
||||
item = intro.getInventory().getItemMeta(slot.index)
|
||||
if not itemDB:get(item) then
|
||||
itemDB:add(item)
|
||||
end
|
||||
end
|
||||
storage:import(storage.localName, slot.index, slot.count, item)
|
||||
storage:import(storage.localName, slot.index, slot.count, slot)
|
||||
end)
|
||||
|
||||
for i = 1, 16 do
|
||||
|
||||
@@ -52,7 +52,6 @@ function ExportTask:cycle(context)
|
||||
end
|
||||
|
||||
for key in pairs(entry.filter or { }) do
|
||||
-- bad for perf to do listItems each time
|
||||
local items = Milo:getMatches(Milo:listItems(), itemDB:splitKey(key), entry.ignoreDamage, entry.ignoreNbtHash)
|
||||
for _,item in pairs(items) do
|
||||
if item and item.count > 0 then
|
||||
@@ -63,7 +62,9 @@ function ExportTask:cycle(context)
|
||||
else
|
||||
-- _debug('attempting to export %s %d', item.name, item.count)
|
||||
-- TODO: always going to try and export even if the chest is full
|
||||
context.storage:export(machine.name, nil, item.count, item)
|
||||
if context.storage:export(machine.name, nil, item.count, item) == 0 then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -64,7 +64,7 @@ function importView:setNode(node)
|
||||
}
|
||||
|
||||
local m = device[self.machine.name]
|
||||
for k = 1, m.size() do
|
||||
for k = 1, m.size() do
|
||||
table.insert(self.slots.choices, { name = k, value = k })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
local Craft = require('turtle.craft')
|
||||
local Milo = require('milo')
|
||||
local Craft = require('turtle.craft')
|
||||
local itemDB = require('itemDB')
|
||||
local Milo = require('milo')
|
||||
|
||||
local BLAZE_POWDER = "minecraft:blaze_powder:0"
|
||||
|
||||
local PotionImportTask = {
|
||||
name = 'potions',
|
||||
@@ -16,6 +19,20 @@ function PotionImportTask:cycle(context)
|
||||
if bs.adapter.getBrewTime() == 0 then
|
||||
local list = bs.adapter.list()
|
||||
|
||||
-- refill blaze powder
|
||||
if not list[5] then
|
||||
local blazePowder = context.storage.cache[BLAZE_POWDER]
|
||||
if blazePowder then
|
||||
context.storage:export(bs.name, 5, 1, blazePowder)
|
||||
else
|
||||
local item = itemDB:get(BLAZE_POWDER)
|
||||
if item then
|
||||
item.requested = 1
|
||||
Milo:requestCrafting(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if list[1] and not list[4] then
|
||||
-- brewing has completd
|
||||
|
||||
@@ -25,6 +42,7 @@ function PotionImportTask:cycle(context)
|
||||
Milo:saveMachineRecipe(self.brewQueue[bs.name], list[1], bs.name)
|
||||
end
|
||||
end
|
||||
|
||||
for slot = 1, 3 do
|
||||
if list[slot] then
|
||||
context.storage:import(bs.name, slot, 1, list[slot])
|
||||
|
||||
Reference in New Issue
Block a user