milo: drop from trashcans
This commit is contained in:
@@ -251,27 +251,13 @@ The settings will take effect immediately!]],
|
|||||||
x = 2, y = -4, height = 3,
|
x = 2, y = -4, height = 3,
|
||||||
margin = 1,
|
margin = 1,
|
||||||
manualControls = true,
|
manualControls = true,
|
||||||
[1] = UI.Chooser {
|
[1] = UI.Checkbox {
|
||||||
width = 7,
|
|
||||||
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
||||||
pruneEmpty = true,
|
help = 'Ignore damage of item',
|
||||||
nochoice = 'No',
|
|
||||||
choices = {
|
|
||||||
{ name = 'Yes', value = true },
|
|
||||||
{ name = 'No', value = false },
|
|
||||||
},
|
|
||||||
help = 'Ignore damage of item'
|
|
||||||
},
|
},
|
||||||
[2] = UI.Chooser {
|
[2] = UI.Checkbox {
|
||||||
width = 7,
|
|
||||||
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
||||||
pruneEmpty = true,
|
help = 'Ignore NBT of item',
|
||||||
nochoice = 'No',
|
|
||||||
choices = {
|
|
||||||
{ name = 'Yes', value = true },
|
|
||||||
{ name = 'No', value = false },
|
|
||||||
},
|
|
||||||
help = 'Ignore NBT of item'
|
|
||||||
},
|
},
|
||||||
[3] = UI.Chooser {
|
[3] = UI.Chooser {
|
||||||
width = 13,
|
width = 13,
|
||||||
|
|||||||
@@ -1,29 +1,52 @@
|
|||||||
local Ansi = require('ansi')
|
local Milo = require('milo')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
|
||||||
--[[ Configuration Screen ]]
|
--[[ Configuration Screen ]]
|
||||||
local template =
|
local wizardPage = UI.Window {
|
||||||
[[%sUse this inventory as a trashcan%s
|
|
||||||
|
|
||||||
If the number of items exceed the maximum value will be sent to this inventory.
|
|
||||||
|
|
||||||
Any items that cannot fit into a locked chest will automatically be sent to this inventory.
|
|
||||||
]]
|
|
||||||
|
|
||||||
local trashcanWizardPage = UI.Window {
|
|
||||||
title = 'Trashcan',
|
title = 'Trashcan',
|
||||||
index = 2,
|
index = 2,
|
||||||
backgroundColor = colors.cyan,
|
backgroundColor = colors.cyan,
|
||||||
[1] = UI.TextArea {
|
form = UI.Form {
|
||||||
x = 2, ex = -2, y = 2, ey = -2,
|
x = 1, y = 1, ex = -1, ey = -2,
|
||||||
value = string.format(template, Ansi.yellow, Ansi.reset),
|
manualControls = true,
|
||||||
|
[1] = UI.Checkbox {
|
||||||
|
formLabel = 'Drop', formKey = 'drop',
|
||||||
|
help = 'Drop the items out of this inventory',
|
||||||
|
},
|
||||||
|
[2] = UI.Chooser {
|
||||||
|
width = 9,
|
||||||
|
formLabel = 'Drop direction', formKey = 'dropDirection',
|
||||||
|
nochoice = 'Down',
|
||||||
|
choices = {
|
||||||
|
{ name = 'Down', value = 'down' },
|
||||||
|
{ name = 'Up', value = 'up' },
|
||||||
|
{ name = 'North', value = 'north' },
|
||||||
|
{ name = 'South', value = 'south' },
|
||||||
|
{ name = 'East', value = 'east' },
|
||||||
|
{ name = 'West', value = 'west' },
|
||||||
|
},
|
||||||
|
help = 'Drop in a specified direction'
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function trashcanWizardPage:isValidType(node)
|
function wizardPage:enable()
|
||||||
|
UI.Window.enable(self)
|
||||||
|
self:focusFirst()
|
||||||
|
end
|
||||||
|
|
||||||
|
function wizardPage:validate()
|
||||||
|
return self.form:save()
|
||||||
|
end
|
||||||
|
|
||||||
|
function wizardPage:setNode(node)
|
||||||
|
self.form:setValues(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
function wizardPage:isValidType(node)
|
||||||
local m = device[node.name]
|
local m = device[node.name]
|
||||||
return m and m.pullItems and {
|
return m and m.pullItems and {
|
||||||
name = 'Trashcan',
|
name = 'Trashcan',
|
||||||
@@ -32,8 +55,29 @@ function trashcanWizardPage:isValidType(node)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function trashcanWizardPage:isValidFor(node)
|
function wizardPage:isValidFor(node)
|
||||||
return node.mtype == 'trashcan'
|
return node.mtype == 'trashcan'
|
||||||
end
|
end
|
||||||
|
|
||||||
UI:getPage('nodeWizard').wizard:add({ trashcan = trashcanWizardPage })
|
UI:getPage('nodeWizard').wizard:add({ trashcan = wizardPage })
|
||||||
|
|
||||||
|
--[[ TASK ]]--
|
||||||
|
local task = {
|
||||||
|
name = 'trashcan',
|
||||||
|
priority = 90,
|
||||||
|
}
|
||||||
|
|
||||||
|
local function filter(a)
|
||||||
|
return a.drop
|
||||||
|
end
|
||||||
|
|
||||||
|
function task:cycle(context)
|
||||||
|
for node in context.storage:filterActive('trashcan', filter) do
|
||||||
|
for k in pairs(node.adapter.list()) do
|
||||||
|
local direction = node.dropDirection or 'down'
|
||||||
|
node.adapter.drop(k, 64, direction)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Milo:registerTask(task)
|
||||||
|
|||||||
Reference in New Issue
Block a user