milo: item rewrite + ability to remove nbts from recipes
This commit is contained in:
@@ -131,16 +131,28 @@ local function turtleCraft(recipe, storage, request, count)
|
|||||||
if storage:export(storage.turtleInventory, k, count, item) ~= count then
|
if storage:export(storage.turtleInventory, k, count, item) ~= count then
|
||||||
request.status = 'unknown error'
|
request.status = 'unknown error'
|
||||||
request.statusCode = Craft.STATUS_ERROR
|
request.statusCode = Craft.STATUS_ERROR
|
||||||
|
_debug(item)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
if turtle.craft() then
|
if turtle.craft() then
|
||||||
request.crafted = request.crafted + count * recipe.count
|
local l = storage.turtleInventory.adapter.list()
|
||||||
request.status = 'crafted'
|
local crafted = l[1]
|
||||||
request.statusCode = Craft.STATUS_SUCCESS
|
if recipe.result ~= itemDB:makeKey(crafted) then
|
||||||
|
_debug('expected: ' .. recipe.result)
|
||||||
|
_debug('got: ' .. itemDB:makeKey(crafted))
|
||||||
|
request.aborted = true
|
||||||
|
request.status = 'Failed to craft: ' .. recipe.result
|
||||||
|
request.statusCode = Craft.STATUS_ERROR
|
||||||
|
else
|
||||||
|
request.crafted = request.crafted + count * recipe.count
|
||||||
|
request.status = 'crafted'
|
||||||
|
request.statusCode = Craft.STATUS_SUCCESS
|
||||||
|
end
|
||||||
else
|
else
|
||||||
|
_debug('just failed')
|
||||||
request.status = 'Failed to craft'
|
request.status = 'Failed to craft'
|
||||||
request.statusCode = Craft.STATUS_ERROR
|
request.statusCode = Craft.STATUS_ERROR
|
||||||
end
|
end
|
||||||
@@ -174,20 +186,35 @@ function Craft.craftRecipe(recipe, count, storage, origItem)
|
|||||||
return Craft.craftRecipeInternal(recipe, count, storage, origItem)
|
return Craft.craftRecipeInternal(recipe, count, storage, origItem)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function adjustCounts(recipe, count, ingredients)
|
local function adjustCounts(recipe, count, ingredients, storage)
|
||||||
-- decrement ingredients used
|
-- decrement ingredients used
|
||||||
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
||||||
ingredients[key].count = ingredients[key].count - (icount * count)
|
ingredients[key].count = ingredients[key].count - (icount * count)
|
||||||
|
if ingredients[key].count == 0 and not storage.cache[key] then
|
||||||
|
--
|
||||||
|
elseif not storage.cache[key] then
|
||||||
|
_debug({ key, ingredients[key].count, 'nocache' })
|
||||||
|
elseif storage.cache[key].count ~= ingredients[key].count then
|
||||||
|
_debug({ key, ingredients[key].count, storage.cache[key].count })
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- increment crafted
|
-- increment crafted
|
||||||
local result = ingredients[recipe.result]
|
local result = ingredients[recipe.result]
|
||||||
result.count = result.count + (count * recipe.count)
|
result.count = result.count + (count * recipe.count)
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Craft.craftRecipeInternal(recipe, count, storage, origItem)
|
function Craft.craftRecipeInternal(recipe, count, storage, origItem)
|
||||||
local request = origItem.ingredients[recipe.result]
|
local request = origItem.ingredients[recipe.result]
|
||||||
|
|
||||||
|
if request.aborted then
|
||||||
|
_debug('aborted')
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
if origItem.pending[recipe.result] then
|
if origItem.pending[recipe.result] then
|
||||||
request.status = 'processing'
|
request.status = 'processing'
|
||||||
request.statusCode = Craft.STATUS_INFO
|
request.statusCode = Craft.STATUS_INFO
|
||||||
@@ -234,7 +261,7 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
_G._p = origItem.ingredients
|
||||||
local crafted = 0
|
local crafted = 0
|
||||||
while canCraft > 0 do
|
while canCraft > 0 do
|
||||||
local batch = math.min(canCraft, maxCount)
|
local batch = math.min(canCraft, maxCount)
|
||||||
@@ -248,7 +275,7 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
adjustCounts(recipe, batch, origItem.ingredients)
|
adjustCounts(recipe, batch, origItem.ingredients, storage)
|
||||||
|
|
||||||
crafted = crafted + batch
|
crafted = crafted + batch
|
||||||
canCraft = canCraft - maxCount
|
canCraft = canCraft - maxCount
|
||||||
|
|||||||
@@ -234,6 +234,17 @@ function Milo:eject(item, count)
|
|||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Milo:updateRecipe(result, recipe)
|
||||||
|
-- save the recipe
|
||||||
|
if recipe then
|
||||||
|
recipe = Util.shallowCopy(recipe)
|
||||||
|
recipe.result = nil
|
||||||
|
end
|
||||||
|
self.context.userRecipes[result] = recipe
|
||||||
|
Util.writeTable(Craft.USER_RECIPES, self.context.userRecipes)
|
||||||
|
Craft.loadRecipes()
|
||||||
|
end
|
||||||
|
|
||||||
function Milo:saveMachineRecipe(recipe, result, machine)
|
function Milo:saveMachineRecipe(recipe, result, machine)
|
||||||
local key = Milo:uniqueKey(result)
|
local key = Milo:uniqueKey(result)
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,14 @@ local craftPage = UI.Page {
|
|||||||
x = 6, y = 4,
|
x = 6, y = 4,
|
||||||
value = 'Eject',
|
value = 'Eject',
|
||||||
},
|
},
|
||||||
eject = UI.Checkbox {
|
eject = UI.Chooser {
|
||||||
x = 15, y = 4, width = 7,
|
x = 15, y = 4, width = 7,
|
||||||
value = true,
|
value = true,
|
||||||
|
nochoice = 'No',
|
||||||
|
choices = {
|
||||||
|
{ name = 'Yes', value = true },
|
||||||
|
{ name = 'No', value = false },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
resources = UI.Window {
|
resources = UI.Window {
|
||||||
|
|||||||
@@ -6,18 +6,14 @@ local UI = require('ui')
|
|||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local device = _G.device
|
|
||||||
|
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
local page = UI.Page {
|
local manageTab = UI.Window {
|
||||||
titleBar = UI.TitleBar {
|
tabTitle = 'Manage',
|
||||||
title = 'Limit Resource',
|
|
||||||
previousPage = true,
|
|
||||||
event = 'form_cancel',
|
|
||||||
},
|
|
||||||
form = UI.Form {
|
form = UI.Form {
|
||||||
x = 1, y = 2, height = 10, ex = -1,
|
x = 1, ex = -1, ey = -1,
|
||||||
|
--manualControls = true,
|
||||||
[1] = UI.TextEntry {
|
[1] = UI.TextEntry {
|
||||||
formLabel = 'Name', formKey = 'displayName', help = 'Override display name',
|
formLabel = 'Name', formKey = 'displayName', help = 'Override display name',
|
||||||
shadowText = 'Display name',
|
shadowText = 'Display name',
|
||||||
@@ -42,100 +38,80 @@ local page = UI.Page {
|
|||||||
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
||||||
help = 'Ignore NBT of item',
|
help = 'Ignore NBT of item',
|
||||||
},
|
},
|
||||||
machineButton = UI.Button {
|
|
||||||
x = 2, y = -2, width = 10,
|
|
||||||
formLabel = 'Machine',
|
|
||||||
event = 'select_machine',
|
|
||||||
text = 'Assign',
|
|
||||||
},
|
|
||||||
infoButton = UI.Button {
|
|
||||||
x = 2, y = -2,
|
|
||||||
event = 'show_info',
|
|
||||||
text = 'Info',
|
|
||||||
},
|
|
||||||
resetButton = UI.Button {
|
|
||||||
x = 9, y = -2,
|
|
||||||
event = 'reset',
|
|
||||||
text = 'Reset',
|
|
||||||
help = 'Clear recipe and all settings',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
rsControl = UI.SlideOut {
|
}
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
titleBar = UI.TitleBar {
|
local machinesTab = UI.Window {
|
||||||
title = "Redstone Control",
|
tabTitle = 'Machine',
|
||||||
},
|
backgroundColor = colors.cyan,
|
||||||
form = UI.Form {
|
grid = UI.ScrollingGrid {
|
||||||
y = 2,
|
x = 2, ex = -2, y = 2, ey = -2,
|
||||||
[1] = UI.Chooser {
|
disableHeader = true,
|
||||||
width = 7,
|
columns = {
|
||||||
formLabel = 'RS Control', formKey = 'rsControl',
|
{ heading = 'Name', key = 'displayName'},
|
||||||
nochoice = 'No',
|
|
||||||
choices = {
|
|
||||||
{ name = 'Yes', value = true },
|
|
||||||
{ name = 'No', value = false },
|
|
||||||
},
|
|
||||||
help = 'Control via redstone'
|
|
||||||
},
|
|
||||||
[2] = UI.Chooser {
|
|
||||||
width = 25,
|
|
||||||
formLabel = 'RS Device', formKey = 'rsDevice',
|
|
||||||
--choices = devices,
|
|
||||||
help = 'Redstone Device'
|
|
||||||
},
|
|
||||||
[3] = UI.Chooser {
|
|
||||||
width = 10,
|
|
||||||
formLabel = 'RS Side', formKey = 'rsSide',
|
|
||||||
--nochoice = 'No',
|
|
||||||
choices = {
|
|
||||||
{ name = 'up', value = 'up' },
|
|
||||||
{ name = 'down', value = 'down' },
|
|
||||||
{ name = 'east', value = 'east' },
|
|
||||||
{ name = 'north', value = 'north' },
|
|
||||||
{ name = 'west', value = 'west' },
|
|
||||||
{ name = 'south', value = 'south' },
|
|
||||||
},
|
|
||||||
help = 'Output side'
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
sortColumn = 'displayName',
|
||||||
|
help = 'Double-click to set machine',
|
||||||
},
|
},
|
||||||
machines = UI.SlideOut {
|
}
|
||||||
backgroundColor = colors.cyan,
|
|
||||||
titleBar = UI.TitleBar {
|
local recipeTab = UI.Window {
|
||||||
title = 'Select Machine',
|
tabTitle = 'Recipe',
|
||||||
event = 'cancel_machine',
|
backgroundColor = colors.cyan,
|
||||||
|
grid = UI.ScrollingGrid {
|
||||||
|
x = 2, ex = -2, y = 2, ey = -4,
|
||||||
|
disableHeader = true,
|
||||||
|
columns = {
|
||||||
|
{ heading = 'Slot', key = 'slot', width = 2 },
|
||||||
|
{ heading = 'Key', key = 'key' },
|
||||||
},
|
},
|
||||||
grid = UI.ScrollingGrid {
|
sortColumn = 'slot',
|
||||||
y = 2, ey = -5,
|
|
||||||
disableHeader = true,
|
|
||||||
columns = {
|
|
||||||
{ heading = 'Name', key = 'displayName'},
|
|
||||||
},
|
|
||||||
sortColumn = 'displayName',
|
|
||||||
},
|
|
||||||
button1 = UI.Button {
|
|
||||||
x = -14, y = -3,
|
|
||||||
text = 'Ok', event = 'set_machine',
|
|
||||||
},
|
|
||||||
button2 = UI.Button {
|
|
||||||
x = -9, y = -3,
|
|
||||||
text = 'Cancel', event = 'cancel_machine',
|
|
||||||
},
|
|
||||||
statusBar = UI.StatusBar { values = 'Enter or double click to select' },
|
|
||||||
},
|
},
|
||||||
info = UI.SlideOut {
|
ignoreNBT = UI.Button {
|
||||||
titleBar = UI.TitleBar {
|
x = -13, y = -2,
|
||||||
title = "Information",
|
text = 'Ignore NBT', event = 'ignore_nbt',
|
||||||
},
|
},
|
||||||
textArea = UI.TextArea {
|
}
|
||||||
x = 2, ex = -2, y = 3, ey = -4,
|
|
||||||
backgroundColor = colors.black,
|
local infoTab = UI.Window {
|
||||||
},
|
tabTitle = 'Info',
|
||||||
cancel = UI.Button {
|
backgroundColor = colors.cyan,
|
||||||
ex = -2, y = -2, width = 6,
|
textArea = UI.TextArea {
|
||||||
text = 'Okay',
|
x = 2, ex = -2, y = 2,
|
||||||
event = 'hide_info',
|
},
|
||||||
},
|
}
|
||||||
|
|
||||||
|
local resetTab = UI.Window {
|
||||||
|
tabTitle = 'Reset',
|
||||||
|
backgroundColor = colors.cyan,
|
||||||
|
textArea = UI.TextArea {
|
||||||
|
y = 2, ey = 6,
|
||||||
|
textColor = colors.yellow,
|
||||||
|
value = [[ Warning!
|
||||||
|
|
||||||
|
This will clear all setting,
|
||||||
|
recipe, and machine for this item.]]
|
||||||
|
},
|
||||||
|
resetButton = UI.Button {
|
||||||
|
x = 17, y = 7,
|
||||||
|
event = 'reset',
|
||||||
|
text = 'Reset',
|
||||||
|
help = 'Clear recipe and all settings',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local page = UI.Page {
|
||||||
|
titleBar = UI.TitleBar {
|
||||||
|
title = 'Item settings',
|
||||||
|
previousPage = true,
|
||||||
|
},
|
||||||
|
tabs = UI.Tabs {
|
||||||
|
y = 2, ey = -2,
|
||||||
|
[1] = manageTab,
|
||||||
|
[2] = recipeTab,
|
||||||
|
[3] = machinesTab,
|
||||||
|
[4] = infoTab,
|
||||||
|
[5] = resetTab,
|
||||||
},
|
},
|
||||||
statusBar = UI.StatusBar { },
|
statusBar = UI.StatusBar { },
|
||||||
notification = UI.Notification { },
|
notification = UI.Notification { },
|
||||||
@@ -146,17 +122,19 @@ function page:enable(item)
|
|||||||
self.item = Util.shallowCopy(item)
|
self.item = Util.shallowCopy(item)
|
||||||
self.res = item.resource or { }
|
self.res = item.resource or { }
|
||||||
self.res.displayName = self.item.displayName
|
self.res.displayName = self.item.displayName
|
||||||
self.form:setValues(self.res)
|
manageTab.form:setValues(self.res)
|
||||||
self.titleBar.title = item.displayName or item.name
|
|
||||||
|
|
||||||
local machine = Craft.machineLookup[self.item.key]
|
local machine = Craft.machineLookup[self.item.key]
|
||||||
self.form.machineButton.inactive = not machine
|
|
||||||
if machine then
|
if machine then
|
||||||
self:filterMachines(machine)
|
self:filterMachines(machine)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.tabs:selectTab(manageTab)
|
||||||
|
|
||||||
|
self.tabs:setActive(machinesTab, machine)
|
||||||
|
self.tabs:setActive(recipeTab, Craft.findRecipe(item))
|
||||||
|
|
||||||
UI.Page.enable(self)
|
UI.Page.enable(self)
|
||||||
self:focusFirst()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:filterMachines(machine)
|
function page:filterMachines(machine)
|
||||||
@@ -165,65 +143,105 @@ function page:filterMachines(machine)
|
|||||||
return node.adapter and node.adapter.online and node.adapter.pushItems
|
return node.adapter and node.adapter.online and node.adapter.pushItems
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
self.machines.grid:setValues(t)
|
machinesTab.grid:setValues(t)
|
||||||
self.machines.grid:setSelected('name', machine)
|
machinesTab.grid:setSelected('name', machine)
|
||||||
end
|
end
|
||||||
|
|
||||||
function page.machines.grid:getDisplayValues(row)
|
function machinesTab.grid:getDisplayValues(row)
|
||||||
row = Util.shallowCopy(row)
|
row = Util.shallowCopy(row)
|
||||||
row.displayName = row.displayName or row.name
|
row.displayName = row.displayName or row.name
|
||||||
return row
|
return row
|
||||||
end
|
end
|
||||||
|
|
||||||
function page.machines.grid:getRowTextColor(row, selected)
|
function machinesTab.grid:getRowTextColor(row, selected)
|
||||||
if row.name == Craft.machineLookup[page.item.key] then
|
if row.name == Craft.machineLookup[page.item.key] then
|
||||||
return colors.yellow
|
return colors.yellow
|
||||||
end
|
end
|
||||||
return UI.Grid:getRowTextColor(row, selected)
|
return UI.Grid:getRowTextColor(row, selected)
|
||||||
end
|
end
|
||||||
|
|
||||||
function page.rsControl:enable()
|
function machinesTab:eventHandler(event)
|
||||||
local devices = self.form[2].choices
|
if event.type == 'grid_select' then
|
||||||
Util.clear(devices)
|
Craft.machineLookup[page.item.key] = event.selected.name
|
||||||
for _,dev in pairs(device) do
|
Util.writeTable(Craft.MACHINE_LOOKUP, Craft.machineLookup)
|
||||||
if dev.setOutput then
|
|
||||||
table.insert(devices, { name = dev.name, value = dev.name })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if Util.size(devices) == 0 then
|
self.grid:draw()
|
||||||
table.insert(devices, { name = 'None found', values = '' })
|
page.notification:info('Machine saved')
|
||||||
end
|
|
||||||
|
|
||||||
UI.SlideOut.enable(self)
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function page.rsControl:eventHandler(event)
|
function recipeTab:enable()
|
||||||
if event.type == 'form_cancel' then
|
self.recipe = Craft.findRecipe(page.item)
|
||||||
self:hide()
|
|
||||||
elseif event.type == 'form_complete' then
|
local t = { }
|
||||||
self:hide()
|
if self.recipe then
|
||||||
else
|
for k, v in pairs(self.recipe.ingredients) do
|
||||||
return UI.SlideOut.eventHandler(self, event)
|
table.insert(t, {
|
||||||
|
slot = k,
|
||||||
|
key = v,
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return true
|
self.grid:setValues(t)
|
||||||
|
UI.Window.enable(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function recipeTab:eventHandler(event)
|
||||||
|
if event.type == 'ignore_nbt' then
|
||||||
|
local selected = self.grid:getSelected()
|
||||||
|
local item = itemDB:splitKey(selected.key)
|
||||||
|
item.nbtHash = nil
|
||||||
|
selected.key = itemDB:makeKey(item)
|
||||||
|
self.grid:draw()
|
||||||
|
|
||||||
|
self.recipe.ingredients = { }
|
||||||
|
for _, v in pairs(self.grid.values) do
|
||||||
|
self.recipe.ingredients[v.slot] = v.key
|
||||||
|
end
|
||||||
|
|
||||||
|
Milo:updateRecipe(self.recipe.result, self.recipe)
|
||||||
|
page.notification:info('Recipe updated')
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function infoTab:draw()
|
||||||
|
local item = page.item
|
||||||
|
local value =
|
||||||
|
string.format('%s%s%s\n%s\n',
|
||||||
|
Ansi.orange, item.displayName, Ansi.reset,
|
||||||
|
item.name)
|
||||||
|
|
||||||
|
if item.nbtHash then
|
||||||
|
value = value .. item.nbtHash .. '\n'
|
||||||
|
end
|
||||||
|
|
||||||
|
value = value .. string.format('\n%sDamage:%s %s',
|
||||||
|
Ansi.yellow, Ansi.reset, item.damage)
|
||||||
|
|
||||||
|
if item.maxDamage and item.maxDamage > 0 then
|
||||||
|
value = value .. string.format(' (max: %s)', item.maxDamage)
|
||||||
|
end
|
||||||
|
|
||||||
|
if item.maxCount then
|
||||||
|
value = value .. string.format('\n%sStack Size: %s%s',
|
||||||
|
Ansi.yellow, Ansi.reset, item.maxCount)
|
||||||
|
end
|
||||||
|
|
||||||
|
self.textArea.value = value
|
||||||
|
UI.Window.draw(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
if event.type == 'form_cancel' then
|
if event.type == 'form_cancel' then
|
||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
elseif event.type == 'show_rs' then
|
|
||||||
self.rsControl:show()
|
|
||||||
|
|
||||||
elseif event.type == 'select_machine' then
|
|
||||||
self.machines:show()
|
|
||||||
|
|
||||||
elseif event.type == 'reset' then
|
elseif event.type == 'reset' then
|
||||||
if context.userRecipes[self.item.key] then
|
if context.userRecipes[self.item.key] then
|
||||||
context.userRecipes[self.item.key] = nil
|
Milo:updateRecipe(self.item.key, nil)
|
||||||
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
|
|
||||||
Craft.loadRecipes()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if context.resources[self.item.key] then
|
if context.resources[self.item.key] then
|
||||||
@@ -238,47 +256,8 @@ function page:eventHandler(event)
|
|||||||
|
|
||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
elseif event.type == 'grid_select' then
|
elseif event.type == 'tab_activate' then
|
||||||
Craft.machineLookup[self.item.key] = event.selected.name
|
event.activated:focusFirst()
|
||||||
self.machines.grid:draw()
|
|
||||||
|
|
||||||
elseif event.type == 'set_machine' then
|
|
||||||
local machine = self.machines.grid:getSelected()
|
|
||||||
if machine then
|
|
||||||
Util.writeTable(Craft.MACHINE_LOOKUP, Craft.machineLookup)
|
|
||||||
end
|
|
||||||
self.machines:hide()
|
|
||||||
|
|
||||||
elseif event.type == 'cancel_machine' then
|
|
||||||
self.machines:hide()
|
|
||||||
|
|
||||||
elseif event.type == 'show_info' then
|
|
||||||
local value =
|
|
||||||
string.format('%s%s%s\n%s\n',
|
|
||||||
Ansi.orange, self.item.displayName, Ansi.reset,
|
|
||||||
self.item.name)
|
|
||||||
|
|
||||||
if self.item.nbtHash then
|
|
||||||
value = value .. self.item.nbtHash .. '\n'
|
|
||||||
end
|
|
||||||
|
|
||||||
value = value .. string.format('\n%sDamage:%s %s',
|
|
||||||
Ansi.yellow, Ansi.reset, self.item.damage)
|
|
||||||
|
|
||||||
if self.item.maxDamage and self.item.maxDamage > 0 then
|
|
||||||
value = value .. string.format(' (max: %s)', self.item.maxDamage)
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.item.maxCount then
|
|
||||||
value = value .. string.format('\n%sStack Size: %s%s',
|
|
||||||
Ansi.yellow, Ansi.reset, self.item.maxCount)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.info.textArea.value = value
|
|
||||||
self.info:show()
|
|
||||||
|
|
||||||
elseif event.type == 'hide_info' then
|
|
||||||
self.info:hide()
|
|
||||||
|
|
||||||
elseif event.type == 'form_invalid' then
|
elseif event.type == 'form_invalid' then
|
||||||
self.notification:error(event.message)
|
self.notification:error(event.message)
|
||||||
@@ -290,7 +269,7 @@ function page:eventHandler(event)
|
|||||||
elseif event.type == 'form_complete' then
|
elseif event.type == 'form_complete' then
|
||||||
local item = self.item
|
local item = self.item
|
||||||
|
|
||||||
if self.form:save() then
|
if manageTab.form:save() then
|
||||||
if self.res.displayName ~= self.origItem.displayName then
|
if self.res.displayName ~= self.origItem.displayName then
|
||||||
self.origItem.displayName = self.res.displayName
|
self.origItem.displayName = self.res.displayName
|
||||||
itemDB:add(self.origItem)
|
itemDB:add(self.origItem)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ local turtle = _G.turtle
|
|||||||
|
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
local function learnRecipe(ignoreNBT)
|
local function learnRecipe()
|
||||||
local ingredients = Milo:getTurtleInventory()
|
local ingredients = Milo:getTurtleInventory()
|
||||||
|
|
||||||
if not ingredients then
|
if not ingredients then
|
||||||
@@ -83,10 +83,6 @@ local function learnRecipe(ignoreNBT)
|
|||||||
|
|
||||||
newRecipe.count = recipe.count
|
newRecipe.count = recipe.count
|
||||||
|
|
||||||
if ignoreNBT then
|
|
||||||
recipe.nbtHash = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local key = Milo:uniqueKey(recipe)
|
local key = Milo:uniqueKey(recipe)
|
||||||
if recipe.maxCount ~= 64 then
|
if recipe.maxCount ~= 64 then
|
||||||
newRecipe.maxCount = recipe.maxCount
|
newRecipe.maxCount = recipe.maxCount
|
||||||
@@ -95,16 +91,10 @@ local function learnRecipe(ignoreNBT)
|
|||||||
if ingredient.maxDamage > 0 then
|
if ingredient.maxDamage > 0 then
|
||||||
-- ingredient.damage = '*' -- I don't think this is right
|
-- ingredient.damage = '*' -- I don't think this is right
|
||||||
end
|
end
|
||||||
if ignoreNBT then
|
|
||||||
ingredient.nbtHash = nil
|
|
||||||
end
|
|
||||||
ingredients[k] = Milo:uniqueKey(ingredient)
|
ingredients[k] = Milo:uniqueKey(ingredient)
|
||||||
end
|
end
|
||||||
|
|
||||||
context.userRecipes[key] = newRecipe
|
Milo:updateRecipe(key, newRecipe)
|
||||||
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
|
|
||||||
Craft.loadRecipes()
|
|
||||||
|
|
||||||
turtle.emptyInventory()
|
turtle.emptyInventory()
|
||||||
|
|
||||||
return recipe
|
return recipe
|
||||||
@@ -115,29 +105,15 @@ local pages = {
|
|||||||
index = 2,
|
index = 2,
|
||||||
validFor = 'Turtle Crafting',
|
validFor = 'Turtle Crafting',
|
||||||
notice = UI.Text {
|
notice = UI.Text {
|
||||||
x = 2, y = 2,
|
x = 3, y = 2,
|
||||||
textColor = colors.yellow,
|
textColor = colors.yellow,
|
||||||
value = 'Place recipe in turtle',
|
value = 'Place recipe in turtle',
|
||||||
},
|
},
|
||||||
ignoreNBT = UI.Checkbox {
|
|
||||||
x = 3, y = 4,
|
|
||||||
help = 'Ignore damage of item',
|
|
||||||
value = true,
|
|
||||||
},
|
|
||||||
text = UI.Text {
|
|
||||||
x = 7, y = 4,
|
|
||||||
value = 'Ignore NBT (recommended)',
|
|
||||||
},
|
|
||||||
ignoreInfo = UI.TextArea {
|
|
||||||
x = 2, ex = -2, y = 6, ey = -2,
|
|
||||||
textColor = colors.yellow,
|
|
||||||
value = 'Some items contain unique NBT information. This information can be ignored for most items.',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function pages.turtleCraft:validate()
|
function pages.turtleCraft:validate()
|
||||||
local recipe, msg = learnRecipe(self, self.ignoreNBT.value)
|
local recipe, msg = learnRecipe()
|
||||||
|
|
||||||
if recipe then
|
if recipe then
|
||||||
local displayName = itemDB:getName(recipe)
|
local displayName = itemDB:getName(recipe)
|
||||||
|
|||||||
Reference in New Issue
Block a user