plethora import/export support
This commit is contained in:
@@ -14,11 +14,11 @@ function ChestAdapter:init(args)
|
|||||||
|
|
||||||
local chest
|
local chest
|
||||||
if not self.side then
|
if not self.side then
|
||||||
chest = Peripheral.getByMethod('list')
|
chest = Peripheral.getByMethod('list') or
|
||||||
-- or Peripheral.getByMethod('listAvailableItems')
|
Peripheral.getByMethod('listAvailableItems')
|
||||||
else
|
else
|
||||||
chest = Peripheral.getBySide(self.side)
|
chest = Peripheral.getBySide(self.side)
|
||||||
if chest and not chest.list then -- and not chest.listAvailableItems then
|
if chest and not chest.list and not chest.listAvailableItems then
|
||||||
chest = nil
|
chest = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ local Util = require('util')
|
|||||||
|
|
||||||
local MEAdapter = class(RSAdapter)
|
local MEAdapter = class(RSAdapter)
|
||||||
|
|
||||||
|
local DEVICE_TYPE = 'appliedenergistics2:interface'
|
||||||
|
|
||||||
function MEAdapter:init(args)
|
function MEAdapter:init(args)
|
||||||
local defaults = {
|
local defaults = {
|
||||||
name = 'appliedEnergistics',
|
name = 'appliedEnergistics',
|
||||||
@@ -15,12 +17,9 @@ function MEAdapter:init(args)
|
|||||||
|
|
||||||
local controller
|
local controller
|
||||||
if not self.side then
|
if not self.side then
|
||||||
controller = Peripheral.getByMethod('getCraftingCPUs')
|
controller = Peripheral.getByType(DEVICE_TYPE)
|
||||||
else
|
else
|
||||||
controller = Peripheral.getBySide(self.side)
|
controller = Peripheral.getBySide(self.side)
|
||||||
if controller and not controller.getCraftingCPUs then
|
|
||||||
controller = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if controller then
|
if controller then
|
||||||
@@ -29,68 +28,60 @@ function MEAdapter:init(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function MEAdapter:isValid()
|
function MEAdapter:isValid()
|
||||||
return not not self.getCraftingCPUs
|
return self.type == DEVICE_TYPE and not not self.findItems
|
||||||
|
end
|
||||||
|
|
||||||
|
function MEAdapter:clearFinished()
|
||||||
|
for _,key in pairs(Util.keys(self.jobList)) do
|
||||||
|
local job = self.jobList[key]
|
||||||
|
if job.info.status() == 'finished' then
|
||||||
|
self.jobList[key] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function MEAdapter:isCPUAvailable()
|
function MEAdapter:isCPUAvailable()
|
||||||
local cpus = self.getCraftingCPUs() or { }
|
local cpus = self.getCraftingCPUs() or { }
|
||||||
local available = false
|
local busy = 0
|
||||||
|
|
||||||
for cpu,v in pairs(cpus) do
|
for _,cpu in pairs(cpus) do
|
||||||
if not v.busy then
|
if cpu.busy then
|
||||||
available = true
|
busy = busy + 1
|
||||||
elseif not self.jobList[cpu] then -- something else is crafting something (don't know what)
|
|
||||||
return false -- return false since we are in an unknown state
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return available
|
self:clearFinished()
|
||||||
|
return busy == Util.size(self.jobList) and busy < #cpus
|
||||||
end
|
end
|
||||||
|
|
||||||
function MEAdapter:craft(item, qty)
|
function MEAdapter:craft(item, count)
|
||||||
if not self:isCPUAvailable() then
|
if not self:isCPUAvailable() then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local detail = self.findItem(item)
|
local detail = self.findItem(item)
|
||||||
if detail and detail.craft then
|
if detail and detail.craft then
|
||||||
|
local info = detail.craft(count or 1)
|
||||||
local cpus = self.getCraftingCPUs() or { }
|
if info.status() == 'unknown' then
|
||||||
for cpu,v in pairs(cpus) do
|
self.jobList[info.getId()] = {
|
||||||
if not v.busy then
|
name = item.name,
|
||||||
self.requestCrafting({
|
damage = item.damage,
|
||||||
id = item.name,
|
nbtHash = item.nbtHash,
|
||||||
dmg = item.damage,
|
info = info,
|
||||||
nbt_hash = item.nbtHash,
|
}
|
||||||
},
|
return true
|
||||||
count or 1,
|
|
||||||
v.name -- CPUs must be named ! use anvil
|
|
||||||
)
|
|
||||||
|
|
||||||
os.sleep(0) -- needed ?
|
|
||||||
cpus = self.getCraftingCPUs() or { }
|
|
||||||
|
|
||||||
if cpus[cpu].busy then
|
|
||||||
self.jobList[cpu] = {
|
|
||||||
name = item.name,
|
|
||||||
damage = item.damage,
|
|
||||||
nbtHash = item.nbtHash,
|
|
||||||
count = count,
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
break -- only need to try the first available cpu
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function MEAdapter:isCrafting(item)
|
function MEAdapter:isCrafting(item)
|
||||||
for _,task in pairs(self.getCraftingTasks()) do
|
self:clearFinished()
|
||||||
local output = task.getPattern().outputs[1]
|
_G._p = self.jobList
|
||||||
if output.name == item.name and
|
for _,job in pairs(self.jobList) do
|
||||||
output.damage == item.damage and
|
if job.name == item.name and
|
||||||
output.nbtHash == item.nbtHash then
|
job.damage == item.damage and
|
||||||
|
job.nbtHash == item.nbtHash then
|
||||||
|
debug('still crafting')
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ function RefinedAdapter:init(args)
|
|||||||
controller = Peripheral.getByMethod('getCraftingTasks')
|
controller = Peripheral.getByMethod('getCraftingTasks')
|
||||||
else
|
else
|
||||||
controller = Peripheral.getBySide(self.side)
|
controller = Peripheral.getBySide(self.side)
|
||||||
if controller and not controller.getCraftingTasks then
|
|
||||||
controller = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if controller then
|
if controller then
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ local config = {
|
|||||||
|
|
||||||
Config.loadWithCheck('inventoryManager', config)
|
Config.loadWithCheck('inventoryManager', config)
|
||||||
|
|
||||||
local controllerAdapter = ControllerAdapter.wrap({ side = config.controller, facing = config.computerFacing })
|
--local controllerAdapter = ControllerAdapter.wrap({ side = config.controller, facing = config.computerFacing })
|
||||||
local inventoryAdapter = InventoryAdapter.wrap({ side = config.inventory, facing = config.computerFacing })
|
local inventoryAdapter = InventoryAdapter.wrap({ side = config.inventory, facing = config.computerFacing })
|
||||||
local stockAdapter = InventoryAdapter.wrap({ side = config.stock, facing = config.computerFacing })
|
local stockAdapter = InventoryAdapter.wrap({ side = config.stock, facing = config.computerFacing })
|
||||||
local turtleChestAdapter = InventoryAdapter.wrap({ side = config.craftingChest, facing = config.computerFacing })
|
local turtleChestAdapter = InventoryAdapter.wrap({ side = config.craftingChest, facing = config.computerFacing })
|
||||||
@@ -133,6 +133,11 @@ if not inventoryAdapter then
|
|||||||
error('Invalid inventory configuration')
|
error('Invalid inventory configuration')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local controllerAdapter
|
||||||
|
if inventoryAdapter.craft then
|
||||||
|
controllerAdapter = inventoryAdapter
|
||||||
|
end
|
||||||
|
|
||||||
if device.workbench and config.duckAntenna then
|
if device.workbench and config.duckAntenna then
|
||||||
local oppositeSide = {
|
local oppositeSide = {
|
||||||
[ 'left' ] = 'right',
|
[ 'left' ] = 'right',
|
||||||
|
|||||||
Reference in New Issue
Block a user