// Kill a pig and collect the dropped item: killMob(bot, "pig", 300); async function killMob(bot, mobName, timeout = 300) { const entity = bot.nearestEntity( (entity) => entity.name === mobName && entity.position.distanceTo(bot.entity.position) < 32 ); await bot.pvp.attack(entity); await bot.pathfinder.goto( new GoalBlock(entity.position.x, entity.position.y, entity.position.z) ); }