Try to update Milo for 1.19
Removes Milo trying to access damage on items (`nil` because of The Flattening). We might also need to reimplement showing durability in the item's display name - I got a little too carried away with removing mentions of "damage". Also renames nbtHash to nbt to be consistent with new CC:T naming. I tried not to touch anything related to MiloRemote for now, and there are probably still many bugs remaining that need to be ironed out. Most of the basic functionality works now, though.
This commit is contained in:
@@ -20,10 +20,11 @@ local Craft = {
|
||||
local function splitKey(key)
|
||||
local t = Util.split(key, '(.-):')
|
||||
local item = { }
|
||||
if #t[#t] > 8 then
|
||||
item.nbtHash = table.remove(t)
|
||||
|
||||
if t[3] then
|
||||
item.nbt = t[3]
|
||||
end
|
||||
item.damage = tonumber(table.remove(t))
|
||||
|
||||
item.name = table.concat(t, ':')
|
||||
return item
|
||||
end
|
||||
@@ -32,7 +33,7 @@ local function makeRecipeKey(item)
|
||||
if type(item) == 'string' then
|
||||
item = splitKey(item)
|
||||
end
|
||||
return table.concat({ item.name, item.damage or 0, item.nbtHash }, ':')
|
||||
return table.concat({ item.name, item.nbt }, ':')
|
||||
end
|
||||
|
||||
local function convert(ingredient)
|
||||
@@ -47,8 +48,7 @@ local function getCraftingTool(storage, item)
|
||||
|
||||
for _,v in pairs(items) do
|
||||
if item.name == v.name and
|
||||
(not item.damage or item.damage == v.damage) and
|
||||
(not item.nbtHash or item.nbtHash == v.nbtHash) then
|
||||
(not item.nbt or item.nbt == v.nbt) then
|
||||
return v
|
||||
end
|
||||
end
|
||||
@@ -93,11 +93,7 @@ function Craft.getItemCount(items, item)
|
||||
local count = 0
|
||||
for _,v in pairs(items) do
|
||||
if v.name == item.name and
|
||||
(not item.damage or v.damage == item.damage) and
|
||||
v.nbtHash == item.nbtHash then
|
||||
if item.damage then
|
||||
return v.count
|
||||
end
|
||||
v.nbt == item.nbt then
|
||||
count = count + v.count
|
||||
end
|
||||
end
|
||||
@@ -387,18 +383,7 @@ function Craft.findRecipe(key)
|
||||
end
|
||||
|
||||
local item = itemDB:splitKey(key)
|
||||
if item.damage then
|
||||
return Craft.recipes[makeRecipeKey(item)]
|
||||
end
|
||||
|
||||
-- handle cases where the request is like : IC2:reactorVent:*
|
||||
for rkey,recipe in pairs(Craft.recipes) do
|
||||
local r = itemDB:splitKey(rkey)
|
||||
if item.name == r.name and
|
||||
(not item.nbtHash or r.nbtHash == item.nbtHash) then
|
||||
return recipe
|
||||
end
|
||||
end
|
||||
return Craft.recipes[makeRecipeKey(item)]
|
||||
end
|
||||
|
||||
-- determine the full list of ingredients needed to craft
|
||||
|
||||
@@ -93,7 +93,7 @@ function Milo:getMatches(item, flags)
|
||||
local count = 0
|
||||
local items = self:listItems()
|
||||
|
||||
if not flags.ignoreDamage and not flags.ignoreNbtHash then
|
||||
if not flags.ignoreNbt then
|
||||
local key = item.key or itemDB:makeKey(item)
|
||||
local v = items[key]
|
||||
if v then
|
||||
@@ -104,8 +104,7 @@ function Milo:getMatches(item, flags)
|
||||
else
|
||||
for key,v in pairs(items) do
|
||||
if item.name == v.name and
|
||||
(flags.ignoreDamage or item.damage == v.damage) and
|
||||
(flags.ignoreNbtHash or item.nbtHash == v.nbtHash) then
|
||||
(flags.ignoreNbt or item.nbt == v.nbt) then
|
||||
|
||||
t[key] = Util.shallowCopy(v)
|
||||
count = count + v.count
|
||||
@@ -125,7 +124,7 @@ function Milo:getTurtleInventory()
|
||||
|
||||
for i, v in pairs(self.context.turtleInventory.adapter.list()) do
|
||||
list[i] = itemDB:get(v, function()
|
||||
return self.context.turtleInventory.adapter.getItemMeta(i)
|
||||
return self.context.turtleInventory.adapter.getItemDetail(i)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -277,22 +276,15 @@ function Milo:learnRecipe()
|
||||
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
|
||||
v1.nbt == v2.nbt then
|
||||
if not newRecipe.crafingTools then
|
||||
newRecipe.craftingTools = { }
|
||||
end
|
||||
local tool = Util.shallowCopy(v2)
|
||||
if tool.maxDamage > 0 then
|
||||
tool.damage = '*'
|
||||
v2.damage = '*'
|
||||
end
|
||||
|
||||
--[[
|
||||
Turtles can only craft one item at a time using a tool :(
|
||||
]]--
|
||||
]] -- Todo: check if this still applies
|
||||
maxCount = 1
|
||||
|
||||
newRecipe.craftingTools[itemDB:makeKey(tool)] = true
|
||||
|
||||
@@ -21,13 +21,13 @@ function Adapter:listItems(throttle)
|
||||
|
||||
for k,v in pairs(self.list()) do
|
||||
if v.count > 0 then
|
||||
local key = table.concat({ v.name, v.damage, v.nbtHash }, ':')
|
||||
local key = table.concat({ v.name, v.nbt }, ':')
|
||||
|
||||
local entry = cache[key]
|
||||
if entry then
|
||||
entry.count = entry.count + v.count
|
||||
else
|
||||
cache[key] = itemDB:get(v, function() return self.getItemMeta(k) end)
|
||||
cache[key] = itemDB:get(v, function() return self.getItemDetail(k) end)
|
||||
end
|
||||
throttle()
|
||||
end
|
||||
|
||||
@@ -321,7 +321,7 @@ function Storage:listItemsRaw(throttle)
|
||||
local items = chest.list()
|
||||
|
||||
for slot, item in pairs(items) do
|
||||
items[slot] = itemDB:get(item, function() return chest.getItemMeta(slot) end)
|
||||
items[slot] = itemDB:get(item, function() return chest.getItemDetail(slot) end)
|
||||
end
|
||||
|
||||
res[v.name] = items
|
||||
@@ -340,7 +340,7 @@ function Storage:listProviders(throttle)
|
||||
|
||||
for chest, items in pairs(rawItems) do
|
||||
for slot, item in pairs(items) do
|
||||
local key = table.concat({item.name, item.damage, item.nbtHash}, ":")
|
||||
local key = table.concat({item.name, item.nbt}, ":")
|
||||
if not res[key] then
|
||||
res[key] = {}
|
||||
end
|
||||
@@ -443,7 +443,7 @@ function Storage:updateCache(adapter, item, count)
|
||||
return
|
||||
end
|
||||
|
||||
local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
local key = item.key or table.concat({ item.name, item.nbt }, ':')
|
||||
local entry = adapter.cache[key]
|
||||
|
||||
if not entry then
|
||||
@@ -490,14 +490,14 @@ end
|
||||
|
||||
local function isValidTransfer(adapter, target)
|
||||
-- lazily cache transfer locations
|
||||
if not adapter.transferLocations then
|
||||
--[[if not adapter.transferLocations then
|
||||
adapter.transferLocations = adapter.getTransferLocations()
|
||||
end
|
||||
for _,v in pairs(adapter.transferLocations) do
|
||||
if v == target then
|
||||
for _,v in pairs(adapter.transferLocations) do]]
|
||||
-- if v == target then
|
||||
return true
|
||||
end
|
||||
end
|
||||
-- end
|
||||
--end
|
||||
end
|
||||
|
||||
local function rawExport(source, target, item, qty, slot)
|
||||
@@ -529,8 +529,7 @@ local function rawExport(source, target, item, qty, slot)
|
||||
local stacks = source.list()
|
||||
for key,stack in Util.rpairs(stacks) do
|
||||
if stack.name == item.name and
|
||||
stack.damage == item.damage and
|
||||
stack.nbtHash == item.nbtHash then
|
||||
stack.nbt == item.nbt then
|
||||
local amount = math.min(qty, stack.count)
|
||||
if amount > 0 then
|
||||
amount = transfer(key, amount, slot)
|
||||
@@ -560,7 +559,7 @@ end
|
||||
function Storage:export(target, slot, count, item)
|
||||
local timer = Util.timer()
|
||||
local total = 0
|
||||
local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
local key = item.key or table.concat({ item.name, item.nbt }, ':')
|
||||
|
||||
local function provide(adapter, pcount)
|
||||
-- update cache before export to allow for simultaneous calls
|
||||
@@ -651,7 +650,7 @@ function Storage:import(source, slot, count, item)
|
||||
|
||||
local timer = Util.timer()
|
||||
local total = 0
|
||||
local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
local key = item.key or table.concat({ item.name, item.nbt }, ':')
|
||||
|
||||
if not self.cache then
|
||||
self:listItems()
|
||||
@@ -664,7 +663,7 @@ function Storage:import(source, slot, count, item)
|
||||
entry = itemDB:add(item)
|
||||
else
|
||||
-- get the metadata from the device and add to db
|
||||
entry = itemDB:add(source.adapter.getItemMeta(slot))
|
||||
entry = itemDB:add(source.adapter.getItemDetail(slot))
|
||||
end
|
||||
itemDB:flush()
|
||||
end
|
||||
|
||||
41
milo/apis/turtleInv.lua
Normal file
41
milo/apis/turtleInv.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
--[[ Emulate a CC:T inventory on the turtle
|
||||
]]
|
||||
|
||||
local TurtleInv = {}
|
||||
|
||||
local turtle = _G.turtle
|
||||
|
||||
local inventorySize = 16
|
||||
|
||||
local localName = "milo_local_name_unset"
|
||||
|
||||
function TurtleInv.setLocalName(name)
|
||||
localName = name
|
||||
end
|
||||
|
||||
function TurtleInv.size()
|
||||
return inventorySize
|
||||
end
|
||||
|
||||
function TurtleInv.list()
|
||||
local list = {}
|
||||
for slot = 1, inventorySize do
|
||||
list[slot] = turtle.getItemDetail(slot)
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function TurtleInv.getItemDetail(slot)
|
||||
return turtle.getItemDetail(slot, true)
|
||||
end
|
||||
|
||||
function TurtleInv.pullItems(fromName, fromSlot, limit, toSlot)
|
||||
return peripheral.call(fromName, "pushItems", localName, fromSlot, limit, toSlot)
|
||||
end
|
||||
|
||||
function TurtleInv.pushItems(toName, fromSlot, limit, toSlot)
|
||||
return peripheral.call(toName, "pullItems", localName, fromSlot, limit, toSlot)
|
||||
end
|
||||
|
||||
|
||||
return TurtleInv
|
||||
Reference in New Issue
Block a user