plethora import/export support + introspection module

This commit is contained in:
kepler155c
2018-03-29 07:04:56 -04:00
parent 08bc0d578e
commit 3d1ee74f0f
3 changed files with 104 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ local Adapter = { }
function Adapter.wrap(args)
local adapters = {
'refinedAdapter',
'meAdapter18',
'chestAdapter18',
-- adapters for version 1.7

100
apis/meAdapter18.lua Normal file
View File

@@ -0,0 +1,100 @@
local class = require('class')
local RSAdapter = require('refinedAdapter')
local Peripheral = require('peripheral')
local Util = require('util')
local MEAdapter = class(RSAdapter)
function MEAdapter:init(args)
local defaults = {
name = 'appliedEnergistics',
jobList = { },
}
Util.merge(self, defaults)
Util.merge(self, args)
local controller
if not self.side then
controller = Peripheral.getByMethod('getCraftingCPUs')
else
controller = Peripheral.getBySide(self.side)
if controller and not controller.getCraftingCPUs then
controller = nil
end
end
if controller then
Util.merge(self, controller)
end
end
function MEAdapter:isValid()
return not not self.getCraftingCPUs
end
function MEAdapter:isCPUAvailable()
local cpus = self.getCraftingCPUs() or { }
local available = false
for cpu,v in pairs(cpus) do
if not v.busy then
available = true
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
return available
end
function MEAdapter:craft(item, qty)
if not self:isCPUAvailable() then
return false
end
local detail = self.findItem(item)
if detail and detail.craft then
local cpus = self.getCraftingCPUs() or { }
for cpu,v in pairs(cpus) do
if not v.busy then
self.requestCrafting({
id = item.name,
dmg = item.damage,
nbt_hash = item.nbtHash,
},
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
return false
end
end
function MEAdapter:isCrafting(item)
for _,task in pairs(self.getCraftingTasks()) do
local output = task.getPattern().outputs[1]
if output.name == item.name and
output.damage == item.damage and
output.nbtHash == item.nbtHash then
return true
end
end
return false
end
return MEAdapter

View File

@@ -14,10 +14,10 @@ function RefinedAdapter:init(args)
local controller
if not self.side then
controller = Peripheral.getByMethod('listAvailableItems')
controller = Peripheral.getByMethod('getCraftingTasks')
else
controller = Peripheral.getBySide(self.side)
if controller and not controller.listAvailableItems then
if controller and not controller.getCraftingTasks then
controller = nil
end
end
@@ -28,7 +28,7 @@ function RefinedAdapter:init(args)
end
function RefinedAdapter:isValid()
return not not self.listAvailableItems
return not not self.getCraftingTasks
end
function RefinedAdapter:getItemDetails(item)