3131import lombok .Value ;
3232import org .checkerframework .checker .nullness .qual .NonNull ;
3333import org .checkerframework .checker .nullness .qual .Nullable ;
34+ import org .cloudburstmc .protocol .bedrock .data .definitions .BlockDefinition ;
3435import org .cloudburstmc .protocol .bedrock .data .definitions .ItemDefinition ;
3536import org .cloudburstmc .protocol .bedrock .data .inventory .CreativeItemData ;
3637import org .cloudburstmc .protocol .bedrock .data .inventory .CreativeItemGroup ;
@@ -73,6 +74,11 @@ public class ItemMappings implements DefinitionRegistry<ItemDefinition> {
7374 List <ItemDefinition > buckets ;
7475 List <ItemDefinition > boats ;
7576 Int2ObjectMap <String > customIdMappings ;
77+ // the item definition runtime id that is actually for the block
78+ // that has the block definition with a 0 runtime id
79+ // as of 1.21.110: cyan_terracotta
80+ // array since it could be multiple
81+ Integer [] zeroBlockDefinitionRuntimeId ;
7682
7783 Object2ObjectMap <CustomBlockData , ItemDefinition > customBlockItemDefinitions ;
7884
@@ -153,7 +159,7 @@ public ItemMapping getMapping(ItemData data) {
153159 return lightBlock ;
154160 }
155161
156- boolean isBlock = data . getBlockDefinition () != null ;
162+ boolean isBlock = isValidBlockItem ( data ) ;
157163 boolean hasDamage = data .getDamage () != 0 ;
158164
159165 for (ItemMapping mapping : this .items ) {
@@ -180,6 +186,28 @@ public ItemMapping getMapping(ItemData data) {
180186 return ItemMapping .AIR ;
181187 }
182188
189+ public boolean isValidBlockItem (ItemData itemData ) {
190+ BlockDefinition blockDefinition = itemData .getBlockDefinition ();
191+ if (blockDefinition == null ) {
192+ return false ;
193+ }
194+
195+ if (blockDefinition .getRuntimeId () != 0 ) {
196+ return true ;
197+ }
198+
199+ // Bedrock likes sending ""block definitions"" that aren't actually any
200+ // Unfortunately, unlike Java, a block definition with runtime id 0 is not air,
201+ // but a block. For example, in 1.21.110: cyan terracotta.
202+ for (int other : zeroBlockDefinitionRuntimeId ) {
203+ if (itemData .getDefinition ().getRuntimeId () == other ) {
204+ return true ;
205+ }
206+ }
207+
208+ return false ;
209+ }
210+
183211 @ Nullable
184212 @ Override
185213 public ItemDefinition getDefinition (int bedrockId ) {
0 commit comments