diff --git a/index.js b/index.js index 3fa4372..f224181 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,12 @@ function loader (registryOrVersion) { this.metadata = metadata == null ? 0 : metadata this.nbt = nbt || null + // pc 1.20.5, TODO: properly implement... + if (registry.supportFeature('itemsWithComponents')) { + this.components = [] + this.removedComponents = [] + } + // Probably add a new feature to mcdata, e.g itemsCanHaveStackId if (registry.type === 'bedrock') { if (stackId == null && !sentByServer) stackId = Item.nextStackId() @@ -77,7 +83,17 @@ function loader (registryOrVersion) { const hasNBT = item && item.nbt && Object.keys(item.nbt.value).length > 0 if (registry.type === 'pc') { - if (registry.supportFeature('itemSerializationAllowsPresent')) { + if (registry.supportFeature('itemsWithComponents')) { + if (!item) return { itemCount: 0 } + return { + itemCount: item.count, + itemId: item.type, + addedComponentCount: item.components.length, + removedComponentCount: item.removedComponents.length, + components: item.components, + removeComponents: item.removedComponents + } + } else if (registry.supportFeature('itemSerializationAllowsPresent')) { if (item == null) return { present: false } return { present: true, @@ -130,7 +146,13 @@ function loader (registryOrVersion) { static fromNotch (networkItem, stackId) { if (registry.type === 'pc') { - if (registry.supportFeature('itemSerializationWillOnlyUsePresent')) { + if (registry.supportFeature('itemsWithComponents')) { // 1.20.5+ + if (networkItem.itemCount === 0) return null + const item = new Item(networkItem.itemId, networkItem.itemCount, null, null, true) + item.components = networkItem.components + item.removedComponents = networkItem.removeComponents + return item + } else if (registry.supportFeature('itemSerializationWillOnlyUsePresent')) { if (networkItem.present === false) return null return new Item(networkItem.itemId, networkItem.itemCount, networkItem.nbtData, null, true) } else if (registry.supportFeature('itemSerializationAllowsPresent')) { @@ -139,6 +161,8 @@ function loader (registryOrVersion) { } else if (registry.supportFeature('itemSerializationUsesBlockId')) { if (networkItem.blockId === -1) return null return new Item(networkItem.blockId, networkItem.itemCount, networkItem.itemDamage, networkItem.nbtData, null, true) + } else { + throw new Error('Unknown Minecraft item version') } } else if (registry.type === 'bedrock') { if (networkItem.network_id === 0) return null @@ -155,7 +179,7 @@ function loader (registryOrVersion) { return item } } - throw new Error("Don't know how to deserialize for this mc version ") + throw new Error("Don't know how to deserialize for this mc version") } get customName () {