27 Commits

Author SHA1 Message Date
Kan18
1ee2751cbb fix potion 2023-09-16 13:46:49 -04:00
Kan18
c0ffb90ba6 fix craft 2023-09-16 13:46:22 -04:00
Kan18
c990465263 Merge most of iuzx's changes into develop-1.8 2023-07-07 13:52:42 -04:00
rspx
f22cad1644 Update recipeBook.db 2023-07-07 13:52:34 -04:00
rspx
a9202a7034 Fixed auto-feeder 2023-07-07 13:52:34 -04:00
rspx
aef1bfa186 Remote fix
Fixed itmes with nbt crashing milo
2023-07-07 13:52:34 -04:00
rspx
488576e0df Revert "Revert "Merge pull request #1 from MarcelskyXD/develop-1.8""
This reverts commit c185cffa227af8116fcfc0f0d920e62e2f98d2b8.
2023-07-07 13:52:34 -04:00
rspx
43e662e68c Revert "Merge pull request #1 from MarcelskyXD/develop-1.8"
This reverts commit f7ac0b1674ee7558578a3c127a4f252dc159eeac, reversing
changes made to a76c59fb361732b111ee3d7965d61372c1c33da8.
2023-07-07 13:52:34 -04:00
Marcelsky
4321f336db Replace getItemMeta with getItemDetail 2023-07-07 13:52:34 -04:00
rspx
1ae380d3b1 Fixed some corrupted recipes 2023-07-07 13:52:34 -04:00
rspx
0db0e58225 Update minecraft.db 2023-07-07 13:52:34 -04:00
rspx
4fe0035498 Fixed item names 2023-07-07 13:52:34 -04:00
rspx
9f8f56064c Update minecraft.db 2023-07-07 13:52:34 -04:00
rspx
f73da8a3da Updated recipes for 1.19.3 2023-07-07 13:52:34 -04:00
rspx
0bbe3a1b06 Hopefully final fixes for remote 2023-07-07 13:52:34 -04:00
iuzx0
e683e834d8 fixing remote 2023-07-07 13:52:34 -04:00
iuzx0
34dab3ccf0 Attempt to fix milo remote 2023-07-07 13:52:34 -04:00
iuzx0
761f388f12 Attempt to fix remote 2023-07-07 13:52:34 -04:00
Kan18
62477844fc Update miniAdapter.lua 2023-07-04 13:27:53 -04:00
Kan18
2e81cdf1f5 Update itemDB.lua 2023-05-26 13:20:06 -04:00
Kan18
fceb99af0b speed up imports by 100x 2023-04-16 14:45:45 -04:00
Kan18
693abd4ec6 FIX THE WEIRD NBT ITEM ISSUES WITH THIS ONE WEIRD TRICK 2023-03-17 12:26:30 -04:00
Kan18
36abdd5d0c second try 2022-12-29 09:13:09 +04:00
Kan18
bf8f9c5f0d Revert "hopefully this works 9removed damage values)"
This reverts commit 13aa4631be.
2022-12-29 09:12:41 +04:00
Kan18
13aa4631be hopefully this works 9removed damage values) 2022-12-29 09:11:53 +04:00
Kan18
f231173236 oops, forgot to update itemDB 2022-12-29 01:26:19 +04:00
Kan18
2f67fb2ef8 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.
2022-12-24 15:39:14 +04:00
25 changed files with 6776 additions and 4610 deletions

View File

