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