Sophisticated Backpacks InventoryWeight
为 Sophisticated Backpacks(非官方 Fabric 移植版) 提供准确的 MT Inventory Weight 支持。
MT Inventory Weight 自带一个通用的背包计算器,用于读取容器 NBT;但 Sophisticated Backpacks 会为每个背包分配一个 UUID,并将其实际内容存储在世界的 BackpackStorage(PersistentState)中——而非始终存储在物品 NBT 里。因此,通用的 NBT 读取方式会低估或错误计算 Sophisticated Backpacks 的背包重量。此插件通过调用 Sophisticated Backpacks API 来读取实际内容,从而修复了该问题。
它通过 inventoryweight 入口点注册了一个 Inventory Weight 物品重量提供者,优先级为 8500 ——高于内置的通用 backpacks 提供者(8000)——这样 Sophisticated Backpacks 的背包将由这个精确的提供者处理,而其他物品则回退到默认行为。
为了读取内容,它使用了 SB 包装器 API。这会自动从 BackpackStorage 解析基于 UUID 的内容,因此装备中、手持中和存储中的背包都能被正确称重。
重量模型
与内置的背包模型一致:
effectiveWeight = emptyBackpackWeight + (contentsWeight / 2)
contentsWeight 是通过递归遍历每个内部堆栈并使用 Inventory Weight 自身的查找机制(context.nested())计算得出的,因此数据包权重、嵌套容器以及其他插件均会生效。
- 结果的基准重量携带完整的(未分割的)内容重量以供显示。
注意事项
- 如果未安装 Sophisticated Backpacks,则该提供者处于非活动状态(会记录警告日志),Inventory Weight 将使用其默认行为。
- 在递归时使用了
nested(),以避免因嵌套背包导致深度失控。
- 空背包的基础重量是一个单一常量(
SophisticatedBackpacksInventoryWeight#EMPTY_BACKPACK_WEIGHT);如果需要使其可由用户配置,可将其接入 fzzy_config。
Sophisticated Backpacks InventoryWeight
Accurate MT Inventory Weight support for Sophisticated Backpacks (Unofficial Fabric port).
MT Inventory Weight ships a generic backpack calculator that reads container NBT, but Sophisticated Backpacks assigns each backpack a UUID and stores its real contents in world BackpackStorage (PersistentState) — not always in the item NBT. Generic NBT reading therefore under- or mis-counts SB backpacks. This add-on fixes that by reading the actual contents through the Sophisticated Backpacks API.
It registers an Inventory Weight item weight provider (via the inventoryweight entrypoint) at priority 8500 — above the built-in generic backpacks provider (8000) — so SB backpacks are handled by this accurate provider while everything else falls through to the defaults.
To read contents it uses the SB wrapper API. This resolves UUID-backed contents from BackpackStorage automatically, so equipped, held, and stored backpacks are all weighed correctly.
Weight model
Matches the built-in backpack model:
effectiveWeight = emptyBackpackWeight + (contentsWeight / 2)
contentsWeight is computed by recursing each inner stack through Inventory Weight's own lookup (context.nested()), so datapack weights, nested containers, and other add-ons all apply.
- The result's base weight carries the full (undivided) contents weight for display.
Notes
- If Sophisticated Backpacks is not installed, the provider is inactive (a warning is logged) and Inventory Weight uses its default behavior.
nested() is used when recursing to avoid runaway depth with nested backpacks.
- The empty-backpack base weight is a single constant (
SophisticatedBackpacksInventoryWeight#EMPTY_BACKPACK_WEIGHT); wire it to fzzy_config if you want it user-configurable.
评论 0
登录后参与评分
还没有评论,来抢沙发吧