4242import org .geysermc .geyser .api .item .custom .v2 .CustomItemDefinition ;
4343import org .geysermc .geyser .api .item .custom .v2 .predicate .CustomItemPredicate ;
4444import org .geysermc .geyser .item .GeyserCustomMappingData ;
45- import org .geysermc .geyser .item .Items ;
4645import org .geysermc .geyser .item .components .WearableSlot ;
47- import org .geysermc .geyser .item .type .ArmorItem ;
4846import org .geysermc .geyser .item .type .Item ;
4947import org .geysermc .geyser .registry .mappings .MappingsConfigReader ;
5048import org .geysermc .geyser .registry .type .GeyserMappingItem ;
5149import org .geysermc .mcprotocollib .protocol .data .game .item .component .Consumable ;
52- import org .geysermc .mcprotocollib .protocol .data .game .item .component .ConsumeEffect ;
5350import org .geysermc .mcprotocollib .protocol .data .game .item .component .DataComponentType ;
5451import org .geysermc .mcprotocollib .protocol .data .game .item .component .DataComponents ;
5552import org .geysermc .mcprotocollib .protocol .data .game .item .component .Equippable ;
5653import org .geysermc .mcprotocollib .protocol .data .game .item .component .FoodProperties ;
5754import org .geysermc .mcprotocollib .protocol .data .game .item .component .UseCooldown ;
58- import org .geysermc .mcprotocollib .protocol .data .game .level .sound .BuiltinSound ;
5955
6056import java .util .ArrayList ;
61- import java .util .HashMap ;
6257import java .util .List ;
6358import java .util .Map ;
6459import java .util .Objects ;
@@ -181,7 +176,7 @@ private static NbtMapBuilder createComponentNbt(CustomItemDefinition customItemD
181176
182177 boolean canDestroyInCreative = true ;
183178 if (vanillaMapping .getToolType () != null ) { // This is not using the isTool boolean because it is not just a render type here.
184- canDestroyInCreative = computeToolProperties (vanillaMapping .getToolType (), itemProperties , componentBuilder , vanillaJavaItem .attackDamage ());
179+ canDestroyInCreative = computeToolProperties (vanillaMapping .getToolType (), itemProperties , componentBuilder , vanillaJavaItem .defaultAttackDamage ());
185180 }
186181 itemProperties .putBoolean ("can_destroy_in_creative" , canDestroyInCreative );
187182
@@ -498,60 +493,9 @@ private static NbtMap xyzToScaleList(float x, float y, float z) {
498493 return NbtMap .builder ().putList ("scale" , NbtType .FLOAT , List .of (x , y , z )).build ();
499494 }
500495
501- // TODO this needs to be a simpler method once we just load default vanilla components from mappings or something
496+ // TODO is this right?
502497 private static DataComponents patchDataComponents (Item javaItem , CustomItemDefinition definition ) {
503- DataComponents components = new DataComponents (new HashMap <>()); // TODO faster map ?
504-
505- components .put (DataComponentType .MAX_STACK_SIZE , javaItem .maxStackSize ());
506- components .put (DataComponentType .MAX_DAMAGE , javaItem .maxDamage ());
507-
508- Consumable consumable = getItemConsumable (javaItem );
509- if (consumable != null ) {
510- components .put (DataComponentType .CONSUMABLE , consumable );
511- }
512-
513- if (canAlwaysEat (javaItem )) {
514- components .put (DataComponentType .FOOD , new FoodProperties (0 , 0 , true ));
515- }
516-
517- if (javaItem .glint ()) {
518- components .put (DataComponentType .ENCHANTMENT_GLINT_OVERRIDE , true );
519- }
520-
521- if (javaItem instanceof ArmorItem armor ) { // TODO equippable
522- }
523-
524- components .put (DataComponentType .RARITY , javaItem .rarity ().ordinal ());
525-
526- components .getDataComponents ().putAll (definition .components ().getDataComponents ());
527- return components ;
528- }
529-
530- private static Consumable getItemConsumable (Item item ) {
531- if (item == Items .APPLE || item == Items .BAKED_POTATO || item == Items .BEETROOT || item == Items .BEETROOT_SOUP || item == Items .BREAD
532- || item == Items .CARROT || item == Items .CHORUS_FRUIT || item == Items .COOKED_CHICKEN || item == Items .COOKED_COD
533- || item == Items .COOKED_MUTTON || item == Items .COOKED_PORKCHOP || item == Items .COOKED_RABBIT || item == Items .COOKED_SALMON
534- || item == Items .COOKIE || item == Items .ENCHANTED_GOLDEN_APPLE || item == Items .GOLDEN_APPLE || item == Items .GLOW_BERRIES
535- || item == Items .GOLDEN_CARROT || item == Items .MELON_SLICE || item == Items .MUSHROOM_STEW || item == Items .POISONOUS_POTATO
536- || item == Items .POTATO || item == Items .PUFFERFISH || item == Items .PUMPKIN_PIE || item == Items .RABBIT_STEW
537- || item == Items .BEEF || item == Items .CHICKEN || item == Items .COD || item == Items .MUTTON || item == Items .PORKCHOP
538- || item == Items .RABBIT || item == Items .ROTTEN_FLESH || item == Items .SPIDER_EYE || item == Items .COOKED_BEEF
539- || item == Items .SUSPICIOUS_STEW || item == Items .SWEET_BERRIES || item == Items .TROPICAL_FISH ) {
540- return Consumables .DEFAULT_FOOD ;
541- } else if (item == Items .POTION ) {
542- return Consumables .DEFAULT_DRINK ;
543- } else if (item == Items .HONEY_BOTTLE ) {
544- return Consumables .HONEY_BOTTLE ;
545- } else if (item == Items .OMINOUS_BOTTLE ) {
546- return Consumables .OMINOUS_BOTTLE ;
547- } else if (item == Items .DRIED_KELP ) {
548- return Consumables .DRIED_KELP ;
549- }
550- return null ;
551- }
552-
553- private static boolean canAlwaysEat (Item item ) {
554- return item == Items .CHORUS_FRUIT || item == Items .ENCHANTED_GOLDEN_APPLE || item == Items .GOLDEN_APPLE || item == Items .HONEY_BOTTLE || item == Items .SUSPICIOUS_STEW ;
498+ return javaItem .gatherComponents (definition .components ());
555499 }
556500
557501 @ SuppressWarnings ("unchecked" )
@@ -568,13 +512,4 @@ private static void addItemTag(NbtMapBuilder builder, String tag) {
568512 }
569513 }
570514 }
571-
572- private static final class Consumables {
573- private static final Consumable DEFAULT_FOOD = new Consumable (1.6F , Consumable .ItemUseAnimation .EAT , BuiltinSound .ENTITY_GENERIC_EAT , true , List .of ());
574- private static final Consumable DEFAULT_DRINK = new Consumable (1.6F , Consumable .ItemUseAnimation .DRINK , BuiltinSound .ENTITY_GENERIC_DRINK , false , List .of ());
575- private static final Consumable HONEY_BOTTLE = new Consumable (2.0F , Consumable .ItemUseAnimation .DRINK , BuiltinSound .ITEM_HONEY_BOTTLE_DRINK , false , List .of ());
576- private static final Consumable OMINOUS_BOTTLE = new Consumable (2.0F , Consumable .ItemUseAnimation .DRINK , BuiltinSound .ITEM_HONEY_BOTTLE_DRINK ,
577- false , List .of (new ConsumeEffect .PlaySound (BuiltinSound .ITEM_OMINOUS_BOTTLE_DISPOSE )));
578- private static final Consumable DRIED_KELP = new Consumable (0.8F , Consumable .ItemUseAnimation .EAT , BuiltinSound .ENTITY_GENERIC_EAT , false , List .of ());
579- }
580515}
0 commit comments