Add support for creator mod ID for modded enchanted books, potions, arrows, and spawn eggs (#4810)

This commit is contained in:
mezz authored and GitHub committed 2018-03-26 23:25:27 -07:00
1 parent 41f1921558
commit a6bbc2761e
2 files changed
+64 -6

No files matched your search

@@ -68,7 +68,7 @@
CreativeTabs creativetabs = this.func_77640_w();
return creativetabs != null && (p_194125_1_ == CreativeTabs.field_78027_g || p_194125_1_ == creativetabs);
}
@@ -435,11 +441,728 @@
@@ -435,11 +441,727 @@
return false;
}
@@ -694,8 +694,7 @@
+ @Nullable
+ public String getCreatorModId(ItemStack itemStack)
+ {
+ ResourceLocation registryName = getRegistryName();
+ return registryName == null ? null : registryName.func_110624_b();
+ return net.minecraftforge.common.ForgeHooks.getDefaultCreatorModId(itemStack);
+ }
+
+ /**
@@ -797,7 +796,7 @@
public static void func_150900_l()
{
func_179214_a(Blocks.field_150350_a, new ItemAir(Blocks.field_150350_a));
@@ -999,6 +1722,8 @@
@@ -999,6 +1721,8 @@
private final float field_78010_h;
private final float field_78011_i;
private final int field_78008_j;
@@ -806,7 +805,7 @@
private ToolMaterial(int p_i1874_3_, int p_i1874_4_, float p_i1874_5_, float p_i1874_6_, int p_i1874_7_)
{
@@ -1034,6 +1759,7 @@
@@ -1034,6 +1758,7 @@
return this.field_78008_j;
}
@@ -814,7 +813,7 @@
public Item func_150995_f()
{
if (this == WOOD)
@@ -1057,5 +1783,21 @@
@@ -1057,5 +1782,21 @@
return this == DIAMOND ? Items.field_151045_i : null;
}
}
@@ -50,6 +50,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -64,18 +65,26 @@ import net.minecraft.init.Items;
import net.minecraft.inventory.ContainerRepair;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemMonsterPlacer;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTippedArrow;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.SPacketBlockChange;
import net.minecraft.network.play.server.SPacketRecipeBook;
import net.minecraft.network.play.server.SPacketRecipeBook.State;
import net.minecraft.potion.PotionType;
import net.minecraft.potion.PotionUtils;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityNote;
@@ -139,6 +148,7 @@ import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.ConnectionType;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryManager;
@@ -1386,4 +1396,53 @@ public class ForgeHooks
{
MinecraftForge.EVENT_BUS.post(new AdvancementEvent(player, advancement));
}
/**
* Used as the default implementation of {@link Item#getCreatorModId}. Call that method instead.
*/
@Nullable
public static String getDefaultCreatorModId(@Nonnull ItemStack itemStack)
{
Item item = itemStack.getItem();
ResourceLocation registryName = item.getRegistryName();
String modId = registryName == null ? null : registryName.getResourceDomain();
if ("minecraft".equals(modId))
{
if (item instanceof ItemEnchantedBook)
{
NBTTagList enchantmentsNbt = ItemEnchantedBook.getEnchantments(itemStack);
if (enchantmentsNbt.tagCount() == 1)
{
NBTTagCompound nbttagcompound = enchantmentsNbt.getCompoundTagAt(0);
Enchantment enchantment = Enchantment.getEnchantmentByID(nbttagcompound.getShort("id"));
if (enchantment != null)
{
ResourceLocation resourceLocation = ForgeRegistries.ENCHANTMENTS.getKey(enchantment);
if (resourceLocation != null)
{
return resourceLocation.getResourceDomain();
}
}
}
}
else if (item instanceof ItemPotion || item instanceof ItemTippedArrow)
{
PotionType potionType = PotionUtils.getPotionFromItem(itemStack);
ResourceLocation resourceLocation = ForgeRegistries.POTION_TYPES.getKey(potionType);
if (resourceLocation != null)
{
return resourceLocation.getResourceDomain();
}
}
else if (item instanceof ItemMonsterPlacer)
{
ResourceLocation resourceLocation = ItemMonsterPlacer.getNamedIdFrom(itemStack);
if (resourceLocation != null)
{
return resourceLocation.getResourceDomain();
}
}
}
return modId;
}
}