refined storage initial update - wip
This commit is contained in:
@@ -147,18 +147,6 @@ function ChestAdapter:provide(item, qty, slot, direction)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestAdapter:eject(item, qty, direction)
|
|
||||||
if not _G.turtle then
|
|
||||||
error('Only a turtle can eject')
|
|
||||||
end
|
|
||||||
|
|
||||||
local s, m = pcall(function()
|
|
||||||
self:provide(item, qty)
|
|
||||||
_G.turtle.emptyInventory()
|
|
||||||
end)
|
|
||||||
return s, m
|
|
||||||
end
|
|
||||||
|
|
||||||
function ChestAdapter:extract(slot, qty, toSlot)
|
function ChestAdapter:extract(slot, qty, toSlot)
|
||||||
if toSlot then
|
if toSlot then
|
||||||
self.pushItemIntoSlot(self.direction, slot, qty, toSlot)
|
self.pushItemIntoSlot(self.direction, slot, qty, toSlot)
|
||||||
|
|||||||
@@ -146,32 +146,6 @@ function ChestAdapter:provide(item, qty, slot, direction)
|
|||||||
return s, m
|
return s, m
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestAdapter:eject(item, qty, direction)
|
|
||||||
|
|
||||||
-- fix
|
|
||||||
direction = self.getMetadata().state.facing
|
|
||||||
|
|
||||||
local s, m = pcall(function()
|
|
||||||
local stacks = self.list()
|
|
||||||
local maxStack = itemDB:getMaxCount(item)
|
|
||||||
for key,stack in Util.rpairs(stacks) do
|
|
||||||
if stack.name == item.name and
|
|
||||||
(not item.damage or stack.damage == item.damage) and
|
|
||||||
(not item.nbtHash or stack.nbtHash == item.nbtHash) then
|
|
||||||
local amount = math.min(maxStack, math.min(qty, stack.count))
|
|
||||||
if amount > 0 then
|
|
||||||
self.drop(key, amount, direction)
|
|
||||||
end
|
|
||||||
qty = qty - amount
|
|
||||||
if qty <= 0 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
return s, m
|
|
||||||
end
|
|
||||||
|
|
||||||
function ChestAdapter:extract(slot, qty, toSlot)
|
function ChestAdapter:extract(slot, qty, toSlot)
|
||||||
self.pushItems(self.direction, slot, qty, toSlot)
|
self.pushItems(self.direction, slot, qty, toSlot)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local Adapter = { }
|
|||||||
|
|
||||||
function Adapter.wrap(args)
|
function Adapter.wrap(args)
|
||||||
local adapters = {
|
local adapters = {
|
||||||
--'refinedAdapter',
|
'refinedAdapter',
|
||||||
'chestAdapter18',
|
'chestAdapter18',
|
||||||
|
|
||||||
-- adapters for version 1.7
|
-- adapters for version 1.7
|
||||||
|
|||||||
@@ -202,28 +202,6 @@ function MEAdapter:isCrafting(item)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function MEAdapter:craftItems(items)
|
|
||||||
local cpus = self.getCraftingCPUs() or { }
|
|
||||||
local count = 0
|
|
||||||
|
|
||||||
for _,cpu in pairs(cpus) do
|
|
||||||
if cpu.busy then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,item in pairs(items) do
|
|
||||||
if count >= #cpus then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
if not self:isCrafting(item) then
|
|
||||||
if self:craft(item, item.count) then
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function MEAdapter:provide(item, qty, slot, direction)
|
function MEAdapter:provide(item, qty, slot, direction)
|
||||||
return pcall(function()
|
return pcall(function()
|
||||||
for _,stack in pairs(self.getAvailableItems('all')) do
|
for _,stack in pairs(self.getAvailableItems('all')) do
|
||||||
@@ -243,18 +221,6 @@ function MEAdapter:provide(item, qty, slot, direction)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function MEAdapter:eject(item, qty, direction)
|
|
||||||
if not _G.turtle then
|
|
||||||
error('Only a turtle can eject')
|
|
||||||
end
|
|
||||||
|
|
||||||
local s, m = pcall(function()
|
|
||||||
self:provide(item, qty)
|
|
||||||
_G.turtle.emptyInventory()
|
|
||||||
end)
|
|
||||||
return s, m
|
|
||||||
end
|
|
||||||
|
|
||||||
function MEAdapter:insert(slot, count)
|
function MEAdapter:insert(slot, count)
|
||||||
local s, m = pcall(function() self.pullItem(self.direction, slot, count) end)
|
local s, m = pcall(function() self.pullItem(self.direction, slot, count) end)
|
||||||
if not s and m then
|
if not s and m then
|
||||||
|
|||||||
@@ -1,35 +1,23 @@
|
|||||||
local class = require('class')
|
local class = require('class')
|
||||||
local Util = require('util')
|
|
||||||
local Peripheral = require('peripheral')
|
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
|
local Peripheral = require('peripheral')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
local RefinedAdapter = class()
|
local RefinedAdapter = class()
|
||||||
|
|
||||||
local keys = {
|
|
||||||
'damage',
|
|
||||||
'displayName',
|
|
||||||
'maxCount',
|
|
||||||
'maxDamage',
|
|
||||||
'name',
|
|
||||||
'nbtHash',
|
|
||||||
}
|
|
||||||
|
|
||||||
function RefinedAdapter:init(args)
|
function RefinedAdapter:init(args)
|
||||||
local defaults = {
|
local defaults = {
|
||||||
items = { },
|
|
||||||
name = 'refinedStorage',
|
name = 'refinedStorage',
|
||||||
direction = 'up',
|
|
||||||
wrapSide = 'bottom',
|
|
||||||
}
|
}
|
||||||
Util.merge(self, defaults)
|
Util.merge(self, defaults)
|
||||||
Util.merge(self, args)
|
Util.merge(self, args)
|
||||||
|
|
||||||
local controller
|
local controller
|
||||||
if self.autoDetect then
|
if not self.side then
|
||||||
controller = Peripheral.getByType('refinedstorage:controller')
|
controller = Peripheral.getByType('refinedstorage:controller')
|
||||||
else
|
else
|
||||||
controller = Peripheral.getBySide(self.wrapSide)
|
controller = Peripheral.getBySide(self.side)
|
||||||
if controller and not controller.listAvailableItems then
|
if controller and not controller.getCraftingTasks then
|
||||||
controller = nil
|
controller = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -43,72 +31,69 @@ function RefinedAdapter:isValid()
|
|||||||
return not not self.listAvailableItems
|
return not not self.listAvailableItems
|
||||||
end
|
end
|
||||||
|
|
||||||
function RefinedAdapter:isOnline()
|
function RefinedAdapter:getItemDetails(item)
|
||||||
return self.getNetworkEnergyStored() > 0
|
local detail = self.findItems(item)
|
||||||
|
if detail and #detail > 0 then
|
||||||
|
return detail[1].getMetadata()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function RefinedAdapter:getCachedItemDetails(item)
|
function RefinedAdapter:getCachedItemDetails(item)
|
||||||
local detail = itemDB:get(item)
|
local cached = itemDB:get(item)
|
||||||
if not detail then
|
if cached then
|
||||||
detail = self.findItem(item)
|
return cached
|
||||||
if detail then
|
|
||||||
local meta
|
|
||||||
pcall(function() meta = detail.getMetadata() end)
|
|
||||||
if not meta then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
Util.merge(detail, meta)
|
|
||||||
|
|
||||||
local t = { }
|
|
||||||
for _,k in pairs(keys) do
|
|
||||||
t[k] = detail[k]
|
|
||||||
end
|
|
||||||
|
|
||||||
detail = t
|
|
||||||
itemDB:add(detail)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local detail = self:getItemDetails(item)
|
||||||
if detail then
|
if detail then
|
||||||
return Util.shallowCopy(detail)
|
return itemDB:add(detail)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function RefinedAdapter:listItems()
|
function RefinedAdapter:refresh(throttle)
|
||||||
|
return self:listItems(throttle)
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedAdapter:listItems(throttle)
|
||||||
local items = { }
|
local items = { }
|
||||||
local list
|
throttle = throttle or Util.throttle()
|
||||||
|
|
||||||
pcall(function()
|
local s, m = pcall(function()
|
||||||
list = self.listAvailableItems()
|
for _,v in pairs(self.listAvailableItems()) do
|
||||||
end)
|
--if v.count > 0 then
|
||||||
|
local item = self:getCachedItemDetails(v)
|
||||||
if list then
|
if item then
|
||||||
|
item = Util.shallowCopy(item)
|
||||||
local throttle = Util.throttle()
|
item.count = v.count
|
||||||
|
table.insert(items, item)
|
||||||
for _,v in pairs(list) do
|
end
|
||||||
local item = self:getCachedItemDetails(v)
|
--end
|
||||||
if item then
|
|
||||||
item.count = v.count
|
|
||||||
table.insert(items, item)
|
|
||||||
end
|
|
||||||
throttle()
|
throttle()
|
||||||
end
|
end
|
||||||
itemDB:flush()
|
end)
|
||||||
|
|
||||||
|
if not s and m then
|
||||||
|
debug(m)
|
||||||
end
|
end
|
||||||
|
|
||||||
return items
|
itemDB:flush()
|
||||||
|
if not Util.empty(items) then
|
||||||
|
return items
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function RefinedAdapter:getItemInfo(fingerprint)
|
function RefinedAdapter:getItemInfo(item)
|
||||||
local item = itemDB:get(fingerprint)
|
return self:getItemDetails(item)
|
||||||
if not item then
|
end
|
||||||
return self:getCachedItemDetails(fingerprint)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
function RefinedAdapter:isCPUAvailable()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function RefinedAdapter:craft(item, qty)
|
||||||
local detail = self.findItem(item)
|
local detail = self.findItem(item)
|
||||||
if detail then
|
if detail then
|
||||||
item.count = detail.count
|
return detail.craft(qty)
|
||||||
return item
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -124,26 +109,29 @@ function RefinedAdapter:isCrafting(item)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function RefinedAdapter:craft(item, qty)
|
function RefinedAdapter:provide(item, qty, slot, direction)
|
||||||
local detail = self.findItem(item)
|
return pcall(function()
|
||||||
if detail then
|
for _,stack in pairs(self.listAvailableItems()) do
|
||||||
return detail.craft(qty)
|
if stack.name == item.name and
|
||||||
end
|
(not item.damage or stack.damage == item.damage) and
|
||||||
end
|
(not item.nbtHash or stack.nbtHash == item.nbtHash) then
|
||||||
|
local amount = math.min(qty, stack.count)
|
||||||
function RefinedAdapter:craftItems()
|
if amount > 0 then
|
||||||
return false
|
local detail = self.findItem(item)
|
||||||
end
|
if detail then
|
||||||
|
return detail.export(direction or self.direction, amount, slot)
|
||||||
function RefinedAdapter:provide()
|
end
|
||||||
end
|
end
|
||||||
|
qty = qty - amount
|
||||||
function RefinedAdapter:extract()
|
if qty <= 0 then
|
||||||
-- self.pushItems(self.direction, slot, qty)
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function RefinedAdapter:insert()
|
function RefinedAdapter:insert()
|
||||||
-- self.pullItems(self.direction, slot, qty)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return RefinedAdapter
|
return RefinedAdapter
|
||||||
|
|||||||
@@ -1028,7 +1028,7 @@ function listingPage:eventHandler(event)
|
|||||||
|
|
||||||
elseif event.type == 'craft' or event.type == 'grid_select_right' then
|
elseif event.type == 'craft' or event.type == 'grid_select_right' then
|
||||||
local item = self.grid:getSelected()
|
local item = self.grid:getSelected()
|
||||||
if Craft.findRecipe(item) or item.is_craftable then
|
if Craft.findRecipe(item) or true then -- or item.is_craftable then
|
||||||
UI:setPage('craft', self.grid:getSelected())
|
UI:setPage('craft', self.grid:getSelected())
|
||||||
else
|
else
|
||||||
self.notification:error('No recipe defined')
|
self.notification:error('No recipe defined')
|
||||||
@@ -1403,11 +1403,10 @@ UI:setPages({
|
|||||||
craft = craftPage,
|
craft = craftPage,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
jobMonitor()
|
||||||
UI:setPage(listingPage)
|
UI:setPage(listingPage)
|
||||||
listingPage:setFocus(listingPage.statusBar.filter)
|
listingPage:setFocus(listingPage.statusBar.filter)
|
||||||
|
|
||||||
jobMonitor()
|
|
||||||
|
|
||||||
Event.onInterval(5, function()
|
Event.onInterval(5, function()
|
||||||
|
|
||||||
if not craftingPaused then
|
if not craftingPaused then
|
||||||
@@ -1438,6 +1437,15 @@ Event.onInterval(5, function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function eject(item, qty)
|
||||||
|
if _G.turtle then
|
||||||
|
local s, m = pcall(function()
|
||||||
|
inventoryAdapter:provide(item, qty)
|
||||||
|
_G.turtle.emptyInventory()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for _,key in pairs(Util.keys(demandCrafting)) do
|
for _,key in pairs(Util.keys(demandCrafting)) do
|
||||||
local item = demandCrafting[key]
|
local item = demandCrafting[key]
|
||||||
if item.crafted then
|
if item.crafted then
|
||||||
@@ -1446,7 +1454,7 @@ Event.onInterval(5, function()
|
|||||||
demandCrafting[key] = nil
|
demandCrafting[key] = nil
|
||||||
item.statusCode = 'success'
|
item.statusCode = 'success'
|
||||||
if item.eject then
|
if item.eject then
|
||||||
inventoryAdapter:eject(item, item.ocount, 'front')
|
eject(item, item.ocount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user