@@ -33,20 +33,19 @@ end
function itemDB:makeKey(item) function itemDB:makeKey(item)
if not item then error('itemDB:makeKey: item is required', 2) end if not item then error('itemDB:makeKey: item is required', 2) end
return table.concat({ item.name, item.damage or '*', item.nbtHash }, ':') return table.concat({ item.name, item.nbt }, ':')
end end
function itemDB:splitKey(key, item) function itemDB:splitKey(key, item)
item = item or { } item = item or { }
local t = Util.split(key, '(.-):') local t = Util.split(key, '(.-):')
if #t[#t] > 8 then
item.nbtHash = table.remove(t) if t[3] then
end item.nbt = t[3]
local damage = table.remove(t) t[3] = nil
if damage ~= '*' then
item.damage = tonumber(damage)
end end
item.name = table.concat(t, ':') item.name = table.concat(t, ':')
return item return item
@@ -82,36 +81,20 @@ function itemDB:_get(key)
return item return item
end end
-- try finding an item that has damage values for k,item in pairs(self.data) do
if type(key.damage) == 'number' then if key.name == item.name and
item = TableDB.get(self, self:makeKey({ name = key.name, nbtHash = key.nbtHash })) key.nbt == item.nbt then
if item and item.maxDamage then
item = Util.shallowCopy(item) item = Util.shallowCopy(item)
item.damage = key.damage
if item.maxDamage > 0 and type(item.damage) == 'number' and item.damage > 0 then
item.displayName = string.format('%s (damage: %s)', item.displayName, item.damage)
end
return item return item
end end
else
for k,item in pairs(self.data) do
if key.name == item.name and
key.nbtHash == key.nbtHash and
item.maxDamage > 0 then
item = Util.shallowCopy(item)
item.nbtHash = key.nbtHash
return item
end
end
end end
if key.nbtHash then if key.nbt then
item = self:get({ name = key.name, damage = key.damage }) item = self:get({ name = key.name })
if item and item.ignoreNBT then if item and item.ignoreNBT then
item = Util.shallowCopy(item) item = Util.shallowCopy(item)
item.nbtHash = key.nbtHash item.nbt = key.nbt
item.damage = key.damage
return item return item
end end
end end
@@ -134,8 +117,7 @@ end
function itemDB:add(baseItem) function itemDB:add(baseItem)
local nItem = { local nItem = {
name = baseItem.name, name = baseItem.name,
damage = baseItem.damage, nbt = baseItem.nbt,
nbtHash = baseItem.nbtHash,
} }
-- if detail.maxDamage > 0 then -- if detail.maxDamage > 0 then
-- nItem.damage = '*' -- nItem.damage = '*'
@@ -143,7 +125,6 @@ function itemDB:add(baseItem)
nItem.displayName = safeString(baseItem.displayName) nItem.displayName = safeString(baseItem.displayName)
nItem.maxCount = baseItem.maxCount nItem.maxCount = baseItem.maxCount
nItem.maxDamage = baseItem.maxDamage
-- enchanted items -- enchanted items
if baseItem.enchantments then if baseItem.enchantments then
@@ -156,7 +137,7 @@ function itemDB:add(baseItem)
if k > 1 then if k > 1 then
nItem.displayName = nItem.displayName .. ', ' nItem.displayName = nItem.displayName .. ', '
end end
nItem.displayName = nItem.displayName .. v.fullName nItem.displayName = nItem.displayName .. v.displayName
end end
-- turtles / computers / etc -- turtles / computers / etc
@@ -192,18 +173,8 @@ function itemDB:add(baseItem)
if nItem.name == item.name and if nItem.name == item.name and
nItem.displayName == item.displayName then nItem.displayName == item.displayName then
if nItem.nbtHash ~= item.nbtHash and nItem.damage ~= item.damage then if nItem.nbt ~= item.nbt then
nItem.damage = '*' nItem.nbt = nil
nItem.nbtHash = nil
nItem.ignoreNBT = true
self.data[k] = nil
break
elseif nItem.damage ~= item.damage then
nItem.damage = '*'
self.data[k] = nil
break
elseif nItem.nbtHash ~= item.nbtHash then
nItem.nbtHash = nil
nItem.ignoreNBT = true nItem.ignoreNBT = true
self.data[k] = nil self.data[k] = nil
break break
@@ -214,8 +185,7 @@ function itemDB:add(baseItem)
TableDB.add(self, self:makeKey(nItem), nItem) TableDB.add(self, self:makeKey(nItem), nItem)
nItem = Util.shallowCopy(nItem) nItem = Util.shallowCopy(nItem)
nItem.damage = baseItem.damage nItem.nbt = baseItem.nbt
nItem.nbtHash = baseItem.nbtHash
return nItem return nItem
end end
@@ -234,8 +204,8 @@ function itemDB:getName(item)
-- fallback to nameDB -- fallback to nameDB
local strId = self:makeKey(item) local strId = self:makeKey(item)
local name = nameDB.data[strId] local name = nameDB.data[strId]
if not name and not item.damage then if not name then
name = nameDB.data[self:makeKey({ name = item.name, damage = 0, nbtHash = item.nbtHash })] name = nameDB.data[self:makeKey({ name = item.name, nbt = item.nbt })]
end end
return name or strId return name or strId
end end
@@ -250,24 +220,17 @@ function itemDB:load()
for key,item in pairs(self.data) do for key,item in pairs(self.data) do
self:splitKey(key, item) self:splitKey(key, item)
item.maxDamage = item.maxDamage or 0
item.maxCount = item.maxCount or 64 item.maxCount = item.maxCount or 64
end end
end end
function itemDB:flush() function itemDB:flush()
if self.dirty then if self.dirty then
local t = { } local t = { }
for k,v in pairs(self.data) do for k,v in pairs(self.data) do
v = Util.shallowCopy(v) v = Util.shallowCopy(v)
v.name = nil v.name = nil
v.damage = nil v.nbt = nil
v.nbtHash = nil
v.count = nil -- wipe out previously saved counts - temporary
if v.maxDamage == 0 then
v.maxDamage = nil
end
if v.maxCount == 64 then if v.maxCount == 64 then
v.maxCount = nil v.maxCount = nil
end end

