forge event.getDrop code example

Example: forge event.getDrop

@SubscribeEvent
public void entityDrops(LivingDropsEvent ev)
{
    if (!ConfigManager.SERVER.dropStringFromSheep.get())
        return;

    Entity entity = ev.getEntity();
    if (!(entity instanceof SheepEntity))
        return;

    Collection<ItemEntity> drops = ev.getDrops();
    if (drops instanceof ImmutableList)
    {
        SurvivalistMod.LOGGER.warn("WARNING: Some mod is returning an ImmutableList, replacing drops will NOT be possible.");
        return;
    }

    if (rnd.nextFloat() < 0.25f)
        drops.add(new ItemEntity(entity.getEntityWorld(), entity.getPosX(), entity.getPosY(), entity.getPosZ(), new ItemStack(Items.STRING)));
}

Tags:

Misc Example