Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 44fa521

Browse files
committed
Clean up getCreatorModId for moving to ForgeHooks later
1 parent 9452c35 commit 44fa521

1 file changed

Lines changed: 11 additions & 23 deletions

File tree

  • patchwork-extensions/src/main/java/net/minecraftforge/common/extensions

patchwork-extensions/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import net.minecraft.item.TippedArrowItem;
5757
import net.minecraft.nbt.CompoundTag;
5858
import net.minecraft.nbt.ListTag;
59-
import net.minecraft.potion.Potion;
6059
import net.minecraft.potion.PotionUtil;
6160
import net.minecraft.tag.Tag;
6261
import net.minecraft.util.ActionResult;
@@ -691,39 +690,28 @@ default boolean canContinueUsing(ItemStack oldStack, ItemStack newStack) {
691690
*/
692691
@Nullable
693692
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);
697695

698-
if ("minecraft".equals(modId)) {
696+
if (id != null && "minecraft".equals(id.getNamespace())) {
699697
if (item instanceof EnchantedBookItem) {
700-
ListTag enchantmentsNbt = EnchantedBookItem.getEnchantmentTag(itemStack);
698+
final ListTag enchantments = EnchantedBookItem.getEnchantmentTag(itemStack);
701699

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"));
705702

706-
if (resourceLocation != null && Registry.ENCHANTMENT.containsId(resourceLocation)) {
707-
return resourceLocation.getNamespace();
703+
if (Registry.ENCHANTMENT.getOrEmpty(enchantmentId).isPresent()) {
704+
id = enchantmentId;
708705
}
709706
}
710707
} 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));
717709
} 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));
723711
}
724712
}
725713

726-
return modId;
714+
return id == null ? null : id.getNamespace();
727715
}
728716

729717
// TODO: Call locations: Patches: ItemStack

0 commit comments

Comments
 (0)