|
37 | 37 | import net.minecraft.client.render.item.ItemDynamicRenderer; |
38 | 38 | import net.minecraft.enchantment.Enchantment; |
39 | 39 | import net.minecraft.entity.Entity; |
| 40 | +import net.minecraft.entity.EntityType; |
40 | 41 | import net.minecraft.entity.EquipmentSlot; |
41 | 42 | import net.minecraft.entity.ItemEntity; |
42 | 43 | import net.minecraft.entity.LivingEntity; |
|
56 | 57 | import net.minecraft.item.TippedArrowItem; |
57 | 58 | import net.minecraft.nbt.CompoundTag; |
58 | 59 | import net.minecraft.nbt.ListTag; |
| 60 | +import net.minecraft.potion.Potion; |
59 | 61 | import net.minecraft.potion.PotionUtil; |
| 62 | +import net.minecraft.potion.Potions; |
60 | 63 | import net.minecraft.tag.Tag; |
61 | 64 | import net.minecraft.util.ActionResult; |
62 | 65 | import net.minecraft.util.Identifier; |
@@ -693,25 +696,50 @@ default String getCreatorModId(ItemStack itemStack) { |
693 | 696 | final Item item = itemStack.getItem(); |
694 | 697 | Identifier id = Registry.ITEM.getId(item); |
695 | 698 |
|
696 | | - if (id != null && "minecraft".equals(id.getNamespace())) { |
697 | | - if (item instanceof EnchantedBookItem) { |
698 | | - final ListTag enchantments = EnchantedBookItem.getEnchantmentTag(itemStack); |
| 699 | + if (!itemStack.isEmpty() && Registry.ITEM.getDefaultId().equals(id)) { |
| 700 | + return null; |
| 701 | + } else { |
| 702 | + final String namespace = id.getNamespace(); |
699 | 703 |
|
700 | | - if (enchantments.size() == 1) { |
701 | | - Identifier enchantmentId = Identifier.tryParse(enchantments.getCompoundTag(0).getString("id")); |
| 704 | + if ("minecraft".equals(namespace)) { |
| 705 | + if (item instanceof EnchantedBookItem) { |
| 706 | + final ListTag enchantments = EnchantedBookItem.getEnchantmentTag(itemStack); |
702 | 707 |
|
703 | | - if (Registry.ENCHANTMENT.getOrEmpty(enchantmentId).isPresent()) { |
704 | | - id = enchantmentId; |
| 708 | + if (enchantments.size() == 1) { |
| 709 | + final Identifier enchantmentId = Identifier.tryParse(enchantments.getCompoundTag(0).getString("id")); |
| 710 | + |
| 711 | + if (Registry.ENCHANTMENT.getOrEmpty(enchantmentId).isPresent()) { |
| 712 | + return enchantmentId.getNamespace(); |
| 713 | + } |
| 714 | + } |
| 715 | + } else if (item instanceof PotionItem || item instanceof TippedArrowItem) { |
| 716 | + final Potion potion = PotionUtil.getPotion(itemStack); |
| 717 | + |
| 718 | + if (potion != Potions.EMPTY) { |
| 719 | + id = Registry.POTION.getId(potion); |
| 720 | + |
| 721 | + if (Registry.POTION.getDefaultId().equals(id)) { |
| 722 | + return namespace; |
| 723 | + } |
| 724 | + |
| 725 | + return id.getNamespace(); |
705 | 726 | } |
| 727 | + } else if (item instanceof SpawnEggItem) { |
| 728 | + final EntityType<?> type = ((SpawnEggItem) item).getEntityType(null); |
| 729 | + id = Registry.ENTITY_TYPE.getId(type); |
| 730 | + |
| 731 | + final Identifier defaultId = Registry.ENTITY_TYPE.getDefaultId(); |
| 732 | + |
| 733 | + if (type != Registry.ENTITY_TYPE.get(defaultId) && defaultId.equals(id)) { |
| 734 | + return namespace; |
| 735 | + } |
| 736 | + |
| 737 | + return id.getNamespace(); |
706 | 738 | } |
707 | | - } else if (item instanceof PotionItem || item instanceof TippedArrowItem) { |
708 | | - id = Registry.POTION.getId(PotionUtil.getPotion(itemStack)); |
709 | | - } else if (item instanceof SpawnEggItem) { |
710 | | - id = Registry.ENTITY_TYPE.getId(((SpawnEggItem) item).getEntityType(null)); |
711 | 739 | } |
712 | | - } |
713 | 740 |
|
714 | | - return id == null ? null : id.getNamespace(); |
| 741 | + return namespace; |
| 742 | + } |
715 | 743 | } |
716 | 744 |
|
717 | 745 | // TODO: Call locations: Patches: ItemStack |
|
0 commit comments