View File

@@ -23,14 +23,10 @@ function nameDB:loadDirectory(directory)
error('Unable to read ' .. fs.combine(directory, file)) error('Unable to read ' .. fs.combine(directory, file))
end end
for strId, block in pairs(blocks) do for strId, blockName in pairs(blocks) do
strId = string.format('%s:%s', mod, strId) strId = string.format('%s:%s', mod, strId)
if type(block.name) == 'string' then if type(blockName) == 'string' then
self.data[strId .. ':0'] = block.name self.data[strId] = blockName
else
for nid,name in pairs(block.name) do
self.data[strId .. ':' .. (nid-1)] = name
end
end end
end end

File diff suppressed because one or more lines are too long

View File

@@ -2,6 +2,7 @@ local Event = require('opus.event')
local Milo = require('milo') local Milo = require('milo')
local Sound = require('opus.sound') local Sound = require('opus.sound')
local Storage = require('milo.storage') local Storage = require('milo.storage')
local TurtleInv = require('milo.turtleInv')
local UI = require('opus.ui') local UI = require('opus.ui')
local Util = require('opus.util') local Util = require('opus.util')
@@ -18,7 +19,6 @@ multishell.setTitle(multishell.getCurrent(), 'Milo')
local function Syntax(msg) local function Syntax(msg)
print([[ print([[
Turtle must be provided with: Turtle must be provided with:
* Introspection module (never bound)
* Workbench * Workbench
Turtle must be connected to: Turtle must be connected to:
@@ -46,10 +46,6 @@ if not modem.getNameLocal() then
Syntax('Wired modem is not active') Syntax('Wired modem is not active')
end end
local introspection = device['plethora:introspection'] or
turtle.equip('left', 'plethora:module:0') and device['plethora:introspection'] or
Syntax('Introspection module missing')
if not device.workbench then if not device.workbench then
turtle.equip('right', 'minecraft:crafting_table:0') turtle.equip('right', 'minecraft:crafting_table:0')
if not device.workbench then if not device.workbench then
@@ -58,6 +54,7 @@ if not device.workbench then
end end
local localName = modem.getNameLocal() local localName = modem.getNameLocal()
TurtleInv.setLocalName(localName)
local context = { local context = {
resources = Util.readTable(Milo.RESOURCE_FILE) or { }, resources = Util.readTable(Milo.RESOURCE_FILE) or { },
@@ -76,7 +73,7 @@ local context = {
turtleInventory = { turtleInventory = {
name = localName, name = localName,
mtype = 'hidden', mtype = 'hidden',
adapter = introspection.getInventory(), adapter = TurtleInv,
} }
} }

View File

@@ -281,11 +281,12 @@ end
local function splitKey(key) local function splitKey(key)
local t = Util.split(key, '(.-):') local t = Util.split(key, '(.-):')
local item = { } local item = { }
if #t[#t] > 8 then if t[3] then
item.nbtHash = table.remove(t) item.nbt = t[3]
end end
item.damage = tonumber(table.remove(t)) t[3] = nil
item.name = table.concat(t, ':') item.name = table.concat(t, ':')
return item return item
end end

View File

@@ -20,10 +20,12 @@ local Craft = {
local function splitKey(key) local function splitKey(key)
local t = Util.split(key, '(.-):') local t = Util.split(key, '(.-):')
local item = { } local item = { }
if #t[#t] > 8 then
item.nbtHash = table.remove(t) if t[3] then
item.nbt = t[3]
t[3] = nil
end end
item.damage = tonumber(table.remove(t))
item.name = table.concat(t, ':') item.name = table.concat(t, ':')
return item return item
end end
@@ -32,7 +34,7 @@ local function makeRecipeKey(item)
if type(item) == 'string' then if type(item) == 'string' then
item = splitKey(item) item = splitKey(item)
end end
return table.concat({ item.name, item.damage or 0, item.nbtHash }, ':') return table.concat({ item.name, item.nbt }, ':')
end end
local function convert(ingredient) local function convert(ingredient)
@@ -47,8 +49,7 @@ local function getCraftingTool(storage, item)
for _,v in pairs(items) do for _,v in pairs(items) do
if item.name == v.name and if item.name == v.name and
(not item.damage or item.damage == v.damage) and (not item.nbt or item.nbt == v.nbt) then
(not item.nbtHash or item.nbtHash == v.nbtHash) then
return v return v
end end
end end
@@ -93,11 +94,7 @@ function Craft.getItemCount(items, item)
local count = 0 local count = 0
for _,v in pairs(items) do for _,v in pairs(items) do
if v.name == item.name and if v.name == item.name and
(not item.damage or v.damage == item.damage) and v.nbt == item.nbt then
v.nbtHash == item.nbtHash then
if item.damage then
return v.count
end
count = count + v.count count = count + v.count
end end
end end
@@ -387,18 +384,7 @@ function Craft.findRecipe(key)
end end
local item = itemDB:splitKey(key) local item = itemDB:splitKey(key)
if item.damage then return Craft.recipes[makeRecipeKey(item)]
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
end end
-- determine the full list of ingredients needed to craft -- determine the full list of ingredients needed to craft

View File

@@ -93,7 +93,7 @@ function Milo:getMatches(item, flags)
local count = 0 local count = 0
local items = self:listItems() 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 key = item.key or itemDB:makeKey(item)
local v = items[key] local v = items[key]
if v then if v then
@@ -104,8 +104,7 @@ function Milo:getMatches(item, flags)
else else
for key,v in pairs(items) do for key,v in pairs(items) do
if item.name == v.name and if item.name == v.name and
(flags.ignoreDamage or item.damage == v.damage) and (flags.ignoreNbt or item.nbt == v.nbt) then
(flags.ignoreNbtHash or item.nbtHash == v.nbtHash) then
t[key] = Util.shallowCopy(v) t[key] = Util.shallowCopy(v)
count = count + v.count count = count + v.count
@@ -125,7 +124,7 @@ function Milo:getTurtleInventory()
for i, v in pairs(self.context.turtleInventory.adapter.list()) do for i, v in pairs(self.context.turtleInventory.adapter.list()) do
list[i] = itemDB:get(v, function() list[i] = itemDB:get(v, function()
return self.context.turtleInventory.adapter.getItemMeta(i) return self.context.turtleInventory.adapter.getItemDetail(i)
end) end)
end end
@@ -277,22 +276,15 @@ function Milo:learnRecipe()
for _,v1 in pairs(results) do for _,v1 in pairs(results) do
for _,v2 in pairs(ingredients) do for _,v2 in pairs(ingredients) do
if v1.name == v2.name and if v1.name == v2.name and
v1.nbtHash == v2.nbtHash and v1.nbt == v2.nbt then
(v1.damage == v2.damage or
(v1.maxDamage > 0 and v2.maxDamage > 0 and
v1.damage ~= v2.damage)) then
if not newRecipe.crafingTools then if not newRecipe.crafingTools then
newRecipe.craftingTools = { } newRecipe.craftingTools = { }
end end
local tool = Util.shallowCopy(v2) 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 :( Turtles can only craft one item at a time using a tool :(
]]-- ]] -- Todo: check if this still applies
maxCount = 1 maxCount = 1
newRecipe.craftingTools[itemDB:makeKey(tool)] = true newRecipe.craftingTools[itemDB:makeKey(tool)] = true

View File

@@ -19,15 +19,17 @@ function Adapter:listItems(throttle)
local cache = { } local cache = { }
throttle = throttle or Util.throttle() throttle = throttle or Util.throttle()
for k,v in pairs(self.list()) do local list = self.list()
for k,v in pairs(list) do
if v.count > 0 then 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] local entry = cache[key]
if entry then if entry then
entry.count = entry.count + v.count entry.count = entry.count + v.count
else else
cache[key] = itemDB:get(v, function() return self.getItemMeta(k) end) cache[key] = itemDB:get(v, function() return self.getItemDetail(k) end)
end end
throttle() throttle()
end end
@@ -37,6 +39,10 @@ function Adapter:listItems(throttle)
-- useful for when inserting into chests -- useful for when inserting into chests
-- ie. insert only if chest does not have item and has free slots -- ie. insert only if chest does not have item and has free slots
-- bodge to make statsView not delay
-- todo: handle this better properly
self.__used = Util.size(list)
self.cache = cache self.cache = cache
end end

View File

@@ -321,7 +321,7 @@ function Storage:listItemsRaw(throttle)
local items = chest.list() local items = chest.list()
for slot, item in pairs(items) do 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 end
res[v.name] = items res[v.name] = items
@@ -340,7 +340,7 @@ function Storage:listProviders(throttle)
for chest, items in pairs(rawItems) do for chest, items in pairs(rawItems) do
for slot, item in pairs(items) 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 if not res[key] then
res[key] = {} res[key] = {}
end end
@@ -443,7 +443,7 @@ function Storage:updateCache(adapter, item, count)
return return
end 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] local entry = adapter.cache[key]
if not entry then if not entry then
@@ -489,15 +489,18 @@ function Storage:_sn(name)
end end
local function isValidTransfer(adapter, target) local function isValidTransfer(adapter, target)
if string.find(target,":inventory") or string.find(target,":equipment") then
return false
end
-- lazily cache transfer locations -- lazily cache transfer locations
if not adapter.transferLocations then --[[if not adapter.transferLocations then
adapter.transferLocations = adapter.getTransferLocations() adapter.transferLocations = adapter.getTransferLocations()
end end
for _,v in pairs(adapter.transferLocations) do for _,v in pairs(adapter.transferLocations) do]]
if v == target then -- if v == target then
return true return true
end -- end
end --end
end end
local function rawExport(source, target, item, qty, slot) local function rawExport(source, target, item, qty, slot)
@@ -529,8 +532,7 @@ local function rawExport(source, target, item, qty, slot)
local stacks = source.list() local stacks = source.list()
for key,stack in Util.rpairs(stacks) do for key,stack in Util.rpairs(stacks) do
if stack.name == item.name and if stack.name == item.name and
stack.damage == item.damage and stack.nbt == item.nbt then
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
amount = transfer(key, amount, slot) amount = transfer(key, amount, slot)
@@ -560,7 +562,7 @@ end
function Storage:export(target, slot, count, item) function Storage:export(target, slot, count, item)
local timer = Util.timer() local timer = Util.timer()
local total = 0 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) local function provide(adapter, pcount)
-- update cache before export to allow for simultaneous calls -- update cache before export to allow for simultaneous calls
@@ -651,7 +653,7 @@ function Storage:import(source, slot, count, item)
local timer = Util.timer() local timer = Util.timer()
local total = 0 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 if not self.cache then
self:listItems() self:listItems()
@@ -664,13 +666,15 @@ function Storage:import(source, slot, count, item)
entry = itemDB:add(item) entry = itemDB:add(item)
else else
-- get the metadata from the device and add to db -- 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 end
itemDB:flush() itemDB:flush()
end end
item = entry item = entry
local function insert(adapter) local function insert(adapter)
if adapter.__used and adapter.__size and adapter.__used == adapter.__size then return 0 end
local amount = rawInsert(adapter, source.adapter, slot, count) local amount = rawInsert(adapter, source.adapter, slot, count)
if amount > 0 then if amount > 0 then

41
milo/apis/turtleInv.lua Normal file
View 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

View File

@@ -312,14 +312,10 @@ The settings will take effect immediately!]],
margin = 1, margin = 1,
manualControls = true, manualControls = true,
[1] = UI.Checkbox { [1] = UI.Checkbox {
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage', formLabel = 'Ignore NBT', formKey = 'ignoreNbt',
help = 'Ignore damage of item',
},
[2] = UI.Checkbox {
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
help = 'Ignore NBT of item', help = 'Ignore NBT of item',
}, },
[3] = UI.Chooser { [2] = UI.Chooser {
width = 13, width = 13,
formLabel = 'Mode', formKey = 'blacklist', formLabel = 'Mode', formKey = 'blacklist',
nochoice = 'whitelist', nochoice = 'whitelist',
@@ -327,7 +323,7 @@ The settings will take effect immediately!]],
{ name = 'whitelist', value = false }, { name = 'whitelist', value = false },
{ name = 'blacklist', value = true }, { name = 'blacklist', value = true },
}, },
help = 'Ignore damage of item' help = 'Accept item by default or deny by default'
}, },
scan = UI.Button { scan = UI.Button {
x = -11, y = 1, x = -11, y = 1,
@@ -349,7 +345,7 @@ The settings will take effect immediately!]],
self.form:setValues(entry) self.form:setValues(entry)
self:resetGrid() self:resetGrid()
self.form[3].inactive = whitelistOnly self.form[2].inactive = whitelistOnly
UI.SlideOut.show(self) UI.SlideOut.show(self)
self:setFocus(self.form.scan) self:setFocus(self.form.scan)

