crafting improvements
This commit is contained in:
@@ -57,10 +57,12 @@ function ChestAdapter:getCachedItemDetails(item, k)
|
|||||||
if not detail then
|
if not detail then
|
||||||
pcall(function() detail = self.getItemMeta(k) end)
|
pcall(function() detail = self.getItemMeta(k) end)
|
||||||
if not detail then
|
if not detail then
|
||||||
|
-- error('Inventory has changed')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- NOT SUFFICIENT
|
-- NOT SUFFICIENT
|
||||||
if detail.name ~= item.name then
|
if detail.name ~= item.name then
|
||||||
|
-- error('Inventory has changed')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -94,11 +96,12 @@ function ChestAdapter:listItems(throttle)
|
|||||||
local entry = self.cache[key]
|
local entry = self.cache[key]
|
||||||
if not entry then
|
if not entry then
|
||||||
entry = self:getCachedItemDetails(v, k)
|
entry = self:getCachedItemDetails(v, k)
|
||||||
if entry then
|
if not entry then
|
||||||
entry.count = 0
|
return -- Inventory has changed
|
||||||
self.cache[key] = entry
|
|
||||||
table.insert(items, entry)
|
|
||||||
end
|
end
|
||||||
|
entry.count = 0
|
||||||
|
self.cache[key] = entry
|
||||||
|
table.insert(items, entry)
|
||||||
end
|
end
|
||||||
|
|
||||||
if entry then
|
if entry then
|
||||||
@@ -129,7 +132,9 @@ end
|
|||||||
function ChestAdapter:provide(item, qty, slot, direction)
|
function ChestAdapter:provide(item, qty, slot, direction)
|
||||||
local stacks = self.list()
|
local stacks = self.list()
|
||||||
for key,stack in Util.rpairs(stacks) do
|
for key,stack in Util.rpairs(stacks) do
|
||||||
if stack.name == item.name and stack.damage == item.damage then
|
if stack.name == item.name and
|
||||||
|
(not item.damage or stack.damage == item.damage) and
|
||||||
|
stack.nbtHash == item.nbtHash then
|
||||||
local amount = math.min(qty, stack.count)
|
local amount = math.min(qty, stack.count)
|
||||||
if amount > 0 then
|
if amount > 0 then
|
||||||
self.pushItems(direction or self.direction, key, amount, slot)
|
self.pushItems(direction or self.direction, key, amount, slot)
|
||||||
|
|||||||
@@ -4,6 +4,33 @@ local Util = require('util')
|
|||||||
|
|
||||||
local itemDB = TableDB({ fileName = 'usr/config/items.db' })
|
local itemDB = TableDB({ fileName = 'usr/config/items.db' })
|
||||||
|
|
||||||
|
local function safeString(text)
|
||||||
|
|
||||||
|
local val = text:byte(1)
|
||||||
|
|
||||||
|
if val < 32 or val > 128 then
|
||||||
|
|
||||||
|
local newText = { }
|
||||||
|
local skip = 0
|
||||||
|
for i = 1, #text do
|
||||||
|
val = text:byte(i)
|
||||||
|
if val == 167 then
|
||||||
|
skip = 2
|
||||||
|
end
|
||||||
|
if skip > 0 then
|
||||||
|
skip = skip - 1
|
||||||
|
else
|
||||||
|
if val >= 32 and val <= 128 then
|
||||||
|
newText[#newText + 1] = val
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return string.char(unpack(newText))
|
||||||
|
end
|
||||||
|
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
function itemDB:makeKey(item)
|
function itemDB:makeKey(item)
|
||||||
return { item.name, item.damage, item.nbtHash }
|
return { item.name, item.damage, item.nbtHash }
|
||||||
end
|
end
|
||||||
@@ -15,7 +42,10 @@ function itemDB:splitKey(key, item)
|
|||||||
if #t[#t] > 8 then
|
if #t[#t] > 8 then
|
||||||
item.nbtHash = table.remove(t)
|
item.nbtHash = table.remove(t)
|
||||||
end
|
end
|
||||||
item.damage = tonumber(table.remove(t))
|
local damage = table.remove(t)
|
||||||
|
if damage ~= '*' then
|
||||||
|
item.damage = tonumber(damage)
|
||||||
|
end
|
||||||
item.name = table.concat(t, ':')
|
item.name = table.concat(t, ':')
|
||||||
|
|
||||||
return item
|
return item
|
||||||
@@ -28,12 +58,16 @@ function itemDB:get(key)
|
|||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
if key[2] ~= 0 then
|
if type(key) == 'string' then
|
||||||
|
key = self:makeKey(self:splitKey(key))
|
||||||
|
end
|
||||||
|
|
||||||
|
if not key[2] or key[2] ~= 0 then
|
||||||
item = TableDB.get(self, { key[1], 0, key[3] })
|
item = TableDB.get(self, { key[1], 0, key[3] })
|
||||||
if item and item.maxDamage > 0 then
|
if item and item.maxDamage > 0 then
|
||||||
item = Util.shallowCopy(item)
|
item = Util.shallowCopy(item)
|
||||||
item.damage = key[2]
|
item.damage = key[2]
|
||||||
item.displayName = string.format('%s (damage: %d)', item.displayName, item.damage)
|
item.displayName = string.format('%s (damage: %s)', item.displayName, (item.damage or '*'))
|
||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -43,6 +77,7 @@ function itemDB:add(key, item)
|
|||||||
if item.maxDamage > 0 then
|
if item.maxDamage > 0 then
|
||||||
key = { key[1], 0, key[3] }
|
key = { key[1], 0, key[3] }
|
||||||
end
|
end
|
||||||
|
item.displayName = safeString(item.displayName)
|
||||||
TableDB.add(self, key, item)
|
TableDB.add(self, key, item)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -58,7 +93,7 @@ function itemDB:getName(item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- fallback to nameDB
|
-- fallback to nameDB
|
||||||
return nameDB:getName(item.name .. ':' .. item.damage)
|
return nameDB:getName(item.name .. ':' .. (item.damage or '*'))
|
||||||
end
|
end
|
||||||
|
|
||||||
function itemDB:getMaxCount(item)
|
function itemDB:getMaxCount(item)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ local function getItemCount(items, key)
|
|||||||
local item = splitKey(key)
|
local item = splitKey(key)
|
||||||
for _,v in pairs(items) do
|
for _,v in pairs(items) do
|
||||||
if v.name == item.name and
|
if v.name == item.name and
|
||||||
v.damage == item.damage and
|
(not item.damage or v.damage == item.damage) and
|
||||||
v.nbtHash == item.nbtHash then
|
v.nbtHash == item.nbtHash then
|
||||||
return v.count
|
return v.count
|
||||||
end
|
end
|
||||||
@@ -47,7 +47,15 @@ local function turtleCraft(recipe, qty, inventoryAdapter)
|
|||||||
|
|
||||||
for k,v in pairs(recipe.ingredients) do
|
for k,v in pairs(recipe.ingredients) do
|
||||||
local item = splitKey(v)
|
local item = splitKey(v)
|
||||||
inventoryAdapter:provide(item, qty, k)
|
local provideQty = qty
|
||||||
|
--[[
|
||||||
|
Turtles can only craft 1 item at a time when using a tool.
|
||||||
|
|
||||||
|
if recipe.craftingTools and recipe.craftingTools[k] then
|
||||||
|
provideQty = 1
|
||||||
|
end
|
||||||
|
]]--
|
||||||
|
inventoryAdapter:provide(item, provideQty, k)
|
||||||
if turtle.getItemCount(k) == 0 then -- ~= qty then
|
if turtle.getItemCount(k) == 0 then -- ~= qty then
|
||||||
-- FIX: ingredients cannot be stacked
|
-- FIX: ingredients cannot be stacked
|
||||||
return false
|
return false
|
||||||
@@ -127,7 +135,9 @@ function Craft.getCraftableAmount(recipe, count, items, missing)
|
|||||||
end
|
end
|
||||||
return canCraft
|
return canCraft
|
||||||
end
|
end
|
||||||
summedItems[item] = summedItem - 1
|
if not recipe.craftingTools or not recipe.craftingTools[item] then
|
||||||
|
summedItems[item] = summedItem - 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
canCraft = canCraft + recipe.count
|
canCraft = canCraft + recipe.count
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ function turtle.craftItem(item, count, inventoryInfo)
|
|||||||
|
|
||||||
local slot = turtle.select(CRAFTING_TABLE)
|
local slot = turtle.select(CRAFTING_TABLE)
|
||||||
turtle.equip(side, CRAFTING_TABLE)
|
turtle.equip(side, CRAFTING_TABLE)
|
||||||
equipped = turtle.getItemDetail(slot)
|
equipped = turtle.getItemDetail(slot.index)
|
||||||
end
|
end
|
||||||
|
|
||||||
success = Craft.craftRecipe(item, count or 1, inventory)
|
success = Craft.craftRecipe(item, count or 1, inventory)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
_G.requireInjector()
|
_G.requireInjector()
|
||||||
|
|
||||||
|
local Ansi = require('ansi')
|
||||||
local ChestAdapter = require('chestAdapter18')
|
local ChestAdapter = require('chestAdapter18')
|
||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
local Craft = require('turtle.craft')
|
local Craft = require('turtle.craft')
|
||||||
@@ -74,27 +75,18 @@ local resources
|
|||||||
|
|
||||||
Craft.setRecipes(recipes)
|
Craft.setRecipes(recipes)
|
||||||
|
|
||||||
local function getItem(items, inItem, ignoreDamage)
|
local function getItem(items, inItem, ignoreDamage, ignoreNbtHash)
|
||||||
for _,item in pairs(items) do
|
for _,item in pairs(items) do
|
||||||
if item.name == inItem.name then
|
if item.name == inItem.name and
|
||||||
if ignoreDamage then
|
(ignoreDamage or item.damage == inItem.damage) and
|
||||||
return item
|
(ignoreNbtHash or item.nbtHash == inItem.nbtHash) then
|
||||||
elseif item.damage == inItem.damage and item.nbtHash == inItem.nbtHash then
|
return item
|
||||||
return item
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function splitKey(key)
|
local function splitKey(key)
|
||||||
local t = Util.split(key, '(.-):')
|
return itemDB:splitKey(key)
|
||||||
local item = { }
|
|
||||||
if #t[#t] > 8 then
|
|
||||||
item.nbtHash = table.remove(t)
|
|
||||||
end
|
|
||||||
item.damage = tonumber(table.remove(t))
|
|
||||||
item.name = table.concat(t, ':')
|
|
||||||
return item
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getItemQuantity(items, item)
|
local function getItemQuantity(items, item)
|
||||||
@@ -219,6 +211,7 @@ local function craftItem(recipe, items, originalItem, craftList, count)
|
|||||||
if missing.name then
|
if missing.name then
|
||||||
originalItem.status = string.format('%s missing', itemDB:getName(missing.name))
|
originalItem.status = string.format('%s missing', itemDB:getName(missing.name))
|
||||||
originalItem.statusCode = 'missing'
|
originalItem.statusCode = 'missing'
|
||||||
|
debug('missing: ' .. missing.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if toCraft > 0 then
|
if toCraft > 0 then
|
||||||
@@ -338,18 +331,18 @@ local function getAutocraftItems()
|
|||||||
return craftList
|
return craftList
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getItemWithQty(items, res, ignoreDamage)
|
local function getItemWithQty(items, res, ignoreDamage, ignoreNbtHash)
|
||||||
|
|
||||||
local item = getItem(items, res, ignoreDamage)
|
local item = getItem(items, res, ignoreDamage, ignoreNbtHash)
|
||||||
|
|
||||||
if item and ignoreDamage then
|
if item and (ignoreDamage or ignoreNbtHash) then
|
||||||
local count = 0
|
local count = 0
|
||||||
|
|
||||||
for _,v in pairs(items) do
|
for _,v in pairs(items) do
|
||||||
if item.name == v.name and item.nbtHash == v.nbtHash then
|
if item.name == v.name and
|
||||||
if item.maxDamage > 0 or item.damage == v.damage then
|
(ignoreDamage or item.damage == v.damage) and
|
||||||
count = count + v.count
|
(ignoreNbtHash or item.nbtHash == v.nbtHash) then
|
||||||
end
|
count = count + v.count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
item.count = count
|
item.count = count
|
||||||
@@ -364,7 +357,7 @@ local function watchResources(items)
|
|||||||
local outputs = { }
|
local outputs = { }
|
||||||
|
|
||||||
for _,res in pairs(resources) do
|
for _,res in pairs(resources) do
|
||||||
local item = getItemWithQty(items, res, res.ignoreDamage)
|
local item = getItemWithQty(items, res, res.ignoreDamage, res.ignoreDamage)
|
||||||
if not item then
|
if not item then
|
||||||
item = {
|
item = {
|
||||||
damage = res.damage,
|
damage = res.damage,
|
||||||
@@ -377,7 +370,7 @@ local function watchResources(items)
|
|||||||
|
|
||||||
if res.limit and item.count > res.limit then
|
if res.limit and item.count > res.limit then
|
||||||
inventoryAdapter:provide(
|
inventoryAdapter:provide(
|
||||||
{ name = item.name, damage = item.damage },
|
{ name = item.name, damage = item.damage, nbtHash = item.nbtHash },
|
||||||
item.count - res.limit,
|
item.count - res.limit,
|
||||||
nil,
|
nil,
|
||||||
config.trashDirection)
|
config.trashDirection)
|
||||||
@@ -505,6 +498,25 @@ local itemPage = UI.Page {
|
|||||||
},
|
},
|
||||||
help = 'Output side'
|
help = 'Output side'
|
||||||
},
|
},
|
||||||
|
infoButton = UI.Button {
|
||||||
|
x = 2, y = -2,
|
||||||
|
event = 'show_info',
|
||||||
|
text = 'Info',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
info = UI.SlideOut {
|
||||||
|
titleBar = UI.TitleBar {
|
||||||
|
title = "Information",
|
||||||
|
},
|
||||||
|
textArea = UI.TextArea {
|
||||||
|
x = 2, ex = -2, y = 3, ey = -4,
|
||||||
|
backgroundColor = colors.black,
|
||||||
|
},
|
||||||
|
cancel = UI.Button {
|
||||||
|
ex = -2, y = -2, width = 6,
|
||||||
|
text = 'Okay',
|
||||||
|
event = 'hide_info',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
statusBar = UI.StatusBar { }
|
statusBar = UI.StatusBar { }
|
||||||
}
|
}
|
||||||
@@ -535,6 +547,22 @@ function itemPage:eventHandler(event)
|
|||||||
if event.type == 'form_cancel' then
|
if event.type == 'form_cancel' then
|
||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
|
elseif event.type == 'show_info' then
|
||||||
|
self.info.textArea.value =
|
||||||
|
string.format(
|
||||||
|
[[%sName: %s%s
|
||||||
|
%sID: %s%s
|
||||||
|
%sDamage: %s%s
|
||||||
|
%sNBT: %s%s]],
|
||||||
|
Ansi.yellow, Ansi.reset, self.item.displayName,
|
||||||
|
Ansi.yellow, Ansi.reset, self.item.name,
|
||||||
|
Ansi.yellow, Ansi.reset, self.item.damage,
|
||||||
|
Ansi.yellow, Ansi.reset, self.item.nbtHash or '(none)')
|
||||||
|
self.info:show()
|
||||||
|
|
||||||
|
elseif event.type == 'hide_info' then
|
||||||
|
self.info:hide()
|
||||||
|
|
||||||
elseif event.type == 'focus_change' then
|
elseif event.type == 'focus_change' then
|
||||||
self.statusBar:setStatus(event.focused.help)
|
self.statusBar:setStatus(event.focused.help)
|
||||||
self.statusBar:draw()
|
self.statusBar:draw()
|
||||||
@@ -763,20 +791,65 @@ local function learnRecipe(page)
|
|||||||
if ingredients then
|
if ingredients then
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
if canCraft and turtle.craft() then
|
if canCraft and turtle.craft() then
|
||||||
local recipe = getTurtleInventory()
|
local results = getTurtleInventory()
|
||||||
if recipe and recipe[1] then
|
if results and results[1] then
|
||||||
clearGrid()
|
clearGrid()
|
||||||
|
|
||||||
local key = uniqueKey(recipe[1])
|
local maxCount
|
||||||
local newRecipe = {
|
local newRecipe = {
|
||||||
count = recipe[1].count,
|
|
||||||
ingredients = ingredients,
|
ingredients = ingredients,
|
||||||
}
|
}
|
||||||
if recipe[1].maxCount ~= 64 then
|
|
||||||
newRecipe.maxCount = recipe[1].maxCount
|
for _,v1 in pairs(results) do
|
||||||
|
for _,v2 in pairs(ingredients) do
|
||||||
|
if v1.name == v2.name and
|
||||||
|
v1.nbtHash == v2.nbtHash and
|
||||||
|
(v1.damage == v2.damage or
|
||||||
|
(v1.maxDamage > 0 and v2.maxDamage > 0 and
|
||||||
|
v1.damage ~= v2.damage)) then
|
||||||
|
if not newRecipe.crafingTools then
|
||||||
|
newRecipe.craftingTools = { }
|
||||||
|
end
|
||||||
|
local tool = Util.shallowCopy(v2)
|
||||||
|
if tool.maxDamage > 0 then
|
||||||
|
tool.damage = '*'
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Turtles can only craft one item at a time using a tool :(
|
||||||
|
]]--
|
||||||
|
maxCount = 1
|
||||||
|
|
||||||
|
newRecipe.craftingTools[uniqueKey(tool)] = true
|
||||||
|
v1.craftingTool = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local recipe
|
||||||
|
for _,v in pairs(results) do
|
||||||
|
if not v.craftingTool then
|
||||||
|
recipe = v
|
||||||
|
recipe.maxCount = maxCount
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not recipe then
|
||||||
|
error('Failed')
|
||||||
|
end
|
||||||
|
|
||||||
|
newRecipe.count = recipe.count
|
||||||
|
|
||||||
|
local key = uniqueKey(recipe)
|
||||||
|
if recipe.maxCount ~= 64 then
|
||||||
|
newRecipe.maxCount = recipe.maxCount
|
||||||
end
|
end
|
||||||
|
|
||||||
for k,ingredient in pairs(ingredients) do
|
for k,ingredient in pairs(ingredients) do
|
||||||
|
if ingredient.maxDamage > 0 then
|
||||||
|
ingredient.damage = '*'
|
||||||
|
end
|
||||||
ingredients[k] = uniqueKey(ingredient)
|
ingredients[k] = uniqueKey(ingredient)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -784,7 +857,7 @@ local function learnRecipe(page)
|
|||||||
|
|
||||||
Util.writeTable(RECIPES_FILE, recipes)
|
Util.writeTable(RECIPES_FILE, recipes)
|
||||||
|
|
||||||
local displayName = itemDB:getName(recipe[1])
|
local displayName = itemDB:getName(recipe)
|
||||||
|
|
||||||
listingPage.statusBar.filter:setValue(displayName)
|
listingPage.statusBar.filter:setValue(displayName)
|
||||||
listingPage.statusBar:timedStatus('Learned: ' .. displayName, 3)
|
listingPage.statusBar:timedStatus('Learned: ' .. displayName, 3)
|
||||||
|
|||||||
@@ -161,6 +161,10 @@ local function craftItem(recipe, items, cItem, count)
|
|||||||
local slot = 1
|
local slot = 1
|
||||||
for key,qty in pairs(recipe.ingredients) do
|
for key,qty in pairs(recipe.ingredients) do
|
||||||
local item = itemDB:get(key)
|
local item = itemDB:get(key)
|
||||||
|
if not item then
|
||||||
|
cItem.status = 'failed'
|
||||||
|
return false
|
||||||
|
end
|
||||||
local c = count * qty
|
local c = count * qty
|
||||||
while c > 0 do
|
while c > 0 do
|
||||||
local maxCount = math.min(c, item.maxCount)
|
local maxCount = math.min(c, item.maxCount)
|
||||||
@@ -169,7 +173,7 @@ local function craftItem(recipe, items, cItem, count)
|
|||||||
cItem.status = 'failed'
|
cItem.status = 'failed'
|
||||||
debug(item)
|
debug(item)
|
||||||
debug({ c, maxCount, count })
|
debug({ c, maxCount, count })
|
||||||
read()
|
--read()
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
c = c - maxCount
|
c = c - maxCount
|
||||||
@@ -198,6 +202,10 @@ local function expandList(list)
|
|||||||
local item = getItem(items, itemDB:splitKey(key))
|
local item = getItem(items, itemDB:splitKey(key))
|
||||||
if not item then
|
if not item then
|
||||||
item = itemDB:get(key)
|
item = itemDB:get(key)
|
||||||
|
if not item then
|
||||||
|
--item = itemDB:splitKey(key)
|
||||||
|
break
|
||||||
|
end
|
||||||
item.count = 0
|
item.count = 0
|
||||||
end
|
end
|
||||||
local need = qty * count
|
local need = qty * count
|
||||||
@@ -210,6 +218,9 @@ debug({ key, count, need })
|
|||||||
list[key].ocount = need
|
list[key].ocount = need
|
||||||
list[key].count = 0
|
list[key].count = 0
|
||||||
else
|
else
|
||||||
|
if not list[key].ocount then
|
||||||
|
list[key].ocount = 0
|
||||||
|
end
|
||||||
list[key].ocount = list[key].ocount + need
|
list[key].ocount = list[key].ocount + need
|
||||||
end
|
end
|
||||||
debug('adding ' .. key .. ' ' .. need)
|
debug('adding ' .. key .. ' ' .. need)
|
||||||
@@ -471,6 +482,10 @@ function itemPage:eventHandler(event)
|
|||||||
filtered.ignoreDamage = true
|
filtered.ignoreDamage = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Util.empty(filtered) then
|
||||||
|
filtered = nil
|
||||||
|
end
|
||||||
|
|
||||||
resources[uniqueKey(filtered)] = filtered
|
resources[uniqueKey(filtered)] = filtered
|
||||||
saveResources()
|
saveResources()
|
||||||
|
|
||||||
@@ -553,7 +568,10 @@ function learnPage:enable(target)
|
|||||||
if target.has_recipe then
|
if target.has_recipe then
|
||||||
local recipe = recipes[uniqueKey(target)]
|
local recipe = recipes[uniqueKey(target)]
|
||||||
screen2.count.value = recipe.count
|
screen2.count.value = recipe.count
|
||||||
screen2.machine:setIndex(select(2, Util.find(machines, 'index', recipe.machine)))
|
local _, index = Util.find(machines, 'index', recipe.machine)
|
||||||
|
if index then
|
||||||
|
screen2.machine:setIndex(index)
|
||||||
|
end
|
||||||
for k,v in pairs(recipe.ingredients) do
|
for k,v in pairs(recipe.ingredients) do
|
||||||
screen1.ingredients.values[k] =
|
screen1.ingredients.values[k] =
|
||||||
{ name = k, count = v, displayName = itemDB:getName(k) }
|
{ name = k, count = v, displayName = itemDB:getName(k) }
|
||||||
|
|||||||
@@ -284,8 +284,8 @@ local function createFurnace()
|
|||||||
print('Adding a furnace')
|
print('Adding a furnace')
|
||||||
getCobblestone(8)
|
getCobblestone(8)
|
||||||
|
|
||||||
if craftItem(FURNACE) then
|
if turtle.has(FURNACE) or craftItem(FURNACE) then
|
||||||
turtle.drop(COBBLESTONE)
|
-- turtle.drop(COBBLESTONE)
|
||||||
local furnacePt = { x = GRID.BL.x + 2, y = 1, z = GRID.BL.z + 2 }
|
local furnacePt = { x = GRID.BL.x + 2, y = 1, z = GRID.BL.z + 2 }
|
||||||
turtle.placeAt(furnacePt, FURNACE)
|
turtle.placeAt(furnacePt, FURNACE)
|
||||||
setState('furnace', furnacePt)
|
setState('furnace', furnacePt)
|
||||||
@@ -306,7 +306,9 @@ local function createPerimeter()
|
|||||||
print('Creating a perimeter')
|
print('Creating a perimeter')
|
||||||
|
|
||||||
getCobblestone(GRID_WIDTH * 2 + 1)
|
getCobblestone(GRID_WIDTH * 2 + 1)
|
||||||
cook(COBBLESTONE, 2, STONE, OAK_PLANK, 2)
|
if not turtle.has(STONE, 2) then
|
||||||
|
cook(COBBLESTONE, 2, STONE, OAK_PLANK, 2)
|
||||||
|
end
|
||||||
turtle.refuel(OAK_PLANK)
|
turtle.refuel(OAK_PLANK)
|
||||||
|
|
||||||
turtle.pathfind(GRID.BL)
|
turtle.pathfind(GRID.BL)
|
||||||
@@ -337,7 +339,7 @@ local function createPerimeter()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function createChests()
|
local function createChests()
|
||||||
if state.chest_1 then
|
if state.chest then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if state.perimeter and
|
if state.perimeter and
|
||||||
@@ -345,27 +347,24 @@ local function createChests()
|
|||||||
turtle.canCraft(CHEST, 4, turtle.getSummedInventory()) then
|
turtle.canCraft(CHEST, 4, turtle.getSummedInventory()) then
|
||||||
|
|
||||||
print('Adding storage')
|
print('Adding storage')
|
||||||
if craftItem(CHEST, 4) then
|
if turtle.has(CHEST, 2) or craftItem(CHEST, 2) then
|
||||||
|
|
||||||
local pt = Point.copy(GRID.BL)
|
local pt = Point.copy(GRID.BL)
|
||||||
pt.x = pt.x + 1
|
pt.x = pt.x + 1
|
||||||
pt.y = pt.y - 1
|
pt.y = pt.y - 1
|
||||||
|
|
||||||
for i = 1, 2 do
|
pt.z = pt.z + 1
|
||||||
pt.z = pt.z + 1
|
|
||||||
|
|
||||||
turtle.digDownAt(pt)
|
turtle.digDownAt(pt)
|
||||||
turtle.placeDown(CHEST)
|
turtle.placeDown(CHEST)
|
||||||
|
|
||||||
pt.z = pt.z + 1
|
pt.z = pt.z + 1
|
||||||
|
|
||||||
turtle.digDownAt(pt)
|
turtle.digDownAt(pt)
|
||||||
turtle.placeDown(CHEST)
|
turtle.placeDown(CHEST)
|
||||||
|
|
||||||
setState('chest_' .. i, Util.shallowCopy(pt))
|
setState('chest', Util.shallowCopy(pt))
|
||||||
|
|
||||||
pt.z = pt.z + 1
|
|
||||||
end
|
|
||||||
turtle.drop(DIRT)
|
turtle.drop(DIRT)
|
||||||
turtle.refuel(OAK_PLANK)
|
turtle.refuel(OAK_PLANK)
|
||||||
end
|
end
|
||||||
@@ -375,24 +374,27 @@ end
|
|||||||
|
|
||||||
local function dropOffItems()
|
local function dropOffItems()
|
||||||
|
|
||||||
if state.chest_1 then
|
if state.chest then
|
||||||
local slots = turtle.getSummedInventory()
|
local slots = turtle.getSummedInventory()
|
||||||
|
|
||||||
if state.chest_1 and
|
if state.chest and
|
||||||
slots[CHARCOAL] and
|
slots[CHARCOAL] and
|
||||||
slots[CHARCOAL].count >= MIN_CHARCOAL and
|
slots[CHARCOAL].count >= MIN_CHARCOAL and
|
||||||
(turtle.getItemCount('minecraft:log') > 0 or
|
(turtle.getItemCount('minecraft:log') > 0 or
|
||||||
turtle.getItemCount('minecraft:log2') > 0) then
|
turtle.getItemCount('minecraft:log2') > 0) then
|
||||||
|
|
||||||
print('Storing logs')
|
print('Storing logs')
|
||||||
turtle.pathfind(Point.above(state.chest_1))
|
turtle.pathfind(Point.above(state.chest))
|
||||||
turtle.dropDown('minecraft:log')
|
turtle.dropDown('minecraft:log')
|
||||||
turtle.dropDown('minecraft:log2')
|
turtle.dropDown('minecraft:log2')
|
||||||
end
|
|
||||||
|
|
||||||
if slots[APPLE] then
|
for _, sapling in pairs(ALL_SAPLINGS) do
|
||||||
print('Storing apples')
|
if slots[sapling] and slots[sapling].count > MAX_SAPLINGS then
|
||||||
turtle.dropDownAt(state.chest_2, APPLE)
|
turtle.dropDown(sapling, slots[sapling].count - MAX_SAPLINGS)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
turtle.dropDown(APPLE)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -421,7 +423,7 @@ local function placeTorches()
|
|||||||
|
|
||||||
print('Placing torches')
|
print('Placing torches')
|
||||||
|
|
||||||
if craftItem(TORCH, 4) then
|
if turtle.has(TORCH, 4) or craftItem(TORCH, 4) then
|
||||||
local pts = { }
|
local pts = { }
|
||||||
for x = -4, 4, 8 do
|
for x = -4, 4, 8 do
|
||||||
for z = -4, 4, 8 do
|
for z = -4, 4, 8 do
|
||||||
@@ -532,7 +534,7 @@ local function moreTrees()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if not state.chest_1 or turtle.getItemCount('minecraft:sapling') < 15 then
|
if not state.chest or turtle.getItemCount('minecraft:sapling') < 15 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -694,7 +696,7 @@ local tasks = {
|
|||||||
{ desc = 'Emptying furnace', fn = emptyFurnace },
|
{ desc = 'Emptying furnace', fn = emptyFurnace },
|
||||||
{ desc = 'Adding trees', fn = moreTrees },
|
{ desc = 'Adding trees', fn = moreTrees },
|
||||||
{ desc = 'Chopping', fn = fell },
|
{ desc = 'Chopping', fn = fell },
|
||||||
{ desc = 'Snacking', fn = eatSaplings },
|
-- { desc = 'Snacking', fn = eatSaplings },
|
||||||
{ desc = 'Creating chest', fn = createChests },
|
{ desc = 'Creating chest', fn = createChests },
|
||||||
{ desc = 'Creating furnace', fn = createFurnace },
|
{ desc = 'Creating furnace', fn = createFurnace },
|
||||||
{ desc = 'Making charcoal', fn = makeSingleCharcoal },
|
{ desc = 'Making charcoal', fn = makeSingleCharcoal },
|
||||||
|
|||||||
4010
etc/recipes.db
4010
etc/recipes.db
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user