Compare commits

...

2 Commits

Author SHA1 Message Date
Gabriel Tofvesson
32361db152 Color-code itemstacks with nbt data 2024-10-09 04:27:07 +02:00
Gabriel Tofvesson
3f3dd111c1 Track nbt entries 2024-10-09 04:26:39 +02:00
3 changed files with 31 additions and 6 deletions

View File

@ -158,7 +158,9 @@ local function itemList(groups, wBudget, hBudget, savedState, onClick, setPage,
text = text:sub(1,textBudget)
end
local textLabel = Text:new{ text = text, bgColor = bgColors[i % 2] }
local nbtColor = group:getNBT() and colors.cyan or nil
local textLabel = Text:new{ text = text, bgColor = bgColors[i % 2], fgColor = nbtColor }
local countLabel = Text:new{ text = count, bgColor = bgColors[i % 2] }
local paddedText = Padding:new{
left = 0,
@ -290,7 +292,7 @@ local PAGES = {
state:setPage("MAIN")
return NOOP
end
local hello = Text:new{
local title = Text:new{
text = "Detail: "..group:getSimpleName(),
parent = state.monitor,
onClick = function(e, x, y, s)
@ -298,7 +300,15 @@ local PAGES = {
end
}
return renderDefault(state, hello)
local paddedTitle = Padding:new{
top = 1,
left = 1,
right = 1,
bottom = 1,
element = title
}
return renderDefault(state, paddedTitle)
end,
REQUEST = function(state, newPage)

View File

@ -49,6 +49,10 @@ function ItemGroup:getEnchantments()
return self:_getIdentityStack():getEnchantments()
end
function ItemGroup:getNBT()
return self:_getIdentityStack():getNBT()
end
function ItemGroup:_getIdentityStack()
return self[1]
end

View File

@ -19,6 +19,7 @@ function ItemStack:fromDetail(inv, detail, slot)
obj.maxCount = detail.maxCount
obj.enchantments = detail.enchantments
obj.displayName = detail.displayName
obj.nbt = detail.nbt
end
setmetatable(obj, self)
@ -37,7 +38,8 @@ function ItemStack:clone(withSlot)
count = self.count,
maxCount = self.maxCount,
enchantments = self.enchantments,
displayName = self.displayName
displayName = self.displayName,
nbt = self.nbt
}
setmetatable(obj, self)
@ -52,7 +54,7 @@ function ItemStack:toSerializable()
maxCount = self.maxCount
}
if self.count ~= nil then
if not self:isEmpty() then
-- Not empty
ser.name = self.name
ser.damage = self.damage
@ -60,6 +62,7 @@ function ItemStack:toSerializable()
ser.count = self.count
ser.enchantments = self.enchantments
ser.displayName = self.displayName
ser.nbt = self.nbt
end
return ser
@ -106,6 +109,10 @@ function ItemStack:getInventory()
return self.inv
end
function ItemStack:getNBT()
return self.nbt
end
function ItemStack:isEmpty()
return self.count == nil or self.count == 0
end
@ -134,7 +141,7 @@ function ItemStack:getSimpleName()
return simpleName
end
return Inventory.getSimpleName(self:getInventory()).."["..(self:getSlot() or "NO_SLOT").."]"
end
@ -163,6 +170,7 @@ function ItemStack:_modify(countDelta, stack)
self.maxCount = nil
self.enchantments = nil
self.displayName = nil
self.nbt = nil
else
-- If stack is empty, copy stack data from source
if self:isEmpty() then
@ -173,6 +181,7 @@ function ItemStack:_modify(countDelta, stack)
self.maxCount = stack.maxCount
self.enchantments = stack.enchantments
self.displayName = stack.displayName
self.nbt = stack.nbt
end
self.count = newCount
@ -243,6 +252,7 @@ function ItemStack:canTransfer(stack)
self.damage == stack.damage and
self.maxDamage == stack.maxDamage and
self.displayName == stack.displayName and
self.nbt == stack.nbt and
objEquals(self.enchantments, stack.enchantments))
end
@ -272,6 +282,7 @@ function ItemStack:matches(query)
queryField(query.maxDamage, self.maxDamage) and
queryField(query.enchantments, self.enchantments) and
queryField(query.maxCount, self.maxCount) and
queryField(query.nbt, self.nbt) and
queryField(query.displayName, self.displayName)
end