View File

@@ -30,7 +30,7 @@ function ExportTask:cycle(context)
end end
local function exportSingleSlot() local function exportSingleSlot()
local slot = node.adapter.getItemMeta(entry.slot) local slot = node.adapter.getItemDetail(entry.slot)
if slot and slot.count == slot.maxCount then if slot and slot.count == slot.maxCount then
return return
@@ -41,8 +41,7 @@ function ExportTask:cycle(context)
for key in pairs(entry.filter) do for key in pairs(entry.filter) do
local filterItem = itemDB:splitKey(key) local filterItem = itemDB:splitKey(key)
if (slot.name == filterItem.name and if (slot.name == filterItem.name and
(entry.ignoreDamage or slot.damage == filterItem.damage) and (entry.ignoreNbt or slot.nbt == filterItem.nbt)) then
(entry.ignoreNbtHash or slot.nbtHash == filterItem.nbtHash)) then
local items = Milo:getMatches(filterItem, entry) local items = Milo:getMatches(filterItem, entry)
local _, item = next(items) local _, item = next(items)
@@ -81,8 +80,7 @@ function ExportTask:cycle(context)
for i = 1, node.adapter.__size do for i = 1, node.adapter.__size do
local slot = slots[i] local slot = slots[i]
if (not slot or slot.name == item.name and if (not slot or slot.name == item.name and
(entry.ignoreDamage or slot.damage == item.damage) and (entry.ignoreNbt or slot.nbt == item.nbt) and
(entry.ignoreNbtHash or slot.nbtHash == item.nbtHash) and
slot.count < item.maxCount) then slot.count < item.maxCount) then
return true return true

