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) text = text:sub(1,textBudget)
end 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 countLabel = Text:new{ text = count, bgColor = bgColors[i % 2] }
local paddedText = Padding:new{ local paddedText = Padding:new{
left = 0, left = 0,
@ -290,7 +292,7 @@ local PAGES = {
state:setPage("MAIN") state:setPage("MAIN")
return NOOP return NOOP
end end
local hello = Text:new{ local title = Text:new{
text = "Detail: "..group:getSimpleName(), text = "Detail: "..group:getSimpleName(),
parent = state.monitor, parent = state.monitor,
onClick = function(e, x, y, s) onClick = function(e, x, y, s)
@ -298,7 +300,15 @@ local PAGES = {
end end
} }
return renderDefault(state, hello) local paddedTitle = Padding:new{
top = 1,
left = 1,
right = 1,
bottom = 1,
element = title
}
return renderDefault(state, paddedTitle)
end, end,
REQUEST = function(state, newPage) REQUEST = function(state, newPage)

View File

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

View File

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