milo manipulator + crafting fixes
This commit is contained in:
@@ -139,7 +139,7 @@ local function harvest(blocks)
|
||||
elseif b.action == 'bump' then
|
||||
if turtle.faceAgainst(b) then
|
||||
turtle.equip('right', 'plethora:module:3')
|
||||
os.sleep(.5)
|
||||
os.sleep(.3)
|
||||
-- search the ground for the dropped cactus
|
||||
local sensed = peripheral.call('right', 'sense')
|
||||
turtle.equip('right', 'minecraft:diamond_pickaxe')
|
||||
|
||||
@@ -154,16 +154,7 @@ function Milo:getMatches(items, item, ignoreDamage, ignoreNbtHash)
|
||||
end
|
||||
|
||||
function Milo:clearGrid()
|
||||
turtle.eachFilledSlot(function(slot)
|
||||
self.context.storage:import(self.context.localName, slot.index, slot.count, slot)
|
||||
end)
|
||||
|
||||
for i = 1, 16 do
|
||||
if turtle.getItemCount(i) ~= 0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
return Craft.clearGrid(self.context.storage)
|
||||
end
|
||||
|
||||
function Milo:getTurtleInventory()
|
||||
|
||||
@@ -218,13 +218,14 @@ function Storage:updateCache(adapter, key, count)
|
||||
else
|
||||
-- TODO: all items imported should be updated in itemdb
|
||||
-- error here if not
|
||||
local item = itemDB:get(key) or itemDB:splitKey(key)
|
||||
if item.displayName then
|
||||
local item = itemDB:get(key)
|
||||
if item then
|
||||
entry = Util.shallowCopy(item)
|
||||
entry.count = count
|
||||
entry.key = key
|
||||
adapter.cache[key] = entry
|
||||
else
|
||||
debug('STORAGE: item missing details')
|
||||
-- TODO: somehow update itemdb with this maybe new item
|
||||
adapter.dirty = true
|
||||
self.dirty = true
|
||||
@@ -243,7 +244,7 @@ local function sn(name)
|
||||
if #t ~= 2 then
|
||||
return name
|
||||
end
|
||||
return table.concat(table.unpack(t), '_')
|
||||
return table.concat(t, '_')
|
||||
end
|
||||
|
||||
function Storage:export(target, slot, count, item)
|
||||
@@ -253,9 +254,11 @@ function Storage:export(target, slot, count, item)
|
||||
local function provide(adapter)
|
||||
local amount = adapter:provide(item, count, slot, target or self.localName)
|
||||
if amount > 0 then
|
||||
|
||||
_G._debug('EXT: %s(%d): %s -> %s%s',
|
||||
item.name, amount, sn(adapter.name), sn(target or self.localName),
|
||||
item.displayName or item.name, amount, sn(adapter.name), sn(target or self.localName),
|
||||
slot and string.format('[%d]', slot) or '')
|
||||
|
||||
self:updateCache(adapter, key, -amount)
|
||||
self:updateCache(self, key, -amount)
|
||||
end
|
||||
@@ -302,7 +305,7 @@ function Storage:import(source, slot, count, item)
|
||||
if amount > 0 then
|
||||
|
||||
_G._debug('INS: %s(%d): %s[%d] -> %s',
|
||||
item.name, amount,
|
||||
item.displayName or item.name, amount,
|
||||
sn(source or self.localName), slot, sn(adapter.name))
|
||||
|
||||
self:updateCache(adapter, key, amount)
|
||||
|
||||
@@ -4,6 +4,7 @@ local Util = require('util')
|
||||
local device = _G.device
|
||||
local fs = _G.fs
|
||||
local turtle = _G.turtle
|
||||
local intro = device['plethora:introspection']
|
||||
|
||||
local Craft = {
|
||||
STATUS_INFO = 'info',
|
||||
@@ -16,20 +17,6 @@ local Craft = {
|
||||
MACHINE_LOOKUP = 'usr/config/machine_crafting.db',
|
||||
}
|
||||
|
||||
local function clearGrid(storage)
|
||||
turtle.eachFilledSlot(function(slot)
|
||||
storage:import(storage.localName, slot.index, slot.count, slot)
|
||||
end)
|
||||
|
||||
for i = 1, 16 do
|
||||
if turtle.getItemCount(i) ~= 0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function splitKey(key)
|
||||
local t = Util.split(key, '(.-):')
|
||||
local item = { }
|
||||
@@ -48,6 +35,27 @@ local function makeRecipeKey(item)
|
||||
return table.concat({ item.name, item.damage or 0, item.nbtHash }, ':')
|
||||
end
|
||||
|
||||
function Craft.clearGrid(storage)
|
||||
turtle.eachFilledSlot(function(slot)
|
||||
local item = 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)
|
||||
|
||||
for i = 1, 16 do
|
||||
if turtle.getItemCount(i) ~= 0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function Craft.getItemCount(items, item)
|
||||
if type(item) == 'string' then
|
||||
item = splitKey(item)
|
||||
@@ -117,7 +125,7 @@ local function machineCraft(recipe, storage, machineName, request, count, item)
|
||||
end
|
||||
|
||||
local function turtleCraft(recipe, storage, request, count)
|
||||
if not clearGrid(storage) then
|
||||
if not Craft.clearGrid(storage) then
|
||||
request.status = 'grid in use'
|
||||
request.statusCode = Craft.STATUS_ERROR
|
||||
return
|
||||
@@ -142,7 +150,7 @@ local function turtleCraft(recipe, storage, request, count)
|
||||
request.status = 'Failed to craft'
|
||||
request.statusCode = Craft.STATUS_ERROR
|
||||
end
|
||||
clearGrid(storage)
|
||||
Craft.clearGrid(storage)
|
||||
return request.statusCode == Craft.STATUS_SUCCESS
|
||||
end
|
||||
|
||||
|
||||
@@ -7,20 +7,26 @@ local colors = _G.colors
|
||||
local device = _G.device
|
||||
local turtle = _G.turtle
|
||||
|
||||
--[[ Configuration Screen ]]
|
||||
local template =
|
||||
[[%sBound Manipulator%s
|
||||
|
||||
Automatically import items into storage from your ender chest.
|
||||
]]
|
||||
|
||||
--[[ Configuration Screen ]]--
|
||||
local wizardPage = UI.Window {
|
||||
title = 'Manipulator',
|
||||
index = 2,
|
||||
backgroundColor = colors.cyan,
|
||||
[1] = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
value = string.format(template, Ansi.yellow, Ansi.reset),
|
||||
form = UI.Form {
|
||||
x = 1, y = 3, ex = -1, ey = -2,
|
||||
manualControls = true,
|
||||
[1] = UI.Checkbox {
|
||||
formLabel = 'Import', formKey = 'importEnder',
|
||||
help = 'Locks chest to a single item type',
|
||||
pruneEmpty = true,
|
||||
},
|
||||
[2] = UI.TextArea {
|
||||
x = 13, ex = -2, y = 2,
|
||||
value = 'Automatically import the user\'s ender chest contents',
|
||||
},
|
||||
},
|
||||
userInfo = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, height = 1,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -36,8 +42,19 @@ function wizardPage:isValidFor(node)
|
||||
return node.mtype == 'manipulator'
|
||||
end
|
||||
|
||||
function wizardPage:setNode(node)
|
||||
self.form:setValues(node)
|
||||
self.userInfo.value = string.format('%sBound to: %s%s',
|
||||
Ansi.black, Ansi.yellow, node.adapter.getName())
|
||||
end
|
||||
|
||||
function wizardPage:validate()
|
||||
return self.form:save()
|
||||
end
|
||||
|
||||
UI:getPage('nodeWizard').wizard:add({ manipulator = wizardPage })
|
||||
|
||||
--[[ Task ]]--
|
||||
local task = {
|
||||
name = 'manipulator',
|
||||
priority = 15,
|
||||
@@ -45,7 +62,7 @@ local task = {
|
||||
|
||||
function task:cycle(context)
|
||||
local function filter(v)
|
||||
return v.adapter.getEnder
|
||||
return v.adapter.getEnder and v.importEnder
|
||||
end
|
||||
|
||||
for manipulator in context.storage:filterActive('manipulator', filter) do
|
||||
|
||||
@@ -30,6 +30,7 @@ function ReplenishTask:cycle(context)
|
||||
damage = res.ignoreDamage and 0 or item.damage,
|
||||
nbtHash = nbtHash,
|
||||
requested = res.low - count,
|
||||
count = count,
|
||||
name = item.name,
|
||||
displayName = item.displayName,
|
||||
replenish = true,
|
||||
|
||||
Reference in New Issue
Block a user