mirror of
https://github.com/kepler155c/opus
synced 2025-12-12 03:18:08 +00:00
upgrade item keys
This commit is contained in:
@@ -4,20 +4,20 @@ end
|
||||
|
||||
requireInjector(getfenv(1))
|
||||
|
||||
local Blocks = require('blocks')
|
||||
local class = require('class')
|
||||
local Event = require('event')
|
||||
local MEProvider = require('meProvider')
|
||||
local Message = require('message')
|
||||
local Point = require('point')
|
||||
local Schematic = require('schematic')
|
||||
local TableDB = require('tableDB')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
local Blocks = require('blocks')
|
||||
local class = require('class')
|
||||
local Event = require('event')
|
||||
local MEAdapter = require('meAdapter')
|
||||
local Message = require('message')
|
||||
local Point = require('point')
|
||||
local Schematic = require('schematic')
|
||||
local TableDB = require('tableDB')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local ChestProvider = require('chestProvider')
|
||||
local ChestAdapter = require('chestAdapter')
|
||||
if Util.getVersion() == 1.8 then
|
||||
ChestProvider = require('chestProvider18')
|
||||
ChestAdapter = require('chestAdapter18')
|
||||
end
|
||||
|
||||
if not _G.device then
|
||||
@@ -45,6 +45,40 @@ local Builder = {
|
||||
|
||||
local pistonFacings
|
||||
|
||||
-- Temp functions until conversion to new adapters is complete
|
||||
local function convertSingleForward(item)
|
||||
item.name = item.id
|
||||
item.damage = item.dmg
|
||||
item.count = item.count
|
||||
item.maxCount = item.max_size
|
||||
return item
|
||||
end
|
||||
|
||||
local function convertForward(t)
|
||||
for _,v in pairs(t) do
|
||||
convertSingleForward(v)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
local function convertSingleBack(item)
|
||||
if item then
|
||||
item.id = item.name
|
||||
item.dmg = item.damage
|
||||
item.qty = item.count
|
||||
item.max_size = item.maxCount
|
||||
item.display_name = item.displayName
|
||||
end
|
||||
return item
|
||||
end
|
||||
|
||||
local function convertBack(t)
|
||||
for _,v in pairs(t) do
|
||||
convertSingleBack(v)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
--[[-- SubDB --]]--
|
||||
subDB = TableDB({
|
||||
fileName = fs.combine(BUILDER_DIR, 'sub.db'),
|
||||
@@ -397,7 +431,7 @@ function Builder:dumpInventory()
|
||||
for i = 1, 16 do
|
||||
local qty = turtle.getItemCount(i)
|
||||
if qty > 0 then
|
||||
self.itemProvider:insert(i, qty)
|
||||
self.itemAdapter:insert(i, qty)
|
||||
end
|
||||
if turtle.getItemCount(i) ~= 0 then
|
||||
success = false
|
||||
@@ -411,7 +445,7 @@ end
|
||||
function Builder:dumpInventoryWithCheck()
|
||||
|
||||
while not self:dumpInventory() do
|
||||
print('Provider is full or missing - make space or replace')
|
||||
print('Storage is full or missing - make space or replace')
|
||||
print('Press enter to continue')
|
||||
turtle.setHeading(0)
|
||||
read()
|
||||
@@ -435,17 +469,17 @@ function Builder:autocraft(supplies)
|
||||
item.qty = item.qty + (s.need - s.qty)
|
||||
end
|
||||
|
||||
Builder.itemProvider:craftItems(t)
|
||||
Builder.itemAdapter:craftItems(convertForward(t))
|
||||
end
|
||||
|
||||
function Builder:getSupplies()
|
||||
|
||||
self.itemProvider:refresh()
|
||||
self.itemAdapter:refresh()
|
||||
|
||||
local t = { }
|
||||
for _,s in ipairs(self.slots) do
|
||||
if s.need > 0 then
|
||||
local item = self.itemProvider:getItemInfo(s.id, s.dmg)
|
||||
local item = convertSingleBack(self.itemAdapter:getItemInfo(s.id, s.dmg))
|
||||
if item then
|
||||
s.name = item.display_name
|
||||
|
||||
@@ -459,7 +493,7 @@ function Builder:getSupplies()
|
||||
s.need = qty
|
||||
end
|
||||
if qty > 0 then
|
||||
self.itemProvider:provide(item, qty, s.index)
|
||||
self.itemAdapter:provide(convertSingleForward(item), qty, s.index)
|
||||
s.qty = turtle.getItemCount(s.index)
|
||||
end
|
||||
else
|
||||
@@ -485,7 +519,7 @@ function Builder:refuel()
|
||||
|
||||
local fuel = subDB:getSubstitutedItem(self.fuelItem.id, self.fuelItem.dmg)
|
||||
|
||||
self.itemProvider:provide(fuel, 64, 1)
|
||||
self.itemAdapter:provide(convertSingleForward(fuel), 64, 1)
|
||||
if turtle.getItemCount(1) == 0 then
|
||||
print('Out of fuel, add fuel to chest/ME system')
|
||||
turtle.setHeading(0)
|
||||
@@ -523,23 +557,23 @@ function Builder:inAirDropoff()
|
||||
turtle.goto(pt.x, pt.z, pt.y)
|
||||
os.sleep(.1) -- random computer is not connected error
|
||||
|
||||
local chestProvider = ChestProvider({ direction = 'down', wrapSide = 'top' })
|
||||
local chestAdapter = ChestAdapter({ direction = 'down', wrapSide = 'top' })
|
||||
|
||||
if not chestProvider:isValid() then
|
||||
if not chestAdapter:isValid() then
|
||||
self:log('Chests above is not valid')
|
||||
return false
|
||||
end
|
||||
|
||||
local oldProvider = self.itemProvider
|
||||
self.itemProvider = chestProvider
|
||||
local oldAdapter = self.itemAdapter
|
||||
self.itemAdapter = chestAdapter
|
||||
|
||||
if not self:dumpInventory() then
|
||||
self:log('Unable to dump inventory')
|
||||
self.itemProvider = oldProvider
|
||||
self.itemAdapter = oldAdapter
|
||||
return false
|
||||
end
|
||||
|
||||
self.itemProvider = oldProvider
|
||||
self.itemAdapter = oldAdapter
|
||||
|
||||
Message.broadcast('thanks', { })
|
||||
|
||||
@@ -563,7 +597,7 @@ function Builder:inAirResupply()
|
||||
return false
|
||||
end
|
||||
|
||||
local oldProvider = self.itemProvider
|
||||
local oldAdapter = self.itemAdapter
|
||||
|
||||
self:log('Requesting air supply drop for supply #: ' .. self.slotUid)
|
||||
while true do
|
||||
@@ -571,7 +605,7 @@ function Builder:inAirResupply()
|
||||
local _, id, msg, _ = Message.waitForMessage('gotSupplies', 1)
|
||||
|
||||
if not msg or not msg.contents then
|
||||
self.itemProvider = oldProvider
|
||||
self.itemAdapter = oldAdapter
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -586,17 +620,17 @@ function Builder:inAirResupply()
|
||||
turtle.goto(pt.x, pt.z, pt.y)
|
||||
os.sleep(.1) -- random computer is not connected error
|
||||
|
||||
local chestProvider = ChestProvider({ direction = 'down', wrapSide = 'top' })
|
||||
local chestAdapter = ChestAdapter({ direction = 'down', wrapSide = 'top' })
|
||||
|
||||
if not chestProvider:isValid() then
|
||||
if not chestAdapter:isValid() then
|
||||
Util.print('not valid')
|
||||
read()
|
||||
end
|
||||
|
||||
self.itemProvider = chestProvider
|
||||
self.itemAdapter = chestAdapter
|
||||
|
||||
if not self:dumpInventory() then
|
||||
self.itemProvider = oldProvider
|
||||
self.itemAdapter = oldAdapter
|
||||
return false
|
||||
end
|
||||
self:refuel()
|
||||
@@ -606,7 +640,7 @@ function Builder:inAirResupply()
|
||||
|
||||
Message.broadcast('thanks', { })
|
||||
|
||||
self.itemProvider = oldProvider
|
||||
self.itemAdapter = oldAdapter
|
||||
|
||||
if #supplies == 0 then
|
||||
|
||||
@@ -1449,7 +1483,7 @@ end
|
||||
|
||||
function substitutionPage:enable()
|
||||
|
||||
self.allItems = Builder.itemProvider:refresh()
|
||||
self.allItems = convertBack(Builder.itemAdapter:refresh())
|
||||
self.grid.values = self.allItems
|
||||
for _,item in pairs(self.grid.values) do
|
||||
item.key = item.id .. ':' .. item.dmg
|
||||
@@ -1583,7 +1617,7 @@ function supplyPage:eventHandler(event)
|
||||
|
||||
if event.type == 'craft' then
|
||||
local s = self.grid:getSelected()
|
||||
if Builder.itemProvider:craft(s.id, s.dmg, s.need-s.qty) then
|
||||
if Builder.itemAdapter:craft(s.id, s.dmg, s.need-s.qty) then
|
||||
local name = s.name or ''
|
||||
self.statusBar:timedStatus('Requested ' .. s.need-s.qty .. ' ' .. name, 3)
|
||||
else
|
||||
@@ -1708,12 +1742,12 @@ function listingPage:eventHandler(event)
|
||||
|
||||
if event.type == 'craft' then
|
||||
local s = self.grid:getSelected()
|
||||
local item = Builder.itemProvider:getItemInfo(s.id, s.dmg)
|
||||
local item = convertSingleBack(Builder.itemAdapter:getItemInfo(s.id, s.dmg))
|
||||
if item and item.is_craftable then
|
||||
local qty = math.max(0, s.need - item.qty)
|
||||
|
||||
if item then
|
||||
Builder.itemProvider:craft(s.id, s.dmg, qty)
|
||||
Builder.itemAdapter:craft(s.id, s.dmg, qty)
|
||||
local name = s.name or s.key
|
||||
self.statusBar:timedStatus('Requested ' .. qty .. ' ' .. name, 3)
|
||||
end
|
||||
@@ -1768,11 +1802,11 @@ function listingPage:refresh(throttle)
|
||||
|
||||
local supplyList = Builder:getBlockCounts()
|
||||
|
||||
Builder.itemProvider:refresh(throttle)
|
||||
Builder.itemAdapter:refresh(throttle)
|
||||
|
||||
for _,b in pairs(supplyList) do
|
||||
if b.need > 0 then
|
||||
local item = Builder.itemProvider:getItemInfo(b.id, b.dmg)
|
||||
local item = convertSingleBack(Builder.itemAdapter:getItemInfo(b.id, b.dmg))
|
||||
|
||||
if item then
|
||||
local block = blocks.blockDB:lookup(b.id, b.dmg)
|
||||
@@ -2054,10 +2088,10 @@ if #args < 1 then
|
||||
error('supply file name')
|
||||
end
|
||||
|
||||
Builder.itemProvider = MEProvider()
|
||||
if not Builder.itemProvider:isValid() then
|
||||
Builder.itemProvider = ChestProvider()
|
||||
if not Builder.itemProvider:isValid() then
|
||||
Builder.itemAdapter = MEAdapter()
|
||||
if not Builder.itemAdapter:isValid() then
|
||||
Builder.itemAdapter = ChestAdapter()
|
||||
if not Builder.itemAdapter:isValid() then
|
||||
error('A chest or ME interface must be below turtle')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
requireInjector(getfenv(1))
|
||||
|
||||
local ChestProvider = require('chestProvider18')
|
||||
local Config = require('config')
|
||||
local Craft = require('turtle.craft')
|
||||
local Event = require('event')
|
||||
local itemDB = require('itemDB')
|
||||
local Peripheral = require('peripheral')
|
||||
local RefinedProvider = require('refinedProvider')
|
||||
local Terminal = require('terminal')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
local ChestAdapter = require('chestAdapter18')
|
||||
local Config = require('config')
|
||||
local Craft = require('turtle.craft')
|
||||
local Event = require('event')
|
||||
local itemDB = require('itemDB')
|
||||
local Peripheral = require('peripheral')
|
||||
local RefinedAdapter = require('refinedAdapter')
|
||||
local Terminal = require('terminal')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
multishell.setTitle(multishell.getCurrent(), 'Resource Manager')
|
||||
|
||||
@@ -25,14 +25,14 @@ local config = {
|
||||
|
||||
Config.load('resourceManager', config)
|
||||
|
||||
local controller = RefinedProvider()
|
||||
local controller = RefinedAdapter()
|
||||
if not controller:isValid() then
|
||||
-- error('Refined storage controller not found')
|
||||
controller = nil
|
||||
end
|
||||
|
||||
local chestProvider = ChestProvider({ direction = 'west', wrapSide = 'back' })
|
||||
local turtleChestProvider = ChestProvider({ direction = 'up', wrapSide = 'bottom' })
|
||||
local chestAdapter = ChestAdapter({ direction = 'west', wrapSide = 'back' })
|
||||
local turtleChestAdapter = ChestAdapter({ direction = 'up', wrapSide = 'bottom' })
|
||||
|
||||
local RESOURCE_FILE = 'usr/etc/resources.db'
|
||||
local RECIPES_FILE = 'sys/etc/recipes.db'
|
||||
@@ -195,7 +195,7 @@ local function clearGrid()
|
||||
for i = 1, 16 do
|
||||
local count = turtle.getItemCount(i)
|
||||
if count > 0 then
|
||||
chestProvider:insert(i, count)
|
||||
chestAdapter:insert(i, count)
|
||||
if turtle.getItemCount(i) ~= 0 then
|
||||
return false
|
||||
end
|
||||
@@ -224,9 +224,9 @@ local function craftItem(recipe, items, originalItem, craftList, count)
|
||||
local toCraft = Craft.getCraftableAmount(recipe, count, items)
|
||||
|
||||
if toCraft > 0 then
|
||||
Craft.craftRecipe(recipe, toCraft, chestProvider)
|
||||
Craft.craftRecipe(recipe, toCraft, chestAdapter)
|
||||
clearGrid()
|
||||
items = chestProvider:listItems()
|
||||
items = chestAdapter:listItems()
|
||||
end
|
||||
|
||||
count = count - toCraft
|
||||
@@ -250,7 +250,7 @@ local function craftItems(craftList, allItems)
|
||||
local recipe = recipes[key]
|
||||
if recipe then
|
||||
craftItem(recipe, allItems, item, craftList, item.count)
|
||||
allItems = chestProvider:listItems() -- refresh counts
|
||||
allItems = chestAdapter:listItems() -- refresh counts
|
||||
elseif item.rsControl then
|
||||
item.status = 'Activated'
|
||||
end
|
||||
@@ -368,7 +368,7 @@ local function watchResources(items)
|
||||
end
|
||||
|
||||
if res.limit and item.count > res.limit then
|
||||
chestProvider:provide({ id = res.name, dmg = res.damage, nbtHash = res.nbt_hash }, item.count - res.limit, nil, config.trashDirection)
|
||||
chestAdapter:provide(res, item.count - res.limit, nil, config.trashDirection)
|
||||
|
||||
elseif res.low and item.count < res.low then
|
||||
if res.ignoreDamage then
|
||||
@@ -701,7 +701,7 @@ function listingPage:enable()
|
||||
end
|
||||
|
||||
function listingPage:refresh()
|
||||
self.allItems = chestProvider:listItems()
|
||||
self.allItems = chestAdapter:listItems()
|
||||
mergeResources(self.allItems)
|
||||
self:applyFilter()
|
||||
end
|
||||
@@ -733,10 +733,10 @@ local function getTurtleInventory()
|
||||
for i = 1,16 do
|
||||
local qty = turtle.getItemCount(i)
|
||||
if qty > 0 then
|
||||
turtleChestProvider:insert(i, qty)
|
||||
local items = turtleChestProvider:listItems()
|
||||
turtleChestAdapter:insert(i, qty)
|
||||
local items = turtleChestAdapter:listItems()
|
||||
_, inventory[i] = next(items)
|
||||
turtleChestProvider:extract(1, qty, i)
|
||||
turtleChestAdapter:extract(1, qty, i)
|
||||
end
|
||||
end
|
||||
return inventory
|
||||
@@ -759,26 +759,26 @@ local function learnRecipe(page)
|
||||
if device.workbench and turtle.craft() then
|
||||
recipe = getTurtleInventory()
|
||||
if recipe and recipe[1] then
|
||||
recipe = recipe[1]
|
||||
local key = uniqueKey(recipe)
|
||||
|
||||
clearGrid()
|
||||
|
||||
filter(recipe, { 'name', 'damage', 'nbtHash', 'count', 'maxCount' })
|
||||
|
||||
for _,ingredient in pairs(ingredients) do
|
||||
filter(ingredient, { 'name', 'damage', 'nbtHash', 'count', 'maxCount' })
|
||||
--if ingredient.max_dmg > 0 then -- let's try this...
|
||||
-- ingredient.dmg = 0
|
||||
--end
|
||||
local key = uniqueKey(recipe[1])
|
||||
local newRecipe = {
|
||||
count = recipe[1].count,
|
||||
ingredients = ingredients,
|
||||
}
|
||||
if recipe[1].maxCount ~= 64 then
|
||||
newRecipe.maxCount = recipe[1].maxCount
|
||||
end
|
||||
recipe.ingredients = ingredients
|
||||
|
||||
recipes[key] = recipe
|
||||
for k,ingredient in pairs(ingredients) do
|
||||
ingredients[k] = uniqueKey(ingredient)
|
||||
end
|
||||
|
||||
recipes[key] = newRecipe
|
||||
|
||||
Util.writeTable(RECIPES_FILE, recipes)
|
||||
|
||||
local displayName = getName(recipe)
|
||||
local displayName = getName(recipe[1])
|
||||
|
||||
listingPage.statusBar.filter:setValue(displayName)
|
||||
listingPage.statusBar:timedStatus('Learned: ' .. displayName, 3)
|
||||
@@ -914,7 +914,7 @@ jobListGrid:sync()
|
||||
Event.onInterval(5, function()
|
||||
|
||||
if not craftingPaused then
|
||||
local items = chestProvider:listItems()
|
||||
local items = chestAdapter:listItems()
|
||||
if Util.size(items) == 0 then
|
||||
jobListGrid.parent:clear()
|
||||
jobListGrid.parent:centeredWrite(math.ceil(jobListGrid.parent.height/2), 'No items in system')
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
requireInjector(getfenv(1))
|
||||
|
||||
local RefinedProvider = require('refinedProvider')
|
||||
local TableDB = require('tableDB')
|
||||
|
||||
local controller = RefinedProvider()
|
||||
if not controller:isValid() then
|
||||
error('Refined storage controller not found')
|
||||
end
|
||||
|
||||
local itemInfoDB = TableDB({
|
||||
fileName = 'items.db'
|
||||
})
|
||||
|
||||
itemInfoDB:load()
|
||||
|
||||
local items = controller:listItems()
|
||||
|
||||
local keys = {
|
||||
'fields',
|
||||
'damage',
|
||||
'displayName',
|
||||
'maxCount',
|
||||
'maxDamage',
|
||||
'name',
|
||||
'nbtHash',
|
||||
'rawName',
|
||||
}
|
||||
|
||||
for _, item in pairs(items) do
|
||||
|
||||
local t = { }
|
||||
for _,key in pairs(keys) do
|
||||
t[key] = item[key]
|
||||
end
|
||||
|
||||
itemInfoDB:add({ item.name, item.damage, item.nbtHash }, t)
|
||||
end
|
||||
|
||||
itemInfoDB:flush()
|
||||
@@ -15,22 +15,22 @@ local script = [[
|
||||
|
||||
requireInjector(getfenv(1))
|
||||
|
||||
local GPS = require('gps')
|
||||
local ChestProvider = require('chestProvider18')
|
||||
local Point = require('point')
|
||||
local Util = require('util')
|
||||
local GPS = require('gps')
|
||||
local ChestAdapter = require('chestAdapter18')
|
||||
local Point = require('point')
|
||||
local Util = require('util')
|
||||
|
||||
local itemProvider
|
||||
local itemAdapter
|
||||
|
||||
function dumpInventory()
|
||||
|
||||
for i = 1, 16 do
|
||||
local qty = turtle.getItemCount(i)
|
||||
if qty > 0 then
|
||||
itemProvider:insert(i, qty)
|
||||
itemAdapter:insert(i, qty)
|
||||
end
|
||||
if turtle.getItemCount(i) ~= 0 then
|
||||
print('Provider is full or missing - make space or replace')
|
||||
print('Adapter is full or missing - make space or replace')
|
||||
print('Press enter to continue')
|
||||
read()
|
||||
end
|
||||
@@ -43,7 +43,7 @@ local function refuel()
|
||||
print('Refueling')
|
||||
turtle.select(1)
|
||||
|
||||
itemProvider:provide({ id = 'minecraft:coal', dmg = 0 }, 64, 1)
|
||||
itemAdapter:provide({ name = 'minecraft:coal', damage = 0 }, 64, 1)
|
||||
if turtle.getItemCount(1) == 0 then
|
||||
print('Out of fuel, add fuel to chest/ME system')
|
||||
turtle.status = 'waiting'
|
||||
@@ -73,7 +73,7 @@ local function resupply()
|
||||
if data.suppliesPt then
|
||||
pathTo(data.suppliesPt)
|
||||
|
||||
itemProvider = ChestProvider({ direction = 'up', wrapSide = 'bottom' })
|
||||
itemAdapter = ChestAdapter({ direction = 'up', wrapSide = 'bottom' })
|
||||
dumpInventory()
|
||||
refuel()
|
||||
end
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
requireInjector(getfenv(1))
|
||||
|
||||
local ChestProvider = require('chestProvider18')
|
||||
local ChestAdapter = require('chestAdapter18')
|
||||
local Event = require('event')
|
||||
local MEProvider = require('meProvider')
|
||||
local RefinedProvider = require('refinedProvider')
|
||||
local MEAdapter = require('meAdapter')
|
||||
local RefinedAdapter = require('refinedAdapter')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local storage = RefinedProvider()
|
||||
local storage = RefinedAdapter()
|
||||
if not storage:isValid() then
|
||||
storage = MEProvider()
|
||||
storage = MEAdapter()
|
||||
if not storage:isValid() then
|
||||
storage = ChestProvider()
|
||||
storage = ChestAdapter()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,11 +25,11 @@ UI:configure('StorageActivity', ...)
|
||||
local changedPage = UI.Page({
|
||||
grid = UI.Grid({
|
||||
columns = {
|
||||
{ heading = 'Qty', key = 'qty', width = 5 },
|
||||
{ heading = 'Change', key = 'change', width = 6 },
|
||||
{ heading = 'Name', key = 'display_name', width = UI.term.width - 15 },
|
||||
{ heading = 'Qty', key = 'count', width = 5 },
|
||||
{ heading = 'Change', key = 'change', width = 6 },
|
||||
{ heading = 'Name', key = 'displayName', width = UI.term.width - 15 },
|
||||
},
|
||||
sortColumn = 'display_name',
|
||||
sortColumn = 'displayName',
|
||||
rey = -6,
|
||||
}),
|
||||
buttons = UI.Window({
|
||||
@@ -77,7 +77,7 @@ function changedPage.grid:getDisplayValues(row)
|
||||
ind = ''
|
||||
end
|
||||
row.change = ind .. Util.toBytes(row.change)
|
||||
row.qty = Util.toBytes(row.qty)
|
||||
row.count = Util.toBytes(row.count)
|
||||
|
||||
return row
|
||||
end
|
||||
@@ -132,9 +132,9 @@ function changedPage:refresh()
|
||||
found = false
|
||||
for k2,v2 in pairs(t) do
|
||||
if uniqueKey(v) == uniqueKey(v2) then
|
||||
if v.qty ~= v2.qty then
|
||||
if v.count ~= v2.count then
|
||||
local c = Util.shallowCopy(v2)
|
||||
c.lastQty = v.qty
|
||||
c.lastCount = v.count
|
||||
table.insert(changedItems, c)
|
||||
end
|
||||
table.remove(t, k2)
|
||||
@@ -145,19 +145,19 @@ function changedPage:refresh()
|
||||
-- New item
|
||||
if not found then
|
||||
local c = Util.shallowCopy(v)
|
||||
c.lastQty = v.qty
|
||||
c.qty = 0
|
||||
c.lastCount = v.count
|
||||
c.count = 0
|
||||
table.insert(changedItems, c)
|
||||
end
|
||||
end
|
||||
-- No items left
|
||||
for k,v in pairs(t) do
|
||||
v.lastQty = 0
|
||||
v.lastCount = 0
|
||||
table.insert(changedItems, v)
|
||||
end
|
||||
|
||||
for k,v in pairs(changedItems) do
|
||||
v.change = v.qty - v.lastQty
|
||||
v.change = v.count - v.lastCount
|
||||
end
|
||||
|
||||
self.grid:setValues(changedItems)
|
||||
|
||||
@@ -4,7 +4,7 @@ requireInjector(getfenv(1))
|
||||
Requirements:
|
||||
Place turtle against an oak tree or oak sapling
|
||||
Area around turtle must be flat and can only be dirt or grass
|
||||
(9 blocks in each direction from turtle)
|
||||
(10 blocks in each direction from turtle)
|
||||
Turtle must have: crafting table, chest
|
||||
Turtle must have a pick equipped on the left side
|
||||
|
||||
@@ -16,15 +16,15 @@ requireInjector(getfenv(1))
|
||||
down another sapling in front of the turtle.
|
||||
|
||||
The program will be able to survive server restarts as long as it has
|
||||
created the cobble line. If the program is stopped before that time,
|
||||
created the cobblestone line. If the program is stopped before that time,
|
||||
place the turtle in the original position before restarting the program.
|
||||
]]--
|
||||
|
||||
local ChestProvider = require('chestProvider18')
|
||||
local Craft = require('turtle.craft')
|
||||
local Level = require('turtle.level')
|
||||
local Point = require('point')
|
||||
local Util = require('util')
|
||||
local ChestAdapter = require('chestAdapter18')
|
||||
local Craft = require('turtle.craft')
|
||||
local Level = require('turtle.level')
|
||||
local Point = require('point')
|
||||
local Util = require('util')
|
||||
|
||||
local FUEL_BASE = 0
|
||||
local FUEL_DIRE = FUEL_BASE + 10
|
||||
@@ -126,18 +126,18 @@ local function craftItem(item, qty)
|
||||
|
||||
if turtle.equip('left', 'minecraft:crafting_table') then
|
||||
|
||||
local chestProvider = ChestProvider({
|
||||
local chestAdapter = ChestAdapter({
|
||||
wrapSide = 'top',
|
||||
direction = 'down',
|
||||
})
|
||||
if not chestProvider:isValid() then
|
||||
print('invalid chestProvider')
|
||||
if not chestAdapter:isValid() then
|
||||
print('invalid chestAdapter')
|
||||
read()
|
||||
end
|
||||
-- turtle.emptyInventory(turtle.dropUp)
|
||||
|
||||
Util.print('Crafting %d %s', (qty or 1), item)
|
||||
success = Craft.craftRecipe(recipes[item], qty or 1, chestProvider)
|
||||
success = Craft.craftRecipe(recipes[item], qty or 1, chestAdapter)
|
||||
|
||||
repeat until not turtle.suckUp()
|
||||
end
|
||||
@@ -265,7 +265,7 @@ local function getCobblestone(count)
|
||||
turtle.select(1)
|
||||
turtle.digDown()
|
||||
turtle.down()
|
||||
for i = 1, 3 do
|
||||
for i = 1, 4 do
|
||||
if inspect(turtle.inspect) == STONE then
|
||||
turtle.dig()
|
||||
end
|
||||
@@ -353,7 +353,7 @@ local function createChests()
|
||||
return false
|
||||
end
|
||||
if state.perimeter and
|
||||
turtle.getFuelLevel() > FUEL_BASE + 100 and
|
||||
turtle.getFuelLevel() > FUEL_GOOD and
|
||||
Craft.canCraft(CHEST, 4, turtle.getSummedInventory()) then
|
||||
|
||||
print('Adding storage')
|
||||
@@ -428,8 +428,8 @@ local function placeTorches()
|
||||
return
|
||||
end
|
||||
|
||||
if Craft.canCraft(TORCH, 4, turtle.getSummedInventory()) and
|
||||
turtle.getFuelLevel() > 100 then
|
||||
if turtle.getFuelLevel() > 100 and
|
||||
Craft.canCraft(TORCH, 4, turtle.getSummedInventory()) then
|
||||
|
||||
print('Placing torches')
|
||||
|
||||
@@ -525,6 +525,7 @@ local function fell()
|
||||
fellTree(pt)
|
||||
end
|
||||
turtle.placeAt(pt, randomSapling())
|
||||
turtle.select(1)
|
||||
end)
|
||||
|
||||
print('Used ' .. (fuel - turtle.getFuelLevel()) .. ' fuel')
|
||||
@@ -635,14 +636,14 @@ local function findHome()
|
||||
while inspect(turtle.inspectDown) ~= COBBLESTONE do
|
||||
pt.x = pt.x - 1
|
||||
turtle.pathfind(pt)
|
||||
if pt.x < -16 then
|
||||
if pt.x < -20 then
|
||||
error('lost')
|
||||
end
|
||||
end
|
||||
while inspect(turtle.inspectDown) == COBBLESTONE do
|
||||
pt.z = pt.z - 1
|
||||
turtle.pathfind(pt)
|
||||
if pt.z < -16 then
|
||||
if pt.z < -20 then
|
||||
error('lost')
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user