Java Code Examples for net.minecraft.item.Item.hasCustomEntity()

The following are Jave code examples for showing how to use hasCustomEntity() of the net.minecraft.item.Item class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: CustomWorldGen   File: ForgeInternalHandler.java   Source Code and License Vote up 4 votes
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onEntityJoinWorld(EntityJoinWorldEvent event)
{
    if (!event.getWorld().isRemote)
    {
        ForgeChunkManager.loadEntity(event.getEntity());
    }

    Entity entity = event.getEntity();
    if (entity.getClass().equals(EntityItem.class))
    {
        ItemStack stack = ((EntityItem)entity).getEntityItem();

        if (stack == null)
        {
            //entity.setDead();
            //event.setCanceled(true);
            return;
        }

        Item item = stack.getItem();
        if (item == null)
        {
            FMLLog.warning("Attempted to add a EntityItem to the world with a invalid item at " +
                "(%2.2f,  %2.2f, %2.2f), this is most likely a config issue between you and the server. Please double check your configs",
                entity.posX, entity.posY, entity.posZ);
            entity.setDead();
            event.setCanceled(true);
            return;
        }

        if (item.hasCustomEntity(stack))
        {
            Entity newEntity = item.createEntity(event.getWorld(), entity, stack);
            if (newEntity != null)
            {
                entity.setDead();
                event.setCanceled(true);
                event.getWorld().spawnEntityInWorld(newEntity);
            }
        }
    }
}