View File

@@ -21,7 +21,7 @@ function ImportTask:cycle(context)
for _, entry in pairs(node.imports) do for _, entry in pairs(node.imports) do
local function itemMatchesFilter(item) local function itemMatchesFilter(item)
if not entry.ignoreDamage and not entry.ignoreNbtHash then if not entry.ignoreNbt then
local key = itemDB:makeKey(item) local key = itemDB:makeKey(item)
return entry.filter[key] return entry.filter[key]
end end
@@ -29,8 +29,7 @@ function ImportTask:cycle(context)
for key in pairs(entry.filter) do for key in pairs(entry.filter) do
local v = itemDB:splitKey(key) local v = itemDB:splitKey(key)
if item.name == v.name and if item.name == v.name and
(entry.ignoreDamage or item.damage == v.damage) and (entry.ignoreNbt or item.nbt == v.nbt) then
(entry.ignoreNbtHash or item.nbtHash == v.nbtHash) then
return true return true
end end
end end
@@ -52,7 +51,7 @@ function ImportTask:cycle(context)
local function importSlot(slotNo) local function importSlot(slotNo)
local item = itemDB:get(list[slotNo], function() local item = itemDB:get(list[slotNo], function()
return node.adapter.getItemMeta(slotNo) return node.adapter.getItemDetail(slotNo)
end) end)
if item and matchesFilter(item) then if item and matchesFilter(item) then
if context.storage:import(node, slotNo, item.count, item) ~= item.count then if context.storage:import(node, slotNo, item.count, item) ~= item.count then

