@@ -18,6 +18,12 @@ function loader (registryOrVersion) {
18
18
this . metadata = metadata == null ? 0 : metadata
19
19
this . nbt = nbt || null
20
20
21
+ // pc 1.20.5, TODO: properly implement...
22
+ if ( registry . supportFeature ( 'itemsWithComponents' ) ) {
23
+ this . components = [ ]
24
+ this . removedComponents = [ ]
25
+ }
26
+
21
27
// Probably add a new feature to mcdata, e.g itemsCanHaveStackId
22
28
if ( registry . type === 'bedrock' ) {
23
29
if ( stackId == null && ! sentByServer ) stackId = Item . nextStackId ( )
@@ -77,7 +83,17 @@ function loader (registryOrVersion) {
77
83
const hasNBT = item && item . nbt && Object . keys ( item . nbt . value ) . length > 0
78
84
79
85
if ( registry . type === 'pc' ) {
80
- if ( registry . supportFeature ( 'itemSerializationAllowsPresent' ) ) {
86
+ if ( registry . supportFeature ( 'itemsWithComponents' ) ) {
87
+ if ( ! item ) return { itemCount : 0 }
88
+ return {
89
+ itemCount : item . count ,
90
+ itemId : item . type ,
91
+ addedComponentCount : item . components . length ,
92
+ removedComponentCount : item . removedComponents . length ,
93
+ components : item . components ,
94
+ removeComponents : item . removedComponents
95
+ }
96
+ } else if ( registry . supportFeature ( 'itemSerializationAllowsPresent' ) ) {
81
97
if ( item == null ) return { present : false }
82
98
return {
83
99
present : true ,
@@ -130,7 +146,13 @@ function loader (registryOrVersion) {
130
146
131
147
static fromNotch ( networkItem , stackId ) {
132
148
if ( registry . type === 'pc' ) {
133
- if ( registry . supportFeature ( 'itemSerializationWillOnlyUsePresent' ) ) {
149
+ if ( registry . supportFeature ( 'itemsWithComponents' ) ) { // 1.20.5+
150
+ if ( networkItem . itemCount === 0 ) return null
151
+ const item = new Item ( networkItem . itemId , networkItem . itemCount , null , null , true )
152
+ item . components = networkItem . components
153
+ item . removedComponents = networkItem . removeComponents
154
+ return item
155
+ } else if ( registry . supportFeature ( 'itemSerializationWillOnlyUsePresent' ) ) {
134
156
if ( networkItem . present === false ) return null
135
157
return new Item ( networkItem . itemId , networkItem . itemCount , networkItem . nbtData , null , true )
136
158
} else if ( registry . supportFeature ( 'itemSerializationAllowsPresent' ) ) {
@@ -139,6 +161,8 @@ function loader (registryOrVersion) {
139
161
} else if ( registry . supportFeature ( 'itemSerializationUsesBlockId' ) ) {
140
162
if ( networkItem . blockId === - 1 ) return null
141
163
return new Item ( networkItem . blockId , networkItem . itemCount , networkItem . itemDamage , networkItem . nbtData , null , true )
164
+ } else {
165
+ throw new Error ( 'Unknown Minecraft item version' )
142
166
}
143
167
} else if ( registry . type === 'bedrock' ) {
144
168
if ( networkItem . network_id === 0 ) return null
@@ -155,7 +179,7 @@ function loader (registryOrVersion) {
155
179
return item
156
180
}
157
181
}
158
- throw new Error ( "Don't know how to deserialize for this mc version " )
182
+ throw new Error ( "Don't know how to deserialize for this mc version" )
159
183
}
160
184
161
185
get customName ( ) {
0 commit comments