|
56 | 56 | import net.minecraft.item.TippedArrowItem; |
57 | 57 | import net.minecraft.nbt.CompoundTag; |
58 | 58 | import net.minecraft.nbt.ListTag; |
59 | | -import net.minecraft.potion.Potion; |
60 | 59 | import net.minecraft.potion.PotionUtil; |
61 | 60 | import net.minecraft.tag.Tag; |
62 | 61 | import net.minecraft.util.ActionResult; |
@@ -691,39 +690,28 @@ default boolean canContinueUsing(ItemStack oldStack, ItemStack newStack) { |
691 | 690 | */ |
692 | 691 | @Nullable |
693 | 692 | default String getCreatorModId(ItemStack itemStack) { |
694 | | - Item item = itemStack.getItem(); |
695 | | - Identifier registryName = Registry.ITEM.getId(item); |
696 | | - String modId = registryName == null ? null : registryName.getNamespace(); |
| 693 | + final Item item = itemStack.getItem(); |
| 694 | + Identifier id = Registry.ITEM.getId(item); |
697 | 695 |
|
698 | | - if ("minecraft".equals(modId)) { |
| 696 | + if (id != null && "minecraft".equals(id.getNamespace())) { |
699 | 697 | if (item instanceof EnchantedBookItem) { |
700 | | - ListTag enchantmentsNbt = EnchantedBookItem.getEnchantmentTag(itemStack); |
| 698 | + final ListTag enchantments = EnchantedBookItem.getEnchantmentTag(itemStack); |
701 | 699 |
|
702 | | - if (enchantmentsNbt.size() == 1) { |
703 | | - CompoundTag nbttagcompound = enchantmentsNbt.getCompoundTag(0); |
704 | | - Identifier resourceLocation = Identifier.tryParse(nbttagcompound.getString("id")); |
| 700 | + if (enchantments.size() == 1) { |
| 701 | + Identifier enchantmentId = Identifier.tryParse(enchantments.getCompoundTag(0).getString("id")); |
705 | 702 |
|
706 | | - if (resourceLocation != null && Registry.ENCHANTMENT.containsId(resourceLocation)) { |
707 | | - return resourceLocation.getNamespace(); |
| 703 | + if (Registry.ENCHANTMENT.getOrEmpty(enchantmentId).isPresent()) { |
| 704 | + id = enchantmentId; |
708 | 705 | } |
709 | 706 | } |
710 | 707 | } else if (item instanceof PotionItem || item instanceof TippedArrowItem) { |
711 | | - Potion potionType = PotionUtil.getPotion(itemStack); |
712 | | - Identifier resourceLocation = Registry.POTION.getId(potionType); |
713 | | - |
714 | | - if (resourceLocation != null) { |
715 | | - return resourceLocation.getNamespace(); |
716 | | - } |
| 708 | + id = Registry.POTION.getId(PotionUtil.getPotion(itemStack)); |
717 | 709 | } else if (item instanceof SpawnEggItem) { |
718 | | - Identifier resourceLocation = Registry.ENTITY_TYPE.getId(((SpawnEggItem) item).getEntityType(null)); |
719 | | - |
720 | | - if (resourceLocation != null) { |
721 | | - return resourceLocation.getNamespace(); |
722 | | - } |
| 710 | + id = Registry.ENTITY_TYPE.getId(((SpawnEggItem) item).getEntityType(null)); |
723 | 711 | } |
724 | 712 | } |
725 | 713 |
|
726 | | - return modId; |
| 714 | + return id == null ? null : id.getNamespace(); |
727 | 715 | } |
728 | 716 |
|
729 | 717 | // TODO: Call locations: Patches: ItemStack |
|
0 commit comments