View File

@@ -20,16 +20,18 @@ function infoTab:draw()
Ansi.orange, item.displayName, Ansi.reset, Ansi.orange, item.displayName, Ansi.reset,
item.name) item.name)
if item.nbtHash then if item.nbt then
value = value .. item.nbtHash .. '\n' value = value .. item.nbt .. '\n'
end end
value = value .. string.format('\n%sCount:%s %s', value = value .. string.format('\n%sCount:%s %s',
Ansi.yellow, Ansi.reset, item.count) Ansi.yellow, Ansi.reset, item.count)
value = value .. string.format('\n%sDamage:%s %s', if item.durability then
Ansi.yellow, Ansi.reset, item.damage) value = value .. string.format('\n%Durability:%s %s',
Ansi.yellow, Ansi.reset, item.durability)
end
if item.maxDamage and item.maxDamage > 0 then if item.maxDamage and item.maxDamage > 0 then
value = value .. string.format(' (max: %s)', item.maxDamage) value = value .. string.format(' (max: %s)', item.maxDamage)
end end

View File

@@ -29,11 +29,7 @@ local manageTab = UI.Tab {
transform = 'number', transform = 'number',
}, },
[4] = UI.Checkbox { [4] = UI.Checkbox {
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage', formLabel = 'Ignore NBT', formKey = 'ignoreNbt',
help = 'Ignore damage of item',
},
[5] = UI.Checkbox {
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
help = 'Ignore NBT of item', help = 'Ignore NBT of item',
}, },
}, },
@@ -44,8 +40,6 @@ function manageTab:setItem(item)
self.res = Util.shallowCopy(context.resources[item.key] or { }) self.res = Util.shallowCopy(context.resources[item.key] or { })
self.res.displayName = self.item.displayName self.res.displayName = self.item.displayName
self.form:setValues(self.res) self.form:setValues(self.res)
-- TODO: ignore damage should not be active if there is not a maxDamage value
end end
function manageTab:eventHandler(event) function manageTab:eventHandler(event)
@@ -76,8 +70,7 @@ function manageTab:eventHandler(event)
local newKey = { local newKey = {
name = self.item.name, name = self.item.name,
damage = self.res.ignoreDamage and 0 or self.item.damage, nbt = not self.res.ignoreNbt and self.item.nbt or nil,
nbtHash = not self.res.ignoreNbtHash and self.item.nbtHash or nil,
} }
context.resources[self.item.key] = nil context.resources[self.item.key] = nil

