Skip to content

Commit

Permalink
1.20.5 (#118)
Browse files Browse the repository at this point in the history
* 1.20.5

* Update index.js

* Update index.js

* Update index.js

* Update index.js

* Update index.js
  • Loading branch information
extremeheat authored Oct 13, 2024
1 parent 094e32a commit 09815d2
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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')) {
Expand All @@ -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
Expand All @@ -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 () {
Expand Down

0 comments on commit 09815d2

Please sign in to comment.