Tough As Nails

Tough As Nails

21M Downloads

Use Forge Spawn Egg Registry instead of rolling your own

CAD97 opened this issue ยท 6 comments

commented

Minecraft Forge has for a good while now (since at least some point in 1.9) exposed a method EntityRegistry::registerEgg to create spawn eggs which are minecraft:spawn_egg variants and increases compatibility with other mods.

This should be as simple as replacing this line:

<<<<<
this.entityEggs.put(Integer.valueOf(tanEntityId), new EntityList.EntityEggInfo(new ResourceLocation(ToughAsNails.MOD_ID, entityName), eggBackgroundColor, eggForegroundColor));
=====
EntityRegistry.registerEgg(entityClass, eggBackgroundColor, eggForegroundColor);
>>>>>

I haven't tested this, thus this being an issue and not a PR. If I get a chance to test this, I'll submit a PR.

I got a request on my mod asking to support your Freeze mob. The mod pack being used is 1.10.2, so a back-port to 1.10.2 of this fix would be appreciated.

commented

I think you might even be able to do this when registering the entity using a method with a few more parameters

commented

We originally had it like that, but added our own spawn egg item so that it'd appear in the creative tab for our mod, rather than the vanilla misc tab. We can change it back if it's for compatibility with other mods though.

commented

You can probably make it show up by putting it in the addCreativeItems (?) of some other item.

commented

That is not a good idea to do, items should only add themselves there.

Creative tabs do have a method (was displayAllReleventItems() in 1.8) which you can use to override the tab's display items though to include additional ones if you don't mind them being in two places.

commented

(For reference:)

Enchanted books are added to the relevant tabs via CreativeTabs::addEnchantmentBooksToList(List<ItemStack>,EnumEnchantmentType...) (net/minecraft/creativetab/CreativeTabs.java line 316 for me).

All of the enchanted books are added to the Search tab via GuiContainerCreative::updateFilteredItems(GuiContainerCreative.ContainerCreative) (net/minecraft/client/gui/inventory/GuiContainerCreative line 384 for me).


If you want to add your spawn egg to your tab, it looks like you are going to want to override CreativeTabs::displayAllRelevantItems(NonNullList<ItemStack>) (net/minecraft/creativetab/CreativeTabs.java line 289 for me).

When you create your custom tab class, you'd then have something like

CreativeTabs tab = new CreativeTabs("tan.tab")
{
    @Override @Nonnull
    public ItemStack getTabIconItem() { return /* your tab ItemStack */; }
    @Override @SideOnly(Side.CLIENT)
    public void displayAllRelevantItems(NonNullList<ItemStack> itemList)
    {
        super.displayAllRelevantItems(itemList);
        itemList.add( /* your spawn egg */ );
    }
}

Another option is just to have two spawn eggs: minecraft:spawn_egg with NBT and tan:spawn_egg. That's undesirable, however. HOWEVER, you might play with that idea, have a tan:spawn_egg placeholder that returned your custom spawn eggs in getSubItems (and is located in your creative tab). That does sound like an unseemly hack as well, though.


Adding spawn eggs via the Forge registry allows other mods to see that spawn egg when they ask Forge for all of the spawn eggs. This enables mods like mine to do something with that set of EntityEggInfos. This is why this request is here.

commented

I would like to second this request as I hope it would allow for the easy creation of Freeze spawners (by right-clicking the Freeze spawn egg on a standard Minecraft spawner block).