View File

@@ -42,7 +42,7 @@ function recipeTab:setItem(item)
}) })
end end
local key = itemDB:splitKey(self.recipe.result) local key = itemDB:splitKey(self.recipe.result)
self.ignoreResultNBT.inactive = not key.nbtHash self.ignoreResultNBT.inactive = not key.nbt
end end
self.grid:setValues(t) self.grid:setValues(t)
end end
@@ -53,7 +53,7 @@ function recipeTab:eventHandler(event)
Milo:updateRecipe(self.recipe.result) Milo:updateRecipe(self.recipe.result)
local item = itemDB:splitKey(self.recipe.result) local item = itemDB:splitKey(self.recipe.result)
item.nbtHash = nil item.nbt = nil
self.recipe.result = itemDB:makeKey(item) self.recipe.result = itemDB:makeKey(item)
-- add updated entry -- add updated entry
@@ -64,13 +64,13 @@ function recipeTab:eventHandler(event)
elseif event.type == 'grid_focus_row' then elseif event.type == 'grid_focus_row' then
local key = itemDB:splitKey(event.selected.key) local key = itemDB:splitKey(event.selected.key)
self.ignoreNBT.inactive = not key.nbtHash self.ignoreNBT.inactive = not key.nbt
self.ignoreNBT:draw() self.ignoreNBT:draw()
elseif event.type == 'ignore_nbt' then elseif event.type == 'ignore_nbt' then
local selected = self.grid:getSelected() local selected = self.grid:getSelected()
local item = itemDB:splitKey(selected.key) local item = itemDB:splitKey(selected.key)
item.nbtHash = nil item.nbt = nil
selected.key = itemDB:makeKey(item) selected.key = itemDB:makeKey(item)
self.grid:draw() self.grid:draw()

View File

