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