Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20.5 #118

Merged
merged 6 commits into from
Oct 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok yeah need something there...

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
Loading