@@ -2,7 +2,7 @@ local Craft = require('milo.craft2')
local itemDB = require('core.itemDB') local itemDB = require('core.itemDB')
local Milo = require('milo') local Milo = require('milo')
local BLAZE_POWDER = "minecraft:blaze_powder:0" local BLAZE_POWDER = "minecraft:blaze_powder"
local PotionImportTask = { local PotionImportTask = {
name = 'potions', name = 'potions',

View File

@@ -94,7 +94,7 @@ local function client(socket)
local function deposit() local function deposit()
local node = makeNode(data.source or 'inventory') local node = makeNode(data.source or 'inventory')
if node then if node then
local slot = node.adapter.getItemMeta(data.slot) local slot = node.adapter.getItemDetail(data.slot)
if slot then if slot then
if context.storage:import(node, data.slot, slot.count, slot) > 0 then if context.storage:import(node, data.slot, slot.count, slot) > 0 then
local item = Milo:getItem(slot) local item = Milo:getItem(slot)

View File

@@ -58,7 +58,7 @@ function page.tabs.inventory:enable()
local list = { } local list = { }
for k, item in pairs(inv) do for k, item in pairs(inv) do
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(k) end) item = itemDB:get(item, function() return ni.getInventory().getItemDetail(k) end)
local key = makeKey(item) local key = makeKey(item)
if not list[key] then if not list[key] then
item.key = key item.key = key
@@ -129,7 +129,7 @@ Event.onInterval(5, function()
pcall(function() -- prevent errors from some mod items pcall(function() -- prevent errors from some mod items
for slot,v in pairs(ni.getInventory().list()) do for slot,v in pairs(ni.getInventory().list()) do
local item = itemDB:get(v, function() ni.getInventory().getItemMeta(slot) end) local item = itemDB:get(v, function() ni.getInventory().getItemDetail(slot) end)
if item then if item then
if context.state.autostore[makeKey(item)] then if context.state.autostore[makeKey(item)] then
context:sendRequest({ context:sendRequest({

View File

@@ -53,7 +53,7 @@ function page:updateInventoryList()
for slot, item in pairs(inv) do for slot, item in pairs(inv) do
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end) item = itemDB:get(item, function() return ni.getInventory().getItemDetail(slot) end)
local key = makeKey(item) local key = makeKey(item)
if not list[key] then if not list[key] then
item.displayName = item.displayName:match('(.+) %(damage:.+%)') or item.displayName item.displayName = item.displayName:match('(.+) %(damage:.+%)') or item.displayName
@@ -89,7 +89,7 @@ function page:depositAll()
local inv = ni.getInventory().list() local inv = ni.getInventory().list()
for slot, item in pairs(inv) do for slot, item in pairs(inv) do
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end) item = itemDB:get(item, function() return ni.getInventory().getItemDetail(slot) end)
local key = makeKey(item) local key = makeKey(item)
if not context.state.depositAll.retain[key] then if not context.state.depositAll.retain[key] then
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then

View File

@@ -33,7 +33,7 @@ function page:enable()
local list = { } local list = { }
for k, item in pairs(inv) do for k, item in pairs(inv) do
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(k) end) item = itemDB:get(item, function() return ni.getInventory().getItemDetail(k) end)
local key = itemDB:makeKey(item) local key = itemDB:makeKey(item)
if not list[key] then if not list[key] then
item.key = key item.key = key
@@ -58,9 +58,9 @@ local function getFood(food)
for slot,v in pairs(ni.getInventory().list()) do for slot,v in pairs(ni.getInventory().list()) do
local key = itemDB:makeKey(v) local key = itemDB:makeKey(v)
if key == food then if key == food then
local item = ni.getInventory().getItem(slot) local item = ni.getInventory().getItemDetail(slot)
if item and item.consume then if item and item.saturation then
return item return slot
end end
break break
end end
@@ -87,7 +87,7 @@ Event.onInterval(5, function()
if context.state.food and ni.getMetaOwner().food.hungry then if context.state.food and ni.getMetaOwner().food.hungry then
local item = getFood(context.state.food) local item = getFood(context.state.food)
if item then if item then
item.consume() ni.getInventory().consume(item)
end end
end end
end) end)
@@ -101,4 +101,4 @@ return {
callback = function() callback = function()
UI:setPage(page) UI:setPage(page)
end, end,
} }

View File

@@ -15,14 +15,13 @@ function ReplenishTask:cycle(context)
local _, count = Milo:getMatches(item, res) local _, count = Milo:getMatches(item, res)
if count < res.low then if count < res.low then
local nbtHash local nbt
if not res.ignoreNbtHash then if not res.ignoreNbt then
nbtHash = item.nbtHash nbt = item.nbt
end end
Milo:requestCrafting({ Milo:requestCrafting({
name = item.name, name = item.name,
damage = res.ignoreDamage and 0 or item.damage, nbt = nbt,
nbtHash = nbtHash,
requested = res.low - count, requested = res.low - count,
count = count, count = count,
replenish = true, replenish = true,

View File

@@ -1,8 +1,8 @@
{ {
{ {
url = "https://raw.githubusercontent.com/kepler155c/opus-recipes/master/switchcraft", url = "https://raw.githubusercontent.com/iuzx0/opus-recipes/main/sc-goodies",
version = "MC 1.12", version = "MC 1.19.4",
localName = "switchcraft", localName = "sc-goodies",
name = "Switchcraft Server", name = "SwitchCraft Goodies mod",
}, },
} }

File diff suppressed because it is too large Load Diff

View File

@@ -12,7 +12,7 @@ local jua = require("swshop.jua")
local await = jua.await local await = jua.await
local device = _G.device local device = _G.device
local json = _G.json local json = { encode=textutils.serializeJSON, decode = textutils.unserialiseJSON }
local rs = _G.rs local rs = _G.rs
local textutils = _G.textutils local textutils = _G.textutils